modx.grid.user.group.namespace.js 8.9 KB

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