modx.namespace.panel.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /**
  2. * Loads the panel for managing namespaces.
  3. *
  4. * @class MODx.panel.Namespaces
  5. * @extends MODx.FormPanel
  6. * @param {Object} config An object of configuration properties
  7. * @xtype modx-panel-namespaces
  8. */
  9. MODx.panel.Namespaces = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. id: 'modx-panel-namespaces'
  13. ,cls: 'container'
  14. ,bodyStyle: ''
  15. ,defaults: { collapsible: false ,autoHeight: true }
  16. ,items: [{
  17. html: _('namespaces')
  18. ,id: 'modx-namespaces-header'
  19. ,xtype: 'modx-header'
  20. },{
  21. layout: 'form'
  22. ,items: [{
  23. html: '<p>'+_('namespaces_desc')+'</p>'
  24. ,xtype: 'modx-description'
  25. },{
  26. xtype: 'modx-grid-namespace'
  27. ,cls:'main-wrapper'
  28. ,preventRender: true
  29. }]
  30. }]
  31. });
  32. MODx.panel.Namespaces.superclass.constructor.call(this,config);
  33. };
  34. Ext.extend(MODx.panel.Namespaces,MODx.FormPanel);
  35. Ext.reg('modx-panel-namespaces',MODx.panel.Namespaces);
  36. /**
  37. * Loads a grid for managing namespaces.
  38. *
  39. * @class MODx.grid.Namespace
  40. * @extends MODx.grid.Grid
  41. * @param {Object} config An object of configuration properties
  42. * @xtype modx-grid-namespace
  43. */
  44. MODx.grid.Namespace = function(config) {
  45. config = config || {};
  46. this.sm = new Ext.grid.CheckboxSelectionModel();
  47. Ext.applyIf(config,{
  48. url: MODx.config.connector_url
  49. ,baseParams: {
  50. action: 'workspace/namespace/getlist'
  51. }
  52. ,fields: ['id','name','path','assets_path','perm']
  53. ,anchor: '100%'
  54. ,paging: true
  55. ,autosave: true
  56. ,save_action: 'workspace/namespace/updatefromgrid'
  57. ,primaryKey: 'name'
  58. ,remoteSort: true
  59. ,sm: this.sm
  60. ,columns: [this.sm,{
  61. header: _('name')
  62. ,dataIndex: 'name'
  63. ,width: 200
  64. ,sortable: true
  65. },{
  66. header: _('namespace_path')
  67. ,dataIndex: 'path'
  68. ,width: 500
  69. ,sortable: false
  70. ,editor: { xtype: 'textfield' }
  71. },{
  72. header: _('namespace_assets_path')
  73. ,dataIndex: 'assets_path'
  74. ,width: 500
  75. ,sortable: false
  76. ,editor: { xtype: 'textfield' }
  77. }]
  78. ,tbar: [{
  79. text: _('create_new')
  80. ,handler: { xtype: 'modx-window-namespace-create' ,blankValues: true }
  81. ,cls:'primary-button'
  82. ,scope: this
  83. },'->',{
  84. xtype: 'textfield'
  85. ,name: 'search'
  86. ,id: 'modx-namespace-search'
  87. ,cls: 'x-form-filter'
  88. ,emptyText: _('search_ellipsis')
  89. ,listeners: {
  90. 'change': {fn: this.search, scope: this}
  91. ,'render': {fn: function(cmp) {
  92. new Ext.KeyMap(cmp.getEl(), {
  93. key: Ext.EventObject.ENTER
  94. ,fn: this.blur
  95. ,scope: cmp
  96. });
  97. },scope:this}
  98. }
  99. },{
  100. xtype: 'button'
  101. ,id: 'modx-filter-clear'
  102. ,cls: 'x-form-filter-clear'
  103. ,text: _('filter_clear')
  104. ,listeners: {
  105. 'click': {fn: this.clearFilter, scope: this},
  106. 'mouseout': { fn: function(evt){
  107. this.removeClass('x-btn-focus');
  108. }
  109. }
  110. }
  111. }]
  112. });
  113. MODx.grid.Namespace.superclass.constructor.call(this,config);
  114. };
  115. Ext.extend(MODx.grid.Namespace,MODx.grid.Grid,{
  116. getMenu: function() {
  117. var r = this.getSelectionModel().getSelected();
  118. var p = r.data.perm;
  119. var m = [];
  120. if (this.getSelectionModel().getCount() > 1) {
  121. m.push({
  122. text: _('selected_remove')
  123. ,handler: this.removeSelected
  124. ,scope: this
  125. });
  126. } else {
  127. m.push({
  128. text: _('namespace_update')
  129. ,handler: this.updateNS
  130. });
  131. if (p.indexOf('premove') != -1 && this.menu.record.name != 'core') {
  132. m.push({
  133. text: _('namespace_remove')
  134. ,handler: this.remove.createDelegate(this,['namespace_remove_confirm','workspace/namespace/remove'])
  135. });
  136. }
  137. }
  138. return m;
  139. }
  140. ,updateNS: function(elem, vent) {
  141. var win = MODx.load({
  142. xtype: 'modx-window-namespace-update'
  143. ,record: this.menu.record
  144. ,listeners: {
  145. success: {
  146. fn: this.refresh
  147. ,scope: this
  148. }
  149. }
  150. });
  151. win.setValues(this.menu.record);
  152. win.show(vent.target);
  153. }
  154. ,search: function(tf,newValue,oldValue) {
  155. var nv = newValue || tf;
  156. this.getStore().baseParams.search = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  157. this.getBottomToolbar().changePage(1);
  158. //this.refresh();
  159. return true;
  160. }
  161. ,clearFilter: function() {
  162. this.getStore().baseParams = {
  163. action: 'workspace/namespace/getList'
  164. };
  165. Ext.getCmp('modx-namespace-search').reset();
  166. this.getBottomToolbar().changePage(1);
  167. //this.refresh();
  168. }
  169. ,removeSelected: function() {
  170. var cs = this.getSelectedAsList();
  171. if (cs === false) return false;
  172. MODx.msg.confirm({
  173. title: _('namespace_remove_multiple')
  174. ,text: _('namespace_remove_multiple_confirm')
  175. ,url: this.config.url
  176. ,params: {
  177. action: 'workspace/namespace/removeMultiple'
  178. ,namespaces: cs
  179. }
  180. ,listeners: {
  181. 'success': {fn:function(r) {
  182. this.getSelectionModel().clearSelections(true);
  183. this.refresh();
  184. },scope:this}
  185. }
  186. });
  187. return true;
  188. }
  189. });
  190. Ext.reg('modx-grid-namespace',MODx.grid.Namespace);