var window = SearchWindow.init({});
window.show(this);
var SearchWindow = function(urls){
return {
urls : {},
store : null,
searchDataPanel: null,
init : function(urls) {
this.urls = urls;
this.searchDataPanel = new Ext.Panel({
region: 'center',
margins:'3 3 3 0',
activeTab: 0,
layout: 'border',
defaults:{autoScroll:true},
items:[SearchPanel, grid]
});
var catTree = TreeCategory.init(urls.treeurl);
var nav = new Ext.Panel({
title: ' ',
region: 'west',
split: true,
id : 'svrgrid3',
autoScroll:true,
width: 200,
collapsible: true,
margins:'3 0 3 3',
cmargins:'3 3 3 3',
items:[catTree]
});
SVR_WIN = new Ext.Window({
title: ' ',
frame: true,
closeAction:'hide',
//closeAction:'close',
closable:true,
width:820,
height:550,
id : 'svrgrid4',
modal:true,
plain:true,
layout: 'border',
listeners : { 'close' : function(){Ext.getBody().unmask();}},
items: [nav, this.searchDataPanel],
buttons : [
{text:' ', handler:function(){SVR_WIN.hide();}},
{text:' ',handler:function(){
selNodes = catTree.getChecked();
var distdata = [];
Ext.each(selNodes, function(node){
if (node.hasChildNodes()) {
var catno = {category_id:node.id, dist_id: 0};
distdata.push(catno);
}else{
var labeltxt = node.text.split("-");
var distno = {category_id:labeltxt[0], dist_id:labeltxt[1]};
distdata.push(distno);
}
});
//InitFormDist
var ips = [];
Ext.getCmp('svrgrid').getSelectionModel().each(function(rec){
ips.push(rec.data.ip);
});
var app_id = [];
Ext.getCmp('svrgrid').getSelectionModel().each(function(rec){
app_id.push(rec.data.app_id);
});
var main_name = [];
Ext.getCmp('svrgrid').getSelectionModel().each(function(rec){
main_name.push(rec.data.main_name);
});
var sub_name = [];
Ext.getCmp('svrgrid').getSelectionModel().each(function(rec){
sub_name.push(rec.data.sub_name);
});
var app_name = [];
Ext.getCmp('svrgrid').getSelectionModel().each(function(rec){
app_name.push(rec.data.app_name);
});
var prefix = [];
Ext.getCmp('svrgrid').getSelectionModel().each(function(rec){
prefix.push(rec.data.prefix);
});
var dist_id = [];
Ext.getCmp('svrgrid').getSelectionModel().each(function(rec){
dist_id.push(rec.data.dist_id);
});
var jsonstr = Ext.util.JSON.encode({dist:distdata,ip:ips,app_id:app_id,main_name:main_name,sub_name:sub_name,
app_name:app_name,prefix:prefix,dist_id:dist_id});
//var jsonstr = Ext.util.JSON.encode({dist:0,ip:ips});
//jsonstr = escape(jsonstr);
Ext.Ajax.request({
url: '{%url combsvrip %}',
params: { param : jsonstr },
success: function(response, options){
var data = Ext.util.JSON.decode(response.responseText);
if(data){
//getCmp('target_ip')
/*Ext.fgetCmp('target_ip').getValue();
Ext.fgetCmp('target_ip').getValue(data.ips);
SVR_WIN.hide();
Ext.getCmp('target_ip').focus();*/
simple.items.item(0).setValue('');
simple.items.item(0).setValue(data.ip);
simple.items.item(1).setValue(data.prefix +'-'+ data.dist_id +'-'+ data.app_name);
simple.items.item(2).setValue(data.app_id);
SVR_WIN.hide();
simple.items.item(1).focus();
}else{
Ext.Msg.alert(" "," ip , ip ");
}
},
failure: function(){Ext.Msg.alert(" "," , ");}
});
}
}
]
});
return SVR_WIN;
}
};
}();
var catTree = TreeCategory.init(urls.treeurl);
var nav = new Ext.Panel({
title: ' ',
region: 'west',
split: true,
id : 'svrgrid3',
autoScroll:true,
width: 200,
collapsible: true,
margins:'3 0 3 3',
cmargins:'3 3 3 3',
items:[catTree]
});
var TreeCategory = function(){
var Tree = Ext.tree;
return {
init : function(url){
var InitFormDist = function(labelTxt, value){
var distGroup = Ext.getCmp("distGroup");
for(var i =0; i<distGroup.items.getCount(); i++){
if(distGroup.items.itemAt(i).getItemId() == value){
return false;
}
}
var check = new Ext.form.Checkbox({
boxLabel:labelTxt,
id: value,
name:"dist",
value:value,
inputValue : value,
checked:true,
boxMaxWidth:90
});
distGroup.items.add(check);
var col = distGroup.panel.items.get((distGroup.items.getCount()-2) % distGroup.panel.items.getCount());
col.add(check);
distGroup.panel.doLayout();
SearchWindow.searchDataPanel.doLayout();
};
var tree = new Tree.TreePanel({
animate:false,
rootVisible : false,
loader: new Tree.TreeLoader({dataUrl:'{%url svrtree %}'}),
enableDD:true,
containerScroll: true,
border: false,
region: 'center',
dropConfig: {appendOnly:true},
listeners: {
'click' : function(node) {
if (node.hasChildNodes()) {
//
var labeltxt = node.text.split("-");
var theForm = SearchPanel.getForm();
theForm.findField("category_id").setValue(labeltxt[0]);
Ext.getCmp("catdisp").setText(node.text + " X").show();
}else{
//
var labeltxt = node.text.split("-");
InitFormDist(labeltxt[2], labeltxt[1]);
var theForm = SearchPanel.getForm();
theForm.findField("category_id").setValue(labeltxt[0]);
grid.store.reload({params:theForm.getValues()});
}
}
}
});
var root = new Tree.AsyncTreeNode({
text : ' 3',
draggable:false,
id:'0'
});
tree.setRootNode(root);
root.expand(false, false);
return tree;
}
};
}();