Ext.define("CompositeTest.controller.ModifyTestCtrlr",{extend:"Ext.app.Controller",views:["AddNewTest"],requires:["CompositeTest.view.AddNewTest","CompositeTest.view.Description"],refs:[{selector:"addnewtest",ref:"addnewtest"}],init:function(b,a){modifyCtrler=this;compTestCtrlr=this.getController("CompositeTest.controller.MeasureWindowController");
this.buildMainData(b,a,"test");this.control({"addnewtest":{"afterrender":this.afterMainRender},'addnewtest button[id="backButton"]':{"click":this.goBack},'addnewtest button[id="add"]':{"click":this.modifyTest},'addnewtest button[id="addNewMeasure"]':{"click":this.showAddMeasure},'addnewtest scrollcombo[id="weightageName"]':{"select":this.weightageTypeChanged},'addnewtest button[id="weightagePopup"]':{"click":this.showPopup}});
},showPopup:function(){Ext.widget("description_window").show();},weightageTypeChanged:function(){var a=Ext.getCmp("weightageName").getValue();if(a==null||a=="SystemDefined"){Ext.getCmp("reporterLogoIMG_enable").show();Ext.getCmp("reporterLogoIMG_disable").hide();Ext.getCmp("alaramKeyContainer").hide();
Ext.getCmp("alaramSupportContainer").hide();}else{Ext.getCmp("reporterLogoIMG_enable").hide();Ext.getCmp("reporterLogoIMG_disable").show();Ext.getCmp("alaramKeyContainer").show();Ext.getCmp("alaramSupportContainer").show();}},buildMainData:function(c,a,b){Ext.Ajax.request({url:"CompositeTest/data/EgModifyTestJson.jsp?test="+c+"&testType="+a,method:"POST",async:false,success:function(d){if(d.status==200&&!Ext.isEmpty(d.responseText)){var e=d.responseText;
publicJSON=Ext.decode(e);pageDesc2=modifyPageDesc;}}});},afterMainRender:function(){var b=(publicJSON.compTest.indexOf("_")==publicJSON.compTest.lastIndexOf("_"));Ext.getCmp("test").setValue(publicJSON.compTest);Ext.getCmp("test").hide();Ext.getCmp("displayCompType").setValue(publicJSON.displayCompType);
Ext.getCmp("displayCompType").show();Ext.getCmp("test_display_name").setValue(publicJSON.testDescription);Ext.getCmp("cx_test_description").setValue(publicJSON.purpose_of_test);Ext.getCmp("allowedId").setValue({"is_info_based_test":publicJSON.descriptorBasedTest});if(b){Ext.getCmp("allowedId").items.items[0].setDisabled(true);
Ext.getCmp("allowedId").items.items[1].setDisabled(true);}Ext.getCmp("componentType").hide();Ext.getCmp("allowedId").show();Ext.getCmp("testForInfos").hide();Ext.getCmp("testForInfos").getStore().clearFilter(true);Ext.getCmp("testForInfos").getStore().suspendEvents(true);Ext.getCmp("testForInfos").getStore().loadRawData(publicJSON.individual_tests);
Ext.getCmp("testForInfos").getStore().resumeEvents();Ext.getCmp("testForInfos").setValue(publicJSON.selectedMasterInfosTest);if(publicJSON.descriptorBasedTest=="true"){Ext.getCmp("testForInfos").show();}Ext.getCmp("addMeasureTab").enable();if(publicJSON.showGenerateTab){Ext.getCmp("generateCntnr").enable();
}else{Ext.getCmp("generateCntnr").disable();}var a=Ext.getCmp("test");Ext.getCmp("add").setText(updateTooltip);Ext.getCmp("add").show();Ext.getCmp("addBtnContainer").show();Ext.getCmp("common_page_desc").update('<center><img src="/final/images/spacer.gif" class="iconAdminInfo" valign="middle" style="margin-right:2px"/>&nbsp'+modifyPageDesc+".</center>");
if(associateDisassociateServers==true){Ext.getCmp("generateCntnr").enable();Ext.getCmp("newtest").setActiveTab(2);Ext.getCmp("testforId").items.items[0].setValue(true);if(!b){Ext.getCmp("associated_comptypes").setVisible(true);Ext.getCmp("associatedCompTypesContainer").setVisible(true);}associateDisassociateServers=false;
}},goBack:function(){Ext.Ajax.request({url:"CompositeTest/data/LookForChanges.jsp",method:"POST",async:false,success:function(a){if(a.status==200&&!Ext.isEmpty(a.responseText)){var b=a.responseText;tempJson=Ext.decode(b);if(tempJson.alertUser){Ext.Msg.show({title:pageTitle1,msg:confirmBackBtn,closable:false,buttons:Ext.Msg.YESNO,icon:"iconInformation",width:300,fn:function(c){if(c=="yes"){window.location.href="/final/admin/compositeTest.jsp";
}}});}else{window.location.href="/final/admin/compositeTest.jsp";}}}});},modifyTest:function(){var f=this;if(!this.validate()){return;}var g=Ext.getCmp("displayCompType").getValue();var e=Ext.getCmp("test").getValue();var h=Ext.getCmp("test_display_name").getValue();var b=Ext.getCmp("cx_test_description").getValue();
var a=Ext.getCmp("allowedId").getValue().is_info_based_test;var c="-1";if(a=="true"){c=Ext.getCmp("testForInfos").getValue();if(c==null||c=="-1"){Ext.Msg.show({title:pageTitle1,msg:message1,buttons:Ext.Msg.OK});return;}}var i={"compType":publicJSON.selectedCompType,"display_name":filterEncode(h),"operation":"modifyTest","purpose_of_test":filterEncode(b),"descriptor_based":a,"selected_master_test":c};
var d="EgaddtestpJson.jsp?add=test&test="+e;Ext.Ajax.request({url:"CompositeTest/data/"+d,method:"POST",params:i,async:false,success:function(j){if(j.status==200&&!Ext.isEmpty(j.responseText)){var k=j.responseText;publicJSON=Ext.decode(k);}}});if(publicJSON.AlertType=="Error"){Ext.Msg.show({title:pageTitle1,msg:publicJSON.AlertMsg,buttons:Ext.Msg.OK,icon:"iconError"});
}else{if(publicJSON.AlertType=="COULD_NOT_CREATE_TEST"){Ext.Msg.show({title:pageTitle1,msg:publicJSON.AlertMsg,buttons:Ext.Msg.OK,icon:"iconError"});}else{if(publicJSON.AlertType=="Result"){Ext.Msg.show({title:pageTitle1,msg:publicJSON.AlertMsg,closable:false,icon:"iconInformation",buttons:Ext.Msg.OK,fn:function(j){if(j=="ok"){f.buildMainData(e,"dummy","test");
f.afterMainRender();Ext.getCmp("addMeasureTab").enable();Ext.getCmp("newtest").setActiveTab(1);}}});}}}},showAddMeasure:function(){operationCompMeasure="addCompMeasure";compTestCtrlr=this.getController("CompositeTest.controller.MeasureWindowController");compTestCtrlr.loadPopup();},validate:function(){var a=Ext.getCmp("cx_test_description");
var b=Ext.getCmp("test_display_name");if(!checkblank(b.getValue())){Ext.Msg.show({title:pageTitle1,msg:testDisplayAlert,buttons:Ext.Msg.OK,icon:"iconExclamation"});b.focus(true);return false;}else{if(!checkblank(a.getValue())){Ext.Msg.show({title:pageTitle1,msg:testDescriptionAlert,buttons:Ext.Msg.OK,icon:"iconExclamation"});
a.focus(true);return false;}else{if(!this.checkSpecialChar(b,"~!@#$%^&*()|:,;'<>={}[]?/\"")){Ext.Msg.show({title:pageTitle1,msg:splCharAlert1,buttons:Ext.Msg.OK,icon:"iconExclamation"});b.focus(true);return false;}else{if(!this.checkSpecialChar(a,"~!@#$%^&*()|:,;'<>={}[]?/\"")){Ext.Msg.show({title:pageTitle1,msg:splCharAlert2,buttons:Ext.Msg.OK,icon:"iconExclamation"});
a.focus(true);return false;}}}}return true;},checkSpecialChar:function(c,b){if(typeof(c)=="object"){obj_val=c.value;}else{obj_val=c;}for(var a=0;a<obj_val.length;a++){check_char=b.indexOf(obj_val.charAt(a));if(check_char>=0){return false;}}return true;}});