var drillDownParams="";Ext.apply(Ext.form.VTypes,{mail_id_validation:function(b,c){var a=true;if(checkmail(b)!=true){c.vtypeText=_checkmail;a=false;}return a;},multiple_mail_id_validation:function(d,e){var a=true;var b=d.split(",");for(var c in b){if(!checkmail(b[c])){a=false;return(a);}}return(a);}});
Ext.define("utilities.SendMail",{extend:"Ext.window.Window",alias:"widget.sendmail",title:"Send Mail",width:580,modal:true,ghost:false,resizable:false,closeAction:"destroy",id:"mailtosend",header:{style:{"margin":"0px 10px 0px 10px","padding":"4px 0px 1px 0px"}},ui:"newPopupWindow withBorderShadow newplainHeader_border",padding:0,items:[{xtype:"form",id:"mailForm",layout:"vbox",padding:10,buttonAlign:"center",bodyStyle:{"background":"none"},defaults:{cls:"textbox",labelAlign:"left",xtype:"textfield",width:540,labelWidth:50,},items:[{fieldLabel:"<b>To</b>",vtype:"multiple_mail_id_validation",allowBlank:false,labelSeparator:"",name:"to",id:"to",msgTarget:"side"},{fieldLabel:"<b>CC</b>",name:"cc",id:"cc",labelSeparator:"",vtype:"multiple_mail_id_validation",msgTarget:"side"},{fieldLabel:"<b>BCC</b>",name:"bcc",id:"bcc",labelSeparator:"",vtype:"multiple_mail_id_validation",msgTarget:"side"},{fieldLabel:"<b>Subject</b>",allowBlank:false,name:"subject",id:"subject",labelSeparator:"",msgTarget:"side"}],buttons:[{text:"Send",ui:"newButtonSmall",id:"sentMailId",handler:function(){var a=this.up("form").getForm();
if(a.isValid()){this.disable();Ext.getCmp("subject").setValue(Ext.widget("erutils").specialCharEncode(Ext.getCmp("subject").getValue()));var c=a.getValues(true);Ext.getCmp("subject").setValue(Ext.widget("erutils").specialCharDecode(Ext.getCmp("subject").getValue()));Ext.Ajax.on("beforerequest",function(l,m){if(Ext.get("mailtosend")!=null){Ext.getBody().mask("Sending Mail...");
}else{Ext.getBody().mask("Loading...");}});Ext.Ajax.on("requestcomplete",function(l,m){Ext.getBody().unmask();});Ext.Ajax.on("requestexception",function(l,m){Ext.getBody().unmask();});var h;var j="";if(!Ext.isEmpty(window["appConstants"])){h=appConstants.er_RmDispName;if(appConstants.drillDown!=undefined){j="&DrillDown="+appConstants.drillDown;
}}else{h=er_RmDispName;}var f=Ext.getCmp("showLegend");var d;var e="";if(typeof bookletId!=="undefined"){e="&bookletId="+bookletId+"&bookletName="+bookletName;}if(f=="undefined"||f==undefined||f=="null"){d="/final/servlet/com.eg.ErSendMail?responseType=json&"+c+"&er_RmDispName="+h+e+j;}else{d="/final/servlet/com.eg.ErSendMail?responseType=json&"+c+"&showLegend="+Ext.getCmp("showLegend").getValue()+"&er_RmDispName="+h+e+j;
}Ext.Ajax.request({url:d,scope:this,success:function(l){var o=l.responseText;var m=Ext.decode(o);if(!Ext.isEmpty(m)){this.hide();var n=m.v_error.mailErrorMsg;if(n=="success"){Ext.Msg.show({title:"Mail Status",msg:"Mail sent successfully",buttons:Ext.Msg.OK,icon:"iconSuccess"});this.show();this.up("#mailtosend").close();
}else{Ext.Msg.show({title:"Mail Status",msg:n,buttons:Ext.Msg.CANCEL,icon:"iconExclamation"});this.show();this.setDisabled(false);}}},failure:function(l){this.hide();var o=l.responseText;if(o!=null&&o!="undefined"){if(Ext.isEmpty()){var m=Ext.decode(o);var n=m.v_error.mailErrorMsg;Ext.Msg.show({title:"Mail Status",msg:n,buttons:Ext.Msg.CANCEL,icon:"iconExclamation"});
this.show();this.enable();}}else{Ext.Msg.show({title:"Mail Status",msg:"Unable to connect Mail Server",buttons:Ext.Msg.CANCEL,icon:"iconExclamation"});this.show();this.enable();}},callback:function(m,n,l){}});}else{var i=Ext.getCmp("subject").getValue();var k=Ext.getCmp("to").getValue();var b=Ext.getCmp("cc").getValue();
var g=Ext.getCmp("bcc").getValue();if(checkmail(k)!=true||checkmail(b)!=true||checkmail(g)!=true){Ext.Msg.show({title:"Alert",msg:_checkmail,buttons:Ext.Msg.OK,icon:"iconExclamation"});return false;}if(Ext.isEmpty(i)){if(!checkblank(i)){Ext.Msg.show({title:"Alert",msg:_checkempty,buttons:Ext.Msg.OK,icon:"iconExclamation"});
return false;}}}}}]}],initComponent:function(){var a=drillDownParams;if(Ext.isEmpty(a)){a="";}Ext.Ajax.request({url:"/final/reporter/ErSendMailJson.jsp",params:a,scope:this,success:function(b){var d=b.responseText;var c=Ext.decode(d);this.loadFldLabels(c);drillDownParams="";}});this.callParent();},listeners:{show:function(b){if(this.modal){console.log(a);
var c=Ext.dom.Query.select(".x-mask");var a;for(var d=0;d<c.length;d++){a=Ext.fly(c[d]);}a.addCls("windowModal");}},hide:function(b){if(this.modal){var c=Ext.dom.Query.select(".x-mask");var a;for(var d=0;d<c.length;d++){a=Ext.fly(c[d]);}a.removeCls("windowModal");}}},loadFldLabels:function(h){var e=Ext.getCmp("to");
var f=Ext.getCmp("cc");var i=Ext.getCmp("bcc");var a=Ext.getCmp("subject");e.setFieldLabel(h.screenLabels["reporter.common.To"]);f.setFieldLabel(h.screenLabels["reporter.common.CC"]);i.setFieldLabel(h.screenLabels["reporter.common.BCC"]);a.setFieldLabel(h.screenLabels["reporter.common.Subject"]);this.setTitle(h.screenLabels["reporter.common.SEND MAIL"]);
Ext.getCmp("sentMailId").setText(h.screenLabels["reporter.common.Send"]);if(h.hasOwnProperty("hiddenParams")){var g=Ext.getCmp("mailForm");var d=Ext.getCmp("mailForm").getForm();var b=h.hiddenParams;for(var c in b){if(!d.findField("'"+c+"'")){g.add({xtype:"hidden",name:c,value:b[c]});}else{d.findField("'"+c+"'").setValue(b[c]);
}}}}});