column.grid.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. collections.grid.TemplateColumn = function(config) {
  2. config = config || {};
  3. Ext.applyIf(config,{
  4. url: collections.config.connectorUrl
  5. ,autosave: true
  6. ,save_action: 'mgr/template/column/updatefromgrid'
  7. ,baseParams: {
  8. action: 'mgr/template/column/getList'
  9. ,template: MODx.request.id
  10. ,sort: 'position'
  11. ,dir: 'asc'
  12. }
  13. ,fields: ['id', 'template', 'name', 'label', 'hidden', 'sortable', 'width', 'position', 'editor', 'renderer', 'php_renderer', 'sort_type']
  14. ,paging: true
  15. ,ddGroup: 'collectionChildDDGroup'
  16. ,enableDragDrop: true
  17. ,remoteSort: true
  18. ,emptyText: _('collections.template.column.none')
  19. ,columns: this.getColumns(config)
  20. ,tbar: [{
  21. text: _('collections.template.column.add')
  22. ,handler: this.createColumn
  23. ,scope: this
  24. }]
  25. });
  26. collections.grid.TemplateColumn.superclass.constructor.call(this,config);
  27. this.on('render', this.registerGridDropTarget, this);
  28. this.on('beforedestroy', this.destroyScrollManager, this);
  29. };
  30. Ext.extend(collections.grid.TemplateColumn,MODx.grid.Grid,{
  31. getMenu: function() {
  32. var m = [];
  33. m.push({
  34. text: _('collections.template.column.update')
  35. ,handler: this.updateColumn
  36. });
  37. var selected = this.getSelectionModel().getSelected();
  38. if (selected.data.name != 'id') {
  39. m.push({
  40. text: _('collections.template.column.remove')
  41. ,handler: this.removeColumn
  42. });
  43. }
  44. return m;
  45. }
  46. ,createColumn: function(btn,e) {
  47. var createColumn = MODx.load({
  48. xtype: 'collections-window-template-column'
  49. ,title: _('collections.template.column.add')
  50. ,record: {template: MODx.request.id}
  51. ,listeners: {
  52. 'success': {fn:function() { this.refresh(); },scope:this}
  53. }
  54. });
  55. createColumn.show(e.target);
  56. }
  57. ,updateColumn: function(btn,e) {
  58. var updateColumn = MODx.load({
  59. xtype: 'collections-window-template-column'
  60. ,title: _('collections.template.column.update')
  61. ,action: 'mgr/template/column/update'
  62. ,isUpdate: true
  63. ,record: this.menu.record
  64. ,listeners: {
  65. 'success': {fn:function() { this.refresh(); },scope:this}
  66. }
  67. });
  68. updateColumn.fp.getForm().reset();
  69. updateColumn.fp.getForm().setValues(this.menu.record);
  70. updateColumn.show(e.target);
  71. }
  72. ,removeColumn: function(btn,e) {
  73. if (!this.menu.record) return false;
  74. MODx.msg.confirm({
  75. title: _('collections.template.column.remove')
  76. ,text: _('collections.template.column.remove_confirm')
  77. ,url: this.config.url
  78. ,params: {
  79. action: 'mgr/template/column/remove'
  80. ,id: this.menu.record.id
  81. }
  82. ,listeners: {
  83. 'success': {fn:function(r) { this.refresh(); },scope:this}
  84. }
  85. });
  86. return true;
  87. }
  88. ,getColumns: function(config) {
  89. return [{
  90. header: _('id')
  91. ,dataIndex: 'id'
  92. ,sortable: true
  93. ,hidden: true
  94. ,width: 40
  95. },{
  96. header: _('collections.template.column.label')
  97. ,dataIndex: 'label'
  98. ,sortable: true
  99. ,editor: {xtype: 'textfield'}
  100. ,width: 100
  101. },{
  102. header: _('collections.template.column.name')
  103. ,dataIndex: 'name'
  104. ,sortable: true
  105. ,editor: {xtype: 'textfield'}
  106. ,width: 100
  107. },{
  108. header: _('collections.template.column.hidden')
  109. ,dataIndex: 'hidden'
  110. ,sortable: true
  111. ,editor: {xtype: 'modx-combo-boolean', renderer: true}
  112. ,width: 50
  113. },{
  114. header: _('collections.template.column.sortable')
  115. ,dataIndex: 'sortable'
  116. ,sortable: true
  117. ,editor: {xtype: 'modx-combo-boolean', renderer: true}
  118. ,width: 50
  119. },{
  120. header: _('collections.template.column.width')
  121. ,dataIndex: 'width'
  122. ,sortable: true
  123. ,editor: {xtype: 'numberfield', allowNegative: false, allowDecimals: false}
  124. ,width: 40
  125. },{
  126. header: _('collections.template.column.editor')
  127. ,dataIndex: 'editor'
  128. ,sortable: true
  129. ,editor: {xtype: 'textarea'}
  130. ,width: 100
  131. },{
  132. header: _('collections.template.column.renderer')
  133. ,dataIndex: 'renderer'
  134. ,sortable: true
  135. ,editor: {xtype: 'textfield'}
  136. ,width: 100
  137. ,renderer: collections.renderer.qtip
  138. },{
  139. header: _('collections.template.column.php_renderer')
  140. ,dataIndex: 'php_renderer'
  141. ,sortable: true
  142. ,editor: {xtype: 'textfield'}
  143. ,hidden: true
  144. ,width: 100
  145. ,renderer: collections.renderer.qtip
  146. },{
  147. header: _('collections.template.column.position')
  148. ,dataIndex: 'position'
  149. ,sortable: true
  150. ,editor: {xtype: 'numberfield', allowNegative: false, allowDecimals: false}
  151. ,width: 50
  152. }];
  153. }
  154. ,registerGridDropTarget: function() {
  155. var ddrow = new Ext.ux.dd.GridReorderDropTarget(this, {
  156. copy: false
  157. ,sortCol: 'position'
  158. ,listeners: {
  159. 'beforerowmove': function(objThis, oldIndex, newIndex, records) {
  160. }
  161. ,'afterrowmove': function(objThis, oldIndex, newIndex, records) {
  162. MODx.Ajax.request({
  163. url: collections.config.connectorUrl
  164. ,params: {
  165. action: 'mgr/template/column/ddreorder'
  166. ,idItem: records.pop().id
  167. ,oldIndex: oldIndex
  168. ,newIndex: newIndex
  169. ,template: MODx.request.id
  170. }
  171. ,listeners: {
  172. 'success': {
  173. fn: function(r) {
  174. this.target.grid.refresh();
  175. },scope: this
  176. }
  177. }
  178. });
  179. }
  180. ,'beforerowcopy': function(objThis, oldIndex, newIndex, records) {
  181. }
  182. ,'afterrowcopy': function(objThis, oldIndex, newIndex, records) {
  183. }
  184. }
  185. });
  186. Ext.dd.ScrollManager.register(this.getView().getEditorParent());
  187. }
  188. ,destroyScrollManager: function() {
  189. Ext.dd.ScrollManager.unregister(this.getView().getEditorParent());
  190. }
  191. ,getDragDropText: function(){
  192. if (this.config.baseParams.sort != 'position') {
  193. if (this.store.sortInfo == undefined || this.store.sortInfo.field != 'position') {
  194. return _('collections.err.bad_sort_column', {column: 'position'});
  195. }
  196. }
  197. return _('collections.global.change_order', {child: this.selModel.selections.items[0].data.name});
  198. }
  199. });
  200. Ext.reg('collections-grid-template-column',collections.grid.TemplateColumn);