Ext.define("Agentlog.controller.Main",{extend:"Ext.app.Controller",views:["AgentLogView"],refs:[{selector:"main",ref:"main"},],init:function(){this.control({"main":{"afterrender":this.afterMainRender},'main combo[id="agent_list"]':{"select":this.agentOnChange},'main combo[id="logdir"]':{"select":this.dirNameOnChange},'main combo[id="logfiles"]':{"select":this.fileNameOnChange},"main button[action=goback]":{"click":this.BackButtonOnClick},"main button[action=refresh]":{"click":this.RefreshOnchange},"main button[action=download]":{"click":this.DownloadOnchange},'main combo[id="agent_type"]':{"select":this.agentTypeOnChange}});
},afterMainRender:function(){Ext.getCmp("logdir").select(Ext.getCmp("logdir").getStore().getAt(0));var a="componentName="+encodeURI(componentName)+"&agentType="+selectedType;loading=false;Ext.getCmp("refresh").setDisabled(true);Ext.getCmp("download").setDisabled(true);Ext.select(".iconRefresh").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";
Ext.select(".iconDownload").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";Ext.getCmp("ipnick").setTitle(lbl_AgentIP+" : "+componentName);Ext.Ajax.request({url:"Agentlog/data/agentLogJson.jsp",params:a,method:"GET",timeout:180000,success:function(b){if(b.status==200&&!Ext.isEmpty(b.responseText)){var c=b.responseText;
publicJSON=Ext.decode(c);Ext.getCmp("agent_type").getStore().suspendEvents(true);Ext.getCmp("agent_type").getStore().loadRawData(publicJSON["agentTypes"]);Ext.getCmp("agent_type").getStore().resumeEvents();Ext.getCmp("agent_type").select(selectedType);Ext.getCmp("agent_list").getStore().suspendEvents(true);
Ext.getCmp("agent_list").getStore().loadRawData(publicJSON["agentListArray"]);Ext.getCmp("agent_list").getStore().resumeEvents();Ext.getCmp("agent_list").select(componentName);Ext.getCmp("logdir").getStore().suspendEvents(true);Ext.getCmp("logdir").getStore().loadRawData(publicJSON["logDirectoryList"]);
Ext.getCmp("logdir").getStore().resumeEvents();Ext.getCmp("logdir").select(Ext.getCmp("logdir").getStore().getAt(0));Ext.getCmp("logfiles").getStore().suspendEvents(true);Ext.getCmp("logfiles").getStore().loadRawData(publicJSON["logFileList"]);Ext.getCmp("logfiles").getStore().resumeEvents();Ext.getCmp("logfiles").select(Ext.getCmp("logfiles").getStore().getAt(0));
Ext.getCmp("logfiles").hide();Ext.getCmp("alert_msg").hide();}},failure:function(b){}});},agentTypeOnChange:function(){Ext.getCmp("resultTexts").reset();Ext.getCmp("ipnick").setTitle("No agent has been selected");Ext.getCmp("logdir").hide();Ext.getCmp("logfiles").hide();Ext.getCmp("refresh").setDisabled(true);
Ext.getCmp("download").setDisabled(true);Ext.select(".iconRefresh").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";Ext.select(".iconDownload").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";selectedType=Ext.getCmp("agent_type").getValue();Ext.Ajax.request({url:"Agentlog/data/agentLogJson.jsp?agentType="+selectedType,method:"GET",timeout:180000,success:function(a){if(a.status==200&&!Ext.isEmpty(a.responseText)){var b=a.responseText;
publicJSON=Ext.decode(b);Ext.getCmp("agent_list").getStore().suspendEvents(true);Ext.getCmp("agent_list").getStore().loadRawData(publicJSON["agentListArray"]);Ext.getCmp("agent_list").getStore().resumeEvents();Ext.getCmp("agent_list").select(Ext.getCmp("agent_list").getStore().getAt(0));}}});},agentOnChange:function(){Ext.getCmp("ipnick").setTitle("No agent has been selected");
Ext.getCmp("logdir").hide();Ext.getCmp("resultTexts").reset();Ext.getCmp("logfiles").hide();Ext.getCmp("refresh").setDisabled(true);Ext.getCmp("download").setDisabled(true);Ext.select(".iconRefresh").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";Ext.select(".iconDownload").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";
componentName=Ext.getCmp("agent_list").getValue();if(componentName!="-1"){Ext.getCmp("logdir").show();Ext.getCmp("ipnick").setTitle(lbl_AgentIP+" : "+componentName);Ext.getCmp("logdir").select(Ext.getCmp("logdir").getStore().getAt(0));}},dirNameOnChange:function(){Ext.getCmp("resultTexts").reset();var b=Ext.getCmp("logdir").getValue();
if(b==null||b=="-1"){Ext.getCmp("logfiles").hide();Ext.getCmp("refresh").setDisabled(true);Ext.getCmp("download").setDisabled(true);Ext.select(".iconRefresh").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";Ext.select(".iconDownload").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";
}else{var a=new Ext.LoadMask(Ext.getBody(),{msg:"Loading... Please wait."});a.show();loading=true;var c="componentName="+encodeURI(componentName)+"&dirname="+b+"&download=false";Ext.Ajax.request({url:"Agentlog/data/agentLogJson.jsp",params:c,method:"GET",timeout:180000,success:function(d){if(d.status==200&&!Ext.isEmpty(d.responseText)){var e=d.responseText;
publicJSON=Ext.decode(e);if(publicJSON.showAlert){Ext.getCmp("logfiles").hide();Ext.getCmp("alert_msg").show();Ext.getCmp("alert_msg").setText(publicJSON.alertMessage);Ext.getCmp("refresh").setDisabled(true);Ext.getCmp("download").setDisabled(true);Ext.select(".iconRefresh").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";
Ext.select(".iconDownload").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";}else{Ext.getCmp("logfiles").getStore().suspendEvents(true);Ext.getCmp("logfiles").getStore().loadRawData(publicJSON["logFileList"]);Ext.getCmp("logfiles").select(Ext.getCmp("logfiles").getStore().getAt(0));Ext.getCmp("logfiles").getStore().resumeEvents();
Ext.getCmp("logfiles").show();Ext.getCmp("alert_msg").hide();}a.hide();loading=false;}},failure:function(d){a.hide();loading=false;}});}},fileNameOnChange:function(){Ext.getCmp("resultTexts").reset();var b=Ext.getCmp("logfiles").getValue();if(b==null||b=="-1"){Ext.getCmp("refresh").setDisabled(true);
Ext.getCmp("download").setDisabled(true);Ext.select(".iconRefresh").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";Ext.select(".iconDownload").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";}else{var a=new Ext.LoadMask(Ext.getBody(),{msg:"Loading..."});a.show();loading=true;
Ext.getCmp("refresh").setDisabled(true);Ext.getCmp("download").setDisabled(true);Ext.select(".iconRefresh").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";Ext.select(".iconDownload").elements[0].style="opacity: 0.3;filter: alpha(opacity=30);";var c="componentName="+encodeURI(componentName)+"&file="+b+"&download=false&agentType="+selectedType;
Ext.Ajax.request({url:"Agentlog/data/agentLogp.jsp",params:c,method:"GET",timeout:180000,success:function(e){if(e.status==200&&!Ext.isEmpty(e.responseText)){var g=e.responseText;if(g.indexOf("~@~")>0&&g.indexOf("&^&")>0){var d=g.substring(0,g.indexOf("~@~"));var f=g.substring(g.indexOf("&^&")+3);Ext.Msg.alert(pageName,f);
Ext.getCmp("resultTexts").setValue("");}else{var d=g.substring(0,g.indexOf("~@~"));var f=g.substring(g.indexOf("~@~")+3);Ext.getCmp("resultTexts").setValue(f);Ext.getCmp("refresh").setDisabled(false);Ext.getCmp("download").setDisabled(false);Ext.select(".iconRefresh").elements[0].style="";Ext.select(".iconDownload").elements[0].style="";
}a.hide();loading=false;}},failure:function(d){a.hide();loading=false;}});}},BackButtonOnClick:function(){var a="/final/admin/EgServerList.jsp";if(showAgentInformationView=="true"){a+="?from=upgradeAdvancedSearchPage&agentIp="+encodeURI(agentID);}else{if(viewFrom=="AgentInfo"||viewFrom=="AgentStatus"){a+="?viewFrom="+viewFrom+"&s_agent_type="+s_Agent_Type+"&agentID="+encodeURI(agentID)+"&agentStatus="+agentState;
if(!Ext.isEmpty(isdebugEnabled)){a+="&debugEnabled="+isdebugEnabled;}}}window.location.href=a;},RefreshOnchange:function(){if(loading){Ext.Msg.alert(pageName,"Already Loading a file");}else{Ext.getCmp("resultTexts").reset();this.fileNameOnChange();}},DownloadOnchange:function(){if(loading){Ext.Msg.alert(pageName,"Already Loading a file");
}else{var a=Ext.getCmp("logfiles").getValue();window.location.href="Agentlog/data/agentLogp.jsp?componentName="+encodeURI(componentName)+"&file="+encodeURI(a)+"&download=true&com.eg.CSRF_NONCE="+csrfToken;}}});