Ext.define("ManagersList.controller.Main",{extend:"Ext.app.Controller",views:["ConfiguredManagersListView","ManagerView"],refs:[{selector:"configuredmanagerslistview",ref:"configuredmanagerslistview"},{selector:"managerview",ref:"managerview"}],init:function(){appCnt=this;this.buildFieldData();this.control({"configuredmanagerslistview":{"afterrender":this.afterMainRender},'configuredmanagerslistview trigger[name="gridSearch"]':{"change":this.mainGridSearch},'configuredmanagerslistview trigger[name="unmanagedGridSearch"]':{"change":this.mainUnmanagedGridSearch},'configuredmanagerslistview button[id="addManager"]':{"click":this.addNewManager},'managerview button[id="backbutton"]':{"click":this.backbutton},'managerview button[id="addManagerBtn"]':{"click":this.updateManager},'managerview button[id="modifyManagerBtn"]':{"click":this.updateManager}});
},handleEditIconClick:function(c,f,b){var e=c.getStore().getAt(f);var d=e.get("managerNickname");var a=this.getController("ManagersList.controller.ManagerViewController");Ext.getCmp("viewport").removeAll();a.buildFieldData("ManagersList/data/displayManagers.jsp?operation=modifyManager&managerId="+d);
Ext.getCmp("viewport").add({xtype:"managerview"});a.afterMainRender("modifyManager",d);},handleDeleteIconClick:function(a,c,g,b){var f=this;var d=Ext.getCmp(a).getStore().getAt(g);var e=d.get("managerNickname");Ext.Msg.show({title:pageTitle,msg:deleteManagerMessage,buttons:Ext.Msg.YESNO,icon:"iconConfirmation",fn:function(h){if(h=="yes"){var k=Ext.getCmp("viewport");
myMask=new Ext.LoadMask(k,{msg:pleaseWait});myMask.show();var j="/final/servlet/com.eg.supermanager.EgConfigManagerProcess?managerId="+e+"&mode=delete";Ext.Ajax.request({url:j,method:"POST",timeout:300000,success:function(l){if(l.status==200&&!Ext.isEmpty(l.responseText)){resultJSON=Ext.decode(l.responseText);
if(resultJSON["operationStatus"]["status"]=="success"){Ext.Msg.show({title:pageTitle,msg:resultJSON["operationStatus"]["statusMessage"],buttons:Ext.Msg.OK,icon:"iconInformation"});Ext.getCmp("viewport").removeAll();f.buildFieldData();Ext.getCmp("viewport").add({xtype:"configuredmanagerslistview"});f.afterMainRender();
}else{Ext.MessageBox.alert(updateManagerLabel,errorTitle);}}myMask.hide();},failure:function(l){myMask.hide();}});}}});},handleDeleteSelected:function(a){thisCopy=this;var e=Ext.getCmp(a).getSelectionModel().getSelection();var c="";var b="";if(e==""){Ext.MessageBox.alert(pageTitle,noManagersSelected);
return false;}for(var d=0;d<e.length;d++){b+=","+e[d].get("managerNickname");}if(b.length>0){b=b.substring(1);}Ext.Msg.show({title:pageTitle,msg:deleteManagersMessage,buttons:Ext.Msg.YESNO,icon:"iconConfirmation",fn:function(f){if(f=="yes"){var h=Ext.getCmp("viewport");myMask=new Ext.LoadMask(h,{msg:pleaseWait});
myMask.show();var g="/final/servlet/com.eg.supermanager.EgConfigManagerProcess?managerId="+b+"&mode=delete";Ext.Ajax.request({url:g,method:"POST",timeout:300000,success:function(j){if(j.status==200&&!Ext.isEmpty(j.responseText)){resultJSON=Ext.decode(j.responseText);if(resultJSON["operationStatus"]["status"]=="success"){Ext.Msg.show({title:pageTitle,msg:resultJSON["operationStatus"]["statusMessage"],buttons:Ext.Msg.OK,icon:"iconInformation"});
Ext.getCmp("viewport").removeAll();thisCopy.buildFieldData();Ext.getCmp("viewport").add({xtype:"configuredmanagerslistview"});thisCopy.afterMainRender();}else{Ext.MessageBox.alert(updateManagerLabel,errorTitle);}}myMask.hide();},failure:function(j){myMask.hide();}});}}});},handleManageUnmanageIconClick:function(a,c,h,b){thisMode="";
message="";var g=this;var d=Ext.getCmp(a).getStore().getAt(h);var e=d.get("managerNickname");var f=d.get("Status");if(f.indexOf("#Configured")>0){thisMode="unmanage";message=unmanageManagerMessage;}else{thisMode="manage";message=manageManagerMessage;}Ext.Msg.show({title:pageTitle,msg:message,buttons:Ext.Msg.YESNO,icon:"iconConfirmation",fn:function(j){if(j=="yes"){var l=Ext.getCmp("viewport");
myMask=new Ext.LoadMask(l,{msg:pleaseWait});myMask.show();var k="/final/servlet/com.eg.supermanager.EgConfigManagerProcess?managerId="+e+"&mode="+thisMode;Ext.Ajax.request({url:k,method:"POST",timeout:300000,success:function(m){if(m.status==200&&!Ext.isEmpty(m.responseText)){resultJSON=Ext.decode(m.responseText);
if(resultJSON["operationStatus"]["status"]=="success"||resultJSON["operationStatus"]["status"]=="failed"){Ext.Msg.show({title:pageTitle,msg:resultJSON["operationStatus"]["statusMessage"],buttons:Ext.Msg.OK,icon:"iconInformation"});Ext.getCmp("viewport").removeAll();g.buildFieldData();Ext.getCmp("viewport").add({xtype:"configuredmanagerslistview"});
g.afterMainRender();}else{Ext.MessageBox.alert(pageTitle,errorTitle);}}myMask.hide();},failure:function(m){myMask.hide();}});}}});},configureOrUnconfigureAllHeaderIconClicked:function(e){thisCopy=this;var b="";var a="";var d=Ext.getCmp("managedManagersGrid").getSelectionModel().getSelection();if(d==""){Ext.MessageBox.alert(pageTitle,noManagersSelected);
return false;}message="";if(e=="manage"){message=manageManagersMessage;}else{message=unmanageManagersMessage;}for(var c=0;c<d.length;c++){a+=","+d[c].get("managerNickname");}if(a.length>0){a=a.substring(1);}Ext.Msg.show({title:pageTitle,msg:message,buttons:Ext.Msg.YESNO,icon:"iconConfirmation",fn:function(f){if(f=="yes"){var h=Ext.getCmp("viewport");
myMask=new Ext.LoadMask(h,{msg:pleaseWait});myMask.show();var g="/final/servlet/com.eg.supermanager.EgConfigManagerProcess?managerId="+a+"&mode="+e;Ext.Ajax.request({url:g,method:"POST",timeout:300000,success:function(j){if(j.status==200&&!Ext.isEmpty(j.responseText)){resultJSON=Ext.decode(j.responseText);
if(resultJSON["operationStatus"]["status"]=="success"){Ext.Msg.show({title:pageTitle,msg:resultJSON["operationStatus"]["statusMessage"],buttons:Ext.Msg.OK,icon:"iconInformation"});Ext.getCmp("viewport").removeAll();thisCopy.buildFieldData();Ext.getCmp("viewport").add({xtype:"configuredmanagerslistview"});
thisCopy.afterMainRender();}else{Ext.MessageBox.alert(pageTitle,resultJSON["operationStatus"]["statusMessage"]);}}myMask.hide();},failure:function(j){myMask.hide();}});}}});},backbutton:function(){var a=this.getController("ManagersList.controller.Main");Ext.getCmp("viewport").removeAll();a.buildFieldData("ManagersList/data/displayManagers.jsp?operation=displayManagers");
Ext.getCmp("viewport").add({xtype:"configuredmanagerslistview"});a.afterMainRender();},updateManager:function(d){var f=this;var k=Ext.getCmp("managerId").getValue();var n=Ext.getCmp("url").getValue();var g=Ext.getCmp("alturl").getValue();var o=false;var e=false;var c=false;if(n!=null&&n.length>0){var j="";
var b=n.split(",");for(var h=0;h<b.length;h++){var l=b[h];var p=l.charAt(l.length-1);if(p=="\\"||p=="/"){e=true;}if(l.toLowerCase().indexOf("http://")==-1&&l.toLowerCase().indexOf("https://")==-1){j+=",http://"+l;}else{j+=","+l;}}n=j.substring(1);}if(g!=null&&g.length>0&&g.toLowerCase()!="none"){var j="";
var b=g.split(",");for(var h=0;h<b.length;h++){var l=b[h];var p=l.charAt(l.length-1);if(p=="\\"||p=="/"){c=true;}if(l.toLowerCase().indexOf("http://")==-1&&l.toLowerCase().indexOf("https://")==-1){j+=",http://"+l;}else{j+=","+l;}}g=j.substring(1);}if(d.getId()=="modifyManagerBtn"){if(!checkblank(n)){Ext.MessageBox.alert(updateManagerLabel,"Manager URL cannot be empty");
return;}else{if(!checkValidURLs(n)){Ext.MessageBox.alert(updateManagerLabel,"Manager URL is not valid");return;}else{if(g!=null&&g.trim().length>0&&g.toLowerCase()!="none"&&!checkValidURLs(g)){Ext.MessageBox.alert(updateManagerLabel,"Alternate manager URL(s) is not valid");return;}else{if(g.indexOf(n)>-1){Ext.MessageBox.alert(updateManagerLabel,"Alternate manager URL(s) should not contain manager URL");
return;}else{if(n==previous_url&&g==previous_alturl){Ext.MessageBox.alert(updateManagerLabel,managerDetailsNotChanged);return;}else{if(e){Ext.MessageBox.alert(updateManagerLabel,"Manager URL should not end with \\ or /");return;}else{if(c){Ext.MessageBox.alert(updateManagerLabel,"Alternate Manager URL should not end with \\ or /");
return;}else{if(g==null||g.trim().length==0){g="none";}var m=Ext.getCmp("viewport");myMask=new Ext.LoadMask(m,{msg:pleaseWait});myMask.show();var a="/final/servlet/com.eg.supermanager.EgConfigManagerProcess?mode=update&modify=true";Ext.Ajax.request({url:a,method:"POST",params:{"managerId":k,"url":n,"alturl":g},timeout:300000,success:function(q){if(q.status==200&&!Ext.isEmpty(q.responseText)){resultJSON=Ext.decode(q.responseText);
if(resultJSON["operationStatus"]["status"]=="success"){Ext.Msg.show({title:updateManagerLabel,msg:updateManager,buttons:Ext.Msg.OK,icon:"iconInformation"});Ext.getCmp("viewport").removeAll();f.buildFieldData();Ext.getCmp("viewport").add({xtype:"configuredmanagerslistview"});f.afterMainRender();}else{Ext.MessageBox.alert(updateManagerLabel,resultJSON["operationStatus"]["statusMessage"]);
}}myMask.hide();},failure:function(q){Ext.MessageBox.alert(updateManagerLabel,modifyExceptionMessage);myMask.hide();}});}}}}}}}}else{if(!validateManagerId(k)){return;}else{if(!checkblank(n)){Ext.MessageBox.alert(addManagerLabel,"Manager URL cannot be empty");return;}else{if(!checkValidURLs(n)){Ext.MessageBox.alert(addManagerLabel,"Manager URL is not valid");
return;}else{if(g!=null&&g.trim().length>0&&g.toLowerCase()!="none"&&!checkValidURLs(g)){Ext.MessageBox.alert(addManagerLabel,"Alternate manager URL(s) is not valid");return;}else{if(g.indexOf(n)>-1){Ext.MessageBox.alert(addManagerLabel,"Alterate manager URL(s) should not contain manager URL");return;
}else{if(e){Ext.MessageBox.alert(addManagerLabel,"Manager URL should not end with \\ or /");return;}else{if(c){Ext.MessageBox.alert(addManagerLabel,"Alternate Manager URL should not end with \\ or /");return;}else{if(g==null||g.trim().length==0){g="none";}var m=Ext.getCmp("viewport");myMask=new Ext.LoadMask(m,{msg:pleaseWait});
myMask.show();var a="/final/servlet/com.eg.supermanager.EgConfigManagerProcess";Ext.Ajax.request({url:a,method:"POST",params:{"managerId":k,"mode":"new"},timeout:300000,success:function(q){if(q.status==200&&!Ext.isEmpty(q.responseText)){resultJSON=Ext.decode(q.responseText);if(resultJSON["operationStatus"]["status"]=="success"){var r="/final/servlet/com.eg.supermanager.EgConfigManagerProcess?mode=update&modify=false";
Ext.Ajax.request({url:r,method:"POST",params:{"managerId":k,"url":n,"alturl":g},timeout:300000,success:function(s){if(s.status==200&&!Ext.isEmpty(s.responseText)){resultJSON=Ext.decode(s.responseText);if(resultJSON["operationStatus"]["status"]=="success"){Ext.Msg.show({title:pageTitle,msg:addManager,buttons:Ext.Msg.OK,icon:"iconInformation"});
Ext.getCmp("viewport").removeAll();f.buildFieldData();Ext.getCmp("viewport").add({xtype:"configuredmanagerslistview"});f.afterMainRender();}else{Ext.MessageBox.alert(addManagerLabel,resultJSON["operationStatus"]["statusMessage"]);}}myMask.hide();},failure:function(s){Ext.MessageBox.alert(addManagerLabel,addExceptionMessage);
myMask.hide();}});}else{Ext.MessageBox.alert(addManagerLabel,resultJSON["operationStatus"]["statusMessage"]);myMask.hide();}}else{myMask.hide();}},failure:function(q){myMask.hide();Ext.MessageBox.alert(addManagerLabel,addExceptionMessage);}});}}}}}}}}},buildFieldData:function(){Ext.Ajax.request({url:"ManagersList/data/displayManagers.jsp?operation=displayManagers",method:"POST",async:false,timeout:300000,success:function(a){if(a.status==200&&!Ext.isEmpty(a.responseText)){var b=a.responseText;
publicJSON=Ext.decode(b);}}});},afterMainRender:function(){var a=publicJSON["managedManagersArray"];if(a==null||a.length==0){Ext.getCmp("managedManagersGrid").hide();Ext.getCmp("noManagersConfigured").show();}else{Ext.getCmp("managedManagersGrid").show();Ext.getCmp("noManagersConfigured").hide();Ext.getCmp("managedManagersGrid").setTitle(managedManagersLabel);
Ext.getCmp("managedManagersGrid").getStore().suspendEvents(true);Ext.getCmp("managedManagersGrid").getStore().loadRawData(a);Ext.getCmp("managedManagersGrid").getStore().resumeEvents();}},mainGridSearch:function(b){var a=Ext.getCmp("gridSearch").getValue();if(a==""||a.length==0){Ext.get("MyTrigger_0").setStyle("display","none");
Ext.get("MyTrigger_1").setStyle("display","block");}else{Ext.get("MyTrigger_1").setStyle("display","none");Ext.get("MyTrigger_0").setStyle("display","block");}Ext.Ajax.request({url:"ManagersList/data/displayManagers.jsp?managedSearch=true&egTitleSearchStr="+encodeURIComponent(filterEncode(a)),method:"POST",timeout:300000,success:function(e){if(e.status==200&&!Ext.isEmpty(e.responseText)){var c=false;
publicJSON=Ext.decode(e.responseText);var f=publicJSON["managedManagersArray"];if(f!=null&&f.length>0){c=true;Ext.getCmp("managedManagersGrid").setTitle(managedManagersLabel);Ext.getCmp("managedManagersGrid").getStore().suspendEvents(true);Ext.getCmp("managedManagersGrid").store.loadData(publicJSON["managedManagersArray"]);
Ext.getCmp("managedManagersGrid").getStore().resumeEvents();}else{Ext.getCmp("managedManagersGrid").getStore().removeAll();var d=(publicJSON.unmanagedManagersFound)?100:300;Ext.get("managedMgrId").setHeight(d);}}}});},mainUnmanagedGridSearch:function(b){var a=Ext.getCmp("unmanagedGridSearch").getValue();
if(a==""||a.length==0){Ext.get("MyTriggerunmanaged_0").setStyle("display","none");Ext.get("MyTriggerunmanaged_1").setStyle("display","block");}else{Ext.get("MyTriggerunmanaged_1").setStyle("display","none");Ext.get("MyTriggerunmanaged_0").setStyle("display","block");}Ext.Ajax.request({url:"ManagersList/data/displayManagers.jsp?unmanagedSearch=true&egTitleSearchStr="+a,method:"POST",timeout:300000,success:function(e){if(e.status==200&&!Ext.isEmpty(e.responseText)){publicJSON=Ext.decode(e.responseText);
var c=false;var f=publicJSON["unmanagedManagersArray"];if(f!=null&&f.length>0){c=true;Ext.getCmp("unmanagedManagersGrid").getStore().suspendEvents(true);Ext.getCmp("unmanagedManagersGrid").store.loadData(publicJSON["unmanagedManagersArray"]);Ext.getCmp("unmanagedManagersGrid").getStore().resumeEvents();
}else{Ext.getCmp("unmanagedManagersGrid").getStore().removeAll();var d=(publicJSON.managedManagersFound)?100:300;Ext.get("unmanagedMgrId").setHeight(d);}}}});},addNewManager:function(){managerViewController=this.getController("ManagersList.controller.ManagerViewController");Ext.getCmp("viewport").removeAll();
managerViewController.buildFieldData("ManagersList/data/displayManagers.jsp?operation=addNewManager");Ext.getCmp("viewport").add({xtype:"managerview"});managerViewController.afterMainRender("addNewManager","");}});function validateManagerId(a){var b="`~!@#$%^&*()+=[]{}|\\:;\"'<>,?/";if(!checkblank(a)){Ext.MessageBox.alert(addManagerLabel,managerIdEmpty);
return false;}else{if(!checkspace(a)){return false;}else{if(!checkdots(a)){return false;}else{if(!checkspecial(a,b)){return false;}else{if(a.toLowerCase()=="supermanager"){Ext.MessageBox.alert(addManagerLabel,(a+" "+reseredWord));return false;}}}}}return true;}function checkblank(a){if(a.length==0){int_Flag=0;
}for(i=1;i<=a.length;i++){if(a.charAt(i-1)==" "){int_Flag=0;}else{int_Flag=1;break;}}if(int_Flag!=1){return false;}return true;}function checkspace(a){for(count=0;count<a.length;count++){if(a.charAt(count)==" "){Ext.MessageBox.alert(pageTitle,spaceFound);return false;}}return true;}function checkdots(a){var d=a;
var c=c;if(d.charAt(0)=="."||d.charAt(d.length-1)=="."){Ext.MessageBox.alert(pageTitle,dot);return false;}else{for(var b=0;b<d.length;b++){if(d.charAt(b)=="."&&d.charAt(b+1)=="."){Ext.MessageBox.alert(pageTitle,dotdot);return false;}}}return true;}function checkspecial(c,b){for(var a=0;a<c.length;a++){check_char=b.indexOf(c.charAt(a));
if(check_char>=0){Ext.MessageBox.alert(pageTitle,_checkspecial);return false;}}return true;}function checkValidURLs(d){var c=new RegExp("^((https?:)?\\/\\/)?"+"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|"+"((\\d{1,3}\\.){3}\\d{1,3}))"+"(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*"+"(\\?[;&a-z\\d%_.~+=-]*)?"+"(\\#[-a-z\\d_]*)?$","i");
if(!c.test(d)){if(d.length>0){if(d.toLowerCase().indexOf("https://")==0){d=d.substring(8);}else{if(d.toLowerCase().indexOf("http://")==0){d=d.substring(7);}}if(d.indexOf(":")>0){d=d.substring(0,d.indexOf(":"));}if(d.length>0){var a="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-";for(var b=0;
b<d.length;b++){if(a.indexOf(d.charAt(b))==-1){return false;}}return true;}}return false;}else{return true;}}