GO.mailings.TemplatesGrid=function(a){if(!a){a={}}a.sm=new Ext.grid.RowSelectionModel({singleSelect:false});a.title=GO.mailings.lang.cmdPanelTemplate;a.tbar=[{iconCls:"btn-add",text:GO.mailings.lang.cmdAddEmailTemplate,cls:"x-btn-text-icon",handler:function(){this.showEmailTemplateDialog()},scope:this},{iconCls:"btn-add",text:GO.mailings.lang.addDocumentTemplate,cls:"x-btn-text-icon",handler:function(){this.showOOTemplateDialog()},scope:this},{iconCls:"btn-delete",text:GO.lang.cmdDelete,cls:"x-btn-text-icon",handler:function(){this.deleteSelected()},scope:this}];var b=new Ext.grid.ColumnModel({defaults:{sortable:true},columns:[{header:GO.lang.strName,dataIndex:"name"},{header:GO.lang.strOwner,dataIndex:"owner",width:300,sortable:false},{header:GO.mailings.lang.cmdType,dataIndex:"type",renderer:this.typeRenderer.createDelegate(this),width:100}]});a.view=new Ext.grid.GridView({autoFill:true,forceFit:true,emptyText:GO.lang.strNoItems});a.cm=b;a.border=false;a.paging=true;a.layout="fit";a.deleteConfig={callback:function(){GO.mailings.ooTemplatesStore.reload()},scope:this};a.store=new GO.data.JsonStore({url:GO.settings.modules.mailings.url+"json.php",baseParams:{task:"writable_templates"},root:"results",id:"id",fields:["id","user_id","owner","name","type","acl_id","extension"],remoteSort:true});a.store.setDefaultSort("name","ASC");a.store.on("load",function(){if(GO.documenttemplates){GO.documenttemplates.ooTemplatesStore.load()}},this);GO.mailings.TemplatesGrid.superclass.constructor.call(this,a);this.on("rowdblclick",function(d,e){var c=d.getStore().getAt(e);if(c.data.type=="0"){this.showEmailTemplateDialog(c.data.id)}else{this.showOOTemplateDialog(c.data.id)}},this)};Ext.extend(GO.mailings.TemplatesGrid,GO.grid.GridPanel,{templateType:{"0":"E-mail","1":GO.mailings.lang.documentTemplate},showOOTemplateDialog:function(a){if(!GO.documenttemplates){alert(GO.lang.moduleRequired.replace("{module}","Document templates"));return false}if(!this.ooTemplateDialog){this.ooTemplateDialog=new GO.documenttemplates.OOTemplateDialog();this.ooTemplateDialog.on("save",function(){this.store.load()},this)}this.ooTemplateDialog.show(a)},showEmailTemplateDialog:function(a){if(!this.emailTemplateDialog){this.emailTemplateDialog=new GO.mailings.EmailTemplateDialog();this.emailTemplateDialog.on("save",function(){this.store.load()},this)}this.emailTemplateDialog.show(a)},typeRenderer:function(d,c,a){var b=this.templateType[d];if(d=="1"){b+=" ("+a.get("extension")+")"}return b},afterRender:function(){GO.mailings.TemplatesGrid.superclass.afterRender.call(this);if(this.isVisible()){if(!this.store.loaded){this.store.load()}}},onShow:function(){GO.mailings.TemplatesGrid.superclass.onShow.call(this);if(!this.store.loaded){this.store.load()}}});GO.mailings.MailingsGrid=function(a){if(!a){a={}}a.title=GO.mailings.lang.cmdPanelMailings;a.layout="fit";a.border=false;a.tbar=[{iconCls:"btn-add",text:GO.lang.cmdAdd,cls:"x-btn-text-icon",handler:function(){this.mailingDialog.show()},disabled:!GO.settings.modules.mailings.write_permission,scope:this},{iconCls:"btn-delete",text:GO.lang.cmdDelete,cls:"x-btn-text-icon",handler:function(){this.deleteSelected()},disabled:!GO.settings.modules.mailings.write_permission,scope:this}];a.paging=false;a.store=GO.mailings.writableMailingsStore;a.view=new Ext.grid.GridView({autoFill:true,forceFit:true,emptyText:GO.lang.strNoItems});a.store.setDefaultSort("name","ASC");var b=new Ext.grid.ColumnModel([{header:GO.lang.strName,dataIndex:"name"},{header:GO.mailings.lang.cmdOwner,dataIndex:"owner",sortable:false}]);a.cm=b;a.sm=new Ext.grid.RowSelectionModel({singleSelect:false});GO.mailings.MailingsGrid.superclass.constructor.call(this,a);this.on("rowdblclick",function(d,e){var c=d.getStore().getAt(e);this.mailingDialog.show(c.data.id)},this)};Ext.extend(GO.mailings.MailingsGrid,GO.grid.GridPanel,{afterRender:function(){GO.mailings.MailingsGrid.superclass.afterRender.call(this);if(!this.store.loaded){this.store.load()}this.mailingDialog=new GO.mailings.MailingDialog();this.mailingDialog.on("save",function(){this.store.reload()},this)}});GO.mailings.MailingDialog=function(b){if(!b){b={}}this.buildForm();var a=function(){this.propertiesPanel.items.items[0].focus()};b.maximizable=true;b.layout="fit";b.modal=false;b.resizable=false;b.width=750;b.height=500;b.closeAction="hide";b.title=GO.mailings.lang.addresslist;b.items=this.formPanel;b.focus=a.createDelegate(this);b.buttons=[{text:GO.lang.cmdOk,handler:function(){this.submitForm(true)},scope:this},{text:GO.lang.cmdApply,handler:function(){this.submitForm()},scope:this},{text:GO.lang.cmdClose,handler:function(){this.hide()},scope:this}];GO.mailings.MailingDialog.superclass.constructor.call(this,b);this.addEvents({save:true})};Ext.extend(GO.mailings.MailingDialog,Ext.Window,{show:function(a){if(!this.rendered){this.render(Ext.getBody())}this.tabPanel.setActiveTab(0);if(!a){a=0}this.setMailingId(a);if(this.mailing_id>0){this.formPanel.load({url:GO.settings.modules.mailings.url+"json.php",success:function(b,c){this.readPermissionsTab.setAcl(c.result.data.acl_id);this.selectUser.setRemoteText(c.result.data.user_name);this.inline_attachments=c.result.data.inline_attachments;GO.mailings.MailingDialog.superclass.show.call(this)},failure:function(b,c){Ext.Msg.alert(GO.lang.strError,c.result.feedback)},scope:this})}else{this.formPanel.form.reset();GO.mailings.MailingDialog.superclass.show.call(this)}},setMailingId:function(a){this.contactsGrid.setMailingId(a);this.companiesGrid.setMailingId(a);this.usersGrid.setMailingId(a);this.formPanel.form.baseParams.mailing_id=a;this.mailing_id=a;if(this.mailing_id==0){this.readPermissionsTab.setAcl(0)}},submitForm:function(a){this.formPanel.form.submit({url:GO.settings.modules.mailings.url+"action.php",params:{task:"save_mailing",inline_attachments:Ext.encode(this.inline_attachments)},waitMsg:GO.lang.waitMsgSave,success:function(b,c){this.fireEvent("save",this);if(a){this.hide()}else{if(c.result.mailing_id){this.setMailingId(c.result.mailing_id);this.readPermissionsTab.setAcl(c.result.acl_id)}}},failure:function(b,c){if(c.failureType=="client"){Ext.MessageBox.alert(GO.lang.strError,GO.lang.strErrorsInForm)}else{Ext.MessageBox.alert(GO.lang.strError,c.result.feedback)}},scope:this})},buildForm:function(){this.propertiesPanel=new Ext.Panel({url:GO.settings.modules.mailings.url+"action.php",border:false,baseParams:{task:"mailing"},title:GO.lang.strProperties,cls:"go-form-panel",layout:"form",autoScroll:true,items:[{xtype:"textfield",name:"name",anchor:"100%",allowBlank:false,fieldLabel:GO.lang.strName},new GO.form.HtmlComponent({html:GO.mailings.lang.defaultSalutationText,style:"padding:10px 0px"}),{xtype:"textfield",name:"default_salutation",anchor:"100%",allowBlank:false,fieldLabel:GO.addressbook.lang.cmdFormLabelSalutation,value:GO.addressbook.lang.cmdSalutation+" "+GO.addressbook.lang.cmdSir+"/"+GO.addressbook.lang.cmdMadam},this.selectUser=new GO.form.SelectUser({fieldLabel:GO.lang.strOwner,disabled:!GO.settings.has_admin_permission,value:GO.settings.user_id,anchor:"100%"})]});var a=[this.propertiesPanel];this.contactsGrid=new GO.mailings.MailingContactsGrid();a.push(this.contactsGrid);this.companiesGrid=new GO.mailings.MailingCompaniesGrid();a.push(this.companiesGrid);this.usersGrid=new GO.mailings.MailingUsersGrid();a.push(this.usersGrid);this.readPermissionsTab=new GO.grid.PermissionsPanel({title:GO.lang.strPermissions});a.push(this.readPermissionsTab);this.tabPanel=new Ext.TabPanel({activeTab:0,deferredRender:false,border:false,items:a,anchor:"100% 100%"});this.formPanel=new Ext.form.FormPanel({waitMsgTarget:true,border:false,baseParams:{task:"mailing"},items:this.tabPanel})}});GO.mailings.EmailTemplateDialog=function(b){if(!b){b={}}this.buildForm();var a=function(){this.propertiesPanel.items.items[0].focus()};b.maximizable=true;b.layout="fit";b.modal=false;b.resizable=false;b.width=760;b.height=500;b.closeAction="hide";b.title=GO.mailings.lang.emailTemplate;b.items=this.formPanel;b.focus=a.createDelegate(this);b.buttons=[{text:GO.lang.cmdOk,handler:function(){this.submitForm(true)},scope:this},{text:GO.lang.cmdApply,handler:function(){this.submitForm()},scope:this},{text:GO.lang.cmdClose,handler:function(){this.hide()},scope:this}];GO.mailings.EmailTemplateDialog.superclass.constructor.call(this,b);this.addEvents({save:true})};Ext.extend(GO.mailings.EmailTemplateDialog,Ext.Window,{inline_attachments:[],show:function(a){if(!this.rendered){this.render(Ext.getBody())}this.tabPanel.setActiveTab(0);if(!a){a=0}this.setEmailTemplateId(a);if(this.email_template_id>0){this.formPanel.load({url:GO.settings.modules.mailings.url+"json.php",success:function(b,c){this.readPermissionsTab.setAcl(c.result.data.acl_id);this.selectUser.setRemoteText(c.result.data.user_name);this.inline_attachments=c.result.data.inline_attachments;GO.mailings.EmailTemplateDialog.superclass.show.call(this)},failure:function(b,c){Ext.Msg.alert(GO.lang.strError,c.result.feedback)},scope:this})}else{this.formPanel.form.reset();this.readPermissionsTab.setAcl(0);GO.mailings.EmailTemplateDialog.superclass.show.call(this)}},setEmailTemplateId:function(a){this.formPanel.form.baseParams.email_template_id=a;this.email_template_id=a},submitForm:function(a){this.emailHtmlEditor.toggleSourceEdit(false);this.emailHtmlEditor.toggleSourceEdit(false);this.formPanel.form.submit({url:GO.settings.modules.mailings.url+"action.php",params:{task:"save_email_template",inline_attachments:Ext.encode(this.inline_attachments)},waitMsg:GO.lang.waitMsgSave,success:function(b,c){this.fireEvent("save",this);this.inline_attachments=c.result.inline_attachments;if(a){this.hide()}else{this.emailHtmlEditor.setValue(c.result.body);if(c.result.email_template_id){this.setEmailTemplateId(c.result.email_template_id);this.readPermissionsTab.setAcl(c.result.acl_id)}}},failure:function(b,c){if(c.failureType=="client"){Ext.MessageBox.alert(GO.lang.strError,GO.lang.strErrorsInForm)}else{Ext.MessageBox.alert(GO.lang.strError,c.result.feedback)}},scope:this})},buildForm:function(){var e=new GO.plugins.HtmlEditorImageInsert();e.on("insert",function(k,l,j,i,m){var c={tmp_file:l,url:j,temp:i};this.inline_attachments.push(c)},this);var d=[["{date}",GO.lang.strDate],["{salutation}",GO.lang.strSalutation],["{first_name}",GO.lang.strFirstName],["{middle_name}",GO.lang.strMiddleName],["{last_name}",GO.lang.strLastName],["{initials}",GO.lang.strInitials],["{title}",GO.lang.strTitle],["{email}",GO.lang.strEmail],["{home_phone}",GO.lang.strPhone],["{fax}",GO.lang.strFax],["{cellular}",GO.lang.strCellular],["{address}",GO.lang.strAddress],["{address_no}",GO.lang.strAddressNo],["{zip}",GO.lang.strZip],["{city}",GO.lang.strCity],["{state}",GO.lang.strState],["{country}",GO.lang.strCountry],["{company}",GO.lang.strCompany],["{department}",GO.lang.strDepartment],["{function}",GO.lang.strFunction],["{work_phone}",GO.lang.strWorkPhone],["{work_fax}",GO.lang.strWorkFax],["{work_address}",GO.lang.strWorkAddress],["{work_address_no}",GO.lang.strWorkAddressNo],["{work_city}",GO.lang.strWorkCity],["{work_zip}",GO.lang.strWorkZip],["{work_state}",GO.lang.strWorkState],["{work_country}",GO.lang.strWorkCountry],["{work_post_address}",GO.lang.strPostAddress],["{work_post_address_no}",GO.lang.strPostAddressNo],["{work_post_city}",GO.lang.strPostCity],["{work_post_zip}",GO.lang.strPostZip],["{work_post_state}",GO.lang.strPostState],["{work_post_country}",GO.lang.strPostCountry],["{homepage}",GO.lang.strHomepage],["{my_name}",GO.lang.strName+" ("+GO.lang.strUser+")"],["{my_first_name}",GO.lang.strFirstName+" ("+GO.lang.strUser+")"],["{my_middle_name}",GO.lang.strMiddleName+" ("+GO.lang.strUser+")"],["{my_last_name}",GO.lang.strLastName+" ("+GO.lang.strUser+")"],["{my_initials}",GO.lang.strInitials+" ("+GO.lang.strUser+")"],["{my_title}",GO.lang.strTitle+" ("+GO.lang.strUser+")"],["{my_email}",GO.lang.strEmail+" ("+GO.lang.strUser+")"],["{my_home_phone}",GO.lang.strPhone+" ("+GO.lang.strUser+")"],["{my_fax}",GO.lang.strFax+" ("+GO.lang.strUser+")"],["{my_cellular}",GO.lang.strCellular+" ("+GO.lang.strUser+")"],["{my_address}",GO.lang.strAddress+" ("+GO.lang.strUser+")"],["{my_address_no}",GO.lang.strAddressNo+" ("+GO.lang.strUser+")"],["{my_zip}",GO.lang.strZip+" ("+GO.lang.strUser+")"],["{my_city}",GO.lang.strCity+" ("+GO.lang.strUser+")"],["{my_state}",GO.lang.strState+" ("+GO.lang.strUser+")"],["{my_country}",GO.lang.strCountry+" ("+GO.lang.strUser+")"],["{my_company}",GO.lang.strCompany+" ("+GO.lang.strUser+")"],["{my_department}",GO.lang.strDepartment+" ("+GO.lang.strUser+")"],["{my_function}",GO.lang.strFunction+" ("+GO.lang.strUser+")"],["{my_work_phone}",GO.lang.strWorkPhone+" ("+GO.lang.strUser+")"],["{my_work_fax}",GO.lang.strWorkFax+" ("+GO.lang.strUser+")"],["{my_work_address}",GO.lang.strWorkAddress+" ("+GO.lang.strUser+")"],["{my_work_address_no}",GO.lang.strWorkAddressNo+" ("+GO.lang.strUser+")"],["{my_work_city}",GO.lang.strWorkCity+" ("+GO.lang.strUser+")"],["{my_work_zip}",GO.lang.strWorkZip+" ("+GO.lang.strUser+")"],["{my_work_state}",GO.lang.strWorkState+" ("+GO.lang.strUser+")"],["{my_work_country}",GO.lang.strWorkCountry+" ("+GO.lang.strUser+")"],["{my_homepage}",GO.lang.strHomepage+" ("+GO.lang.strUser+")"],["{unsubscribe_link}",GO.mailings.lang.unsubscribeLink],["%unsubscribe_href%",GO.mailings.lang.unsubscribeHref]];var a=[new Ext.Panel({title:GO.mailings.lang.autoData,autoScroll:true,items:new GO.grid.SimpleSelectList({store:new Ext.data.SimpleStore({fields:["value","name"],data:d}),listeners:{scope:this,click:function(c,i){this.emailHtmlEditor.insertAtCursor(c.store.data.items[i].data.value);this.emailHtmlEditor.deferFocus();c.clearSelections()}}})})];if(GO.customfields){d=[];if(GO.customfields.types["2"]&&GO.customfields.types["2"].panels.length){for(var b=0;b<GO.customfields.types["2"].panels.length;b++){var g=GO.customfields.types["2"].panels[b];for(var h=0;h<g.customfields.length;h++){d.push(["{"+g.customfields[h].dataname+"}",g.customfields[h].name])}}}if(d.length){a.push(new Ext.Panel({autoScroll:true,title:GO.mailings.lang.customContactFields,items:new GO.grid.SimpleSelectList({store:new Ext.data.SimpleStore({fields:["value","name"],data:d}),listeners:{scope:this,click:function(c,i){this.emailHtmlEditor.insertAtCursor(c.store.data.items[i].data.value);this.emailHtmlEditor.deferFocus();c.clearSelections()}}})}))}d=[];if(GO.customfields.types["3"]&&GO.customfields.types["3"].panels.length){for(var b=0;b<GO.customfields.types["3"].panels.length;b++){var g=GO.customfields.types["3"].panels[b];for(var h=0;h<g.customfields.length;h++){d.push(["{"+g.customfields[h].dataname+"}",g.customfields[h].name])}}}if(d.length){a.push(new Ext.Panel({autoScroll:true,title:GO.mailings.lang.customCompanyFields,items:new GO.grid.SimpleSelectList({store:new Ext.data.SimpleStore({fields:["value","name"],data:d}),listeners:{scope:this,click:function(c,i){this.emailHtmlEditor.insertAtCursor(c.store.data.items[i].data.value);this.emailHtmlEditor.deferFocus();c.clearSelections()}}})}))}d=[];if(GO.customfields.types["8"]&&GO.customfields.types["8"].panels.length){for(var b=0;b<GO.customfields.types["8"].panels.length;b++){var g=GO.customfields.types["8"].panels[b];for(var h=0;h<g.customfields.length;h++){d.push(["{my_"+g.customfields[h].dataname+"}",g.customfields[h].name])}}}if(d.length){a.push(new Ext.Panel({autoScroll:true,title:GO.mailings.lang.customUserFields,items:new GO.grid.SimpleSelectList({store:new Ext.data.SimpleStore({fields:["value","name"],data:d}),listeners:{scope:this,click:function(c,i){this.emailHtmlEditor.insertAtCursor(c.store.data.items[i].data.value);this.emailHtmlEditor.deferFocus();c.clearSelections()}}})}))}}this.autoDataPanel=new Ext.Panel({region:"east",layout:"accordion",border:false,autoScroll:true,width:180,split:true,resizable:true,items:a});this.propertiesPanel=new Ext.Panel({region:"center",border:false,baseParams:{task:"email_template"},cls:"go-form-panel",layout:"form",items:[{xtype:"textfield",name:"name",anchor:"100%",allowBlank:false,fieldLabel:GO.lang.strName},this.selectUser=new GO.form.SelectUser({fieldLabel:GO.lang.strOwner,disabled:!GO.settings.modules.addressbook["write_permission"],value:GO.settings.user_id,anchor:"100%"}),this.emailHtmlEditor=new Ext.form.HtmlEditor({hideLabel:true,name:"body",border:false,allowBlank:true,value:'<font style="font:12px arial"><br /></font>',plugins:[e],style:'font:12px arial";',defaultFont:"arial",anchor:"100% -90"})]});var f=new Ext.Panel({layout:"border",title:GO.lang.strProperties,items:[this.propertiesPanel,this.autoDataPanel]});var a=[f];this.readPermissionsTab=new GO.grid.PermissionsPanel({});a.push(this.readPermissionsTab);this.tabPanel=new Ext.TabPanel({activeTab:0,deferredRender:false,border:false,items:a,anchor:"100% 100%"});this.formPanel=new Ext.form.FormPanel({border:false,baseParams:{task:"email_template"},waitMsgTarget:true,items:this.tabPanel})}});GO.mailings.createMailingGrids=function(){GO.mailings.MailingUsersGrid=function(a){if(!a){a={}}a.store=new GO.data.JsonStore({url:GO.settings.modules.mailings.url+"json.php",baseParams:{task:"mailing_users",mailing_id:"0"},root:"results",id:"id",totalProperty:"total",fields:["id","name","email","company_name","home_phone","work_phone","cellular"],remoteSort:true});this.selectUserDialog=new GO.dialog.SelectUsers({handler:function(d){var c=d.getSelectionModel();this.store.baseParams.add_keys=Ext.encode(c.selections.keys);this.store.load();delete this.store.baseParams.add_keys},scope:this});a.border=false;a.paging=true;a.disabled=true;var b=new Ext.grid.ColumnModel({defaults:{sortable:true},columns:[{header:GO.lang.strName,dataIndex:"name"},{header:GO.lang.strEmail,dataIndex:"email",width:150}]});a.cm=b;a.view=new Ext.grid.GridView({autoFill:true,forceFit:true,emptyText:GO.lang.strNoItems});a.sm=new Ext.grid.RowSelectionModel();a.loadMask=true;a.title=GO.addressbook.lang.users;a.tbar=[{iconCls:"btn-add",text:GO.lang.cmdAdd,cls:"x-btn-text-icon",handler:function(){this.selectUserDialog.show()},scope:this},{iconCls:"btn-delete",text:GO.lang.cmdDelete,cls:"x-btn-text-icon",handler:function(){this.deleteSelected()},scope:this}];GO.mailings.MailingUsersGrid.superclass.constructor.call(this,a)};Ext.extend(GO.mailings.MailingUsersGrid,GO.grid.GridPanel,{onShow:function(){if(!this.store.loaded){this.store.load()}GO.mailings.MailingCompaniesGrid.superclass.onShow.call(this)},setMailingId:function(a){this.store.baseParams.mailing_id=a;this.store.loaded=false;this.setDisabled(a==0)}});GO.mailings.MailingContactsGrid=Ext.extend(function(a){if(!a){a={}}a.title=GO.addressbook.lang.contacts;this.selectContactDialog=new GO.addressbook.SelectContactDialog({handler:function(e,c){if(!c){var d=e.getSelectionModel();this.store.baseParams.add_keys=Ext.encode(d.selections.keys);this.store.load();delete this.store.baseParams.add_keys}else{this.store.baseParams.add_search_result=Ext.encode(e.store.baseParams);this.store.load();delete this.store.baseParams.add_search_result}},scope:this});a.disabled=true;a.tbar=[{iconCls:"btn-add",text:GO.lang.cmdAdd,cls:"x-btn-text-icon",handler:function(){this.selectContactDialog.show()},scope:this},{iconCls:"btn-add",text:GO.mailings.lang.addEntireAddressbook,cls:"x-btn-text-icon",handler:function(){if(!this.selectAddressbookWindow){this.selectAddressbookWindow=new GO.mailings.SelectAddressbookWindow();this.selectAddressbookWindow.on("select",function(c){if(confirm(GO.mailings.lang.confirmAddEntireAddressbook)){this.store.load({params:{start:0,add_addressbook_id:c}})}},this)}this.selectAddressbookWindow.show()},scope:this},{iconCls:"btn-delete",text:GO.lang.cmdDelete,cls:"x-btn-text-icon",handler:function(){this.deleteSelected()},scope:this}];a.store=new GO.data.JsonStore({url:GO.settings.modules.mailings.url+"json.php",baseParams:{task:"mailing_contacts",mailing_id:"0"},root:"results",id:"id",totalProperty:"total",fields:["id","name","company_name","email","home_phone","work_phone","cellular"],remoteSort:true});a.paging=true;a.border=false;var b=new Ext.grid.ColumnModel({defaults:{sortable:true},columns:[{header:GO.lang.strName,dataIndex:"name"},{header:GO.lang.strCompany,dataIndex:"company_name"},{header:GO.lang.strEmail,dataIndex:"email",width:150,hidden:true},{header:GO.lang.strPhone,dataIndex:"home_phone",width:100,hidden:true},{header:GO.lang.strWorkPhone,dataIndex:"work_phone",width:100,hidden:true},{header:GO.lang.strWorkFax,dataIndex:"work_fax",width:100,hidden:true},{header:GO.lang.strCellular,dataIndex:"cellular",width:100,hidden:true}]});a.cm=b;a.view=new Ext.grid.GridView({autoFill:true,forceFit:true,emptyText:GO.lang.strNoItems}),a.sm=new Ext.grid.RowSelectionModel();a.loadMask=true;GO.mailings.MailingContactsGrid.superclass.constructor.call(this,a)},GO.grid.GridPanel,{onShow:function(){if(!this.store.loaded){this.store.load()}GO.mailings.MailingContactsGrid.superclass.onShow.call(this)},setMailingId:function(a){this.store.baseParams.mailing_id=a;this.store.loaded=false;this.setDisabled(a==0)}});GO.mailings.MailingCompaniesGrid=Ext.extend(function(a){if(!a){a={}}a.title=GO.addressbook.lang.companies;this.selectCompanyDialog=new GO.addressbook.SelectCompanyDialog({handler:function(e,c){if(!c){var d=e.getSelectionModel();this.store.baseParams.add_keys=Ext.encode(d.selections.keys);this.store.load();delete this.store.baseParams.add_keys}else{this.store.baseParams.add_search_result=Ext.encode(e.store.baseParams);this.store.load();delete this.store.baseParams.add_search_result}},scope:this});a.disabled=true;a.tbar=[{iconCls:"btn-add",text:GO.lang.cmdAdd,cls:"x-btn-text-icon",handler:function(){this.selectCompanyDialog.show()},scope:this},{iconCls:"btn-add",text:GO.mailings.lang.addEntireAddressbook,cls:"x-btn-text-icon",handler:function(){if(!this.selectAddressbookWindow){this.selectAddressbookWindow=new GO.mailings.SelectAddressbookWindow();this.selectAddressbookWindow.on("select",function(c){if(confirm(GO.mailings.lang.confirmAddEntireAddressbook)){this.store.load({params:{start:0,add_addressbook_id:c}})}},this)}this.selectAddressbookWindow.show()},scope:this},{iconCls:"btn-delete",text:GO.lang.cmdDelete,cls:"x-btn-text-icon",handler:function(){this.deleteSelected()},scope:this}];a.store=new GO.data.JsonStore({url:GO.settings.modules.mailings.url+"json.php",baseParams:{task:"mailing_companies",mailing_id:"0"},root:"results",id:"id",totalProperty:"total",fields:["id","name","homepage","email","phone","fax"],remoteSort:true});a.border=false;a.paging=true;var b=new Ext.grid.ColumnModel({defaults:{sortable:true},columns:[{header:GO.lang.strName,dataIndex:"name"},{header:GO.lang.strEmail,dataIndex:"email",width:150,hidden:true},{header:GO.lang.strHomepage,dataIndex:"homepage",width:100,hidden:true},{header:GO.lang.strPhone,dataIndex:"phone",width:100},{header:GO.lang.strFax,dataIndex:"fax",width:100,hidden:true}]});a.cm=b;a.view=new Ext.grid.GridView({autoFill:true,forceFit:true,emptyText:GO.lang.strNoItems}),a.sm=new Ext.grid.RowSelectionModel();a.loadMask=true;GO.addressbook.CompaniesGrid.superclass.constructor.call(this,a)},GO.grid.GridPanel,{onShow:function(){if(!this.store.loaded){this.store.load()}GO.mailings.MailingContactsGrid.superclass.onShow.call(this)},setMailingId:function(a){this.store.baseParams.mailing_id=a;this.store.loaded=false;this.setDisabled(a==0)}})};if(!GO.addressbook){GO.moduleManager.onModuleReady("addressbook",GO.mailings.createMailingGrids)}else{GO.mailings.createMailingGrids()}GO.mailings.SelectMailingsPanel=Ext.extend(Ext.Panel,{addresslistElements:[],hideAllowCheck:false,initComponent:function(){this.title=GO.mailings.lang.cmdPanelMailings;this.cls="go-form-panel";this.autoScroll=true;this.items=[];if(!this.hideAllowCheck){this.items.push(new Ext.form.Checkbox({boxLabel:GO.mailings.lang.sendingEmailAllowed,labelSeparator:"",name:"email_allowed",autoCreate:{tag:"input",type:"checkbox",autocomplete:"off",value:"1"},checked:true}))}this.items.push(new GO.form.HtmlComponent({html:"<br /><h1>"+GO.mailings.lang.enabledMailingGroups+"</h1>"}));GO.mailings.SelectMailingsPanel.superclass.initComponent.call(this)},removeComponents:function(){var b=this.ownerCt.ownerCt.form;for(var a=0;a<this.addresslistElements.length;a++){b.remove(this.addresslistElements[a]);this.remove(this.addresslistElements[a],true)}this.addresslistElements=[]},loadComponents:function(){this.removeComponents();var c=this.ownerCt.ownerCt.form;for(var b=0;b<GO.mailings.writableMailingsStore.data.items.length;b++){var a=GO.mailings.writableMailingsStore.data.items[b];this.addresslistElements.push(new Ext.form.Checkbox({boxLabel:a.data.name,labelSeparator:"",name:"mailing_"+a.data.id,autoCreate:{tag:"input",type:"checkbox",autocomplete:"off",value:a.data.id},value:false}));this.add(this.addresslistElements[b]);c.add(this.addresslistElements[b])}this.doLayout()},afterRender:function(){GO.mailings.SelectMailingsPanel.superclass.afterRender.call(this);if(GO.mailings.writableMailingsStore.loaded){this.loadComponents()}else{this.disabled=true}GO.mailings.writableMailingsStore.on("load",function(){this.loadComponents();this.setDisabled(false)},this)}});GO.mailings.SelectMailingGroupWindow=Ext.extend(Ext.Window,{initComponent:function(){this.title=GO.mailings.lang.selectMailingGroup;this.list=new GO.grid.SimpleSelectList({store:GO.mailings.readableMailingsStore});this.list.on("click",function(b,c){var a=b.store.data.items[c].id;this.fireEvent("select",this,a);this.list.clearSelections();this.hide()},this);this.title=GO.mailings.lang.selectMailingGroup;this.layout="fit";this.modal=false;this.height=400;this.width=400;this.closable=true;this.closeAction="hide";this.items=this.panel=new Ext.Panel({autoScroll:true,items:this.list,cls:"go-form-panel"});this.buttons=[{text:GO.lang.cmdClose,handler:function(){this.hide()},scope:this}];GO.mailings.SelectMailingGroupWindow.superclass.initComponent.call(this);this.addEvents({select:true})},show:function(){if(!this.list.store.loaded){this.list.store.load({callback:function(){this.show()},scope:this});return false}GO.mailings.SelectMailingGroupWindow.superclass.show.call(this);if(this.list.store.getCount()==0){this.panel.body.update(GO.mailings.lang.noMailingGroups)}}});GO.mailings.SentMailingsGrid=function(a){if(!a){a={}}a.layout="fit";a.autoScroll=true;a.split=true;a.store=new GO.data.JsonStore({url:GO.settings.modules.mailings.url+"json.php",baseParams:{task:"sent_mailings",mailing_group_id:0},root:"results",id:"id",totalProperty:"total",fields:["id","mailing_group","subject","user_name","ctime","status","sent","total","errors","hide_pause","hide_play","message_path"],remoteSort:true});var c=new Ext.ux.grid.RowActions({header:"",hideMode:"display",keepSelection:true,actions:[{iconCls:"ml-btn-view",qtip:GO.mailings.lang.viewMessage},{iconCls:"ml-btn-view-log",qtip:GO.mailings.lang.viewLog},{iconCls:"ml-btn-pause",hideIndex:"hide_pause",qtip:GO.mailings.lang.pauseMailing},{iconCls:"ml-btn-play",hideIndex:"hide_play",qtip:GO.mailings.lang.resumeMailing}],width:50});c.on({action:function(f,d,g,h,e){switch(g){case"ml-btn-pause":f.store.baseParams.pause_mailing_id=d.id;f.store.load();delete f.store.baseParams.pause_mailing_id;break;case"ml-btn-play":f.store.baseParams.start_mailing_id=d.id;f.store.load();delete f.store.baseParams.start_mailing_id;break;case"ml-btn-view":GO.linkHandlers[9].call(this,0,{path:d.get("message_path")});break;case"ml-btn-view-log":document.location=GO.settings.modules.mailings.url+"log.php?mailing_id="+d.id;break}}});a.plugins=c;a.paging=true;var b=new Ext.grid.ColumnModel({defaults:{sortable:true},columns:[{header:GO.mailings.lang.addresslist,dataIndex:"mailing_group"},{header:GO.mailings.lang.subject,dataIndex:"subject"},{header:GO.lang.strOwner,dataIndex:"user_name"},{header:GO.lang.strCtime,dataIndex:"ctime"},{header:GO.mailings.lang.status,dataIndex:"status"},{header:GO.mailings.lang.sent,dataIndex:"sent",align:"center",width:60},{header:GO.mailings.lang.total,dataIndex:"total",align:"center",width:60},{header:GO.mailings.lang.errors,dataIndex:"errors",align:"center",width:60},c]});a.cm=b;a.view=new Ext.grid.GridView({autoFill:true,forceFit:true,emptyText:GO.lang.strNoItems}),a.sm=new Ext.grid.RowSelectionModel();a.loadMask=true;GO.mailings.SentMailingsGrid.superclass.constructor.call(this,a)};Ext.extend(GO.mailings.SentMailingsGrid,GO.grid.GridPanel,{setMailingId:function(a){this.store.baseParams.mailing_group_id=a;this.store.loaded=false},afterRender:function(){GO.mailings.SentMailingsGrid.superclass.afterRender.call(this);this.store.load()}});GO.mailings.SelectAddressbookWindow=Ext.extend(Ext.Window,{initComponent:function(){this.addEvents({select:true});this.title=GO.mailings.lang.selectAddressbook;this.list=new GO.grid.SimpleSelectList({store:GO.addressbook.readableAddressbooksStore});this.list.on("click",function(a,b){var c=a.store.data.items[b].id;this.fireEvent("select",c);this.hide()},this);this.title=GO.mailings.lang.selectAddressbook;this.layout="fit";this.modal=false;this.height=400;this.width=400;this.closable=true;this.closeAction="hide";this.items=this.panel=new Ext.Panel({autoScroll:true,items:this.list,cls:"go-form-panel"});this.buttons=[{text:GO.lang.cmdClose,handler:function(){this.hide()},scope:this}];GO.mailings.SelectAddressbookWindow.superclass.initComponent.call(this)}});GO.mailings.writableMailingsStore=new GO.data.JsonStore({url:GO.settings.modules.mailings.url+"json.php",baseParams:{task:"mailings",auth_type:"write"},root:"results",id:"id",totalProperty:"total",fields:["id","name","owner","acl_id"],remoteSort:true});GO.mailings.writableMailingsStore.on("load",function(){GO.mailings.writableMailingsStore.on("load",function(){GO.mailings.readableMailingsStore.load()},this)},this,{single:true});GO.mailings.readableMailingsStore=new GO.data.JsonStore({url:GO.settings.modules.mailings.url+"json.php",baseParams:{task:"mailings",auth_type:"read"},root:"results",id:"id",totalProperty:"total",fields:["id","name","owner","acl_id","checked"],remoteSort:true});GO.moduleManager.addModule("mailings");GO.mainLayout.onReady(function(){if(!GO.addressbook){alert("The mailings module is installed but depends on the not available addressbook module. The administrator should correct this.")}});GO.mailings.MailingStatusWindow=function(a){a=a||{};a.title=GO.mailings.lang.sentMailings;a.id="ml-sent-mailings";a.width=770;a.height=500;a.layout="fit";a.items=this.sentMailingsGrid=new GO.mailings.SentMailingsGrid();a.tbar=[{iconCls:"ml-btn-mailings",text:GO.addressbook.lang.sendMailing,cls:"x-btn-text-icon",handler:function(){if(!this.selectMailingGroupWindow){this.selectMailingGroupWindow=new GO.mailings.SelectMailingGroupWindow();this.selectMailingGroupWindow.on("select",function(d,b){var c=GO.email.showComposer({mailing_group_id:b});c.on("hide",function(){this.sentMailingsGrid.store.load()},this,{single:true})},this)}this.selectMailingGroupWindow.show()},scope:this}];GO.mailings.MailingStatusWindow.superclass.constructor.call(this,a)};Ext.extend(GO.mailings.MailingStatusWindow,GO.Window);