Ext.namespace('MODx.panel'); MODx.Panel = function(config) { config = config || {}; Ext.applyIf(config,{ cls: 'modx-panel' ,title: '' }); MODx.Panel.superclass.constructor.call(this,config); this.config = config; }; Ext.extend(MODx.Panel,Ext.Panel); Ext.reg('modx-panel',MODx.Panel); MODx.FormPanel = function(config) { config = config || {}; Ext.applyIf(config,{ autoHeight: true ,collapsible: true ,bodyStyle: '' ,layout: 'anchor' ,border: false ,header: false ,method: 'POST' ,cls: 'modx-form' ,allowDrop: true ,errorReader: MODx.util.JSONReader ,checkDirty: true ,useLoadingMask: false ,defaults: { collapsible: false ,autoHeight: true, border: false } }); if (config.items) { this.addChangeEvent(config.items); } MODx.FormPanel.superclass.constructor.call(this,config); this.config = config; this.addEvents({ setup: true ,fieldChange: true ,ready: true ,beforeSubmit: true ,success: true ,failure: true ,save: true ,actionNew: true ,actionContinue: true ,actionClose: true ,postReady: true }); this.getForm().addEvents({ success: true ,failure: true }); this.dropTargets = []; this.on('ready',this.onReady); if (this.config.useLoadingMask) { this.on('render', function() { this.mask = new Ext.LoadMask(this.getEl()); this.mask.show(); }); } if (this.fireEvent('setup',config)) { this.clearDirty(); } this.focusFirstField(); }; Ext.extend(MODx.FormPanel,Ext.FormPanel,{ isReady: false ,defaultValues: [] ,initialized: false ,submit: function(o) { var fm = this.getForm(); if (fm.isValid() || o.bypassValidCheck) { o = o || {}; o.headers = { 'Powered-By': 'MODx' ,'modAuth': MODx.siteId }; if (this.fireEvent('beforeSubmit',{ form: fm ,options: o ,config: this.config })) { fm.submit({ waitMsg: this.config.saveMsg || _('saving') ,scope: this ,headers: o.headers ,clientValidation: (o.bypassValidCheck ? false : true) ,failure: function(f,a) { if (this.fireEvent('failure',{ form: f ,result: a.result ,options: o ,config: this.config })) { MODx.form.Handler.errorExt(a.result,f); } } ,success: function(f,a) { if (this.config.success) { Ext.callback(this.config.success,this.config.scope || this,[f,a]); } this.fireEvent('success',{ form:f ,result:a.result ,options:o ,config:this.config }); this.clearDirty(); this.fireEvent('setup',this.config); //get our Active input value and keep focus var lastActiveEle = Ext.state.Manager.get('curFocus'); if (lastActiveEle && lastActiveEle != '') { Ext.state.Manager.clear('curFocus'); var initFocus = document.getElementById(lastActiveEle); if(initFocus) initFocus.focus(); } } }); } } else { return false; } return true; } ,focusFirstField: function() { if (this.getForm().items.getCount() > 0) { var fld = this.findFirstTextField(); if (fld) { fld.focus(false,200); } } } ,findFirstTextField: function(i) { i = i || 0; var fld = this.getForm().items.itemAt(i); if (!fld) return false; if (fld.isXType('combo') || fld.isXType('checkbox') || fld.isXType('radio') || fld.isXType('displayfield') || fld.isXType('statictextfield') || fld.isXType('hidden')) { i = i+1; fld = this.findFirstTextField(i); } return fld; } ,addChangeEvent: function(items) { if (!items) { return false; } if (typeof(items) == 'object' && items.items) { items = items.items; } for (var f=0;f' ,border: false }; /** * A template panel base class * * @class MODx.TemplatePanel * @extends Ext.Panel * @param {Object} config An object of options. * @xtype modx-template-panel */ MODx.TemplatePanel = function(config) { config = config || {}; Ext.applyIf(config,{ frame:false ,startingMarkup: '' +'

{text}

' +'
' ,startingText: 'Loading...' ,markup: null ,plain:true ,border: false }); MODx.TemplatePanel.superclass.constructor.call(this,config); this.on('render', this.init, this); } Ext.extend(MODx.TemplatePanel,Ext.Panel,{ init: function(){ this.defaultMarkup = new Ext.XTemplate(this.startingMarkup, { compiled: true }); this.reset(); this.tpl = new Ext.XTemplate(this.markup, { compiled: true }); } ,reset: function(){ this.body.hide(); this.defaultMarkup.overwrite(this.body, {text: this.startingText}); this.body.slideIn('r', {stopFx:true, duration:.2}); setTimeout(function(){ Ext.getCmp('modx-content').doLayout(); }, 500); } ,updateDetail: function(data) { this.body.hide(); this.tpl.overwrite(this.body, data); this.body.slideIn('r', {stopFx:true, duration:.2}); setTimeout(function(){ Ext.getCmp('modx-content').doLayout(); }, 500); } }); Ext.reg('modx-template-panel',MODx.TemplatePanel); /** * A breacrumb builder + the panel desc if necessary * * @class MODx.BreadcrumbsPanel * @extends Ext.Panel * @param {Object} config An object of options. * @xtype modx-breadcrumbs-panel */ MODx.BreadcrumbsPanel = function(config) { config = config || {}; Ext.applyIf(config,{ frame:false ,plain:true ,border: false ,desc: 'This the description part of this panel' ,bdMarkup: '' +'
    ' +'' +'' +'' +'' +'' +'' +'' +'' +'{text}' +'' +'' +'
' +'
' +'' +'

{text}

' +'
' ,root : { text : 'Home' ,className: 'first' ,root: true ,pnl: '' } ,bodyCssClass: 'breadcrumbs' }); MODx.BreadcrumbsPanel.superclass.constructor.call(this,config); this.on('render', this.init, this); } Ext.extend(MODx.BreadcrumbsPanel,Ext.Panel,{ data: {trail: []} ,init: function(){ this.tpl = new Ext.XTemplate(this.bdMarkup, { compiled: true }); this.reset(this.desc); this.body.on('click', this.onClick, this); } ,getResetText: function(srcInstance){ if(typeof(srcInstance) != 'object' || srcInstance == null){ return srcInstance; } var newInstance = srcInstance.constructor(); for(var i in srcInstance){ newInstance[i] = this.getResetText(srcInstance[i]); } //The trail is not a link if(newInstance.hasOwnProperty('pnl')){ delete newInstance['pnl']; } return newInstance; } ,updateDetail: function(data){ this.data = data; // Automagically the trail root if(data.hasOwnProperty('trail')){ var trail = data.trail; trail.unshift(this.root); } this._updatePanel(data); } ,getData: function() { return this.data; } ,reset: function(msg){ if(typeof(this.resetText) == "undefined"){ this.resetText = this.getResetText(this.root); } this.data = { text : msg ,trail : [this.resetText] }; this._updatePanel(this.data); } ,onClick: function(e){ var target = e.getTarget(); var index = 1; var parent = target.parentElement; while ((parent = parent.previousSibling) != null) { index += 1; } var remove = this.data.trail.length - index; while (remove > 0) { this.data.trail.pop(); remove -= 1; } elm = target.className.split(' ')[0]; if(elm != "" && elm == 'controlBtn'){ // Don't use "pnl" shorthand, it make the breadcrumb fail var panel = target.className.split(' ')[1]; if (panel == 'install') { var last = this.data.trail[this.data.trail.length - 1]; if (last != undefined && last.rec != undefined) { this.data.trail.pop(); var grid = Ext.getCmp('modx-package-grid'); grid.install(last.rec); return; } } else { Ext.getCmp(panel).activate(); } } } ,_updatePanel: function(data){ this.body.hide(); this.tpl.overwrite(this.body, data); this.body.slideIn('r', {stopFx:true, duration:.2}); setTimeout(function(){ Ext.getCmp('modx-content').doLayout(); }, 500); } }); Ext.reg('modx-breadcrumbs-panel',MODx.BreadcrumbsPanel);