AdminTools.window.Plugins = function (config) { config = config || {}; if (!config.id) { config.id = 'admintools-plugins-window'; } Ext.applyIf(config, { url: adminToolsSettings.config.connector_url, title: _('plugins'), width: 1000, maxHeight: 800, height: 700, //autoHeight: true, stateful: true, //layout: 'fit', modal: true, maximizable: false, items: [{ xtype: 'admintools-plugins-grid' }], buttons: [{ text: _('admintools_close'), handler: function(){this.hide();}, scope: this }] }); AdminTools.window.Plugins.superclass.constructor.call(this, config); /*this.on('show',function() { this.center(); },this);*/ }; Ext.extend(AdminTools.window.Plugins, MODx.Window); Ext.reg('admintools-plugins-window', AdminTools.window.Plugins); AdminTools.window.BindPlugin = function (config) { config = config || {}; if (!config.id) { config.id = 'admintools-bind-plugin-window'; } Ext.applyIf(config, { title: _('admintools_plugin_bind'), width: 400, autoHeight: true, modal: true, maximizable: false, url: adminToolsSettings.config.connector_url, action: 'mgr/plugins/bind', fields: [{ xtype: 'admintools-combo-plugins', fieldLabel: _('admintools_plugin'), id: config.id + '-plugin', anchor: '100%', allowBlank: false }, { xtype: 'admintools-combo-events', fieldLabel: _('admintools_event'), name: 'event', id: config.id + '-event', anchor: '100%', allowBlank: false }, { xtype: 'numberfield', fieldLabel: _('admintools_priority'), name: 'priority', id: config.id + '-priority', anchor: '100%', allowBlank: true }], keys: [{ key: Ext.EventObject.ENTER, shift: true, fn: function () { this.submit() }, scope: this }] }); AdminTools.window.BindPlugin.superclass.constructor.call(this, config); }; Ext.extend(AdminTools.window.BindPlugin, MODx.Window); Ext.reg('admintools-bind-plugin-window', AdminTools.window.BindPlugin); /** Plugins Table **/ AdminTools.grid.Plugins = function (config) { config = config || {}; if (!config.id) { config.id = 'admintools-plugins-grid'; } Ext.applyIf(config, { url: adminToolsSettings.config.connector_url, baseParams: { action: 'mgr/plugins/getlist' }, primaryKey: 'key', autosave: true, //sm: new Ext.grid.CheckboxSelectionModel(), fields: ['key','id','event','name','priority','catName','active','description','actions'], columns: [{ header: 'Key', dataIndex: 'key', width: 80, hidden: true }, { /* header: 'ID', dataIndex: 'id', width: 80, fixed: false }, {*/ header: _('admintools_event'), dataIndex: 'event', sortable: false, // hidden: true, width: 150 }, { header: _('admintools_plugin'), dataIndex: 'name', sortable: false, width: 150 }, { header: _('admintools_category'), dataIndex: 'catName', sortable: false, menuDisabled: true, width: 150 }, { header: _('admintools_priority'), dataIndex: 'priority', sortable: false, editable: true, editor: {xtype: 'numberfield'}, menuDisabled: true, width: 90 }, { header: _('admintools_active'), dataIndex: 'active', renderer: AdminTools.utils.renderBoolean, fixed: true, menuDisabled: true, width: 90 }, { header: '', dataIndex: 'actions', renderer: AdminTools.utils.renderActions, sortable: false, width: 140, fixed: true, menuDisabled: true, id: 'actions' }], tbar: new Ext.Toolbar({ style: {paddingRight:'20px'}, items: [{ text: '', handler: this.createPlugin, scope: this }, { text: '', iconCls: 'icon-columns', tooltip: _('admintools_change_view'), // tooltipType: 'title', style: {width: '15px'}, handler: function (b,e) { this.store.groupField = this.store.groupField == 'event' ? 'name' : 'event'; this.store.sortInfo = {field: this.store.groupField, direction: 'ASC'}; this.store.load(); Ext.getCmp('admintools-view-toggle-btn').setIconClass('icon-plus-square-o'); Ext.getCmp('admintools-view-toggle-btn').collapsed = false; }, scope: this }, { id: 'admintools-view-toggle-btn', text: '', iconCls: 'icon-plus-square-o', tooltip: _('admintools_collapse_all'), // tooltipType: 'title', handler: this._toggleCollapsible, collapsed: false, style: {width: '15px'}, scope: this }, '->', { xtype: 'trigger', onTriggerClick: this._clearEvent, triggerClass: 'x-field-trigger-clear', name: 'event', width: 200, id: 'admintools-filter-event-field', emptyText: _('admintools_event'), listeners: { render: { fn: function (tf) { tf.getEl().addKeyListener(Ext.EventObject.ENTER, function () { this._doSearch(); }, this); }, scope: this }, clearEvent: { fn: function(field) { field.setValue(''); this._clearSearch(field, 'event'); }, scope: this } } }, { xtype: 'trigger', onTriggerClick: this._clearQuery, triggerClass: 'x-field-trigger-clear', name: 'query', width: 200, id: 'admintools-filter-query-field', emptyText: _('admintools_plugin_category'), style: {marginRight:'15px'}, listeners: { render: { fn: function (tf) { tf.getEl().addKeyListener(Ext.EventObject.ENTER, function () { this._doSearch(); }, this); }, scope: this }, clearQuery: { fn: function(field) { field.setValue(''); this._clearSearch(field, 'query'); }, scope: this } } }] }), listeners: { /*rowDblClick: function (grid, rowIndex, e) { var row = grid.store.getAt(rowIndex); this.openElement(grid,e,row); }*/ }, height: '100%', width: '100%', paging: false, pageSize: 0, remoteSort: true, // singleText: _('admintools_element'), pluralText: _('admintools_elements'), grouping: true, groupBy: 'event', sortBy: 'event', sortDir: 'ASC', tools: [{ id: 'plus', qtip: _('admintools_expand_all'), handler: this.expandAll, scope: this },{ id: 'minus', hidden: true, qtip: _('admintools_collapse_all'), handler: this.collapseAll, scope: this }], groupingConfig: { emptyText: 'Empty', // groupOnSort: false, hideGroupedColumn: true, forceFit: true, autoFill: true, showPreview: true, enableRowBody: false, scrollOffset: 0 } }); AdminTools.grid.Plugins.superclass.constructor.call(this, config); if (config.autosave) { this.on('afteredit',this.saveRecord,this); } }; Ext.extend(AdminTools.grid.Plugins, MODx.grid.Grid, { getMenu: function (grid, rowIndex) { var ids = this._getSelectedIds(); var row = grid.getStore().getAt(rowIndex); var menu = AdminTools.utils.getMenu(row.data['actions'], this, ids); this.addContextMenuItem(menu); }, saveRecord: function(e) { var oldValue = +e.originalValue, newValue = e.value; if (oldValue==newValue || newValue === '') { e.record.reject(); return false; } var id = e.record.data.key; id = id.substring(id.indexOf('_') + 1); MODx.Ajax.request({ url: this.config.url, params: { action: 'mgr/plugins/updatefromgrid', priority: newValue, id: id, event: e.record.data.event }, listeners: { success: { fn: function(r) { e.record.commit(); this.refresh(); this.fireEvent('afterAutoSave',r); } ,scope: this } ,failure: { fn: function(r) { e.record.reject(); this.fireEvent('afterAutoSave', r); } ,scope: this } } }); }, createPlugin: function (btn, e) { var w = MODx.load({ xtype: 'admintools-quick-create-plugin', listeners: { success: { fn: function () { AdminTools.treePluginNode.reload(); this.refresh(); }, scope: this }, hide: { fn: function () { setTimeout(function (){w.destroy();},200); }, scope: this } } }); w.reset(); w.setValues({plugincode:"event->name) {\n"; for (var i = 0; i < count; i++) { code += "\tcase '"+childNodes[i].textContent+"':\n\t\tbreak;\n"; } code += "}"; } Ext.getCmp(config.id+'-plugincode').setValue(code); } }, { xtype: 'displayfield', fieldLabel: _('admintools_events'), // hideLabel: true, id: 'admintools-plugin-events', labelStyle: 'margin-top:0px;' }] }] }, { // xtype: 'textarea' xtype: Ext.ComponentMgr.types['modx-texteditor'] ? 'modx-texteditor' : 'textarea', mimeType: 'application/x-php', name: 'plugincode', id: config.id + '-plugincode', fieldLabel: _('code'), anchor: '100%', height: 280, labelStyle: 'padding-top:0;' // ,grow: true // ,growMax: 300 }], keys: [{ key: Ext.EventObject.ENTER, ctrl: true, fn: function(keyCode, event) { var elem = event.getTarget(); var component = Ext.getCmp(elem.id); if (component instanceof Ext.form.TextArea) { return component.append("\n"); } else { this.submit(); } } ,scope: this }] }); AdminTools.window.QuickCreatePlugin.superclass.constructor.call(this,config); this.on('beforesubmit', function () { var childNodes = document.getElementById('admintools-plugin-events').childNodes, count = childNodes.length, events = []; if (count) { for (var i = 0; i < count; i++) { events.push(childNodes[i].textContent); } } this.fp.getForm().findField('events').setValue(Ext.util.JSON.encode(events)); }); }; Ext.extend(AdminTools.window.QuickCreatePlugin, MODx.Window, { addEventElement: function (event) { var span = Ext.DomHelper.createDom({tag:'span',id:'event-'+event,cls:'x-superboxselect-item',html:event}), a = Ext.DomHelper.createDom({tag:'a',cls:'x-superboxselect-item-close',href:'#'}); a.addEventListener('click', function (e) { this.parentNode.remove(); }); span.appendChild(a); document.getElementById('admintools-plugin-events').appendChild(span); } }); Ext.reg('admintools-quick-create-plugin', AdminTools.window.QuickCreatePlugin); /**************** Combos *************************/ AdminTools.combo.Plugins = function(config) { config = config || {}; Ext.applyIf(config, { fields: ['id', 'name'], valueField: 'id', displayField: 'name', name: 'pluginid', hiddenName: 'pluginid', url: adminToolsSettings.config.connector_url, baseParams: { action: 'mgr/plugins/getplugins' }, pageSize: 20, typeAhead: true, editable: true, forceSelection: false, allowBlank: false }); AdminTools.combo.Plugins.superclass.constructor.call(this, config); }; Ext.extend(AdminTools.combo.Plugins, MODx.combo.ComboBox); Ext.reg('admintools-combo-plugins', AdminTools.combo.Plugins); AdminTools.combo.Events = function(config) { config = config || {}; Ext.applyIf(config, { fields: ['name'], valueField: 'name', displayField: 'name', name: 'event', hiddenName: 'event', url: adminToolsSettings.config.connector_url, baseParams: { action: 'mgr/plugins/getevents' }, pageSize: 20, typeAhead: false, editable: true, forceSelection: true, triggerAction: 'all' // }); AdminTools.combo.Events.superclass.constructor.call(this, config); }; Ext.extend(AdminTools.combo.Events, MODx.combo.ComboBox); Ext.reg('admintools-combo-events', AdminTools.combo.Events);