modx.grid.plugin.event.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /**
  2. * Loads a grid of Plugin Events
  3. *
  4. * @class MODx.grid.PluginEvent
  5. * @extends MODx.grid.Grid
  6. * @param {Object} config An object of options.
  7. * @xtype modx-grid-plugin-event
  8. */
  9. MODx.grid.PluginEvent = function(config) {
  10. config = config || {};
  11. this.ident = config.ident || 'grid-pluge'+Ext.id();
  12. var ec = new Ext.ux.grid.CheckColumn({
  13. header: _('enabled')
  14. ,dataIndex: 'enabled'
  15. ,editable: true
  16. ,width: 80
  17. ,sortable: true
  18. });
  19. Ext.applyIf(config,{
  20. title: _('system_events')
  21. ,id: 'modx-grid-plugin-event'
  22. ,url: MODx.config.connector_url
  23. ,baseParams: {
  24. action: 'element/plugin/event/getList'
  25. ,plugin: config.plugin
  26. ,limit: 0
  27. }
  28. ,saveParams: {
  29. plugin: config.plugin
  30. }
  31. ,enableColumnResize: true
  32. ,enableColumnMove: true
  33. ,primaryKey: 'name'
  34. ,fields: ['name','service','groupname','enabled','priority','propertyset','menu']
  35. ,paging: false
  36. ,pageSize: 0
  37. ,remoteSort: false
  38. ,singleText: _('event')
  39. ,pluralText: _('events')
  40. ,plugins: ec
  41. ,columns: [{
  42. header: _('name')
  43. ,dataIndex: 'name'
  44. ,id: 'modx-'+this.ident+'-col-name'
  45. ,width: 250
  46. ,sortable: true
  47. },ec
  48. ,{
  49. header: _('group')
  50. ,dataIndex: 'groupname'
  51. ,id: 'modx-'+this.ident+'-col-groupname'
  52. ,width: 200
  53. ,editor: { xtype: 'textfield' }
  54. ,sortable: true
  55. },{
  56. header: _('propertyset')
  57. ,dataIndex: 'propertyset'
  58. ,id: 'modx-'+this.ident+'-col-propertyset'
  59. ,width: 180
  60. ,editor: {
  61. xtype: 'modx-combo-property-set'
  62. ,renderer: true
  63. ,baseParams: {
  64. action: 'element/propertyset/getList'
  65. ,showAssociated: true
  66. ,elementId: config.plugin
  67. ,elementType: 'modPlugin'
  68. }
  69. }
  70. ,sortable: true
  71. },{
  72. header: _('priority')
  73. ,dataIndex: 'priority'
  74. ,id: 'modx-'+this.ident+'-priority'
  75. ,width: 100
  76. ,editor: { xtype: 'textfield' ,allowBlank: false }
  77. ,sortable: true
  78. }]
  79. ,tbar: ['->',{
  80. xtype: 'modx-combo-eventgroup'
  81. ,name: 'group'
  82. ,id: 'modx-plugin-event-filter-group'
  83. ,itemId: 'group'
  84. ,emptyText: _('group')+'...'
  85. ,width: 200
  86. ,listeners: {
  87. 'select': {fn:this.filterGroup,scope:this}
  88. }
  89. },{
  90. xtype: 'textfield'
  91. ,name: 'search'
  92. ,id: 'modx-plugin-event-search'
  93. ,cls: 'x-form-filter'
  94. ,emptyText: _('search_ellipsis')
  95. ,listeners: {
  96. 'change': {fn: this.search, scope: this}
  97. ,'render': {fn: function(cmp) {
  98. new Ext.KeyMap(cmp.getEl(), {
  99. key: Ext.EventObject.ENTER
  100. ,fn: this.blur
  101. ,scope: cmp
  102. });
  103. },scope:this}
  104. }
  105. },{
  106. xtype: 'button'
  107. ,id: 'modx-filter-clear'
  108. ,cls: 'x-form-filter-clear'
  109. ,text: _('filter_clear')
  110. ,listeners: {
  111. 'click': {fn: this.clearFilter, scope: this},
  112. 'mouseout': {fn: function () {this.removeClass('x-btn-focus')}}
  113. }
  114. }]
  115. });
  116. MODx.grid.PluginEvent.superclass.constructor.call(this,config);
  117. this.store.sortInfo = {
  118. field: 'enabled',
  119. direction: 'DESC'
  120. };
  121. this.addEvents('updateEvent');
  122. };
  123. Ext.extend(MODx.grid.PluginEvent,MODx.grid.Grid,{
  124. search: function(tf,newValue) {
  125. var nv = newValue || tf;
  126. this.getStore().baseParams.query = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  127. this.getStore().load();
  128. return true;
  129. }
  130. ,filterGroup: function (cb,nv,ov) {
  131. this.getStore().baseParams.group = Ext.isEmpty(nv) || Ext.isObject(nv) ? cb.getValue() : nv;
  132. this.getStore().load();
  133. return true;
  134. }
  135. ,clearFilter: function() {
  136. delete this.getStore().baseParams.query;
  137. delete this.getStore().baseParams.group;
  138. Ext.getCmp('modx-plugin-event-search').reset();
  139. Ext.getCmp('modx-plugin-event-filter-group').reset();
  140. this.getStore().load();
  141. }
  142. ,updateEvent: function(btn,e) {
  143. var r = this.menu.record;
  144. if (!this.windows.peu) {
  145. this.windows.peu = MODx.load({
  146. xtype: 'modx-window-plugin-event-update'
  147. ,record: r
  148. ,plugin: this.config.plugin
  149. ,listeners: {
  150. 'success': {fn:function(r) {
  151. this.refresh();
  152. this.fireEvent('updateEvent',r);
  153. },scope:this}
  154. }
  155. });
  156. }
  157. this.windows.peu.setValues(r);
  158. this.windows.peu.show(e.target);
  159. }
  160. });
  161. Ext.reg('modx-grid-plugin-event',MODx.grid.PluginEvent);
  162. MODx.window.UpdatePluginEvent = function(config) {
  163. config = config || {};
  164. this.ident = config.ident || 'upluge'+Ext.id();
  165. Ext.applyIf(config,{
  166. title: _('plugin_event_update')
  167. ,id: 'modx-window-plugin-event-update'
  168. ,url: MODx.config.connector_url
  169. ,action: 'element/plugin/event/associate'
  170. ,autoHeight: true // needed here or the window will always show a scrollbar
  171. ,width: 600
  172. ,fields: [{
  173. fieldLabel: _('name')
  174. ,name: 'name'
  175. ,id: 'modx-'+this.ident+'-name'
  176. ,xtype: 'statictextfield'
  177. ,anchor: '100%'
  178. ,submitValue: true
  179. },{
  180. xtype: 'modx-grid-plugin-event-assoc'
  181. ,id: 'modx-grid-'+this.ident+'-assoc'
  182. ,autoHeight: true
  183. ,plugin: config.plugin
  184. }]
  185. });
  186. MODx.window.UpdatePluginEvent.superclass.constructor.call(this,config);
  187. this.on('beforeSubmit',this.beforeSubmit,this);
  188. };
  189. Ext.extend(MODx.window.UpdatePluginEvent,MODx.Window,{
  190. onShow: function() {
  191. var evt = this.fp.getForm().findField('name').getValue();
  192. MODx.Ajax.request({
  193. url: MODx.config.connector_url
  194. ,params: {
  195. action: 'element/plugin/event/getAssoc'
  196. ,'event': evt
  197. }
  198. ,listeners: {
  199. 'success':{fn:function(r) {
  200. var data = r.results;
  201. var g = Ext.getCmp('modx-grid-'+this.ident+'-assoc');
  202. var s = g.getStore();
  203. s.removeAll();
  204. if (data.length > 0) {
  205. s.loadData(data);
  206. }
  207. },scope:this}
  208. }
  209. });
  210. }
  211. ,beforeSubmit: function(vs) {
  212. this.fp.getForm().baseParams = {
  213. action: 'element/plugin/event/associate'
  214. ,plugins: Ext.getCmp('modx-grid-'+this.ident+'-assoc').encode()
  215. };
  216. }
  217. });
  218. Ext.reg('modx-window-plugin-event-update',MODx.window.UpdatePluginEvent);
  219. MODx.grid.PluginEventAssoc = function(config) {
  220. config = config || {};
  221. this.ident = config.ident || 'grid-pluge-assoc'+Ext.id();
  222. Ext.applyIf(config,{
  223. title: _('plugins')
  224. ,id: this.ident
  225. ,url: MODx.config.connector_url
  226. ,baseParams: {
  227. action: 'element/plugin/event/getPlugins'
  228. ,plugin: config.plugin
  229. }
  230. ,saveParams: {
  231. plugin: config.plugin
  232. }
  233. ,fields: ['id','name','priority','propertyset']
  234. ,pluginRecord: [{name:'id'},{name:'name'},{name:'priority'},{name:'propertyset'}]
  235. ,paging: true
  236. ,remoteSort: true
  237. ,columns: [{
  238. header: _('id')
  239. ,dataIndex: 'id'
  240. ,width: 80
  241. ,sortable: true
  242. },{
  243. header: _('plugin')
  244. ,dataIndex: 'name'
  245. ,width: 150
  246. ,sortable: true
  247. },{
  248. header: _('propertyset')
  249. ,dataIndex: 'propertyset'
  250. ,width: 150
  251. ,editor: {
  252. xtype: 'modx-combo-property-set'
  253. ,renderer: true
  254. ,baseParams: {
  255. action: 'element/propertyset/getList'
  256. ,showAssociated: true
  257. ,elementId: config.plugin
  258. ,elementType: 'modPlugin'
  259. }
  260. }
  261. },{
  262. header: _('priority')
  263. ,dataIndex: 'priority'
  264. ,width: 100
  265. ,editor: { xtype: 'textfield' ,allowBlank: false }
  266. }]
  267. ,tbar: [{
  268. text: _('plugin_add')
  269. ,cls: 'primary-button'
  270. ,handler: this.addPlugin
  271. ,scope: this
  272. }]
  273. });
  274. MODx.grid.PluginEventAssoc.superclass.constructor.call(this,config);
  275. this.pluginRecord = Ext.data.Record.create(config.pluginRecord);
  276. };
  277. Ext.extend(MODx.grid.PluginEventAssoc,MODx.grid.LocalGrid,{
  278. addPlugin: function(btn,e) {
  279. this.loadWindow(btn,e,{
  280. xtype: 'modx-window-plugin-event-add-plugin'
  281. ,record: this.menu.record
  282. ,plugin: this.config.plugin
  283. ,listeners: {
  284. 'success': {fn:function(r) {
  285. var rec = new this.pluginRecord({
  286. id: r.id
  287. ,name: r.name
  288. ,priority: r.priority
  289. ,propertyset: r.propertyset
  290. });
  291. this.getStore().add(rec);
  292. },scope:this}
  293. }
  294. });
  295. }
  296. ,_showMenu: function(g,ri,e) {
  297. var sm = this.getSelectionModel();
  298. e.stopEvent();
  299. e.preventDefault();
  300. if (!sm.isSelected(ri)) {
  301. sm.selectRow(ri);
  302. }
  303. this.menu.removeAll();
  304. this.addContextMenuItem([{
  305. text: _('remove')
  306. ,handler: this.remove.createDelegate(this,[{
  307. title: _('warning')
  308. ,text: _('plugin_event_plugin_remove_confirm')
  309. }])
  310. ,scope: this
  311. }]);
  312. this.menu.show(e.target);
  313. }
  314. });
  315. Ext.reg('modx-grid-plugin-event-assoc',MODx.grid.PluginEventAssoc);
  316. MODx.window.AddPluginToEvent = function(config) {
  317. config = config || {};
  318. this.ident = config.ident || 'apluge'+Ext.id();
  319. Ext.applyIf(config,{
  320. title: _('plugin_add_to_event')
  321. ,id: this.ident
  322. ,url: MODx.config.connector_url
  323. ,action: 'element/plugin/event/addplugin'
  324. ,autoHeight: true
  325. // ,height: 250
  326. // ,width: 600
  327. ,fields: [{
  328. xtype: 'modx-combo-plugin'
  329. ,fieldLabel: _('plugin')
  330. ,name: 'plugin'
  331. ,id: 'modx-'+this.ident+'-plugin'
  332. ,anchor: '100%'
  333. ,allowBlank: false
  334. },{
  335. xtype: 'numberfield'
  336. ,name: 'priority'
  337. ,fieldLabel: _('priority')
  338. ,id: 'modx-'+this.ident+'-priority'
  339. ,value: 0
  340. ,allowBlank: false
  341. ,anchor: '100%'
  342. }]
  343. });
  344. MODx.window.AddPluginToEvent.superclass.constructor.call(this,config);
  345. };
  346. Ext.extend(MODx.window.AddPluginToEvent,MODx.Window,{
  347. submit: function() {
  348. var f = this.fp.getForm();
  349. var vs = f.getValues();
  350. var cb = f.findField('plugin');
  351. vs.id = cb.getValue();
  352. vs.name = cb.getRawValue();
  353. if (this.fp.getForm().isValid()) {
  354. if (this.fireEvent('success',vs)) {
  355. this.fp.getForm().reset();
  356. this.hide();
  357. return true;
  358. }
  359. }
  360. return false;
  361. }
  362. });
  363. Ext.reg('modx-window-plugin-event-add-plugin',MODx.window.AddPluginToEvent);
  364. MODx.combo.Plugin = function(config) {
  365. config = config || {};
  366. Ext.applyIf(config,{
  367. url: MODx.config.connector_url
  368. ,baseParams: {
  369. action: 'element/plugin/getlist'
  370. }
  371. ,fields: ['id','name','description']
  372. ,name: 'plugin'
  373. ,hiddenName: 'plugin'
  374. ,displayField: 'name'
  375. ,valueField: 'id'
  376. ,editable: false
  377. ,tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><span style="font-weight: bold">{name:htmlEncode}</span>'
  378. ,'<br />{description:htmlEncode}</div></tpl>')
  379. });
  380. MODx.combo.Plugin.superclass.constructor.call(this,config);
  381. };
  382. Ext.extend(MODx.combo.Plugin,MODx.combo.ComboBox);
  383. Ext.reg('modx-combo-plugin',MODx.combo.Plugin);