elementlog.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. AdminTools.window.lastEditedElements = function (config) {
  2. config = config || {};
  3. if (!config.id) {
  4. config.id = 'admintools-led-window';
  5. }
  6. Ext.applyIf(config, {
  7. url: adminToolsSettings.config.connector_url,
  8. title: _('admintools_last_edited'),
  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-led-elements-grid'
  19. }],
  20. buttons: [{
  21. text: _('admintools_close'),
  22. //id: 'admintools-led-window-close-btn',
  23. handler: function(){this.hide();},
  24. scope: this
  25. }]
  26. });
  27. AdminTools.window.lastEditedElements.superclass.constructor.call(this, config);
  28. /*this.on('show',function() {
  29. this.center();
  30. },this);*/
  31. };
  32. Ext.extend(AdminTools.window.lastEditedElements, MODx.Window);
  33. Ext.reg('admintools-led-window', AdminTools.window.lastEditedElements);
  34. /**************************************************************/
  35. AdminTools.grid.lastEditedElements = function (config) {
  36. config = config || {};
  37. if (!config.id) {
  38. config.id = 'admintools-led-elements-table';
  39. }
  40. Ext.applyIf(config, {
  41. url: adminToolsSettings.config.connector_url,
  42. baseParams: {
  43. action: 'mgr/lastedited/getlist'
  44. },
  45. primaryKey: 'key',
  46. //sm: new Ext.grid.CheckboxSelectionModel(),
  47. viewConfig: {
  48. forceFit: true,
  49. enableRowBody: true,
  50. autoFill: true,
  51. showPreview: true,
  52. scrollOffset: 0
  53. },
  54. fields: ['key','classKey','name','item','occurred','username','actions'],
  55. columns: [{
  56. header: 'Key',
  57. dataIndex: 'key',
  58. width: 50,
  59. hidden: true
  60. }, {
  61. header: 'ID',
  62. dataIndex: 'item',
  63. fixed: true,
  64. width: 50
  65. }, {
  66. header: _('admintools_type'),
  67. dataIndex: 'classKey',
  68. sortable: true,
  69. width: 70
  70. }, {
  71. header: _('admintools_name'),
  72. dataIndex: 'name',
  73. sortable: false,
  74. width: 200
  75. }, {
  76. header: _('admintools_date'),
  77. dataIndex: 'occurred',
  78. sortable: true,
  79. width: 80
  80. }, {
  81. header: _('admintools_user'),
  82. dataIndex: 'username',
  83. sortable: true,
  84. width: 100
  85. }, {
  86. header: '<i class="icon icon-cog"></i>',
  87. dataIndex: 'actions',
  88. renderer: AdminTools.utils.renderActions,
  89. sortable: false,
  90. width: 40,
  91. fixed: true,
  92. id: 'actions'
  93. }],
  94. tbar: [{
  95. xtype: 'modx-combo-user',
  96. id: 'log-filter-user-id',
  97. //fieldLabel: _('user'),
  98. emptyText: _('user'),
  99. width: 200,
  100. listeners: {
  101. 'select': {fn: this._doSearch, scope: this}
  102. }
  103. },{
  104. xtype: 'datefield',
  105. emptyText: _('date_start'),
  106. id: 'log-filter-datestart',
  107. allowBlank: true,
  108. format: 'd.m.Y',
  109. startDay: 1,
  110. width: 140,
  111. listeners: {
  112. 'select': {fn: this._doSearch, scope: this},
  113. 'render': {
  114. fn: function (tf) {
  115. tf.getEl().addKeyListener(Ext.EventObject.ENTER, function () {
  116. this._doSearch();
  117. }, this);
  118. }, scope: this
  119. }
  120. }
  121. },{
  122. xtype: 'datefield',
  123. emptyText: _('date_end'),
  124. id: 'log-filter-dateend',
  125. format: 'd.m.Y',
  126. startDay: 1,
  127. allowBlank: true,
  128. width: 140,
  129. listeners: {
  130. 'select': {fn: this._doSearch, scope: this},
  131. 'render': {
  132. fn: function (tf) {
  133. tf.getEl().addKeyListener(Ext.EventObject.ENTER, function () {
  134. this._doSearch();
  135. }, this);
  136. }, scope: this
  137. }
  138. }
  139. }, {
  140. xtype: 'textfield',
  141. name: 'query',
  142. width: 200,
  143. id: 'log-filter-query-field',
  144. emptyText: _('admintools_element_name'),
  145. listeners: {
  146. 'render': {
  147. fn: function (tf) {
  148. tf.getEl().addKeyListener(Ext.EventObject.ENTER, function () {
  149. this._doSearch();
  150. }, this);
  151. }, scope: this
  152. }
  153. }
  154. }, {
  155. xtype: 'button',
  156. id: config.id + '-search-clear',
  157. text: '<i class="icon icon-times"></i>',
  158. listeners: {
  159. click: {fn: this._clearSearch, scope: this}
  160. }
  161. }],
  162. listeners: {
  163. rowDblClick: function (grid, rowIndex, e) {
  164. var row = grid.store.getAt(rowIndex);
  165. this.openElement(grid,e,row);
  166. }
  167. },
  168. height: '100%',
  169. paging: true,
  170. pageSize: 10,
  171. remoteSort: true
  172. });
  173. AdminTools.grid.lastEditedElements.superclass.constructor.call(this, config);
  174. };
  175. Ext.extend(AdminTools.grid.lastEditedElements, MODx.grid.Grid, {
  176. getMenu: function (grid, rowIndex) {
  177. var ids = this._getSelectedIds();
  178. var row = grid.getStore().getAt(rowIndex);
  179. var menu = AdminTools.utils.getMenu(row.data['actions'], this, ids);
  180. this.addContextMenuItem(menu);
  181. },
  182. openElement: function(o,e,row) {
  183. //row = row || this.getSelectionModel().getSelected();
  184. if (typeof(row) != 'undefined') {
  185. this.menu.record = row.data;
  186. }
  187. else if (!this.menu.record) {
  188. return false;
  189. }
  190. var grid = this,
  191. type = this.menu.record.classKey.toLowerCase().substring(3);
  192. if (type == 'templatevar') type = 'tv';
  193. MODx.Ajax.request({
  194. url: this.config.url,
  195. params: {
  196. action: 'mgr/lastedited/verify',
  197. classKey: this.menu.record.classKey,
  198. id: this.menu.record.item
  199. },
  200. listeners: {
  201. success: {
  202. fn: function(r) {
  203. MODx.loadPage('element/'+ type +'/update', 'id='+ this.menu.record.item);
  204. }
  205. ,scope: this
  206. }
  207. ,failure: {
  208. fn: function(r) {
  209. var oldFn = MODx.form.Handler.showError;
  210. MODx.form.Handler.showError = function(message) {
  211. if (message === '') {
  212. MODx.msg.hide();
  213. } else {
  214. Ext.MessageBox.show({
  215. title: _('error'),
  216. msg: message,
  217. buttons: Ext.MessageBox.OK,
  218. fn: function(btn) {
  219. MODx.form.Handler.showError = oldFn;
  220. }
  221. });
  222. }
  223. };
  224. }
  225. ,scope: this
  226. }
  227. }
  228. });
  229. },
  230. removeItem: function () {
  231. var ids = this._getSelectedIds();
  232. if (!ids.length) {
  233. return false;
  234. }
  235. MODx.msg.confirm({
  236. title: _('admintools_item_remove'),
  237. text: _('admintools_item_remove_confirm'),
  238. url: this.config.url,
  239. params: {
  240. action: 'mgr/lastedited/remove',
  241. ids: Ext.util.JSON.encode(ids)
  242. },
  243. listeners: {
  244. success: {
  245. fn: function (r) {
  246. this.refresh();
  247. }, scope: this
  248. }
  249. }
  250. });
  251. return true;
  252. },
  253. onClick: function (e) {
  254. var elem = e.getTarget();
  255. if (elem.nodeName == 'BUTTON') {
  256. var row = this.getSelectionModel().getSelected();
  257. if (typeof(row) != 'undefined') {
  258. var action = elem.getAttribute('action');
  259. if (action == 'showMenu') {
  260. var ri = this.getStore().find('eid', row.data.eid);
  261. return this._showMenu(this, ri, e);
  262. }
  263. else if (typeof this[action] === 'function') {
  264. this.menu.record = row.data;
  265. return this[action](this, e);
  266. }
  267. }
  268. }
  269. return this.processEvent('click', e);
  270. },
  271. _getSelectedIds: function () {
  272. var ids = [];
  273. var selected = this.getSelectionModel().getSelections();
  274. for (var i in selected) {
  275. if (!selected.hasOwnProperty(i)) {
  276. continue;
  277. }
  278. ids.push(selected[i]['data']['key']);
  279. }
  280. return ids;
  281. },
  282. _doSearch: function (tf, nv, ov) {
  283. this.getStore().baseParams.user = Ext.getCmp('log-filter-user-id').getValue();
  284. this.getStore().baseParams.query = Ext.getCmp('log-filter-query-field').getValue();
  285. this.getStore().baseParams.datestart = Ext.getCmp('log-filter-datestart').getValue();
  286. this.getStore().baseParams.dateend = Ext.getCmp('log-filter-dateend').getValue();
  287. //this.getStore().baseParams.query = tf.getValue();
  288. this.getBottomToolbar().changePage(1);
  289. //this.refresh();
  290. },
  291. _clearSearch: function (btn, e) {
  292. this.getStore().baseParams.query = '';
  293. this.getStore().baseParams.user = '';
  294. this.getStore().baseParams.datestart = '';
  295. this.getStore().baseParams.dateend = '';
  296. Ext.getCmp('log-filter-user-id').setValue('');
  297. Ext.getCmp('log-filter-query-field').setValue('');
  298. Ext.getCmp('log-filter-datestart').setValue('');
  299. Ext.getCmp('log-filter-dateend').setValue('');
  300. this.getBottomToolbar().changePage(1);
  301. //this.refresh();
  302. }
  303. });
  304. Ext.reg('admintools-led-elements-grid', AdminTools.grid.lastEditedElements);
  305. /** ******************************** **/
  306. Ext.onReady(function () {
  307. var tree = Ext.getCmp('modx-tree-element'),
  308. tbar = tree.topToolbar;
  309. tree.showLastEditedElements = function(){
  310. var w = MODx.load({
  311. xtype: 'admintools-led-window',
  312. id: Ext.id(),
  313. //closeAction: 'close',
  314. listeners: {
  315. hide: {fn: function () {setTimeout(function(){w.destroy()},200);}}
  316. }
  317. });
  318. w.show(Ext.EventObject.target,function() {
  319. Ext.isSafari ? w.setPosition(null,30) : w.setPosition(null,60);
  320. },this);
  321. };
  322. var arr = [];
  323. arr.push({xtype:'tbfill'});
  324. arr.push({
  325. cls: 'tree-last-edited',
  326. tooltip: {text: _('admintools_last_edited')},
  327. scope: tree,
  328. handler: function() {
  329. tree.showLastEditedElements();
  330. }
  331. });
  332. tbar.addButton(arr);
  333. tbar.doLayout();
  334. });