modx.grid.user.recent.resource.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Loads a grid of all the resources a user has recently edited.
  3. *
  4. * @class MODx.grid.RecentlyEditedResourcesByUser
  5. * @extends MODx.grid.Grid
  6. * @param {Object} config An object of options.
  7. * @xtype modx-grid-user-recent-resource
  8. */
  9. MODx.grid.RecentlyEditedResourcesByUser = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. title: _('recent_docs')
  13. ,url: MODx.config.connector_url
  14. ,baseParams: {
  15. action: 'security/user/getRecentlyEditedResources'
  16. ,user: config.user
  17. }
  18. ,autosave: true
  19. ,save_action: 'resource/updatefromgrid'
  20. ,pageSize: 10
  21. ,fields: ['id','pagetitle','description','editedon','deleted','published','context_key','menu', 'link']
  22. ,columns: [{
  23. header: _('id')
  24. ,dataIndex: 'id'
  25. ,width: 75
  26. ,fixed: true
  27. },{
  28. header: _('pagetitle')
  29. ,dataIndex: 'pagetitle'
  30. },{
  31. header: _('published')
  32. ,dataIndex: 'published'
  33. ,width: 120
  34. ,fixed: true
  35. ,editor: { xtype: 'combo-boolean' ,renderer: 'boolean' }
  36. }]
  37. ,paging: true
  38. ,listeners: {
  39. afteredit: this.refresh
  40. ,afterrender: this.onAfterRender
  41. ,scope: this
  42. }
  43. });
  44. MODx.grid.RecentlyEditedResourcesByUser.superclass.constructor.call(this,config);
  45. };
  46. Ext.extend(MODx.grid.RecentlyEditedResourcesByUser,MODx.grid.Grid,{
  47. preview: function() {
  48. window.open(this.menu.record.link);
  49. }
  50. ,refresh: function() {
  51. var tree = Ext.getCmp('modx-resource-tree');
  52. if (tree && tree.rendered) {
  53. tree.refresh();
  54. }
  55. }
  56. // Workaround to resize the grid when in a dashboard widget
  57. ,onAfterRender: function() {
  58. var cnt = Ext.getCmp('modx-content')
  59. // Dashboard widget "parent" (renderTo)
  60. ,parent = Ext.get('modx-grid-user-recent-resource');
  61. if (cnt && parent) {
  62. cnt.on('afterlayout', function(elem, layout) {
  63. var width = parent.getWidth();
  64. // Only resize when more than 500px (else let's use/enable the horizontal scrolling)
  65. if (width > 500) {
  66. this.setWidth(width);
  67. }
  68. }, this);
  69. }
  70. }
  71. });
  72. Ext.reg('modx-grid-user-recent-resource',MODx.grid.RecentlyEditedResourcesByUser);