modx.grid.access.policy.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /**
  2. * Loads the panel for managing access policies.
  3. *
  4. * @class MODx.panel.AccessPolicies
  5. * @extends MODx.FormPanel
  6. * @param {Object} config An object of configuration properties
  7. * @xtype modx-panel-access-policies
  8. */
  9. MODx.panel.AccessPolicies = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. id: 'modx-panel-access-policies'
  13. ,bodyStyle: ''
  14. ,defaults: { collapsible: false ,autoHeight: true }
  15. ,items: [{
  16. html: _('policies')
  17. ,id: 'modx-policies-header'
  18. ,xtype: 'modx-header'
  19. },{
  20. layout: 'form'
  21. ,cls: 'main-wrapper'
  22. ,items: [{
  23. html: '<p>'+_('policy_management_msg')+'</p>'
  24. ,border: false
  25. },{
  26. xtype: 'modx-grid-access-policy'
  27. ,preventRender: true
  28. }]
  29. }]
  30. });
  31. MODx.panel.AccessPolicies.superclass.constructor.call(this,config);
  32. };
  33. Ext.extend(MODx.panel.AccessPolicies,MODx.FormPanel);
  34. Ext.reg('modx-panel-access-policies',MODx.panel.AccessPolicies);
  35. /**
  36. * Loads a grid of modAccessPolicies.
  37. *
  38. * @class MODx.grid.AccessPolicy
  39. * @extends MODx.grid.Grid
  40. * @param {Object} config An object of options.
  41. * @xtype modx-grid-access-policy
  42. */
  43. MODx.grid.AccessPolicy = function(config) {
  44. config = config || {};
  45. this.sm = new Ext.grid.CheckboxSelectionModel();
  46. Ext.applyIf(config,{
  47. id: 'modx-grid-access-policy'
  48. ,url: MODx.config.connector_url
  49. ,baseParams: {
  50. action: 'security/access/policy/getlist'
  51. }
  52. ,fields: ['id','name','description','class','data','parent','template','template_name','active_permissions','total_permissions','active_of','cls']
  53. ,paging: true
  54. ,autosave: true
  55. ,save_action: 'security/access/policy/updatefromgrid'
  56. ,remoteSort: true
  57. ,sm: this.sm
  58. ,columns: [this.sm,{
  59. header: _('policy_name')
  60. ,dataIndex: 'name'
  61. ,width: 200
  62. ,editor: { xtype: 'textfield' ,allowBlank: false }
  63. ,sortable: true
  64. },{
  65. header: _('description')
  66. ,dataIndex: 'description'
  67. ,width: 375
  68. ,editor: { xtype: 'textfield' }
  69. },{
  70. header: _('policy_template')
  71. ,dataIndex: 'template_name'
  72. ,width: 375
  73. },{
  74. header: _('active_permissions')
  75. ,dataIndex: 'active_of'
  76. ,width: 100
  77. ,editable: false
  78. }]
  79. ,tbar: [{
  80. text: _('policy_create')
  81. ,cls:'primary-button'
  82. ,scope: this
  83. ,handler: this.createPolicy
  84. },{
  85. text: _('import')
  86. ,scope: this
  87. ,handler: this.importPolicy
  88. },{
  89. text: _('bulk_actions')
  90. ,menu: [{
  91. text: _('policy_remove_multiple')
  92. ,handler: this.removeSelected
  93. ,scope: this
  94. }]
  95. },'->',{
  96. xtype: 'textfield'
  97. ,name: 'search'
  98. ,id: 'modx-policy-search'
  99. ,cls: 'x-form-filter'
  100. ,emptyText: _('search_ellipsis')
  101. ,listeners: {
  102. 'change': {fn: this.search, scope: this}
  103. ,'render': {fn: function(cmp) {
  104. new Ext.KeyMap(cmp.getEl(), {
  105. key: Ext.EventObject.ENTER
  106. ,fn: function() {
  107. this.fireEvent('change',this.getValue());
  108. this.blur();
  109. return true;}
  110. ,scope: cmp
  111. });
  112. },scope:this}
  113. }
  114. },{
  115. xtype: 'button'
  116. ,id: 'modx-sacpol-filter-clear'
  117. ,cls: 'x-form-filter-clear'
  118. ,text: _('filter_clear')
  119. ,listeners: {
  120. 'click': {fn: this.clearFilter, scope: this},
  121. 'mouseout': { fn: function(evt){
  122. this.removeClass('x-btn-focus');
  123. }
  124. }
  125. }
  126. }]
  127. });
  128. MODx.grid.AccessPolicy.superclass.constructor.call(this,config);
  129. };
  130. Ext.extend(MODx.grid.AccessPolicy,MODx.grid.Grid,{
  131. search: function(tf,newValue,oldValue) {
  132. var nv = newValue || tf;
  133. this.getStore().baseParams.query = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  134. this.getBottomToolbar().changePage(1);
  135. //this.refresh();
  136. return true;
  137. }
  138. ,clearFilter: function() {
  139. this.getStore().baseParams = {
  140. action: 'security/access/policy/getList'
  141. };
  142. Ext.getCmp('modx-policy-search').reset();
  143. this.getBottomToolbar().changePage(1);
  144. //this.refresh();
  145. }
  146. ,editPolicy: function(itm,e) {
  147. MODx.loadPage('security/access/policy/update', 'id='+this.menu.record.id);
  148. }
  149. ,createPolicy: function(btn,e) {
  150. var r = this.menu.record;
  151. if (!this.windows.apc) {
  152. this.windows.apc = MODx.load({
  153. xtype: 'modx-window-access-policy-create'
  154. ,record: r
  155. ,plugin: this.config.plugin
  156. ,listeners: {
  157. 'success': {fn:function(r) {
  158. this.refresh();
  159. },scope:this}
  160. }
  161. });
  162. }
  163. this.windows.apc.reset();
  164. this.windows.apc.show(e.target);
  165. }
  166. ,exportPolicy: function(btn,e) {
  167. var id = this.menu.record.id;
  168. MODx.Ajax.request({
  169. url: this.config.url
  170. ,params: {
  171. action: 'security/access/policy/export'
  172. ,id: id
  173. }
  174. ,listeners: {
  175. 'success': {fn:function(r) {
  176. location.href = this.config.url+'?action=security/access/policy/export&download=1&id='+id+'&HTTP_MODAUTH='+MODx.siteId;
  177. },scope:this}
  178. }
  179. });
  180. }
  181. ,importPolicy: function(btn,e) {
  182. var r = {};
  183. if (!this.windows.importPolicy) {
  184. this.windows.importPolicy = MODx.load({
  185. xtype: 'modx-window-policy-import'
  186. ,record: r
  187. ,listeners: {
  188. 'success': {fn:function(o) {
  189. this.refresh();
  190. },scope:this}
  191. }
  192. });
  193. }
  194. this.windows.importPolicy.reset();
  195. this.windows.importPolicy.setValues(r);
  196. this.windows.importPolicy.show(e.target);
  197. }
  198. ,getMenu: function() {
  199. var r = this.getSelectionModel().getSelected();
  200. var p = r.data.cls;
  201. var m = [];
  202. if (this.getSelectionModel().getCount() > 1) {
  203. m.push({
  204. text: _('policy_remove_multiple')
  205. ,handler: this.removeSelected
  206. });
  207. } else {
  208. if (p.indexOf('pedit') != -1) {
  209. m.push({
  210. text: _('policy_update')
  211. ,handler: this.editPolicy
  212. });
  213. m.push({
  214. text: _('policy_duplicate')
  215. ,handler: this.confirm.createDelegate(this,["security/access/policy/duplicate","policy_duplicate_confirm"])
  216. });
  217. }
  218. if (m.length > 0) { m.push('-'); }
  219. m.push({
  220. text: _('policy_export')
  221. ,handler: this.exportPolicy
  222. });
  223. if (p.indexOf('premove') != -1) {
  224. if (m.length > 0) m.push('-');
  225. m.push({
  226. text: _('policy_remove')
  227. ,handler: this.confirm.createDelegate(this,["security/access/policy/remove","policy_remove_confirm"])
  228. });
  229. }
  230. }
  231. if (m.length > 0) {
  232. this.addContextMenuItem(m);
  233. }
  234. }
  235. ,removeSelected: function() {
  236. var cs = this.getSelectedAsList();
  237. if (cs === false) return false;
  238. MODx.msg.confirm({
  239. title: _('policy_remove_multiple')
  240. ,text: _('policy_remove_multiple_confirm')
  241. ,url: this.config.url
  242. ,params: {
  243. action: 'security/access/policy/removeMultiple'
  244. ,policies: cs
  245. }
  246. ,listeners: {
  247. 'success': {fn:function(r) {
  248. this.getSelectionModel().clearSelections(true);
  249. this.refresh();
  250. },scope:this}
  251. }
  252. });
  253. return true;
  254. }
  255. });
  256. Ext.reg('modx-grid-access-policy',MODx.grid.AccessPolicy);
  257. /**
  258. * Generates a window for creating Access Policies.
  259. *
  260. * @class MODx.window.CreateAccessPolicy
  261. * @extends MODx.Window
  262. * @param {Object} config An object of options.
  263. * @xtype modx-window-access-policy-create
  264. */
  265. MODx.window.CreateAccessPolicy = function(config) {
  266. config = config || {};
  267. this.ident = config.ident || 'cacp'+Ext.id();
  268. Ext.applyIf(config,{
  269. // width: 500
  270. title: _('policy_create')
  271. ,url: MODx.config.connector_url
  272. ,action: 'security/access/policy/create'
  273. ,fields: [{
  274. fieldLabel: _('name')
  275. ,description: MODx.expandHelp ? '' : _('policy_desc_name')
  276. ,name: 'name'
  277. ,id: 'modx-'+this.ident+'-name'
  278. ,xtype: 'textfield'
  279. ,anchor: '100%'
  280. },{
  281. xtype: MODx.expandHelp ? 'label' : 'hidden'
  282. ,forId: 'modx-'+this.ident+'-name'
  283. ,html: _('policy_desc_name')
  284. ,cls: 'desc-under'
  285. },{
  286. fieldLabel: _('policy_template')
  287. ,description: MODx.expandHelp ? '' : _('policy_desc_template')
  288. ,name: 'template'
  289. ,hiddenName: 'template'
  290. ,id: 'modx-'+this.ident+'-template'
  291. ,xtype: 'modx-combo-access-policy-template'
  292. ,anchor: '100%'
  293. },{
  294. xtype: MODx.expandHelp ? 'label' : 'hidden'
  295. ,forId: 'modx-'+this.ident+'-template'
  296. ,html: _('policy_desc_template')
  297. ,cls: 'desc-under'
  298. },{
  299. fieldLabel: _('description')
  300. ,description: MODx.expandHelp ? '' : _('policy_desc_description')
  301. ,name: 'description'
  302. ,id: 'modx-'+this.ident+'-description'
  303. ,xtype: 'textarea'
  304. ,anchor: '100%'
  305. ,height: 50
  306. },{
  307. xtype: MODx.expandHelp ? 'label' : 'hidden'
  308. ,forId: 'modx-'+this.ident+'-description'
  309. ,html: _('policy_desc_description')
  310. ,cls: 'desc-under'
  311. },{
  312. name: 'class'
  313. ,id: 'modx-'+this.ident+'-class'
  314. ,xtype: 'hidden'
  315. },{
  316. name: 'id'
  317. ,id: 'modx-'+this.ident+'-id'
  318. ,xtype: 'hidden'
  319. }]
  320. ,keys: []
  321. });
  322. MODx.window.CreateAccessPolicy.superclass.constructor.call(this,config);
  323. };
  324. Ext.extend(MODx.window.CreateAccessPolicy,MODx.Window);
  325. Ext.reg('modx-window-access-policy-create',MODx.window.CreateAccessPolicy);
  326. MODx.combo.AccessPolicyTemplate = function(config) {
  327. config = config || {};
  328. Ext.applyIf(config,{
  329. name: 'template'
  330. ,hiddenName: 'template'
  331. ,fields: ['id','name','description']
  332. ,forceSelection: true
  333. ,typeAhead: false
  334. ,editable: false
  335. ,allowBlank: false
  336. // ,listWidth: 300
  337. ,pageSize: 20
  338. ,url: MODx.config.connector_url
  339. ,baseParams: {
  340. action: 'security/access/policy/template/getlist'
  341. }
  342. ,tpl: new Ext.XTemplate('<tpl for="."><div class="x-combo-list-item"><span style="font-weight: bold">{name:htmlEncode}</span>'
  343. ,'<p style="margin: 0; font-size: 11px; color: gray;">{description:htmlEncode}</p></div></tpl>')
  344. });
  345. MODx.combo.AccessPolicyTemplate.superclass.constructor.call(this,config);
  346. };
  347. Ext.extend(MODx.combo.AccessPolicyTemplate,MODx.combo.ComboBox);
  348. Ext.reg('modx-combo-access-policy-template',MODx.combo.AccessPolicyTemplate);
  349. MODx.window.ImportPolicy = function(config) {
  350. config = config || {};
  351. this.ident = config.ident || 'imppol-'+Ext.id();
  352. Ext.applyIf(config,{
  353. title: _('policy_import')
  354. ,id: 'modx-window-policy-import'
  355. ,url: MODx.config.connector_url
  356. ,action: 'security/access/policy/import'
  357. ,fileUpload: true
  358. ,saveBtnText: _('import')
  359. ,fields: [{
  360. html: _('policy_import_msg')
  361. ,id: this.ident+'-desc'
  362. ,xtype: 'modx-description'
  363. ,style: 'margin-bottom: 10px;'
  364. },{
  365. xtype: 'fileuploadfield'
  366. ,fieldLabel: _('file')
  367. ,buttonText: _('upload.buttons.upload')
  368. ,name: 'file'
  369. ,id: this.ident+'-file'
  370. ,anchor: '100%'
  371. // ,inputType: 'file'
  372. }]
  373. });
  374. MODx.window.ImportPolicy.superclass.constructor.call(this,config);
  375. };
  376. Ext.extend(MODx.window.ImportPolicy,MODx.Window);
  377. Ext.reg('modx-window-policy-import',MODx.window.ImportPolicy);