MODx.grid.LocalProperty=function(config){config=config||{};Ext.applyIf(config,{dynProperty:'xtype',dynField:'value',propertyRecord:[{name:'name'},{name:'value'}],data:[]});MODx.grid.LocalProperty.superclass.constructor.call(this,config);this.propRecord=Ext.data.Record.create(config.propertyRecord);};Ext.extend(MODx.grid.LocalProperty,MODx.grid.LocalGrid,{onCellDblClick:function(g,ri,ci,e){var cm=this.getColumnModel();if(cm.getColumnId(ci)!=this.config.dynField){this.onCellDblClick(g,ri,ci,e);}else{e.preventDefault();var r=this.getStore().getAt(ri).data;this.initEditor(cm,ci,ri,r);this.startEditing(ri,ci);}},initEditor:function(cm,ci,ri,r){cm.setEditable(ci,true);var xtype=this.config.dynProperty;var o;if(r[xtype]=='list'){o=this.createCombo(r);}else{var z={};z[xtype]=r[xtype]||'textfield';try{o=Ext.ComponentMgr.create(z);}catch(e){z[xtype]='textfield';o=MODx.load(z);}}
var ed=new Ext.grid.GridEditor(o);cm.setEditor(ci,ed);return ed;},renderDynField:function(v,md,rec,ri,ci,s,g){var r=s.getAt(ri).data;var f;var oz=v;var xtype=this.config.dynProperty;if(!r[xtype]||r[xtype]=='combo-boolean'){f=MODx.grid.Grid.prototype.rendYesNo;oz=f(v==1,md);}else if(r[xtype]==='datefield'){f=Ext.util.Format.dateRenderer('Y-m-d');oz=f(v);}else if(r[xtype]==='password'){f=this.rendPassword;oz=f(v,md);}else if(r[xtype].substr(0,5)=='combo'||r[xtype]=='list'||r[xtype].substr(0,9)=='modx-combo'){var cm=g.getColumnModel();var ed=cm.getCellEditor(ci,ri);var cb;if(!ed){r.xtype=r.xtype||'combo-boolean';cb=this.createCombo(r);ed=new Ext.grid.GridEditor(cb);cm.setEditor(ci,ed);}else if(ed&&ed.field&&ed.field.xtype=='modx-combo'){cb=ed.field;}
if(r[xtype]!='list'){f=MODx.combo.Renderer(ed.field);oz=f(v);}else if(cb){idx=cb.getStore().find(cb.valueField,v);rec=cb.getStore().getAt(idx);if(rec){oz=rec.get(cb.displayField);}else{oz=v;}}}
return Ext.util.Format.htmlEncode(oz);},createCombo:function(p){var obj;try{obj=Ext.ComponentMgr.create({xtype:r.xtype,id:Ext.id()});}catch(e){try{var flds=p.options;var data=[];for(var i=0;i<flds.length;i=i+1){data.push([flds[i].name,flds[i].value,flds[i].text]);}
obj=MODx.load({xtype:'modx-combo',store:new Ext.data.SimpleStore({fields:['d','v','t'],data:data}),displayField:'d',valueField:'v',mode:'local',triggerAction:'all',editable:false,selectOnFocus:false,preventRender:true});}catch(e2){obj=Ext.ComponentMgr.create({xtype:'combo-boolean',id:Ext.id()});}}
return obj;}});Ext.reg('grid-local-property',MODx.grid.LocalProperty);
;MODx.panel.ElementProperties=function(config){config=config||{};Ext.applyIf(config,{id:'modx-panel-element-properties',title:_('properties'),header:false,defaults:{collapsible:false,autoHeight:true,border:false},layout:'form',items:[{html:'<p>'+_('element_properties_desc')+'</p>',bodyCssClass:'panel-desc',itemId:'desc-properties'},{xtype:'modx-grid-element-properties',cls:'main-wrapper',id:'modx-grid-element-properties',itemId:'grid-properties',autoHeight:true,border:true,panel:config.elementPanel,elementId:config.elementId,elementType:config.elementType},{layout:'form',border:false,cls:'main-wrapper',items:[{xtype:'xcheckbox',boxLabel:_('property_preprocess'),description:MODx.expandHelp?'':_('property_preprocess_msg'),name:'property_preprocess',id:'modx-element-property-preprocess',inputValue:true,hideLabel:true,checked:config.record.property_preprocess||0,listeners:{'check':{fn:function(){Ext.getCmp(this.config.elementPanel).markDirty();},scope:this}}},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-element-property-preprocess',html:_('property_preprocess_msg'),cls:'desc-under'}]}]});MODx.panel.ElementProperties.superclass.constructor.call(this,config);};Ext.extend(MODx.panel.ElementProperties,MODx.Panel);Ext.reg('modx-panel-element-properties',MODx.panel.ElementProperties);MODx.grid.ElementProperties=function(config){config=config||{};this.exp=new Ext.grid.RowExpander({tpl:new Ext.Template('<p class="modx-property-description"><i>{desc_trans}</i></p>')});Ext.applyIf(config,{title:_('properties'),id:'modx-grid-element-properties',maxHeight:300,fields:['name','desc','xtype','options','value','lexicon','overridden','desc_trans'],autoExpandColumn:'value',sortBy:'name',anchor:'100%',sm:new Ext.grid.RowSelectionModel({singleSelect:false}),loadMask:true,lockProperties:true,plugins:[this.exp],columns:[this.exp,{header:_('name'),dataIndex:'name',width:200,sortable:true,renderer:this._renderName},{header:_('type'),dataIndex:'xtype',width:100,renderer:this._renderType,sortable:true},{header:_('value'),dataIndex:'value',id:'value',width:250,renderer:this.renderDynField.createDelegate(this,[this],true),sortable:true}],tbar:[{xtype:'modx-combo-property-set',id:'modx-combo-property-set',baseParams:{action:'getList',showAssociated:true,elementId:config.elementId,elementType:config.elementType},value:_('default'),listeners:{'select':{fn:this.changePropertySet,scope:this}}},{text:_('property_create'),id:'modx-btn-property-create',handler:this.create,scope:this,disabled:true},'-',{text:_('property_revert_all'),id:'modx-btn-property-revert-all',handler:this.revertAll,scope:this,disabled:true},'-',{text:_('properties_default_locked'),id:'modx-btn-propset-lock',handler:this.togglePropertiesLock,enableToggle:true,pressed:true,disabled:MODx.perm.unlock_element_properties?false:true,scope:this},'->',{text:_('propertyset_add'),handler:this.addPropertySet,scope:this},'-',{text:_('propertyset_save'),handler:this.save,scope:this,hidden:MODx.request.id?false:true}],bbar:[{text:_('properties_import'),handler:this.importProperties,scope:this},'-',{text:_('properties_export'),handler:this.exportProperties,scope:this}],collapseFirst:false,tools:[{id:'plus',qtip:_('expand_all'),handler:this.expandAll,scope:this},{id:'minus',hidden:true,qtip:_('collapse_all'),handler:this.collapseAll,scope:this}]});MODx.grid.ElementProperties.superclass.constructor.call(this,config);this.on('afteredit',this.propertyChanged,this);this.on('afterRemoveRow',this.propertyChanged,this);this.on('celldblclick',this.onDirty,this);this.on('render',function(){this.mask=new Ext.LoadMask(this.getEl(),{msg:_('loading')});},this);if(this.config.lockProperties){this.on('render',function(){this.lockMask=MODx.load({xtype:'modx-lockmask',el:this.getGridEl(),msg:_('properties_default_locked')});this.lockMask.toggle();},this);}};Ext.extend(MODx.grid.ElementProperties,MODx.grid.LocalProperty,{defaultProperties:[],onDirty:function(){if(this.config.panel){Ext.getCmp(this.config.panel).fireEvent('fieldChange');}},_renderType:function(v,md,rec,ri){switch(v){case'combo-boolean':return _('yesno');break;case'datefield':return _('date');break;case'numberfield':return _('integer');break;}
return _(v);},_renderName:function(v,md,rec,ri){switch(rec.data.overridden){case 1:return'<span style="color: green;">'+v+'</span>';break;case 2:return'<span style="color: purple;">'+v+'</span>';default:return'<span>'+v+'</span>';}},save:function(){var d=this.encode();var cb=Ext.getCmp('modx-combo-property-set');if(!cb){this.getStore().commitChanges();this.onDirty();return true;}
var p={action:'updatefromelement',id:cb.getValue(),data:d};if(this.config.elementId){Ext.apply(p,{elementId:this.config.elementId,elementType:this.config.elementType});}
try{if(!this.mask){this.mask=new Ext.LoadMask(this.getEl(),{msg:_('loading')});}
if(this.mask){this.mask.show();}}catch(e){}
MODx.Ajax.request({url:MODx.config.connectors_url+'element/propertyset.php',params:p,listeners:{'success':{fn:function(r){this.getStore().commitChanges();this.changePropertySet(cb);this.onDirty();if(this.mask){this.mask.hide();}
MODx.msg.status({title:_('success'),message:_('save_successful'),dontHide:r.message!=''?true:false});},scope:this}}});},addPropertySet:function(btn,e){this.loadWindow(btn,e,{xtype:'modx-window-element-property-set-add',record:{elementId:this.config.elementId!=0?this.config.elementId:'',elementType:this.config.elementType},listeners:{'success':{fn:function(o){var cb=Ext.getCmp('modx-combo-property-set');cb.store.reload({callback:function(){cb.setValue(o.a.result.object.id);this.changePropertySet(cb);},scope:this});this.onDirty();},scope:this}}});},togglePropertiesLock:function(){var ps=Ext.getCmp('modx-combo-property-set').getValue();if(ps==0||ps==_('default')){Ext.getCmp('modx-btn-propset-lock').setText(this.lockMask.locked?_('properties_default_unlocked'):_('properties_default_locked'));this.lockMask.toggle();this.toggleButtons(this.lockMask.locked);}},toggleButtons:function(v){var btn=Ext.getCmp('modx-btn-property-create');if(btn){Ext.getCmp('modx-btn-property-create').setDisabled(v);Ext.getCmp('modx-btn-property-revert-all').setDisabled(v);}},changePropertySet:function(cb){var ps=cb.getValue();var lockbtn=Ext.getCmp('modx-btn-propset-lock');if(ps==0||ps==_('default')){if(MODx.perm.unlock_element_properties){if(lockbtn){lockbtn.setDisabled(false);}}
if(this.lockMask&&this.lockMask.locked){this.lockMask.show();this.toggleButtons(true);}}else{if(lockbtn){lockbtn.setDisabled(true);}
if(this.lockMask)this.lockMask.hide();this.toggleButtons(false);}
MODx.Ajax.request({url:MODx.config.connectors_url+'element/propertyset.php',params:{action:'get',id:ps,elementId:this.config.elementId,elementType:this.config.elementType},listeners:{'success':{fn:function(r){var s=this.getStore();var data=Ext.decode(r.object.data);s.removeAll();s.loadData(data);},scope:this}}});},create:function(btn,e){this.loadWindow(btn,e,{xtype:'modx-window-element-property-create',blankValues:true,listeners:{'success':{fn:function(r){var rec=new this.propRecord({name:r.name,desc:r.desc,desc_trans:r.desc,xtype:r.xtype,options:r.options,value:r.value,lexicon:r.lexicon,overridden:this.isDefaultPropSet()?0:2});this.getStore().add(rec);this.propertyChanged();this.onDirty();},scope:this}}});},update:function(btn,e){this.loadWindow(btn,e,{xtype:'modx-window-element-property-update',record:this.menu.record,listeners:{'success':{fn:function(r){var def=this.isDefaultPropSet();var s=this.getStore();var rec=s.getAt(this.menu.recordIndex);rec.set('name',r.name);rec.set('desc',r.desc);rec.set('desc_trans',r.desc);rec.set('xtype',r.xtype);rec.set('options',r.options);rec.set('value',r.value);rec.set('lexicon',r.lexicon);rec.set('overridden',r.overridden==2?2:(!def?1:0));this.getView().refresh();this.onDirty();},scope:this}}});},revert:function(btn,e){Ext.Msg.confirm(_('warning'),_('property_revert_confirm'),function(e){if(e=='yes'){var ri=this.menu.recordIndex;var d=this.defaultProperties[ri];var rec=this.getStore().getAt(ri);rec.set('name',d[0]);rec.set('desc',d[1]);rec.set('xtype',d[2]);rec.set('options',d[3]);rec.set('value',d[4]);rec.set('overridden',0);rec.commit();}},this);},revertAll:function(btn,e){Ext.Msg.confirm(_('warning'),_('property_revert_all_confirm'),function(e){if(e=='yes'){this.getStore().loadData(this.defaultProperties);}},this);},removeMultiple:function(btn,e){var rows=this.getSelectionModel().getSelections();var rids=[];for(var i=0;i<rows.length;i=i+1){rids.push(rows[i].data.id);}
Ext.Msg.confirm(_('warning'),_('properties_remove_confirm'),function(e){if(e=='yes'){for(var f=0;f<rows.length;f=f+1){this.store.remove(rows[f]);}}},this);},exportProperties:function(btn,e){var id=Ext.getCmp('modx-combo-property-set').getValue();MODx.Ajax.request({url:MODx.config.connectors_url+'element/index.php',params:{action:'exportProperties',data:this.encode(),id:id},listeners:{'success':{fn:function(r){location.href=MODx.config.connectors_url+'element/index.php?action=exportProperties&download='+r.message+'&id='+id+'&HTTP_MODAUTH='+MODx.siteId;},scope:this}}});},importProperties:function(btn,e){this.loadWindow(btn,e,{xtype:'modx-window-properties-import',record:this.menu.record,listeners:{'success':{fn:function(o){var s=this.getStore();var data=o.a.result.object;for(var i in data){if(data[i][4]){data[i][4]=data[i][4].replace(/&gt;/g,'>').replace(/&lt;/g,'<');}
if(data[i][1]){data[i][1]=data[i][1].replace(/&gt;/g,'>').replace(/&lt;/g,'<');}}
s.loadData(data);var recs=s.getRange(0,s.getTotalCount());for(var i=0;i<recs.length;i++){recs[i].markDirty();}
this.getView().refresh();},scope:this}}});},_showMenu:function(g,ri,e){var sm=this.getSelectionModel();if(sm.getSelections().length>1){e.stopEvent();e.preventDefault();this.menu.removeAll();this.addContextMenuItem([{text:_('properties_remove'),handler:this.removeMultiple,scope:this}]);this.menu.show(e.target);}else{MODx.grid.ElementProperties.superclass._showMenu.call(this,g,ri,e);}},isDefaultPropSet:function(){var ps=Ext.getCmp('modx-combo-property-set').getValue();return(ps==0||ps==_('default'));},getMenu:function(){var def=this.isDefaultPropSet();var r=this.menu.record;var m=[]
m.push({text:_('property_update'),scope:this,handler:this.update});if(r.overridden){m.push({text:_('property_revert'),scope:this,handler:this.revert});}
if(r.overridden==2&&!def){m.push({text:_('property_remove'),scope:this,handler:this.remove.createDelegate(this,[{title:_('warning'),text:_('property_remove_confirm')}])});}
if(r.overridden!=1&&def){m.push({text:_('property_remove'),scope:this,handler:this.remove.createDelegate(this,[{title:_('warning'),text:_('property_remove_confirm')}])});}
return m;},propertyChanged:function(){var ep=Ext.getCmp(this.config.panel);if(!ep)return false;var hf=this.config.hiddenPropField||'props';ep.getForm().findField(hf).setValue('1');ep.fireEvent('fieldChange',{field:hf,form:ep.getForm()});return true;}});Ext.reg('modx-grid-element-properties',MODx.grid.ElementProperties);MODx.grid.ElementPropertyOption=function(config){config=config||{};Ext.applyIf(config,{title:_('property_options'),id:'modx-grid-element-property-options',autoHeight:true,maxHeight:300,width:'100%',fields:['text','value','name'],data:[],columns:[{header:_('name'),dataIndex:'text',width:150,editor:{xtype:'textfield',allowBlank:false}},{header:_('value'),dataIndex:'value',id:'value',width:250,editor:{xtype:'textfield',allowBlank:true}}],tbar:[{text:_('property_option_create'),handler:this.create,scope:this}]});MODx.grid.ElementPropertyOption.superclass.constructor.call(this,config);this.optRecord=Ext.data.Record.create([{name:'text'},{name:'value'}]);};Ext.extend(MODx.grid.ElementPropertyOption,MODx.grid.LocalGrid,{create:function(btn,e){this.loadWindow(btn,e,{xtype:'modx-window-element-property-option-create',listeners:{'success':{fn:function(r){var rec=new this.optRecord({text:r.text,value:r.value});this.getStore().add(rec);},scope:this}}});},getMenu:function(){return[{text:_('property_option_remove'),scope:this,handler:this.remove.createDelegate(this,[{title:_('warning'),text:_('property_option_remove_confirm')}])}];}});Ext.reg('modx-grid-element-property-options',MODx.grid.ElementPropertyOption);MODx.window.CreateElementProperty=function(config){config=config||{};Ext.applyIf(config,{title:_('property_create'),id:'modx-window-element-property-create',height:250,width:650,saveBtnText:_('done'),fields:[{layout:'column',border:false,defaults:{layout:'form',labelAlign:'top',anchor:'100%',border:false},items:[{columnWidth:.6,items:[{fieldLabel:_('name'),description:MODx.expandHelp?'':_('property_name_desc'),name:'name',id:'modx-cep-name',xtype:'textfield',anchor:'100%',allowBlank:false},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-cep-name',html:_('property_name_desc'),cls:'desc-under'},{fieldLabel:_('description'),description:MODx.expandHelp?'':_('property_description_desc'),name:'desc',id:'modx-cep-desc',xtype:'textarea',anchor:'100%'},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-cep-description',html:_('property_description_desc'),cls:'desc-under'}]},{columnWidth:.4,items:[{fieldLabel:_('type'),description:MODx.expandHelp?'':_('property_xtype_desc'),name:'xtype',id:'modx-cep-xtype',xtype:'modx-combo-xtype',anchor:'100%',listeners:{'select':{fn:function(cb){var g=Ext.getCmp('modx-cep-grid-element-property-options');if(!g)return;if(cb.getValue()=='list'){g.show();}else{g.hide();}
this.syncSize();},scope:this}}},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-cep-xtype',html:_('property_xtype_desc'),cls:'desc-under'},{xtype:'textfield',fieldLabel:_('lexicon'),description:MODx.expandHelp?'':_('property_lexicon_desc'),name:'lexicon',id:'modx-cep-lexicon',anchor:'100%',allowBlank:true},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-cep-lexicon',html:_('property_lexicon_desc'),cls:'desc-under'}]}]},{xtype:'modx-element-value-field',xtypeField:'modx-cep-xtype',id:'modx-cep-value',anchor:'100%'},{xtype:'modx-grid-element-property-options',id:'modx-cep-grid-element-property-options',anchor:'100%'}]});MODx.window.CreateElementProperty.superclass.constructor.call(this,config);this.on('show',this.onShow,this);};Ext.extend(MODx.window.CreateElementProperty,MODx.Window,{submit:function(){var v=this.fp.getForm().getValues();var g=Ext.getCmp('modx-cep-grid-element-property-options');var opt=eval(g.encode());Ext.apply(v,{options:opt});if(this.fp.getForm().isValid()){if(this.fireEvent('success',v)){this.fp.getForm().reset();this.hide();return true;}}
return false;},onShow:function(){var g=Ext.getCmp('modx-cep-grid-element-property-options');g.getStore().removeAll();g.hide();this.syncSize();this.center();}});Ext.reg('modx-window-element-property-create',MODx.window.CreateElementProperty);MODx.window.UpdateElementProperty=function(config){config=config||{};Ext.applyIf(config,{title:_('property_update'),id:'modx-window-element-property-update',height:250,width:650,saveBtnText:_('done'),forceLayout:true,fields:[{layout:'column',border:false,defaults:{layout:'form',labelAlign:'top',anchor:'100%',border:false},items:[{columnWidth:.6,items:[{fieldLabel:_('name'),description:MODx.expandHelp?'':_('property_name_desc'),name:'name',id:'modx-uep-name',xtype:'textfield',anchor:'100%'},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-uep-name',html:_('property_name_desc'),cls:'desc-under'},{fieldLabel:_('description'),description:MODx.expandHelp?'':_('property_description_desc'),name:'desc',id:'modx-uep-desc',xtype:'textarea',anchor:'100%'},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-uep-description',html:_('property_description_desc'),cls:'desc-under'}]},{columnWidth:.4,items:[{fieldLabel:_('type'),description:MODx.expandHelp?'':_('property_xtype_desc'),name:'xtype',xtype:'modx-combo-xtype',id:'modx-uep-xtype',anchor:'100%',listeners:{'select':{fn:function(cb){var g=Ext.getCmp('modx-uep-grid-element-property-options');if(!g)return;var v=cb.getValue();if(v=='list'){g.show();}else{g.hide();}
this.syncSize();},scope:this}}},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-uep-xtype',html:_('property_xtype_desc'),cls:'desc-under'},{xtype:'textfield',fieldLabel:_('lexicon'),description:MODx.expandHelp?'':_('property_lexicon_desc'),name:'lexicon',id:'modx-uep-lexicon',anchor:'100%',allowBlank:true},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-uep-lexicon',html:_('property_lexicon_desc'),cls:'desc-under'}]}]},{xtype:'hidden',name:'overridden',id:'modx-uep-overridden'},{xtype:'modx-element-value-field',xtypeField:'modx-uep-xtype',name:'value',id:'modx-uep-value',anchor:'100%'},{id:'modx-uep-grid-element-property-options',xtype:'modx-grid-element-property-options',autoHeight:true}]});MODx.window.UpdateElementProperty.superclass.constructor.call(this,config);this.on('show',this.onShow,this);};Ext.extend(MODx.window.UpdateElementProperty,MODx.Window,{submit:function(){var v=this.fp.getForm().getValues();var g=Ext.getCmp('modx-uep-grid-element-property-options');var opt=eval(g.encode());Ext.apply(v,{options:opt});if(this.fp.getForm().isValid()){if(this.fireEvent('success',v)){this.fp.getForm().reset();this.hide();return true;}}
return false;},onShow:function(){var g=Ext.getCmp('modx-uep-grid-element-property-options');if(!g)return;if(this.fp.getForm().findField('xtype').getValue()=='list'){g.show();}else{g.hide();}
g.getStore().removeAll();var gp=Ext.getCmp('modx-grid-element-properties');var rec=gp.getSelectionModel().getSelected();if(rec){var opt=rec.data.options;var opts=[];for(var x in opt){if(opt.hasOwnProperty(x)){opts.push([opt[x].text,opt[x].value]);}}
g.getStore().loadData(opts);}
this.syncSize();this.center();}});Ext.reg('modx-window-element-property-update',MODx.window.UpdateElementProperty);MODx.window.CreateElementPropertyOption=function(config){config=config||{};Ext.applyIf(config,{title:_('property_option_create'),id:'modx-window-element-property-option-create',height:250,width:450,saveBtnText:_('done'),fields:[{fieldLabel:_('name'),name:'text',id:'modx-cepo-text',xtype:'textfield',anchor:'100%'},{fieldLabel:_('value'),name:'value',id:'modx-cepo-value',xtype:'textfield',anchor:'100%'}]});MODx.window.CreateElementPropertyOption.superclass.constructor.call(this,config);};Ext.extend(MODx.window.CreateElementPropertyOption,MODx.Window,{submit:function(){if(this.fp.getForm().isValid()){if(this.fireEvent('success',this.fp.getForm().getValues())){this.fp.getForm().reset();this.hide();return true;}}
return false;}});Ext.reg('modx-window-element-property-option-create',MODx.window.CreateElementPropertyOption);MODx.combo.xType=function(config){config=config||{};Ext.applyIf(config,{store:new Ext.data.SimpleStore({fields:['d','v'],data:[[_('textfield'),'textfield'],[_('textarea'),'textarea'],[_('yesno'),'combo-boolean'],[_('date'),'datefield'],[_('list'),'list'],[_('integer'),'numberfield']]}),displayField:'d',valueField:'v',mode:'local',name:'xtype',hiddenName:'xtype',triggerAction:'all',editable:false,selectOnFocus:false,value:'textfield'});MODx.combo.xType.superclass.constructor.call(this,config);};Ext.extend(MODx.combo.xType,Ext.form.ComboBox);Ext.reg('modx-combo-xtype',MODx.combo.xType);MODx.form.ElementValueField=function(config){config=config||{};Ext.applyIf(config,{fieldLabel:_('value'),name:'value',xtype:'textfield'});MODx.form.ElementValueField.superclass.constructor.call(this,config);this.config=config;this.on('change',this.checkValue,this);};Ext.extend(MODx.form.ElementValueField,Ext.form.TextField,{checkValue:function(fld,nv,ov){var t=Ext.getCmp(this.config.xtypeField).getValue();var v=fld.getValue();if(t=='combo-boolean'){v=(v=='1'||v=='true'||v==1||v==true||v==_('yes')||v=='yes')?1:0;fld.setValue(v);}}});Ext.reg('modx-element-value-field',MODx.form.ElementValueField);MODx.combo.PropertySet=function(config){config=config||{};Ext.applyIf(config,{name:'propertyset',hiddenName:'propertyset',url:MODx.config.connectors_url+'element/propertyset.php',baseParams:{action:'getList'},displayField:'name',valueField:'id',fields:['id','name','description','properties'],editable:false,value:0,pageSize:10});MODx.combo.PropertySet.superclass.constructor.call(this,config);};Ext.extend(MODx.combo.PropertySet,MODx.combo.ComboBox);Ext.reg('modx-combo-property-set',MODx.combo.PropertySet);MODx.window.AddPropertySet=function(config){config=config||{};Ext.applyIf(config,{title:_('propertyset_add'),id:'modx-window-element-property-set-add',url:MODx.config.connectors_url+'element/propertyset.php',action:'associate',fields:[{xtype:'hidden',name:'elementId',id:'modx-aps-elementId'},{xtype:'hidden',name:'elementType',id:'modx-aps-elementType'},{html:_('propertyset_panel_desc'),cls:'panel-desc'},MODx.PanelSpacer,{xtype:'modx-combo-property-set',fieldLabel:_('propertyset'),name:'propertyset',id:'modx-aps-propertyset',anchor:'100%',baseParams:{action:'getList',showNotAssociated:true,elementId:config.record.elementId,elementType:config.record.elementType}},{xtype:'hidden',name:'propertyset_new',id:'modx-aps-propertyset-new',value:false},{xtype:'fieldset',title:_('propertyset_create_new'),autoHeight:true,checkboxToggle:true,collapsed:true,forceLayout:true,id:'modx-aps-propertyset-new-fs',listeners:{'expand':{fn:function(p){Ext.getCmp('modx-aps-propertyset-new').setValue(true);},scope:this},'collapse':{fn:function(p){Ext.getCmp('modx-aps-propertyset-new').setValue(false);},scope:this}},items:[{xtype:'textfield',fieldLabel:_('name'),name:'name',id:'modx-aps-name',anchor:'100%'},{xtype:'textarea',fieldLabel:_('description'),name:'description',id:'modx-aps-description',anchor:'100%',grow:true}]}]});MODx.window.AddPropertySet.superclass.constructor.call(this,config);};Ext.extend(MODx.window.AddPropertySet,MODx.Window);Ext.reg('modx-window-element-property-set-add',MODx.window.AddPropertySet);MODx.window.ImportProperties=function(config){config=config||{};Ext.applyIf(config,{title:_('properties_import'),id:'modx-window-properties-import',url:MODx.config.connectors_url+'element/index.php',action:'importProperties',fileUpload:true,saveBtnText:_('import'),fields:[{html:_('properties_import_msg'),id:'modx-impp-desc',border:false,cls:'panel-desc',style:'margin-bottom: 10px;'},{xtype:'textfield',fieldLabel:_('file'),name:'file',id:'modx-impp-file',anchor:'100%',inputType:'file'}]});MODx.window.ImportProperties.superclass.constructor.call(this,config);};Ext.extend(MODx.window.ImportProperties,MODx.Window);Ext.reg('modx-window-properties-import',MODx.window.ImportProperties);
;MODx.grid.TemplateTV=function(config){config=config||{};var tt=new Ext.ux.grid.CheckColumn({header:_('access'),dataIndex:'access',width:70,sortable:false});Ext.applyIf(config,{title:_('template_assignedtv_tab'),id:'modx-grid-template-tv',url:MODx.config.connectors_url+'element/template/tv.php',fields:['id','name','description','tv_rank','access','category_name','category'],baseParams:{action:'getList',template:config.template},saveParams:{template:config.template},width:800,paging:true,plugins:tt,remoteSort:true,columns:[{header:_('name'),dataIndex:'name',width:150,editor:{xtype:'textfield',allowBlank:false},sortable:true},{header:_('category'),dataIndex:'category_name',width:150,sortable:true},{header:_('description'),dataIndex:'description',width:350,editor:{xtype:'textfield'},sortable:false},tt,{header:_('rank'),dataIndex:'tv_rank',width:100,editor:{xtype:'textfield',allowBlank:false},sortable:true}],tbar:['->',{xtype:'modx-combo-category',name:'filter_category',hiddenName:'filter_category',id:'modx-temptv-filter-category',emptyText:_('filter_by_category'),value:'',allowBlank:true,width:150,listeners:{'select':{fn:this.filterByCategory,scope:this}}},'-',{xtype:'textfield',name:'search',id:'modx-temptv-search',emptyText:_('search_ellipsis'),listeners:{'change':{fn:this.search,scope:this},'render':{fn:function(cmp){new Ext.KeyMap(cmp.getEl(),{key:Ext.EventObject.ENTER,fn:function(){this.fireEvent('change',this.getValue());this.blur();return true;},scope:cmp});},scope:this}}},{xtype:'button',id:'modx-filter-clear',text:_('filter_clear'),listeners:{'click':{fn:this.clearFilter,scope:this}}}]});MODx.grid.TemplateTV.superclass.constructor.call(this,config);};Ext.extend(MODx.grid.TemplateTV,MODx.grid.Grid,{filterByCategory:function(cb,rec,ri){this.getStore().baseParams['category']=cb.getValue();this.getBottomToolbar().changePage(1);this.refresh();},search:function(tf,newValue,oldValue){var nv=newValue||tf;this.getStore().baseParams.search=Ext.isEmpty(nv)||Ext.isObject(nv)?'':nv;Ext.getCmp('modx-temptv-filter-category').setValue('');this.getBottomToolbar().changePage(1);this.refresh();return true;},clearFilter:function(){this.getStore().baseParams={action:'getList'};Ext.getCmp('modx-temptv-filter-category').reset();Ext.getCmp('modx-temptv-search').setValue('');this.getBottomToolbar().changePage(1);this.refresh();}});Ext.reg('modx-grid-template-tv',MODx.grid.TemplateTV);
;MODx.panel.Template=function(config){config=config||{record:{}};config.record=config.record||{};Ext.applyIf(config,{url:MODx.config.connectors_url+'element/template.php',baseParams:{},id:'modx-panel-template',cls:'container form-with-labels',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'),defaults:{border:false,msgTarget:'side'},layout:'form',id:'modx-template-form',labelWidth:150,items:[{html:'<p>'+_('template_msg')+'</p>',id:'modx-template-msg',bodyCssClass:'panel-desc'},{layout:'column',border:false,defaults:{layout:'form',labelAlign:'top',anchor:'100%',border:false,cls:'main-wrapper',labelSeparator:''},items:[{columnWidth:.6,items:[{xtype:'hidden',name:'id',id:'modx-template-id',value:config.template},{xtype:'hidden',name:'props',id:'modx-template-props',value:config.record.props||null},{xtype:'textfield',fieldLabel:_('name')+'<span class="required">*</span>',description:MODx.expandHelp?'':_('template_desc_name'),name:'templatename',id:'modx-template-templatename',anchor:'100%',maxLength:100,enableKeyEvents:true,allowBlank:false,value:config.record.templatename,listeners:{'keyup':{scope:this,fn:function(f,e){Ext.getCmp('modx-template-header').getEl().update('<h2>'+_('template')+': '+f.getValue()+'</h2>');}}}},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-template-templatename',html:_('template_desc_name'),cls:'desc-under'},{xtype:'textarea',fieldLabel:_('template_desc'),description:MODx.expandHelp?'':_('template_desc_description'),name:'description',id:'modx-template-description',anchor:'100%',maxLength:255,value:config.record.description||''},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-template-description',html:_('template_desc_description'),cls:'desc-under'},{xtype:'modx-combo-browser',browserEl:'modx-browser',fieldLabel:_('static_file'),description:MODx.expandHelp?'':_('static_file_msg'),name:'static_file',prependPath:false,prependUrl:false,hideFiles:false,openTo:config.record.openTo||'',id:'modx-template-static-file',anchor:'100%',maxLength:255,value:config.record.static_file||'',hidden:!config.record['static'],hideMode:'offsets'},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-template-static-file',id:'modx-template-static-file-help',html:_('static_file_msg'),cls:'desc-under',hidden:!config.record['static'],hideMode:'offsets'},{html:MODx.onTempFormRender,border:false}]},{columnWidth:.4,items:[{xtype:'modx-combo-category',fieldLabel:_('category'),description:MODx.expandHelp?'':_('template_desc_category'),name:'category',id:'modx-template-category',anchor:'100%',value:config.record.category||0},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-template-category',html:_('template_desc_category'),cls:'desc-under'},{xtype:'xcheckbox',boxLabel:_('template_lock'),description:_('template_lock_msg'),name:'locked',id:'modx-template-locked',inputValue:1,checked:config.record.locked||false},{xtype:'checkbox',boxLabel:_('clear_cache_on_save'),description:_('clear_cache_on_save_msg'),hideLabel:true,name:'clearCache',id:'modx-template-clear-cache',inputValue:1,checked:Ext.isDefined(config.record.clearCache)||true},{xtype:'xcheckbox',hideLabel:true,boxLabel:_('is_static'),description:MODx.expandHelp?'':_('is_static_msg'),name:'static',id:'modx-template-static',inputValue:1,checked:config.record['static']||false},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-template-static',id:'modx-template-static-help',html:_('is_static_msg'),cls:'desc-under'},{xtype:'modx-combo-source',fieldLabel:_('static_source'),description:MODx.expandHelp?'':_('static_source_msg'),name:'source',id:'modx-template-static-source',anchor:'100%',maxLength:255,value:config.record.source!=null?config.record.source:MODx.config.default_media_source,hidden:!config.record['static'],hideMode:'offsets',baseParams:{action:'getList',showNone:true,streamsOnly:true}},{xtype:MODx.expandHelp?'label':'hidden',forId:'modx-template-static-source',id:'modx-template-static-source-help',html:_('static_source_msg'),cls:'desc-under',hidden:!config.record['static'],hideMode:'offsets'}]}]},{xtype:'panel',border:false,layout:'form',cls:'main-wrapper',labelAlign:'top',items:[{xtype:'textarea',fieldLabel:_('template_code'),name:'content',id:'modx-template-content',anchor:'100%',height:400,value:config.record.content||''}]}]},{xtype:'modx-panel-element-properties',preventRender:true,collapsible:true,elementPanel:'modx-panel-template',elementId:config.template,elementType:'modTemplate',record:config.record},{title:_('template_variables'),itemId:'form-template',defaults:{autoHeight:true},layout:'form',items:[{html:'<p>'+_('template_tv_msg')+'</p>',bodyCssClass:'panel-desc',border:false},{xtype:'modx-grid-template-tv',cls:'main-wrapper',preventRender:true,anchor:'100%',template:config.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,config);var isStatic=Ext.getCmp('modx-template-static');if(isStatic){isStatic.on('check',this.toggleStaticFile);}};Ext.extend(MODx.panel.Template,MODx.FormPanel,{initialized:false,setup:function(){if(this.initialized){this.clearDirty();return true;}
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 d=this.config.record.properties;var g=Ext.getCmp('modx-grid-element-properties');if(g){g.defaultProperties=d;g.getStore().loadData(d);}}
this.fireEvent('ready',this.config.record);if(MODx.onLoadEditor){MODx.onLoadEditor(this);}
this.clearDirty();this.initialized=true;MODx.fireEvent('ready');return true;},beforeSubmit:function(o){var g=Ext.getCmp('modx-grid-template-tv');Ext.apply(o.form.baseParams,{tvs:g.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(r){if(MODx.request.id)Ext.getCmp('modx-grid-element-properties').save();Ext.getCmp('modx-grid-template-tv').getStore().commitChanges();this.getForm().setValues(r.result.object);var t=Ext.getCmp('modx-element-tree');if(t){var c=Ext.getCmp('modx-template-category').getValue();var u=c!=''&&c!=null&&c!=0?'n_template_category_'+c:'n_type_template';var node=t.getNodeById('n_template_element_'+Ext.getCmp('modx-template-id').getValue()+'_'+r.result.object.previous_category);if(node)node.destroy();t.refreshNode(u,true);}},changeEditor:function(){this.cleanupEditor();this.on('success',function(o){var id=o.result.object.id;var w=Ext.getCmp('modx-template-which-editor').getValue();MODx.request.a=MODx.action['element/template/update'];var u='?'+Ext.urlEncode(MODx.request)+'&which_editor='+w+'&id='+id;location.href=u;});this.submit();},cleanupEditor:function(){if(MODx.onSaveEditor){var fld=Ext.getCmp('modx-template-content');MODx.onSaveEditor(fld);}},toggleStaticFile:function(cb){var flds=['modx-template-static-file','modx-template-static-file-help','modx-template-static-source','modx-template-static-source-help'];var fld,i;if(cb.checked){for(i in flds){fld=Ext.getCmp(flds[i]);if(fld){fld.show();}}}else{for(i in flds){fld=Ext.getCmp(flds[i]);if(fld){fld.hide();}}}}});Ext.reg('modx-panel-template',MODx.panel.Template);
;MODx.page.UpdateTemplate=function(config){config=config||{};Ext.applyIf(config,{formpanel:'modx-panel-template',actions:{'new':MODx.action['element/template/create'],edit:MODx.action['element/template/update'],cancel:MODx.action['welcome']},buttons:[{process:'update',text:_('save'),method:'remote',checkDirty:true,keys:[{key:MODx.config.keymap_save||'s',ctrl:true}]},'-',{process:'cancel',text:_('cancel'),params:{a:MODx.action['welcome']}},'-',{text:_('help_ex'),handler:MODx.loadHelpPane}],loadStay:true,components:[{xtype:'modx-panel-template',renderTo:'modx-panel-template-div',template:config.id,record:config.record||{},baseParams:{action:'update',id:config.id}}]});MODx.page.UpdateTemplate.superclass.constructor.call(this,config);};Ext.extend(MODx.page.UpdateTemplate,MODx.Component);Ext.reg('modx-page-template-update',MODx.page.UpdateTemplate);