grid.resources.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. VersionX.grid.Resources = function(config) {
  2. config = config || {};
  3. Ext.applyIf(config,{
  4. url: VersionX.config.connector_url,
  5. id: 'versionx-grid-resources',
  6. baseParams: {
  7. action: 'mgr/resources/getlist',
  8. resource: (VersionX.inVersion) ? MODx.request['id'] : 0
  9. },
  10. params: [],
  11. viewConfig: {
  12. forceFit: true,
  13. enableRowBody: true,
  14. emptyText: _('versionx.error.noresults')
  15. },
  16. fields: [
  17. {name: 'version_id', type: 'int'},
  18. {name: 'content_id', type: 'int'},
  19. {name: 'saved', type: 'string'},
  20. {name: 'username', type: 'string'},
  21. {name: 'mode', type: 'string'},
  22. {name: 'marked', type: 'boolean'},
  23. {name: 'title', type: 'string'},
  24. {name: 'context_key', type: 'string'},
  25. {name: 'class', type: 'string'}
  26. ],
  27. paging: true,
  28. remoteSort: true,
  29. columns: [{
  30. header: _('versionx.version_id'),
  31. dataIndex: 'version_id',
  32. sortable: true,
  33. width: .1
  34. },{
  35. header: _('versionx.content_id',{what: _('resource')}),
  36. dataIndex: 'content_id',
  37. sortable: true,
  38. width: .1
  39. },{
  40. header: _('versionx.saved'),
  41. dataIndex: 'saved',
  42. sortable: true,
  43. width: .2
  44. },{
  45. header: _('versionx.title'),
  46. dataIndex: 'title',
  47. sortable: true,
  48. width: .4
  49. },{
  50. header: _('user'),
  51. dataIndex: 'username',
  52. sortable: true,
  53. width: .2
  54. },{
  55. header: _('versionx.mode'),
  56. dataIndex: 'mode',
  57. sortable: true,
  58. width: .1,
  59. renderer: function (val) { return _('versionx.mode.'+val); }
  60. },{
  61. header: _('versionx.marked'),
  62. dataIndex: 'marked',
  63. sortable: true,
  64. width: .1,
  65. hidden: true
  66. },{
  67. header: _('context'),
  68. dataIndex: 'context_key',
  69. sortable: true,
  70. width: .1
  71. },{
  72. header: _('class_key'),
  73. dataIndex: 'class',
  74. sortable: true,
  75. width: .2
  76. }]
  77. ,listeners: {}
  78. });
  79. VersionX.grid.Resources.superclass.constructor.call(this,config);
  80. };
  81. Ext.extend(VersionX.grid.Resources,MODx.grid.Grid,{
  82. getMenu: function() {
  83. var r = this.getSelectionModel().getSelected();
  84. var d = r.data;
  85. var m = [];
  86. m.push({
  87. text: _('versionx.menu.viewdetails'),
  88. handler: function() {
  89. var eid = d.version_id;
  90. var backTo = (VersionX.inVersion) ? '&backTo='+MODx.request['a']+'-'+MODx.request['id'] : '';
  91. MODx.loadPage('?namespace=versionx&a=resource&vid='+eid+backTo)
  92. }
  93. },'-',{
  94. text: _('versionx.resources.revert', {id: d.version_id}),
  95. handler: function() {
  96. this.revertVersion(d.version_id, d.content_id)
  97. },
  98. scope: this
  99. });
  100. return m;
  101. },
  102. revertVersion: function(version, content) {
  103. if (version < 1) { MODx.alert(_('error'), 'Version not properly defined: '+version); }
  104. MODx.msg.confirm({
  105. title: _('versionx.resources.revert.confirm'),
  106. text: _('versionx.resources.revert.confirm.text',{id: version}),
  107. url: VersionX.config.connector_url,
  108. params: {
  109. version_id: version,
  110. content_id: content,
  111. action: 'mgr/resources/revert'
  112. },
  113. listeners: {
  114. success: {fn: function() {
  115. MODx.msg.status({
  116. message: _('versionx.resources.reverted'),
  117. delay: 4
  118. });
  119. }, scope: this }
  120. }
  121. });
  122. }
  123. });
  124. Ext.reg('versionx-grid-resources',VersionX.grid.Resources);