modx.grid.access.policy.template.js 13 KB

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