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

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