themed_templates.grid.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. fred.grid.ThemedTemplates = function (config) {
  2. config = config || {};
  3. config.permission = config.permission || {};
  4. if (!config.permission.fred_themed_templates_save && !config.permission.fred_themed_templates_delete) {
  5. config.showGear = false;
  6. }
  7. Ext.applyIf(config, {
  8. url: fred.config.connectorUrl,
  9. baseParams: {
  10. action: 'mgr/themed_templates/getlist'
  11. },
  12. preventSaveRefresh: false,
  13. fields: ['id', 'theme', 'template', 'theme_name', 'template_templatename'],
  14. paging: true,
  15. remoteSort: true,
  16. emptyText: _('fred.themes.none'),
  17. columns: [
  18. {
  19. header: _('id'),
  20. dataIndex: 'id',
  21. sortable: true,
  22. hidden: true
  23. },
  24. {
  25. header: _('fred.themed_templates.template'),
  26. dataIndex: 'template_templatename',
  27. sortable: true,
  28. width: 80
  29. },
  30. {
  31. header: _('fred.themed_templates.theme'),
  32. dataIndex: 'theme_name',
  33. sortable: true,
  34. width: 80
  35. }
  36. ],
  37. tbar: this.getTbar(config)
  38. });
  39. fred.grid.ThemedTemplates.superclass.constructor.call(this, config);
  40. fred.globalEvents.on('delete-theme', function(theme) {
  41. this.getBottomToolbar().changePage(1);
  42. }, this);
  43. };
  44. Ext.extend(fred.grid.ThemedTemplates, fred.grid.GearGrid, {
  45. getMenu: function () {
  46. var m = [];
  47. if (this.config.permission.fred_themed_templates_save) {
  48. m.push({
  49. text: _('fred.themed_templates.update'),
  50. handler: this.updateTheme
  51. });
  52. }
  53. if (this.config.permission.fred_themed_templates_delete) {
  54. if (m.length > 0) {
  55. m.push('-');
  56. }
  57. m.push({
  58. text: _('fred.themed_templates.remove'),
  59. handler: this.unassignTheme
  60. });
  61. }
  62. return m;
  63. },
  64. getTbar: function(config) {
  65. var output = [];
  66. if (config.permission.fred_themed_templates_save) {
  67. output.push({
  68. text: _('fred.themed_templates.create'),
  69. handler: this.assignTheme
  70. });
  71. }
  72. return output;
  73. },
  74. assignTheme: function (btn, e) {
  75. var assignTheme = MODx.load({
  76. xtype: 'fred-window-themed-template',
  77. listeners: {
  78. success: {
  79. fn: function () {
  80. this.refresh();
  81. },
  82. scope: this
  83. }
  84. }
  85. });
  86. assignTheme.show(e.target);
  87. return true;
  88. },
  89. updateTheme: function (btn, e) {
  90. this.menu.record.template_value = this.menu.record.template;
  91. var updateTheme = MODx.load({
  92. xtype: 'fred-window-themed-template',
  93. title: _('fred.themed_templates.update'),
  94. action: 'mgr/themed_templates/update',
  95. isUpdate: true,
  96. record: this.menu.record,
  97. listeners: {
  98. success: {
  99. fn: function () {
  100. this.refresh();
  101. },
  102. scope: this
  103. }
  104. }
  105. });
  106. // updateTheme.fp.getForm().reset();
  107. updateTheme.fp.getForm().setValues(this.menu.record);
  108. updateTheme.show(e.target);
  109. return true;
  110. },
  111. unassignTheme: function (btn, e) {
  112. if (!this.menu.record) return false;
  113. MODx.msg.confirm({
  114. title: _('fred.themed_templates.remove'),
  115. text: _('fred.themed_templates.remove_confirm', {template: this.menu.record.template_templatename, theme: this.menu.record.theme_name}),
  116. url: this.config.url,
  117. params: {
  118. action: 'mgr/themed_templates/remove',
  119. template: this.menu.record.template
  120. },
  121. listeners: {
  122. success: {
  123. fn: function (r) {
  124. this.refresh();
  125. },
  126. scope: this
  127. }
  128. }
  129. });
  130. return true;
  131. },
  132. search: function (field, value) {
  133. var s = this.getStore();
  134. s.baseParams.search = value;
  135. this.getBottomToolbar().changePage(1);
  136. },
  137. filterCombo: function (combo, record) {
  138. var s = this.getStore();
  139. s.baseParams[combo.filterName] = record.data.v;
  140. this.getBottomToolbar().changePage(1);
  141. }
  142. });
  143. Ext.reg('fred-grid-themed-templates', fred.grid.ThemedTemplates);