modx.grid.context.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /**
  2. * Loads a grid of modContexts.
  3. *
  4. * @class MODx.grid.Context
  5. * @extends MODx.grid.Grid
  6. * @param {Object} config An object of configuration properties
  7. * @xtype modx-grid-contexts
  8. */
  9. MODx.grid.Context = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. title: _('contexts')
  13. ,id: 'modx-grid-context'
  14. ,url: MODx.config.connector_url
  15. ,baseParams: {
  16. action: 'context/getlist'
  17. }
  18. ,fields: ['key','name','description','perm', 'rank']
  19. ,paging: true
  20. ,autosave: true
  21. ,save_action: 'context/updatefromgrid'
  22. ,remoteSort: true
  23. ,primaryKey: 'key'
  24. ,columns: [{
  25. header: _('key')
  26. ,dataIndex: 'key'
  27. ,width: 100
  28. ,sortable: true
  29. },{
  30. header: _('name')
  31. ,dataIndex: 'name'
  32. ,width: 150
  33. ,sortable: true
  34. ,editor: { xtype: 'textfield' }
  35. ,renderer: Ext.util.Format.htmlEncode
  36. },{
  37. header: _('description')
  38. ,dataIndex: 'description'
  39. ,width: 575
  40. ,sortable: false
  41. ,editor: { xtype: 'textfield' }
  42. ,renderer: Ext.util.Format.htmlEncode
  43. },{
  44. header: _('rank')
  45. ,dataIndex: 'rank'
  46. ,width: 100
  47. ,sortable: true
  48. ,editor: { xtype: 'numberfield' }
  49. }]
  50. ,tbar: [{
  51. text: _('create_new')
  52. ,cls:'primary-button'
  53. ,handler: this.create
  54. ,scope: this
  55. },'->',{
  56. xtype: 'textfield'
  57. ,name: 'search'
  58. ,id: 'modx-ctx-search'
  59. ,cls: 'x-form-filter'
  60. ,emptyText: _('search_ellipsis')
  61. ,listeners: {
  62. 'change': {fn: this.search, scope: this}
  63. ,'render': {fn: function(cmp) {
  64. new Ext.KeyMap(cmp.getEl(), {
  65. key: Ext.EventObject.ENTER
  66. ,fn: this.blur
  67. ,scope: cmp
  68. });
  69. },scope:this}
  70. }
  71. },{
  72. xtype: 'button'
  73. ,id: 'modx-filter-clear'
  74. ,cls: 'x-form-filter-clear'
  75. ,text: _('filter_clear')
  76. ,listeners: {
  77. 'click': {fn: this.clearFilter, scope: this},
  78. 'mouseout': { fn: function(evt){
  79. this.removeClass('x-btn-focus');
  80. }
  81. }
  82. }
  83. }]
  84. });
  85. MODx.grid.Context.superclass.constructor.call(this,config);
  86. };
  87. Ext.extend(MODx.grid.Context,MODx.grid.Grid,{
  88. updateContext: function(itm,e) {
  89. MODx.loadPage('context/update', 'key='+this.menu.record.key);
  90. }
  91. ,getMenu: function() {
  92. var r = this.getSelectionModel().getSelected();
  93. var p = r.data.perm;
  94. var m = [];
  95. if (p.indexOf('pnew') != -1) {
  96. m.push({
  97. text: _('context_duplicate')
  98. ,handler: this.duplicateContext
  99. ,scope: this
  100. });
  101. }
  102. if (p.indexOf('pedit') != -1) {
  103. m.push({
  104. text: _('context_update')
  105. ,handler: this.updateContext
  106. });
  107. }
  108. if (p.indexOf('premove') != -1) {
  109. m.push('-');
  110. m.push({
  111. text: _('context_remove')
  112. ,handler: this.remove
  113. ,scope: this
  114. });
  115. }
  116. return m;
  117. }
  118. ,duplicateContext: function() {
  119. var r = {
  120. key: this.menu.record.key
  121. ,newkey: ''
  122. };
  123. var w = MODx.load({
  124. xtype: 'modx-window-context-duplicate'
  125. ,record: r
  126. ,listeners: {
  127. 'success': {fn:function() {
  128. this.refresh();
  129. var tree = Ext.getCmp('modx-resource-tree');
  130. if (tree) {
  131. tree.refresh();
  132. }
  133. },scope:this}
  134. }
  135. });
  136. w.show();
  137. }
  138. ,search: function(tf,newValue,oldValue) {
  139. var nv = newValue || tf;
  140. this.getStore().baseParams.search = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  141. this.getBottomToolbar().changePage(1);
  142. //this.refresh();
  143. return true;
  144. }
  145. ,clearFilter: function() {
  146. this.getStore().baseParams = {
  147. action: 'context/getList'
  148. };
  149. Ext.getCmp('modx-ctx-search').reset();
  150. this.getBottomToolbar().changePage(1);
  151. //this.refresh();
  152. }
  153. ,create: function(btn, e) {
  154. if (this.createWindow) {
  155. this.createWindow.destroy();
  156. }
  157. this.createWindow = MODx.load({
  158. xtype : 'modx-window-context-create',
  159. closeAction :'close',
  160. listeners : {
  161. 'success' : {
  162. fn : function() {
  163. this.afterAction();
  164. },
  165. scope : this
  166. }
  167. }
  168. });
  169. this.createWindow.show(e.target);
  170. }
  171. ,remove: function(btn, e) {
  172. MODx.msg.confirm({
  173. title : _('warning'),
  174. text : _('context_remove_confirm'),
  175. url : this.config.url,
  176. params : {
  177. action : 'context/remove',
  178. key : this.menu.record.key
  179. },
  180. listeners : {
  181. 'success' : {
  182. fn : function() {
  183. this.afterAction();
  184. },
  185. scope : this
  186. }
  187. }
  188. });
  189. }
  190. ,afterAction: function() {
  191. var cmp = Ext.getCmp('modx-resource-tree');
  192. if (cmp) {
  193. cmp.refresh();
  194. }
  195. this.getSelectionModel().clearSelections(true);
  196. this.refresh();
  197. }
  198. });
  199. Ext.reg('modx-grid-contexts',MODx.grid.Context);
  200. /**
  201. * Generates the create context window.
  202. *
  203. * @class MODx.window.CreateContext
  204. * @extends MODx.Window
  205. * @param {Object} config An object of options.
  206. * @xtype modx-window-context-create
  207. */
  208. MODx.window.CreateContext = function(config) {
  209. config = config || {};
  210. Ext.applyIf(config,{
  211. title: _('context_create')
  212. ,url: MODx.config.connector_url
  213. ,action: 'context/create'
  214. ,fields: [{
  215. xtype: 'textfield'
  216. ,fieldLabel: _('context_key')
  217. ,name: 'key'
  218. ,anchor: '100%'
  219. ,maxLength: 100
  220. },{
  221. xtype: 'textfield'
  222. ,fieldLabel: _('name')
  223. ,name: 'name'
  224. ,anchor: '100%'
  225. ,maxLength: 100
  226. ,renderer: Ext.util.Format.htmlEncode
  227. },{
  228. xtype: 'textarea'
  229. ,fieldLabel: _('description')
  230. ,name: 'description'
  231. ,anchor: '100%'
  232. ,grow: true
  233. ,renderer: Ext.util.Format.htmlEncode
  234. },{
  235. xtype: 'numberfield'
  236. ,fieldLabel: _('rank')
  237. ,name: 'rank'
  238. ,allowBlank: true
  239. ,anchor: '100%'
  240. }]
  241. ,keys: []
  242. });
  243. MODx.window.CreateContext.superclass.constructor.call(this,config);
  244. };
  245. Ext.extend(MODx.window.CreateContext,MODx.Window);
  246. Ext.reg('modx-window-context-create',MODx.window.CreateContext);
  247. /**
  248. * Loads the Contexts panel
  249. *
  250. * @class MODx.panel.Contexts
  251. * @extends MODx.FormPanel
  252. * @param {Object} config An object of configuration options
  253. * @xtype modx-panel-contexts
  254. */
  255. MODx.panel.Contexts = function(config) {
  256. config = config || {};
  257. Ext.applyIf(config,{
  258. id: 'modx-panel-contexts'
  259. ,cls: 'container'
  260. ,bodyStyle: ''
  261. ,defaults: { collapsible: false ,autoHeight: true }
  262. ,items: [{
  263. html: _('contexts')
  264. ,id: 'modx-contexts-header'
  265. ,xtype: 'modx-header'
  266. },{
  267. layout: 'form'
  268. ,items: [{
  269. html: '<p>'+_('context_management_message')+'</p>'
  270. ,xtype: 'modx-description'
  271. },{
  272. xtype: 'modx-grid-contexts'
  273. ,cls:'main-wrapper'
  274. ,preventRender: true
  275. }]
  276. }]
  277. });
  278. MODx.panel.Contexts.superclass.constructor.call(this,config);
  279. };
  280. Ext.extend(MODx.panel.Contexts,MODx.FormPanel);
  281. Ext.reg('modx-panel-contexts',MODx.panel.Contexts);