modx.grid.user.group.category.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. MODx.grid.UserGroupCategory = function(config) {
  2. config = config || {};
  3. this.exp = new Ext.grid.RowExpander({
  4. tpl: new Ext.Template('<p class="desc">{permissions}</p>'),
  5. lazyRender: false,
  6. enableCaching: false
  7. });
  8. Ext.applyIf(config,{
  9. id: 'modx-grid-user-group-categories'
  10. ,url: MODx.config.connector_url
  11. ,baseParams: {
  12. action: 'security/access/usergroup/category/getList'
  13. ,usergroup: config.usergroup
  14. }
  15. ,paging: true
  16. ,hideMode: 'offsets'
  17. ,fields: ['id','target','name','principal','authority','authority_name','policy','policy_name','context_key','permissions','menu']
  18. ,grouping: true
  19. ,groupBy: 'authority_name'
  20. ,singleText: _('policy')
  21. ,pluralText: _('policies')
  22. ,sortBy: 'authority'
  23. ,sortDir: 'ASC'
  24. ,remoteSort: true
  25. ,plugins: [this.exp]
  26. ,columns: [this.exp,{
  27. header: _('category')
  28. ,dataIndex: 'name'
  29. ,width: 120
  30. ,sortable: true
  31. },{
  32. header: _('minimum_role')
  33. ,dataIndex: 'authority_name'
  34. ,width: 100
  35. },{
  36. header: _('policy')
  37. ,dataIndex: 'policy_name'
  38. ,width: 200
  39. },{
  40. header: _('context')
  41. ,dataIndex: 'context_key'
  42. ,width: 150
  43. ,sortable: true
  44. }]
  45. ,tbar: [{
  46. text: _('category_add')
  47. ,cls: 'primary-button'
  48. ,scope: this
  49. ,handler: this.createAcl
  50. },'->',{
  51. xtype: 'modx-combo-category'
  52. ,id: 'modx-ugcat-category-filter'
  53. ,emptyText: _('filter_by_category')
  54. ,width: 200
  55. ,allowBlank: true
  56. ,listeners: {
  57. 'select': {fn:this.filterCategory,scope:this}
  58. }
  59. },{
  60. xtype: 'modx-combo-policy'
  61. ,id: 'modx-ugcat-policy-filter'
  62. ,emptyText: _('filter_by_policy')
  63. ,allowBlank: true
  64. ,baseParams: {
  65. action: 'security/access/policy/getList'
  66. ,group: 'Object'
  67. }
  68. ,listeners: {
  69. 'select': {fn:this.filterPolicy,scope:this}
  70. }
  71. },{
  72. text: _('clear_filter')
  73. ,id: 'modx-ugcat-clear-filter'
  74. ,handler: this.clearFilter
  75. ,scope: this
  76. }]
  77. });
  78. MODx.grid.UserGroupCategory.superclass.constructor.call(this,config);
  79. this.addEvents('createAcl','updateAcl');
  80. };
  81. Ext.extend(MODx.grid.UserGroupCategory,MODx.grid.Grid,{
  82. combos: {}
  83. ,windows: {}
  84. ,filterCategory: function(cb,rec,ri) {
  85. this.getStore().baseParams['category'] = rec.data['id'];
  86. this.getBottomToolbar().changePage(1);
  87. this.refresh();
  88. }
  89. ,filterPolicy: function(cb,rec,ri) {
  90. this.getStore().baseParams['policy'] = rec.data['id'];
  91. this.getBottomToolbar().changePage(1);
  92. //this.refresh();
  93. }
  94. ,clearFilter: function(btn,e) {
  95. Ext.getCmp('modx-ugcat-category-filter').setValue('');
  96. this.getStore().baseParams['category'] = '';
  97. Ext.getCmp('modx-ugcat-policy-filter').setValue('');
  98. this.getStore().baseParams['policy'] = '';
  99. this.getBottomToolbar().changePage(1);
  100. //this.refresh();
  101. }
  102. ,createAcl: function(itm,e) {
  103. var r = {
  104. principal: this.config.usergroup
  105. };
  106. if (!this.windows.createAcl) {
  107. this.windows.createAcl = MODx.load({
  108. xtype: 'modx-window-user-group-category-create'
  109. ,record: r
  110. ,listeners: {
  111. 'success': {fn:function(r) {
  112. this.refresh();
  113. this.fireEvent('createAcl',r);
  114. },scope:this}
  115. }
  116. });
  117. }
  118. this.windows.createAcl.setValues(r);
  119. this.windows.createAcl.show(e.target);
  120. }
  121. ,updateAcl: function(itm,e) {
  122. var r = this.menu.record;
  123. if (!this.windows.updateAcl) {
  124. this.windows.updateAcl = MODx.load({
  125. xtype: 'modx-window-user-group-category-update'
  126. ,record: r
  127. ,listeners: {
  128. 'success': {fn:function(r) {
  129. this.refresh();
  130. this.fireEvent('updateAcl',r);
  131. },scope:this}
  132. }
  133. });
  134. }
  135. this.windows.updateAcl.setValues(r);
  136. this.windows.updateAcl.show(e.target);
  137. }
  138. });
  139. Ext.reg('modx-grid-user-group-category',MODx.grid.UserGroupCategory);
  140. MODx.window.CreateUGCat = function(config) {
  141. config = config || {};
  142. this.ident = config.ident || 'cugcat'+Ext.id();
  143. Ext.applyIf(config,{
  144. title: _('category_add')
  145. ,url: MODx.config.connector_url
  146. ,action: 'security/access/usergroup/category/create'
  147. // ,height: 250
  148. // ,width: 500
  149. ,fields: [{
  150. xtype: 'hidden'
  151. ,name: 'id'
  152. },{
  153. xtype: 'hidden'
  154. ,name: 'principal'
  155. ,hiddenName: 'principal'
  156. },{
  157. xtype: 'hidden'
  158. ,name: 'principal_class'
  159. ,value: 'modUserGroup'
  160. },{
  161. xtype: 'modx-combo-category'
  162. ,fieldLabel: _('category')
  163. ,description: MODx.expandHelp ? '' : _('user_group_category_category_desc')
  164. ,id: 'modx-'+this.ident+'-category'
  165. ,name: 'target'
  166. ,hiddenName: 'target'
  167. ,editable: false
  168. ,anchor: '100%'
  169. },{
  170. xtype: MODx.expandHelp ? 'label' : 'hidden'
  171. ,forId: 'modx-'+this.ident+'-category'
  172. ,html: _('user_group_category_category_desc')
  173. ,cls: 'desc-under'
  174. },{
  175. xtype: 'modx-combo-context'
  176. ,fieldLabel: _('context')
  177. ,description: MODx.expandHelp ? '' : _('user_group_category_context_desc')
  178. ,id: 'modx-'+this.ident+'-context'
  179. ,name: 'context_key'
  180. ,hiddenName: 'context_key'
  181. ,editable: false
  182. ,anchor: '100%'
  183. },{
  184. xtype: MODx.expandHelp ? 'label' : 'hidden'
  185. ,forId: 'modx-'+this.ident+'-context'
  186. ,html: _('user_group_category_context_desc')
  187. ,cls: 'desc-under'
  188. },{
  189. xtype: 'modx-combo-authority'
  190. ,fieldLabel: _('minimum_role')
  191. ,description: MODx.expandHelp ? '' : _('user_group_category_policy_desc')
  192. ,id: 'modx-'+this.ident+'-authority'
  193. ,name: 'authority'
  194. ,value: 0
  195. ,anchor: '100%'
  196. },{
  197. xtype: MODx.expandHelp ? 'label' : 'hidden'
  198. ,forId: 'modx-'+this.ident+'-authority'
  199. ,html: _('user_group_category_authority_desc')
  200. ,cls: 'desc-under'
  201. },{
  202. xtype: 'modx-combo-policy'
  203. ,fieldLabel: _('policy')
  204. ,description: MODx.expandHelp ? '' : _('user_group_category_policy_desc')
  205. ,id: 'modx-'+this.ident+'-policy'
  206. ,name: 'policy'
  207. ,hiddenName: 'policy'
  208. ,baseParams: {
  209. action: 'security/access/policy/getList'
  210. ,group: 'Element,Object'
  211. ,combo: '1'
  212. }
  213. ,anchor: '100%'
  214. ,listeners: {
  215. 'select':{fn:this.onPolicySelect,scope:this}
  216. }
  217. },{
  218. xtype: MODx.expandHelp ? 'label' : 'hidden'
  219. ,forId: 'modx-'+this.ident+'-policy'
  220. ,html: _('user_group_category_policy_desc')
  221. ,cls: 'desc-under'
  222. },{
  223. id: 'modx-'+this.ident+'-permissions-list-ct'
  224. ,cls: 'modx-permissions-list'
  225. ,defaults: {border: false}
  226. ,autoHeight: true
  227. ,hidden: true
  228. ,anchor: '100%'
  229. ,items: [{
  230. html: '<h4>'+_('permissions_in_policy')+'</h4>'
  231. ,id: 'modx-'+this.ident+'-permissions-list-header'
  232. },{
  233. id: 'modx-'+this.ident+'-permissions-list'
  234. ,cls: 'modx-permissions-list-textarea'
  235. ,xtype: 'textarea'
  236. ,name: 'permissions'
  237. ,grow: false
  238. ,anchor: '100%'
  239. ,height: 100
  240. ,width: '97%'
  241. ,readOnly: true
  242. }]
  243. }]
  244. });
  245. MODx.window.CreateUGCat.superclass.constructor.call(this,config);
  246. };
  247. Ext.extend(MODx.window.CreateUGCat,MODx.Window,{
  248. onPolicySelect: function(cb,rec,idx) {
  249. var s = cb.getStore();
  250. if (!s) return;
  251. var r = s.getAt(idx);
  252. var lc = Ext.getCmp('modx-'+this.ident+'-permissions-list-ct');
  253. if (r && idx>0) {
  254. lc.show();
  255. var pl = Ext.getCmp('modx-'+this.ident+'-permissions-list');
  256. var o = rec.data.permissions.join(', ');
  257. pl.setValue(o);
  258. } else {
  259. lc.hide();
  260. }
  261. this.doLayout();
  262. }
  263. });
  264. Ext.reg('modx-window-user-group-category-create',MODx.window.CreateUGCat);
  265. MODx.window.UpdateUGCat = function(config) {
  266. config = config || {};
  267. this.ident = config.ident || 'updugcat'+Ext.id();
  268. Ext.applyIf(config,{
  269. title: _('access_category_update')
  270. ,action: 'security/access/usergroup/category/update'
  271. });
  272. MODx.window.UpdateUGCat.superclass.constructor.call(this,config);
  273. };
  274. Ext.extend(MODx.window.UpdateUGCat, MODx.window.CreateUGCat);
  275. Ext.reg('modx-window-user-group-category-update',MODx.window.UpdateUGCat);