plugins.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. AdminTools.window.Plugins = function (config) {
  2. config = config || {};
  3. if (!config.id) {
  4. config.id = 'admintools-plugins-window';
  5. }
  6. Ext.applyIf(config, {
  7. url: adminToolsSettings.config.connector_url,
  8. title: _('plugins'),
  9. width: 1000,
  10. maxHeight: 800,
  11. height: 700,
  12. //autoHeight: true,
  13. stateful: true,
  14. //layout: 'fit',
  15. modal: true,
  16. maximizable: false,
  17. items: [{
  18. xtype: 'admintools-plugins-grid'
  19. }],
  20. buttons: [{
  21. text: _('admintools_close'),
  22. handler: function(){this.hide();},
  23. scope: this
  24. }]
  25. });
  26. AdminTools.window.Plugins.superclass.constructor.call(this, config);
  27. /*this.on('show',function() {
  28. this.center();
  29. },this);*/
  30. };
  31. Ext.extend(AdminTools.window.Plugins, MODx.Window);
  32. Ext.reg('admintools-plugins-window', AdminTools.window.Plugins);
  33. AdminTools.window.BindPlugin = function (config) {
  34. config = config || {};
  35. if (!config.id) {
  36. config.id = 'admintools-bind-plugin-window';
  37. }
  38. Ext.applyIf(config, {
  39. title: _('admintools_plugin_bind'),
  40. width: 400,
  41. autoHeight: true,
  42. modal: true,
  43. maximizable: false,
  44. url: adminToolsSettings.config.connector_url,
  45. action: 'mgr/plugins/bind',
  46. fields: [{
  47. xtype: 'admintools-combo-plugins',
  48. fieldLabel: _('admintools_plugin'),
  49. id: config.id + '-plugin',
  50. anchor: '100%',
  51. allowBlank: false
  52. }, {
  53. xtype: 'admintools-combo-events',
  54. fieldLabel: _('admintools_event'),
  55. name: 'event',
  56. id: config.id + '-event',
  57. anchor: '100%',
  58. allowBlank: false
  59. }, {
  60. xtype: 'numberfield',
  61. fieldLabel: _('admintools_priority'),
  62. name: 'priority',
  63. id: config.id + '-priority',
  64. anchor: '100%',
  65. allowBlank: true
  66. }],
  67. keys: [{
  68. key: Ext.EventObject.ENTER, shift: true, fn: function () {
  69. this.submit()
  70. }, scope: this
  71. }]
  72. });
  73. AdminTools.window.BindPlugin.superclass.constructor.call(this, config);
  74. };
  75. Ext.extend(AdminTools.window.BindPlugin, MODx.Window);
  76. Ext.reg('admintools-bind-plugin-window', AdminTools.window.BindPlugin);
  77. /** Plugins Table **/
  78. AdminTools.grid.Plugins = function (config) {
  79. config = config || {};
  80. if (!config.id) {
  81. config.id = 'admintools-plugins-grid';
  82. }
  83. Ext.applyIf(config, {
  84. url: adminToolsSettings.config.connector_url,
  85. baseParams: {
  86. action: 'mgr/plugins/getlist'
  87. },
  88. primaryKey: 'key',
  89. autosave: true,
  90. //sm: new Ext.grid.CheckboxSelectionModel(),
  91. fields: ['key','id','event','name','priority','catName','active','description','actions'],
  92. columns: [{
  93. header: 'Key',
  94. dataIndex: 'key',
  95. width: 80,
  96. hidden: true
  97. }, {
  98. /* header: 'ID',
  99. dataIndex: 'id',
  100. width: 80,
  101. fixed: false
  102. }, {*/
  103. header: _('admintools_event'),
  104. dataIndex: 'event',
  105. sortable: false,
  106. // hidden: true,
  107. width: 150
  108. }, {
  109. header: _('admintools_plugin'),
  110. dataIndex: 'name',
  111. sortable: false,
  112. width: 150
  113. }, {
  114. header: _('admintools_category'),
  115. dataIndex: 'catName',
  116. sortable: false,
  117. menuDisabled: true,
  118. width: 150
  119. }, {
  120. header: _('admintools_priority'),
  121. dataIndex: 'priority',
  122. sortable: false,
  123. editable: true,
  124. editor: {xtype: 'numberfield'},
  125. menuDisabled: true,
  126. width: 90
  127. }, {
  128. header: _('admintools_active'),
  129. dataIndex: 'active',
  130. renderer: AdminTools.utils.renderBoolean,
  131. fixed: true,
  132. menuDisabled: true,
  133. width: 90
  134. }, {
  135. header: '<i class="icon icon-cog"></i>',
  136. dataIndex: 'actions',
  137. renderer: AdminTools.utils.renderActions,
  138. sortable: false,
  139. width: 140,
  140. fixed: true,
  141. menuDisabled: true,
  142. id: 'actions'
  143. }],
  144. tbar: new Ext.Toolbar({
  145. style: {paddingRight:'20px'},
  146. items: [{
  147. text: '<i class="icon icon-plus"></i>',
  148. handler: this.createPlugin,
  149. scope: this
  150. }, {
  151. text: '',
  152. iconCls: 'icon-columns',
  153. tooltip: _('admintools_change_view'),
  154. // tooltipType: 'title',
  155. style: {width: '15px'},
  156. handler: function (b,e) {
  157. this.store.groupField = this.store.groupField == 'event' ? 'name' : 'event';
  158. this.store.sortInfo = {field: this.store.groupField, direction: 'ASC'};
  159. this.store.load();
  160. Ext.getCmp('admintools-view-toggle-btn').setIconClass('icon-plus-square-o');
  161. Ext.getCmp('admintools-view-toggle-btn').collapsed = false;
  162. },
  163. scope: this
  164. }, {
  165. id: 'admintools-view-toggle-btn',
  166. text: '',
  167. iconCls: 'icon-plus-square-o',
  168. tooltip: _('admintools_collapse_all'),
  169. // tooltipType: 'title',
  170. handler: this._toggleCollapsible,
  171. collapsed: false,
  172. style: {width: '15px'},
  173. scope: this
  174. }, '->', {
  175. xtype: 'trigger',
  176. onTriggerClick: this._clearEvent,
  177. triggerClass: 'x-field-trigger-clear',
  178. name: 'event',
  179. width: 200,
  180. id: 'admintools-filter-event-field',
  181. emptyText: _('admintools_event'),
  182. listeners: {
  183. render: {
  184. fn: function (tf) {
  185. tf.getEl().addKeyListener(Ext.EventObject.ENTER, function () {
  186. this._doSearch();
  187. }, this);
  188. }, scope: this
  189. },
  190. clearEvent: {
  191. fn: function(field) {
  192. field.setValue('');
  193. this._clearSearch(field, 'event');
  194. }, scope: this
  195. }
  196. }
  197. }, {
  198. xtype: 'trigger',
  199. onTriggerClick: this._clearQuery,
  200. triggerClass: 'x-field-trigger-clear',
  201. name: 'query',
  202. width: 200,
  203. id: 'admintools-filter-query-field',
  204. emptyText: _('admintools_plugin_category'),
  205. style: {marginRight:'15px'},
  206. listeners: {
  207. render: {
  208. fn: function (tf) {
  209. tf.getEl().addKeyListener(Ext.EventObject.ENTER, function () {
  210. this._doSearch();
  211. }, this);
  212. }, scope: this
  213. },
  214. clearQuery: {
  215. fn: function(field) {
  216. field.setValue('');
  217. this._clearSearch(field, 'query');
  218. }, scope: this
  219. }
  220. }
  221. }]
  222. }),
  223. listeners: {
  224. /*rowDblClick: function (grid, rowIndex, e) {
  225. var row = grid.store.getAt(rowIndex);
  226. this.openElement(grid,e,row);
  227. }*/
  228. },
  229. height: '100%',
  230. width: '100%',
  231. paging: false,
  232. pageSize: 0,
  233. remoteSort: true,
  234. //
  235. singleText: _('admintools_element'),
  236. pluralText: _('admintools_elements'),
  237. grouping: true,
  238. groupBy: 'event',
  239. sortBy: 'event',
  240. sortDir: 'ASC',
  241. tools: [{
  242. id: 'plus',
  243. qtip: _('admintools_expand_all'),
  244. handler: this.expandAll,
  245. scope: this
  246. },{
  247. id: 'minus',
  248. hidden: true,
  249. qtip: _('admintools_collapse_all'),
  250. handler: this.collapseAll,
  251. scope: this
  252. }],
  253. groupingConfig: {
  254. emptyText: 'Empty',
  255. // groupOnSort: false,
  256. hideGroupedColumn: true,
  257. forceFit: true,
  258. autoFill: true,
  259. showPreview: true,
  260. enableRowBody: false,
  261. scrollOffset: 0
  262. }
  263. });
  264. AdminTools.grid.Plugins.superclass.constructor.call(this, config);
  265. if (config.autosave) {
  266. this.on('afteredit',this.saveRecord,this);
  267. }
  268. };
  269. Ext.extend(AdminTools.grid.Plugins, MODx.grid.Grid, {
  270. getMenu: function (grid, rowIndex) {
  271. var ids = this._getSelectedIds();
  272. var row = grid.getStore().getAt(rowIndex);
  273. var menu = AdminTools.utils.getMenu(row.data['actions'], this, ids);
  274. this.addContextMenuItem(menu);
  275. },
  276. saveRecord: function(e) {
  277. var oldValue = +e.originalValue,
  278. newValue = e.value;
  279. if (oldValue==newValue || newValue === '') {
  280. e.record.reject();
  281. return false;
  282. }
  283. var id = e.record.data.key;
  284. id = id.substring(id.indexOf('_') + 1);
  285. MODx.Ajax.request({
  286. url: this.config.url,
  287. params: {
  288. action: 'mgr/plugins/updatefromgrid',
  289. priority: newValue,
  290. id: id,
  291. event: e.record.data.event
  292. },
  293. listeners: {
  294. success: {
  295. fn: function(r) {
  296. e.record.commit();
  297. this.refresh();
  298. this.fireEvent('afterAutoSave',r);
  299. }
  300. ,scope: this
  301. }
  302. ,failure: {
  303. fn: function(r) {
  304. e.record.reject();
  305. this.fireEvent('afterAutoSave', r);
  306. }
  307. ,scope: this
  308. }
  309. }
  310. });
  311. },
  312. createPlugin: function (btn, e) {
  313. var w = MODx.load({
  314. xtype: 'admintools-quick-create-plugin',
  315. listeners: {
  316. success: {
  317. fn: function () {
  318. AdminTools.treePluginNode.reload();
  319. this.refresh();
  320. }, scope: this
  321. },
  322. hide: {
  323. fn: function () {
  324. setTimeout(function (){w.destroy();},200);
  325. }, scope: this
  326. }
  327. }
  328. });
  329. w.reset();
  330. w.setValues({plugincode:"<?php\n",clearCache:true,formCode:true});
  331. w.show(e.target);
  332. },
  333. bindEvent: function (g,e) {
  334. var id = this.getSelectionModel().getSelected().data.key;
  335. id = id.substring(id.indexOf('_') + 1);
  336. this.bindAll(this, e, {pluginid:id, priority:0});
  337. },
  338. bindPlugin: function (g,e) {
  339. this.bindAll(this, e, {event:this.getSelectionModel().getSelected().data.event, priority:0});
  340. },
  341. bindAll: function (obj, e, data) {
  342. var w = MODx.load({
  343. xtype: 'admintools-bind-plugin-window',
  344. listeners: {
  345. success: {
  346. fn: function () {
  347. this.refresh();
  348. }, scope: this
  349. },
  350. hide: {
  351. fn: function () {
  352. setTimeout(function (){w.destroy();},200);
  353. }, scope: this
  354. }
  355. }
  356. });
  357. w.reset();
  358. w.setValues(data);
  359. w.show(e.target);
  360. },
  361. disablePlugin: function (act, btn, e) {
  362. var id = this.getSelectionModel().getSelected().data.key;
  363. id = id.substring(id.indexOf('_') + 1);
  364. MODx.Ajax.request({
  365. url: MODx.config.connectors_url,
  366. params: {
  367. action: 'element/plugin/deactivate',
  368. id: id
  369. },
  370. listeners: {
  371. success: {
  372. fn: function () {
  373. this.refresh();
  374. //Ext.getCmp('modx-tree-element').refreshParentNode();
  375. AdminTools.treePluginNode.reload();
  376. }, scope: this
  377. }
  378. }
  379. })
  380. },
  381. enablePlugin: function (act, btn, e) {
  382. var id = this.getSelectionModel().getSelected().data.key;
  383. id = id.substring(id.indexOf('_') + 1);
  384. MODx.Ajax.request({
  385. url: MODx.config.connectors_url,
  386. params: {
  387. action: 'element/plugin/activate',
  388. id: id
  389. },
  390. listeners: {
  391. success: {
  392. fn: function () {
  393. this.refresh();
  394. AdminTools.treePluginNode.reload();
  395. // Ext.getCmp('modx-tree-element').refreshParentNode();
  396. }, scope: this
  397. }
  398. }
  399. })
  400. },
  401. unbindPlugin: function (act, btn, e) {
  402. var data = this.getSelectionModel().getSelected().data,
  403. id = data.key,
  404. event = data.event;
  405. id = id.substring(id.indexOf('_') + 1);
  406. MODx.msg.confirm({
  407. title: _('warning'),
  408. text: _('admintools_plugin_unbind_confirm'),
  409. url: this.config.url,
  410. params: {
  411. action: 'mgr/plugins/unbind',
  412. id: id,
  413. event: event
  414. },
  415. listeners: {
  416. success: {
  417. fn: function (r) {
  418. this.refresh();
  419. }, scope: this
  420. }
  421. }
  422. });
  423. return true;
  424. },
  425. removePlugin: function (act, btn, e) {
  426. var data = this.getSelectionModel().getSelected().data,
  427. id = data.key;
  428. id = id.substring(id.indexOf('_') + 1);
  429. MODx.msg.confirm({
  430. title: _('warning'),
  431. text: _('admintools_plugin_remove_confirm'),
  432. url: MODx.config.connectors_url,
  433. params: {
  434. action: 'element/plugin/remove',
  435. id: id
  436. },
  437. listeners: {
  438. success: {
  439. fn: function (r) {
  440. this.refresh();
  441. AdminTools.treePluginNode.reload();
  442. }, scope: this
  443. }
  444. }
  445. });
  446. return true;
  447. },
  448. onClick: function (e) {
  449. var elem = e.getTarget();
  450. if (elem.nodeName == 'BUTTON') {
  451. var row = this.getSelectionModel().getSelected();
  452. if (typeof(row) != 'undefined') {
  453. var action = elem.getAttribute('action');
  454. if (action == 'showMenu') {
  455. var ri = this.getStore().find('key', row.data.key);
  456. return this._showMenu(this, ri, e);
  457. }
  458. else if (typeof this[action] === 'function') {
  459. this.menu.record = row.data;
  460. return this[action](this, e);
  461. }
  462. }
  463. }
  464. return this.processEvent('click', e);
  465. },
  466. _getSelectedIds: function () {
  467. var ids = [];
  468. var selected = this.getSelectionModel().getSelections();
  469. for (var i in selected) {
  470. if (!selected.hasOwnProperty(i)) {
  471. continue;
  472. }
  473. ids.push(selected[i]['data']['key']);
  474. }
  475. return ids;
  476. },
  477. _doSearch: function (tf, nv, ov) {
  478. this.getStore().baseParams.event = Ext.getCmp('admintools-filter-event-field').getValue();
  479. this.getStore().baseParams.query = Ext.getCmp('admintools-filter-query-field').getValue();
  480. // this.getBottomToolbar().changePage(1);
  481. this.refresh();
  482. },
  483. _clearEvent: function () {
  484. this.fireEvent('clearEvent', this);
  485. },
  486. _clearQuery: function () {
  487. this.fireEvent('clearQuery', this);
  488. },
  489. _clearSearch: function (field, param) {
  490. field.setValue('');
  491. this.getStore().baseParams[param] = '';
  492. this.refresh();
  493. },
  494. _toggleCollapsible: function (btn, e) {
  495. if (btn.collapsed) {
  496. btn.setIconClass('icon-plus-square-o');
  497. btn.setTooltip(_('admintools_collapse_all'));
  498. this.view.expandAllGroups();
  499. btn.collapsed = false;
  500. } else {
  501. btn.setIconClass('icon-minus-square-o');
  502. btn.setTooltip(_('admintools_expand_all'));
  503. this.view.collapseAllGroups();
  504. btn.collapsed = true;
  505. }
  506. }
  507. });
  508. Ext.reg('admintools-plugins-grid', AdminTools.grid.Plugins);
  509. Ext.onReady(function () {
  510. function showEventPluginButton() {
  511. if (typeof tree.nodeHash.n_type_plugin == 'undefined') return;
  512. var elId = tree.nodeHash.n_type_plugin.ui.elNode.id + '_tools';
  513. if (document.getElementById(elId)) {
  514. AdminTools.treePluginNode = tree.nodeHash.n_type_plugin;
  515. var btn = MODx.load({
  516. xtype: 'modx-button',
  517. text: '',
  518. tooltip: new Ext.ToolTip({
  519. title: _('admintools_events'),
  520. target: this
  521. }),
  522. node: AdminTools.treePluginNode,
  523. enableToggle: true,
  524. handler: function (btn, e) {
  525. e.stopEvent();
  526. var w = MODx.load({
  527. xtype: 'admintools-plugins-window',
  528. listeners: {
  529. hide: {
  530. fn: function () {
  531. setTimeout(function () {
  532. w.destroy()
  533. }, 200);
  534. }
  535. }
  536. }
  537. });
  538. w.show(Ext.EventObject.target, function () {
  539. Ext.isSafari ? w.setPosition(null, 30) : w.setPosition(null, 60);
  540. }, w);
  541. },
  542. iconCls: 'icon-list',
  543. listeners: {
  544. mouseover: function (button, e) {
  545. button.tooltip.onTargetOver(e);
  546. },
  547. mouseout: function (button, e) {
  548. button.tooltip.onTargetOut(e);
  549. }
  550. }
  551. });
  552. btn.render(elId, 0);
  553. clearInterval(interval);
  554. }
  555. }
  556. var tree = Ext.getCmp('modx-tree-element');
  557. if (tree) {
  558. if (tree.rendered) {
  559. var interval = setInterval(showEventPluginButton, 500);
  560. } else {
  561. tree.on('render', function () {
  562. setTimeout(showEventPluginButton, 500);
  563. });
  564. }
  565. }
  566. });
  567. /**************** Dialog **************************/
  568. AdminTools.window.QuickCreatePlugin = function(config) {
  569. config = config || {};
  570. Ext.applyIf(config,{
  571. title: _('quick_create_plugin'),
  572. width: 1000,
  573. autoHeight: true,
  574. layout: 'anchor',
  575. modal: true,
  576. stateful: false,
  577. url: adminToolsSettings.config.connector_url,
  578. action: 'mgr/plugins/create',
  579. fields: [{
  580. xtype: 'hidden',
  581. name: 'id'
  582. },{
  583. xtype: 'hidden',
  584. name: 'events'
  585. },{
  586. layout: 'column',
  587. border: false,
  588. defaults: {
  589. layout: 'form',
  590. labelAlign: 'top',
  591. anchor: '100%',
  592. border: false,
  593. style: {padding: '15px 0'},
  594. labelSeparator: ''
  595. },
  596. items: [{
  597. columnWidth: .5,
  598. items: [{
  599. xtype: 'textfield',
  600. name: 'name',
  601. fieldLabel: _('name'),
  602. anchor: '100%'
  603. }, {
  604. xtype: 'textarea',
  605. name: 'description',
  606. fieldLabel: _('description'),
  607. anchor: '100%',
  608. height: 92
  609. //,rows: 2
  610. }, {
  611. xtype: 'admintools-combo-events',
  612. fieldLabel: _('admintools_event'),
  613. name: 'event',
  614. id: 'admintools-combo-events',
  615. anchor: '100%',
  616. allowBlank: true,
  617. triggerConfig: {
  618. tag: 'span',
  619. cls: 'x-field-combo-btns',
  620. cn: [
  621. {tag: 'div', cls: 'x-form-trigger x-field-combo-events'},
  622. {tag: 'div', cls: 'x-form-trigger x-field-combo-event-add'}
  623. ]
  624. },
  625. onTriggerClick: function(event, btn){
  626. if (btn && Ext.get(btn).hasClass('x-field-combo-event-add')) {
  627. this.addEventElement();
  628. } else {
  629. AdminTools.combo.Events.superclass.onTriggerClick.call(this);
  630. }
  631. },
  632. addEventElement: function (event) {
  633. event = event || Ext.getCmp('admintools-combo-events').getValue();
  634. if (!event) return;
  635. var span = Ext.DomHelper.createDom({tag:'span',id:'event-'+event,cls:'x-superboxselect-item',html:event}),
  636. a = Ext.DomHelper.createDom({tag:'a',cls:'x-superboxselect-item-close',href:'#'});
  637. a.addEventListener('click', function (e) {
  638. this.parentNode.remove();
  639. });
  640. span.appendChild(a);
  641. if (!document.getElementById('event-'+event)) {
  642. document.getElementById('admintools-plugin-events').appendChild(span);
  643. }
  644. },
  645. listeners: {
  646. render: {
  647. fn: function (c) {
  648. var self = this;
  649. c.getEl().addKeyListener(Ext.EventObject.ENTER, function () {
  650. var event = c.getValue();
  651. if (!event || Ext.getCmp('admintools-combo-events').isExpanded()) return;
  652. Ext.getCmp('admintools-combo-events').addEventElement(event);
  653. }, this);
  654. }, scope: this
  655. }
  656. }
  657. }]
  658. },{
  659. columnWidth: .5,
  660. items: [{
  661. xtype: 'modx-combo-category',
  662. name: 'category',
  663. fieldLabel: _('category'),
  664. anchor: '100%'
  665. },{
  666. xtype: MODx.expandHelp ? 'label' : 'hidden',
  667. html: _('plugin_desc_category'),
  668. cls: 'desc-under',
  669. style: {marginBottom: '10px'}
  670. },{
  671. xtype: 'xcheckbox',
  672. name: 'disabled',
  673. boxLabel: _('disabled'),
  674. hideLabel: true,
  675. inputValue: 1,
  676. checked: false
  677. }, {
  678. xtype: 'xcheckbox',
  679. name: 'clearCache',
  680. hideLabel: true,
  681. boxLabel: _('clear_cache_on_save'),
  682. description: _('clear_cache_on_save_msg'),
  683. inputValue: 1,
  684. checked: true
  685. }, {
  686. xtype: 'button',
  687. id: 'admintools-plugin-formcode-btn',
  688. text: _('admintools_plugin_form_code'),
  689. tooltip: _('admintools_plugin_form_code_desc'),
  690. tooltipType: 'title',
  691. style: {marginTop:'10px'},
  692. handler: function () {
  693. var childNodes = document.getElementById('admintools-plugin-events').childNodes,
  694. count = childNodes.length;
  695. var code = "<?php\n";
  696. if (count) {
  697. code += "switch ($modx->event->name) {\n";
  698. for (var i = 0; i < count; i++) {
  699. code += "\tcase '"+childNodes[i].textContent+"':\n\t\tbreak;\n";
  700. }
  701. code += "}";
  702. }
  703. Ext.getCmp(config.id+'-plugincode').setValue(code);
  704. }
  705. }, {
  706. xtype: 'displayfield',
  707. fieldLabel: _('admintools_events'),
  708. // hideLabel: true,
  709. id: 'admintools-plugin-events',
  710. labelStyle: 'margin-top:0px;'
  711. }]
  712. }]
  713. }, {
  714. // xtype: 'textarea'
  715. xtype: Ext.ComponentMgr.types['modx-texteditor'] ? 'modx-texteditor' : 'textarea',
  716. mimeType: 'application/x-php',
  717. name: 'plugincode',
  718. id: config.id + '-plugincode',
  719. fieldLabel: _('code'),
  720. anchor: '100%',
  721. height: 280,
  722. labelStyle: 'padding-top:0;'
  723. // ,grow: true
  724. // ,growMax: 300
  725. }],
  726. keys: [{
  727. key: Ext.EventObject.ENTER,
  728. ctrl: true,
  729. fn: function(keyCode, event) {
  730. var elem = event.getTarget();
  731. var component = Ext.getCmp(elem.id);
  732. if (component instanceof Ext.form.TextArea) {
  733. return component.append("\n");
  734. } else {
  735. this.submit();
  736. }
  737. }
  738. ,scope: this
  739. }]
  740. });
  741. AdminTools.window.QuickCreatePlugin.superclass.constructor.call(this,config);
  742. this.on('beforesubmit', function () {
  743. var childNodes = document.getElementById('admintools-plugin-events').childNodes,
  744. count = childNodes.length,
  745. events = [];
  746. if (count) {
  747. for (var i = 0; i < count; i++) {
  748. events.push(childNodes[i].textContent);
  749. }
  750. }
  751. this.fp.getForm().findField('events').setValue(Ext.util.JSON.encode(events));
  752. });
  753. };
  754. Ext.extend(AdminTools.window.QuickCreatePlugin, MODx.Window, {
  755. addEventElement: function (event) {
  756. var span = Ext.DomHelper.createDom({tag:'span',id:'event-'+event,cls:'x-superboxselect-item',html:event}),
  757. a = Ext.DomHelper.createDom({tag:'a',cls:'x-superboxselect-item-close',href:'#'});
  758. a.addEventListener('click', function (e) {
  759. this.parentNode.remove();
  760. });
  761. span.appendChild(a);
  762. document.getElementById('admintools-plugin-events').appendChild(span);
  763. }
  764. });
  765. Ext.reg('admintools-quick-create-plugin', AdminTools.window.QuickCreatePlugin);
  766. /**************** Combos *************************/
  767. AdminTools.combo.Plugins = function(config) {
  768. config = config || {};
  769. Ext.applyIf(config, {
  770. fields: ['id', 'name'],
  771. valueField: 'id',
  772. displayField: 'name',
  773. name: 'pluginid',
  774. hiddenName: 'pluginid',
  775. url: adminToolsSettings.config.connector_url,
  776. baseParams: {
  777. action: 'mgr/plugins/getplugins'
  778. },
  779. pageSize: 20,
  780. typeAhead: true,
  781. editable: true,
  782. forceSelection: false,
  783. allowBlank: false
  784. });
  785. AdminTools.combo.Plugins.superclass.constructor.call(this, config);
  786. };
  787. Ext.extend(AdminTools.combo.Plugins, MODx.combo.ComboBox);
  788. Ext.reg('admintools-combo-plugins', AdminTools.combo.Plugins);
  789. AdminTools.combo.Events = function(config) {
  790. config = config || {};
  791. Ext.applyIf(config, {
  792. fields: ['name'],
  793. valueField: 'name',
  794. displayField: 'name',
  795. name: 'event',
  796. hiddenName: 'event',
  797. url: adminToolsSettings.config.connector_url,
  798. baseParams: {
  799. action: 'mgr/plugins/getevents'
  800. },
  801. pageSize: 20,
  802. typeAhead: false,
  803. editable: true,
  804. forceSelection: true,
  805. triggerAction: 'all'
  806. //
  807. });
  808. AdminTools.combo.Events.superclass.constructor.call(this, config);
  809. };
  810. Ext.extend(AdminTools.combo.Events, MODx.combo.ComboBox);
  811. Ext.reg('admintools-combo-events', AdminTools.combo.Events);