Ext.namespace("GO.wordpress");var wpIframe;var wpConfig={title:GO.wordpress.lang.wordpress,iconCls:"go-tab-icon-wordpress",layout:"fit",items:[wpIframe=new GO.panel.IFrameComponent({itemId:"iframe",url:GO.settings.modules.wordpress.url+"redirect.php"})],border:false};var tbarItems=[{iconCls:"btn-settings",text:GO.wordpress.lang.wordpressAdmin,handler:function(){wpIframe.el.dom.src=GO.settings.modules.wordpress.url+"redirect.php"},scope:this}];if(GO.settings.has_admin_permission){tbarItems.push("-",{iconCls:"btn-settings",text:GO.lang.cmdSettings,handler:function(){if(!this.adminDialog){this.adminDialog=new GO.wordpress.AdminDialog()}this.adminDialog.show()}})}wpConfig.tbar=new Ext.Toolbar({cls:"go-head-tb",items:tbarItems});GO.moduleManager.addModule("wordpress",Ext.Panel,wpConfig);GO.wordpress.edit=function(c,b){var a=GO.mainLayout.openModule("wordpress");a.items.item("iframe").el.dom.src=GO.settings.modules.wordpress.url+"redirect.php?link_id="+c+"&link_type="+b};GO.wordpress.addPublishComponents=function(c,a,d,b){c.editBtn=new Ext.Button({handler:function(){GO.wordpress.edit(c[b],d);c.collapse()},scope:c,text:GO.lang.cmdEdit});c.on("show",function(){c.editBtn.setDisabled(true);c.publishChanged=false},c);c.on("save",function(){if(c.publishCheck.getValue()){c.editBtn.setDisabled(false);if(c.publishChanged){GO.wordpress.edit(c[b],d);c.collapse();c.publishChanged=false}}else{c.editBtn.setDisabled(true)}},c);c.formPanel.on("actioncomplete",function(e,f){if(f.type=="load"){if(f.result.data.wp_publish){c.editBtn.setDisabled(false)}}},c);c.publishCheck=new Ext.form.Checkbox({hideLabel:true,boxLabel:GO.wordpress.lang.publishToWebsite,name:"wp_publish",listeners:{check:function(){c.publishChanged=true},scope:c}});a.add({xtype:"compositefield",hideLabel:true,items:[c.publishCheck,c.editBtn]})};GO.mainLayout.onReady(function(){if(GO.projects&&GO.wordpress.mapping["5"]){Ext.override(GO.projects.ProjectDialog,{initComponent:GO.projects.ProjectDialog.prototype.initComponent.createInterceptor(function(){GO.wordpress.addPublishComponents(this,this.propertiesPanel.items.item("leftCol"),5,"project_id")})})}if(GO.addressbook&&GO.wordpress.mapping["2"]){Ext.override(GO.addressbook.ContactDialog,{initComponent:GO.addressbook.ContactDialog.prototype.initComponent.createInterceptor(function(){GO.wordpress.addPublishComponents(this,this.personalPanel.items.item("leftCol"),2,"contact_id")})})}});GO.wordpress.AdminDialog=function(a){a=a||{};a.width=400;a.autoHeight=true;a.title=GO.lang.cmdSettings;this.formPanel=new Ext.FormPanel({waitMsgTarget:true,cls:"go-form-panel",url:GO.settings.modules.wordpress.url+"action.php",items:[{xtype:"textfield",fieldLabel:"Wordpress URL",name:"wp_url",anchor:"100%"}]});a.items=[this.formPanel];a.listeners={show:function(){this.formPanel.form.load({url:GO.settings.modules.wordpress.url+"json.php",waitMsg:GO.lang.waitMsgLoad})},scope:this};a.buttons=[{text:GO.lang.cmdOk,handler:function(){this.formPanel.form.submit({waitMsg:GO.lang.waitMsgSave,success:function(){this.hide()},scope:this})},scope:this}];GO.wordpress.AdminDialog.superclass.constructor.call(this,a)};Ext.extend(GO.wordpress.AdminDialog,GO.Window);