Ext.Msg.cls="adminAlert";Ext.Msg.layout={type:"anchor",pack:"center",align:"center"};Ext.define("AdvanceSearch.controller.Main",{extend:"Ext.app.Controller",views:["Firstpanel"],views:["TotalResultGrid"],requires:["AdvanceSearch.view.TotalResultGrid"],refs:[{selector:"firstpanel",ref:"firstpanel"},{selector:"totalResult",ref:"totalResult"},],init:function(){appCtn=this;
temp=0;displayOnly="yes";this.buildFieldData();this.control({"firstpanel":{"afterrender":this.afterMainRender,},'firstpanel button[id="setRefreshon"]':{"click":this.setRefreshOn},'firstpanel button[id="Clear"]':{"click":this.Clear},'firstpanel button[id="Search"]':{"click":this.Search},'firstpanel combo[id="searchCriteria"]':{"select":this.changeSearchOption},'firstpanel button[id="csv"]':{"click":this.saveInCSVFormat},'firstpanel combo[id="compType"]':{"select":this.changeCompType}});
},changeSearchOption:function(c){var a=c.value;if(!Ext.isEmpty(a)&&a!=undefined&&a=="Component/Agent Type"){Ext.getCmp("fetchIPContainer").hide();Ext.getCmp("fetchCompContainer").show();Ext.getCmp("comp_Name").reset();Ext.getCmp("compType").reset();Ext.getCmp("compType").setValue("all");Ext.getCmp("status").reset();
Ext.getCmp("status").setValue("All");Ext.getCmp("agent_version").reset();Ext.getCmp("agent_version").setValue("All");Ext.getCmp("agent_os").reset();Ext.getCmp("agent_os").setValue("All");}else{if(!Ext.isEmpty(a)&&a!=undefined&&a=="IP Address"){Ext.getCmp("fetchCompContainer").hide();Ext.getCmp("fetchIPContainer").show();
Ext.getCmp("Rangefrom").reset();Ext.getCmp("RangeTo").reset();}}var d=publicJSON["screenLabels"]["Set Refresh On"];Ext.getCmp("setRefreshon").setText(d);var b=Ext.getCmp("resultContainer");if(!Ext.isEmpty(b)&&b!=undefined){Ext.getCmp("labelContainer1").hide();b.removeAll();b.hide();}},buildFieldData:function(){Ext.Ajax.request({url:"/final/admin/AdvanceSearch/data/AdvanceSearchJSON.jsp",params:"sessionId="+sessionId,method:"POST",timeout:300000,async:false,success:function(a){if(a.status==200&&!Ext.isEmpty(a.responseText)){var b=a.responseText;
publicJSON=Ext.decode(b);}}});},afterMainRender:function(){this.loadFields();var a="";var e="";var f=publicJSON["screenLabels"]["Set Refresh On"];var b=publicJSON["screenLabels"]["Set Refresh Off"];var c=publicJSON["screenLabels"]["Search"];var d=publicJSON["screenLabels"]["Clear"];temp=publicJSON["screenLabels"]["refreshTime"];
Ext.getCmp("compGroup").hide();Ext.getCmp("status").setValue("All");Ext.getCmp("Search").setText(c);Ext.getCmp("Clear").setText(d);Ext.getCmp("setRefreshon").setText(f);},saveInCSVFormat:function(){window.location.href="/final/servlet/com.eg.SaveInCSVFormat?user_language=en_US";},loadFields:function(){var c=this;
var d=publicJSON["groupListArr"]&&publicJSON["groupListArr"].length>0;var a=publicJSON["cmpt_type"];var b=this.getFirstpanel().getForm();if(a=="null"){c.setValueWithOptionInList(b,"compType",publicJSON["cmpt_type"],"");c.setValueWithOptionInList(b,"agent_version",publicJSON["versionArr"],"");c.setValueWithOptionInList(b,"agent_os",publicJSON["osArr"],"");
if(d){c.setValueWithOptionInList(b,"compGroup",publicJSON["groupListArr"],"");}}else{c.setValueWithOptionInList(b,"compType",publicJSON["cmpt_type"],"");c.setValueWithOptionInList(b,"agent_version",publicJSON["versionArr"],"");c.setValueWithOptionInList(b,"agent_os",publicJSON["osArr"],"");if(d){c.setValueWithOptionInList(b,"compGroup",publicJSON["groupListArr"],"");
}}Ext.getCmp("status").getStore().loadRawData(publicJSON["statusVal"]);},setValueWithOptionInList:function(c,f,e,d){c.findField(f).getStore().loadRawData(e);c.findField(f).suspendEvents(false);var a=false;for(var b=0;b<e.length;b++){if(e[b].valueField==d&&!Ext.isEmpty(d)&&d!=null){c.findField(f).setValue(d);
a=true;}}if(!a){c.findField(f).setValue(e[0].valueField);}c.findField(f).resumeEvents();},changeCompType:function(){var a=Ext.getCmp("compType").getValue();if(a=="Component_Groups"){Ext.getCmp("compGroup").show();}else{Ext.getCmp("compGroup").hide();}},Clear:function(){this.changeSearchOption(Ext.getCmp("searchCriteria"));
},Search:function(){displayOnly="yes";fieldsValidate("search");},setRefreshOn:function(a){displayOnly="yes";fieldsValidate("refresh");},setAutoUpgrade:function(a){displayOnly="no";this.update(a);},resetAutoUpgrade:function(a){displayOnly="no";this.update(a);},upgradenow:function(a){displayOnly="no";this.update(a);
},cancel_upgrade_now:function(a){displayOnly="no";this.update(a);},update:function(l){var c="";var h="";var m="";var a="";g_label=l;selectedAgentIDs="";default_upgrade_now_enabled="";selected_indices="";var k=new Array();a=Ext.getCmp("TotalGridValues").getSelectionModel().getSelection();if(a==""){Ext.MessageBox.alert(pageTitle,agentNotSelected);
}for(var g=0;g<a.length;g++){m=a[g];c=m.get("id");if(c!=null){if(c.indexOf("_")>0){c=c.substring(0,c.lastIndexOf("_"));}k.push(c);}}var b=false;var o=Ext.getCmp("TotalGridValues").getSelectionModel();var e=Ext.getCmp("TotalGridValues").getStore();for(var g=0;g<e.getCount();g++){if(o.isSelected(e.getAt(g))){var n=e.getAt(g).get("autoUpgrade").trim();
var d=e.getAt(g).get("upgradeNow").trim();if(n=="Disabled"&&d=="Disabled"){b=true;break;}}}for(var f=0;f<k.length;f++){selectedAgentIDs+=k[f]+"$";}if(selectedAgentIDs.length>0){if(l=="upgradeNow"&&b){Ext.Msg.show({title:pageTitle,msg:agent_msg,buttons:Ext.Msg.YESNO,icon:"iconConfirmation",fn:function(p){if(p=="yes"){selectedAgentIDs=selectedAgentIDs.substring(0,selectedAgentIDs.lastIndexOf("$"));
g_label=l;default_upgrade_now_enabled="Yes";goes("update");}else{if(p=="no"){selectedAgentIDs=selectedAgentIDs.substring(0,selectedAgentIDs.lastIndexOf("$"));g_label=l;default_upgrade_now_enabled="No";}}}});}else{selectedAgentIDs=selectedAgentIDs.substring(0,selectedAgentIDs.lastIndexOf("$"));g_label=l;
goes("update");}}}});var timerID=0;var tStart=null;var isStarted="false";function displayTime(){isStarted="true";num=parseInt(temp);var a=0;var b=0;var d=0;tseconds=parseInt(num/1000);if(parseInt(tseconds)>=3600){a=parseInt(tseconds/3600);}tseconds=parseInt(tseconds)-parseInt(a)*3600;if(parseInt(tseconds)>=60){b=parseInt(tseconds/60);
}d=tseconds%60;var c="";if(parseInt(a)>0){if(parseInt(a)<2){c="0"+a+" "+hourLabel+" ";}else{if(parseInt(a)<10){c="0"+a+" "+hoursLabel+" ";}else{c=a+" "+hoursLabel+" ";}}}if(parseInt(b)>0){if(parseInt(b)<2){c+="0"+b+" "+minLabel+" ";}else{if(parseInt(b)<10){c+="0"+b+" "+minsLabel+" ";}else{c+=b+" "+minsLabel+" ";
}}}if(parseInt(d)>0){if(parseInt(d)<2){c+="0"+d+" "+secLabel;}else{if(parseInt(d)<10){c+="0"+d+" "+secsLabel;}else{c+=d+" "+secsLabel;}}}Ext.getCmp("setTime").setValue(setTimeLabel+c);if(num==0){temp=publicJSON["screenLabels"]["refreshTime"];num=parseInt(temp);}temp=(parseInt(temp)-1000);setTimeout("displayTime()",1000);
if(c==""){UpdateTimer();}}function fieldsValidate(n,h){var q=publicJSON["screenLabels"]["Set Refresh On"];var o=publicJSON["screenLabels"]["Set Refresh Off"];var s=Ext.getCmp("setRefreshon").value;var l=Ext.getCmp("searchCriteria").value;if(n=="refresh"&&s=="0"){Ext.getCmp("setRefreshon").setText(q);
Ext.getCmp("setRefreshon").value="1";Ext.getCmp("labelContainer1").hide();}else{var d=Ext.getCmp("Rangefrom").getValue();var e=Ext.getCmp("RangeTo").getValue();if(d==""&&e==""){if(!Ext.isEmpty(l)&&l=="IP Address"){Ext.MessageBox.alert(pageTitle,Empty_fields);}else{goes(n);}}else{if(d!=""&&e==""){var g=isValidIPAddress(d);
if(g==true){goes(n);}else{Ext.MessageBox.alert(pageTitle,FromIP_notValid);}}else{if(d!=""&&e!=""){var c=isValidIPAddress(d);var f=isValidIPAddress(e);var k=new Array();var p=new Array();var b="";var r="";k=d.split(".");p=e.split(".");for(var a=0;a<k.length;a++){b=parseInt(k[a],10);r=parseInt(p[a],10);
if(r>b){break;}else{if(r<b){Ext.MessageBox.alert(pageTitle,Invalid_range);return;}}}if(c==true&&f==true){goes(n);}else{if(f==false){Ext.MessageBox.alert(pageTitle,ToIP_notValid);}if(c==false){Ext.MessageBox.alert(pageTitle,FromIP_notValid);}}}else{if(d==""&&e!=""){var f=isValidIPAddress(e);if(f==false){Ext.MessageBox.alert(pageTitle,ToIP_notValid);
}Ext.MessageBox.alert(pageTitle,Empty_fields);}}}}}}function goes(h){var o="true";var d="true";var q=null;var k=Ext.getCmp("comp_Name").getValue();var m="";var n="";if(Ext.getCmp("searchCriteria").value=="IP Address"){m=Ext.getCmp("RangeTo").getValue();n=Ext.getCmp("Rangefrom").getValue();}var e=Ext.getCmp("compType").getValue();
if(e=="Component_Groups"){q=Ext.getCmp("compGroup").getValue();}var g=Ext.getCmp("status").getValue();var b=Ext.getCmp("agent_version").getValue();var a=Ext.getCmp("agent_os").getValue();var f="Range";var p=publicJSON["screenLabels"]["Set Refresh On"];var l=publicJSON["screenLabels"]["Set Refresh Off"];
if(n.length==0&&m.length==0){f="Single";}if(n.length>0&&m.length==0){f="Single";}if(n.length>0&&m.length>0){f="Range";}if(n.length>0&&!isValidIPAddress(n)){d="false";Ext.MessageBox.alert(pageTitle,FromIP_notValid);}if(m.length>0&&!isValidIPAddress(m)){o="false";Ext.MessageBox.alert(pageTitle,ToIP_notValid);
}if(d=="true"&&o=="true"){if(n.length>0){k="";e="all";g="all";}Ext.getCmp("csv").setDisabled(true);var c="servertype="+e+"&status="+g+"&choice="+f+"&from="+n+"&to="+m+"&nickname="+filterEncode(k)+"&option="+g_label+"&sai="+selectedAgentIDs+"&default_upgrade_now_enabled="+default_upgrade_now_enabled+"&sessionId="+sessionId+"&gridrequest=ok&s_agent_version="+b+"&displayOnly="+displayOnly+"&s_agent_os="+a;
if(q!=null){c+="&groupName="+q;}Ext.Ajax.request({url:"../admin/AdvanceSearch/data/AdvanceSearchJSON.jsp",params:c,method:"POST",timeout:300000,success:function(s){if(s.status==200&!Ext.isEmpty(s.responseText)){var w=Ext.getCmp("setRefreshon").value;var v=s.responseText;publicJSON=Ext.decode(v);var t=publicJSON["gridValues"];
var u=publicJSON["total_Result"];if(Ext.isEmpty(t)){if(h=="search"){Ext.getCmp("labelContainer1").hide();}if(w=="0"&&h=="refresh"){Ext.getCmp("setRefreshon").setText(p);Ext.getCmp("setRefreshon").value="1";Ext.getCmp("labelContainer1").hide();}else{if(h=="refresh"||h=="refreshAgain"){if(w=="1"){refresh_this_page("refresh");
Ext.getCmp("labelContainer1").hide();}}var r=Ext.getCmp("resultContainer");r.removeAll();r.add({xtype:"component",width:900,margin:"0 60 0 60",padding:10,border:false,style:{"text-align":"center"},html:"<div class='error_panel' style='height:100%;display:flex;flex;flex-direction: column;align-items:center;justify-content:center;'><div class='iconInformation'></div><div class='commonErrorMsgText'>"+noAgents+".</div></div>"});
r.show();}}else{if(h=="update"){if(g_label=="setAutoUpgrade"){Ext.MessageBox.show({title:pageTitle,msg:setAutoUpgradeResult,buttons:Ext.Msg.OK,icon:"iconInformation"});}else{if(g_label=="resetAutoUpgrade"){Ext.MessageBox.show({title:pageTitle,msg:disableAutoUpgradeResult,buttons:Ext.Msg.OK,icon:"iconInformation"});
}else{if(g_label=="upgradeNow"){Ext.MessageBox.show({title:pageTitle,msg:upgradeNowResult,buttons:Ext.Msg.OK,icon:"iconInformation"});}else{if(g_label=="cancelUpgradeNow"){Ext.MessageBox.show({title:pageTitle,msg:cancelUpgradeNowResult,buttons:Ext.Msg.OK,icon:"iconInformation"});}}}}}if(w=="0"&&h=="refresh"){Ext.getCmp("setRefreshon").setText(p);
Ext.getCmp("setRefreshon").value="1";Ext.getCmp("labelContainer1").hide();return;}if(h=="refresh"||h=="refreshAgain"){refresh_this_page(h);var r=Ext.getCmp("resultContainer");r.removeAll();r.add({xtype:"totalResult",arrayStore:t,pageLimit:15});r.show();}if(h=="search"&&w=="0"){Ext.getCmp("labelContainer1").show();
}if(h!="refresh"||h!="refreshAgain"){Ext.getCmp("csv").setDisabled(false);var r=Ext.getCmp("resultContainer");r.removeAll();r.add({xtype:"totalResult",arrayStore:t,pageLimit:15});r.show();}}}}});}}function isValidIPAddress(c){var b=c.split(".");if(b.length!=4){return false;}for(i=0;i<b.length;i++){if(parseInt(b[i])>255||parseInt(b[i])<0){return false;
}}return this.checkNumber(b);}function checkNumber(d){var c=".0123456789";var b=true;for(i=0;i<d.length;i++){for(j=0;j<d[i].length;j++){cha=c.indexOf(d[i].substring(j,1));if(cha==-1){b=false;break;}}}return b;}function justcall(a){if(a=="on"){displayTime();}}function refresh_this_page(d){var c=publicJSON["screenLabels"]["Set Refresh On"];
var a=publicJSON["screenLabels"]["Set Refresh Off"];var b=Ext.getCmp("setRefreshon").value;if(b=="1"){if(isStarted=="true"){temp=publicJSON["screenLabels"]["refreshTime"];Ext.getCmp("setRefreshon").setText(a);Ext.getCmp("setRefreshon").value="0";Ext.getCmp("labelContainer1").show();return;}else{justcall("on");
Ext.getCmp("setRefreshon").setText(a);Ext.getCmp("setRefreshon").value="0";Ext.getCmp("labelContainer1").show();}}else{if(d=="refreshAgain"){Ext.getCmp("labelContainer1").show();Ext.getCmp("setRefreshon").setText(a);Ext.getCmp("setRefreshon").value="0";}else{Ext.getCmp("setRefreshon").setText(c);Ext.getCmp("setRefreshon").value="1";
Ext.getCmp("labelContainer1").hide();}}}function UpdateTimer(){var a=publicJSON["screenLabels"]["Set Refresh Off"];var b=Ext.getCmp("setRefreshon").value;if(b=="0"){goes("refreshAgain");}}