MODx.panel.Template=function(A){A=A||{record:{}};A.record=A.record||{};Ext.applyIf(A,{url:MODx.config.connectors_url+"element/template.php",baseParams:{},id:"modx-panel-template",class_key:"modTemplate",template:"",bodyStyle:"",items:[{html:"<h2>"+_("template_new")+"</h2>",id:"modx-template-header",cls:"modx-page-header",border:false},MODx.getPageStructure([{title:_("template_title"),bodyStyle:"padding: 15px;",defaults:{border:false,msgTarget:"side"},layout:"form",id:"modx-template-form",labelWidth:150,items:[{html:"<p>"+_("template_msg")+"</p>",id:"modx-template-msg"},{xtype:"hidden",name:"id",id:"modx-template-id",value:A.template},{xtype:"hidden",name:"props",id:"modx-template-props",value:A.record.props||null},{xtype:"textfield",fieldLabel:_("template_name"),name:"templatename",id:"modx-template-templatename",width:300,maxLength:100,enableKeyEvents:true,allowBlank:false,value:A.record.templatename,listeners:{keyup:{scope:this,fn:function(B,C){Ext.getCmp("modx-template-header").getEl().update("<h2>"+_("template")+": "+B.getValue()+"</h2>");}}}},{xtype:"textfield",fieldLabel:_("template_desc"),name:"description",id:"modx-template-description",width:300,maxLength:255,value:A.record.description||""},{xtype:"modx-combo-category",fieldLabel:_("category"),name:"category",id:"modx-template-category",width:250,value:A.record.category||0},{xtype:"xcheckbox",fieldLabel:_("template_lock"),description:_("template_lock_msg"),name:"locked",id:"modx-template-locked",inputValue:1,checked:A.record.locked||false},{xtype:"checkbox",fieldLabel:_("clear_cache_on_save"),description:_("clear_cache_on_save_msg"),name:"clearCache",id:"modx-template-clear-cache",inputValue:1,checked:Ext.isDefined(A.record.clearCache)||true},{html:MODx.onTempFormRender,border:false},{html:"<br />"+_("template_code")},{xtype:"textarea",hideLabel:true,name:"content",id:"modx-template-content",width:"95%",height:400,value:A.record.content||""}]},{xtype:"modx-panel-element-properties",preventRender:true,collapsible:true,elementPanel:"modx-panel-template",elementId:A.template,elementType:"modTemplate"},{title:_("template_variables"),itemId:"form-template",bodyStyle:"padding: 15px;",defaults:{autoHeight:true},items:[{html:"<p>"+_("template_tv_msg")+"</p>",border:false},{xtype:"modx-grid-template-tv",preventRender:true,width:"100%",template:A.template,listeners:{rowclick:{fn:this.markDirty,scope:this},afterEdit:{fn:this.markDirty,scope:this},afterRemoveRow:{fn:this.markDirty,scope:this}}}]}],{id:"modx-template-tabs"})],useLoadingMask:true,listeners:{setup:{fn:this.setup,scope:this},success:{fn:this.success,scope:this},beforeSubmit:{fn:this.beforeSubmit,scope:this}}});MODx.panel.Template.superclass.constructor.call(this,A);};Ext.extend(MODx.panel.Template,MODx.FormPanel,{initialized:false,setup:function(){if(!this.initialized){this.getForm().setValues(this.config.record);}if(!Ext.isEmpty(this.config.record.templatename)){Ext.getCmp("modx-template-header").getEl().update("<h2>"+_("template")+": "+this.config.record.templatename+"</h2>");}if(!Ext.isEmpty(this.config.record.properties)){var B=this.config.record.properties;var A=Ext.getCmp("modx-grid-element-properties");if(A){A.defaultProperties=B;A.getStore().loadData(B);}}this.fireEvent("ready",this.config.record);if(MODx.onLoadEditor){MODx.onLoadEditor(this);}this.clearDirty();this.initialized=true;MODx.fireEvent("ready");return true;},beforeSubmit:function(B){var A=Ext.getCmp("modx-grid-template-tv");Ext.apply(B.form.baseParams,{tvs:A.encodeModified(),propdata:Ext.getCmp("modx-grid-element-properties").encode()});this.cleanupEditor();return this.fireEvent("save",{values:this.getForm().getValues(),stay:MODx.config.stay});},success:function(C){if(MODx.request.id){Ext.getCmp("modx-grid-element-properties").save();}Ext.getCmp("modx-grid-template-tv").getStore().commitChanges();this.getForm().setValues(C.result.object);var B=Ext.getCmp("modx-element-tree");if(B){var D=Ext.getCmp("modx-template-category").getValue();var A=D!=""&&D!=null?"n_template_category_"+D:"n_type_template";B.refreshNode(A,true);}},changeEditor:function(){this.cleanupEditor();this.on("success",function(C){var D=C.result.object.id;var A=Ext.getCmp("modx-template-which-editor").getValue();MODx.request.a=MODx.action["element/template/update"];var B="?"+Ext.urlEncode(MODx.request)+"&which_editor="+A+"&id="+D;location.href=B;});this.submit();},cleanupEditor:function(){if(MODx.onSaveEditor){var A=Ext.getCmp("modx-template-content");MODx.onSaveEditor(A);}}});Ext.reg("modx-panel-template",MODx.panel.Template);