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

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