template.grid.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. collections.grid.Template = function(config) {
  2. config = config || {};
  3. this.sm = new Ext.grid.CheckboxSelectionModel({
  4. listeners: {
  5. rowselect: {
  6. fn: function (sm, rowIndex, record) {
  7. this.rememberRow(record);
  8. }, scope: this
  9. },
  10. rowdeselect: {
  11. fn: function (sm, rowIndex, record) {
  12. this.forgotRow(record);
  13. }
  14. ,scope: this
  15. }
  16. }
  17. });
  18. Ext.applyIf(config,{
  19. title: _('collections.collections')
  20. ,url: collections.config.connectorUrl
  21. ,baseParams: {
  22. action: 'mgr/template/getList'
  23. ,'template': 1
  24. }
  25. ,save_action: 'mgr/template/updatefromgrid'
  26. ,autosave: true
  27. ,preventSaveRefresh: false
  28. ,fields: ['id','name', 'description', 'global_template', 'default_for_templates']
  29. ,paging: true
  30. ,remoteSort: true
  31. ,emptyText: _('collections.template.none')
  32. ,sm: this.sm
  33. ,columns: [this.sm,{
  34. header: _('id')
  35. ,dataIndex: 'id'
  36. ,sortable: true
  37. ,hidden: true
  38. },{
  39. header: _('collections.template.name')
  40. ,dataIndex: 'name'
  41. ,sortable: true
  42. ,width: 80
  43. ,editor: {xtype: 'textfield'}
  44. },{
  45. header: _('collections.template.description')
  46. ,dataIndex: 'description'
  47. ,sortable: true
  48. ,width: 100
  49. ,editor: {xtype: 'textfield'}
  50. },{
  51. header: 'Default for Templates'
  52. ,dataIndex: 'default_for_templates'
  53. ,sortable: false
  54. ,width: 60
  55. ,renderer: function(value, metaData, record, rowIndex, colIndex, store) {
  56. metaData.attr = 'ext:qtip="' + value.join('<br />') + '"';
  57. return value;
  58. }
  59. },{
  60. header: _('collections.template.global_template')
  61. ,dataIndex: 'global_template'
  62. ,sortable: true
  63. ,width: 30
  64. ,editor: {xtype: 'modx-combo-boolean', renderer: true}
  65. }]
  66. ,tbar: [{
  67. text: _('collections.template.add')
  68. ,handler: this.createTemplate
  69. ,scope: this
  70. },{
  71. text: _('collections.template.import')
  72. ,handler: this.importTemplate
  73. ,scope: this
  74. }]
  75. });
  76. collections.grid.Template.superclass.constructor.call(this,config);
  77. this.getView().on('refresh', this.refreshSelection, this);
  78. };
  79. Ext.extend(collections.grid.Template,MODx.grid.Grid,{
  80. selectedRecords: []
  81. ,rememberRow: function(record) {
  82. if(this.selectedRecords.indexOf(record.id) == -1){
  83. this.selectedRecords.push(record.id);
  84. }
  85. }
  86. ,forgotRow: function(record){
  87. this.selectedRecords.remove(record.id);
  88. }
  89. ,refreshSelection: function() {
  90. var rowsToSelect = [];
  91. Ext.each(this.selectedRecords, function(item){
  92. rowsToSelect.push(this.store.indexOfId(item));
  93. },this);
  94. this.getSelectionModel().selectRows(rowsToSelect);
  95. }
  96. ,getSelectedAsList: function(){
  97. return this.selectedRecords.join();
  98. }
  99. ,getMenu: function() {
  100. var m = [];
  101. m.push({
  102. text: _('collections.template.update')
  103. ,handler: this.editTemplate
  104. });
  105. m.push({
  106. text: _('collections.template.duplicate')
  107. ,handler: this.duplicateTemplate
  108. });
  109. m.push('-');
  110. m.push({
  111. text: (this.selectedRecords.length > 1) ? _('collections.template.export_more') : _('collections.template.export')
  112. ,handler: this.exportTemplate
  113. });
  114. m.push('-');
  115. m.push({
  116. text: _('collections.template.remove')
  117. ,handler: this.removeTemplate
  118. });
  119. return m;
  120. }
  121. ,editTemplate: function() {
  122. MODx.loadPage('template/update', 'namespace=collections&id='+ this.menu.record.id);
  123. }
  124. ,createTemplate: function() {
  125. MODx.loadPage('template/create', 'namespace=collections');
  126. }
  127. ,exportTemplate: function(){
  128. MODx.loadPage('template/export', 'namespace=collections&ids=' + this.getSelectedAsList());
  129. }
  130. ,removeTemplate: function(btn,e) {
  131. if (!this.menu.record) return false;
  132. MODx.msg.confirm({
  133. title: _('collections.template.remove')
  134. ,text: _('collections.template.remove_confirm')
  135. ,url: this.config.url
  136. ,params: {
  137. action: 'mgr/template/remove'
  138. ,id: this.menu.record.id
  139. }
  140. ,listeners: {
  141. 'success': {fn:function(r) { this.refresh(); },scope:this}
  142. }
  143. });
  144. return true;
  145. }
  146. ,duplicateTemplate: function(btn,e) {
  147. if (!this.menu.record) return false;
  148. var r = {};
  149. r.name = 'Copy of ' + this.menu.record.name;
  150. r.id = this.menu.record.id;
  151. var updateColumn = MODx.load({
  152. xtype: 'collections-window-template-duplicate'
  153. ,record: r
  154. ,listeners: {
  155. 'success': {fn:function() { this.refresh(); },scope:this}
  156. }
  157. });
  158. updateColumn.fp.getForm().reset();
  159. updateColumn.fp.getForm().setValues(r);
  160. updateColumn.show(e.target);
  161. return true;
  162. }
  163. ,importTemplate: function(btn, e) {
  164. var importWindow = MODx.load({
  165. xtype: 'collections-window-template-import'
  166. ,listeners: {
  167. 'success': {fn:function() { this.refresh(); },scope:this}
  168. }
  169. });
  170. importWindow.show(e.target);
  171. return true;
  172. }
  173. });
  174. Ext.reg('collections-grid-template',collections.grid.Template);