grid.settings.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. ClientConfig.grid.Settings = function(config) {
  2. config = config || {};
  3. Ext.applyIf(config, {
  4. // Basic Grid Configuration
  5. url: ClientConfig.config.connectorUrl,
  6. id: 'clientconfig-grid-settings',
  7. baseParams: {
  8. action: 'mgr/settings/getlist'
  9. },
  10. save_action: 'mgr/settings/updatefromgrid',
  11. autosave: true,
  12. emptyText: _('clientconfig.error.noresults'),
  13. paging: true,
  14. remoteSort: true,
  15. // Available Fields
  16. fields: [
  17. {name: 'id', type: 'int'},
  18. {name: 'key', type: 'string'},
  19. {name: 'label', type: 'string'},
  20. {name: 'xtype', type: 'string'},
  21. {name: 'description', type: 'string'},
  22. {name: 'is_required', type: 'bool'},
  23. {name: 'value', type: 'string'},
  24. {name: 'default', type: 'string'},
  25. {name: 'source', type: 'int'},
  26. {name: 'group', type: 'int'},
  27. {name: 'group_label', type: 'string'},
  28. {name: 'sortorder', type: 'int'},
  29. {name: 'options', type: 'object'},
  30. {name: 'process_options', type: 'bool'}
  31. ],
  32. // Visible Columns
  33. columns: [{
  34. header: _('clientconfig.id'),
  35. dataIndex: 'id',
  36. sortable: true,
  37. width: .1
  38. },{
  39. header: _('clientconfig.key'),
  40. dataIndex: 'key',
  41. editor: { xtype: 'textfield' },
  42. sortable: true,
  43. width: .3
  44. },{
  45. header: _('clientconfig.label'),
  46. dataIndex: 'label',
  47. editor: { xtype: 'textfield' },
  48. sortable: true,
  49. width: .3
  50. },{
  51. header: _('clientconfig.xtype'),
  52. dataIndex: 'xtype',
  53. editor: {
  54. xtype: 'clientconfig-combo-fieldtypes',
  55. renderer: true
  56. },
  57. sortable: true,
  58. width: .15
  59. },{
  60. header: _('clientconfig.is_required'),
  61. dataIndex: 'is_required',
  62. editor: {
  63. xtype: 'combo-boolean',
  64. renderer: 'boolean'
  65. },
  66. sortable: true,
  67. width: .15,
  68. renderer: this.rendYesNo
  69. },{
  70. header: _('clientconfig.group'),
  71. dataIndex: 'group',
  72. editor: {
  73. xtype: 'clientconfig-combo-groups',
  74. renderer: true
  75. },
  76. sortable: true,
  77. width: .3
  78. },{
  79. header: _('clientconfig.sortorder'),
  80. dataIndex: 'sortorder',
  81. editor: {
  82. xtype: 'numberfield',
  83. allowDecimal: false,
  84. allowNegative: false
  85. },
  86. sortable: true,
  87. width: .2
  88. }],
  89. // Top-Bar
  90. tbar: [{
  91. text: _('clientconfig.add_setting'),
  92. handler: this.addSetting,
  93. scope: this
  94. },'->',{
  95. emptyText: _('clientconfig.filter_on_group'),
  96. xtype: 'clientconfig-combo-groups',
  97. id: 'clientconfig-settings-filter-group',
  98. listeners: {
  99. select: {fn: function(combo, record) {
  100. this.getStore().baseParams['group'] = record.id;
  101. this.getBottomToolbar().changePage(1);
  102. }, scope: this}
  103. },
  104. width: 250
  105. }, '-', {
  106. text: _('clientconfig.export_settings'),
  107. handler: this.exportSettings,
  108. scope: this
  109. }, '-', {
  110. text: _('clientconfig.import_settings'),
  111. handler: this.importSettings,
  112. scope: this
  113. }]
  114. });
  115. ClientConfig.grid.Settings.superclass.constructor.call(this,config);
  116. };
  117. Ext.extend(ClientConfig.grid.Settings,MODx.grid.Grid,{
  118. addSetting: function() {
  119. var groups = Ext.getCmp('clientconfig-grid-groups');
  120. if (groups.store.data.items.length < 1) {
  121. MODx.msg.alert(
  122. _('clientconfig.create_groups_first'),
  123. _('clientconfig.create_groups_first.desc'),
  124. function() {
  125. groups.addGroup();
  126. },
  127. groups
  128. );
  129. return;
  130. }
  131. var win = MODx.load({
  132. xtype: 'clientconfig-window-setting',
  133. listeners: {
  134. success: {fn: function(r) {
  135. this.refresh();
  136. },scope: this},
  137. scope: this
  138. }
  139. });
  140. win.show();
  141. },
  142. updateSetting: function() {
  143. var record = this.menu.record;
  144. var win = MODx.load({
  145. xtype: 'clientconfig-window-setting',
  146. record: record,
  147. listeners: {
  148. success: {fn: function(r) {
  149. this.refresh();
  150. },scope: this},
  151. scope: this
  152. },
  153. isUpdate: true
  154. });
  155. win.setValues(record);
  156. win.show();
  157. },
  158. duplicateSetting: function() {
  159. var record = this.menu.record;
  160. record.id = 0;
  161. var win = MODx.load({
  162. xtype: 'clientconfig-window-setting',
  163. record: record,
  164. listeners: {
  165. success: {fn: function(r) {
  166. this.refresh();
  167. },scope: this},
  168. scope: this
  169. },
  170. isDuplicate: true
  171. });
  172. win.setValues(record);
  173. win.show();
  174. },
  175. removeSetting: function() {
  176. var id = this.menu.record.id;
  177. MODx.msg.confirm({
  178. title: _('clientconfig.remove_setting'),
  179. text: _('clientconfig.remove_setting.confirm'),
  180. url: this.config.url,
  181. params: {
  182. action: 'mgr/settings/remove',
  183. id: id
  184. },
  185. listeners: {
  186. success: {fn: function(r) {
  187. this.refresh();
  188. },scope: this},
  189. scope: this
  190. }
  191. });
  192. },
  193. getMenu: function(node) {
  194. var m = [];
  195. m.push({
  196. text: _('clientconfig.update_setting'),
  197. handler: this.updateSetting,
  198. scope: this
  199. },{
  200. text: _('clientconfig.duplicate_setting'),
  201. handler: this.duplicateSetting,
  202. scope: this
  203. },'-',{
  204. text: _('clientconfig.remove_setting'),
  205. handler: this.removeSetting,
  206. scope: this
  207. });
  208. return m;
  209. },
  210. filterOnGroup: function() {
  211. this.baseParams['group'] = Ext.getCmp('clientconfig-settings-filter-group').getValue();
  212. this.getBottomToolbar().changePage(1);
  213. this.refresh();
  214. },
  215. exportSettings: function() {
  216. Ext.Msg.confirm(_('clientconfig.export_settings'), _('clientconfig.export_settings.confirm'), function(e) {
  217. if (e == 'yes') {
  218. window.location = ClientConfig.config.connectorUrl + '?action=mgr/settings/export&HTTP_MODAUTH=' + MODx.siteId;
  219. }
  220. });
  221. },
  222. importSettings: function() {
  223. var win = MODx.load({
  224. xtype: 'clientconfig-window-import',
  225. title: _('clientconfig.import_settings'),
  226. introduction: _('clientconfig.import_settings.desc'),
  227. what: _('clientconfig.settings'),
  228. baseParams: {
  229. action: 'mgr/settings/import'
  230. },
  231. listeners: {
  232. success: {fn: function(r) {
  233. this.refresh();
  234. },scope: this},
  235. scope: this
  236. }
  237. });
  238. win.show();
  239. }
  240. });
  241. Ext.reg('clientconfig-grid-settings',ClientConfig.grid.Settings);