modx.grid.fcset.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. MODx.grid.FCSet = function(config) {
  2. config = config || {};
  3. this.sm = new Ext.grid.CheckboxSelectionModel();
  4. Ext.applyIf(config,{
  5. id: 'modx-grid-fc-set'
  6. ,url: MODx.config.connector_url
  7. ,baseParams: {
  8. action: 'security/forms/set/getlist'
  9. }
  10. ,fields: ['id','profile','action','description','active','template','templatename','constraint_data','constraint','constraint_field','constraint_class','rules','perm']
  11. ,paging: true
  12. ,autosave: true
  13. ,sm: this.sm
  14. ,remoteSort: true
  15. ,autoExpandColumn: 'controller'
  16. ,columns: [this.sm,{
  17. header: _('id')
  18. ,dataIndex: 'id'
  19. ,width: 40
  20. ,sortable: true
  21. },{
  22. header: _('action')
  23. ,dataIndex: 'action'
  24. ,width: 200
  25. ,editable: false
  26. ,sortable: true
  27. ,editor: {
  28. xtype: 'modx-combo-fc-action',
  29. renderer: true
  30. }
  31. },{
  32. header: _('description')
  33. ,dataIndex: 'description'
  34. ,width: 200
  35. ,editable: true
  36. ,sortable: true
  37. },{
  38. header: _('template')
  39. ,dataIndex: 'templatename'
  40. ,width: 150
  41. ,sortable: true
  42. },{
  43. header: _('constraint')
  44. ,dataIndex: 'constraint_data'
  45. ,width: 200
  46. ,editable: false
  47. ,sortable: false
  48. }]
  49. ,viewConfig: {
  50. forceFit:true
  51. ,enableRowBody:true
  52. ,scrollOffset: 0
  53. ,autoFill: true
  54. ,showPreview: true
  55. ,getRowClass : function(rec, ri, p){
  56. return rec.data.active ? 'grid-row-active' : 'grid-row-inactive';
  57. }
  58. }
  59. ,tbar: [{
  60. text: _('set_new')
  61. ,cls: 'primary-button'
  62. ,scope: this
  63. ,handler: this.createSet
  64. },{
  65. text: _('bulk_actions')
  66. ,menu: [{
  67. text: _('selected_activate')
  68. ,handler: this.activateSelected
  69. ,scope: this
  70. },{
  71. text: _('selected_deactivate')
  72. ,handler: this.deactivateSelected
  73. ,scope: this
  74. },{
  75. text: _('selected_remove')
  76. ,handler: this.removeSelected
  77. ,scope: this
  78. }]
  79. },{
  80. text: _('import_from_xml')
  81. ,handler: this.importSet
  82. ,scope: this
  83. },'->',{
  84. xtype: 'textfield'
  85. ,name: 'search'
  86. ,id: 'modx-fcs-search'
  87. ,cls: 'x-form-filter'
  88. ,emptyText: _('filter_by_search')
  89. ,listeners: {
  90. 'change': {fn: this.search, scope: this}
  91. ,'render': {fn: function(cmp) {
  92. new Ext.KeyMap(cmp.getEl(), {
  93. key: Ext.EventObject.ENTER
  94. ,fn: this.blur
  95. ,scope: cmp
  96. });
  97. },scope:this}
  98. }
  99. },{
  100. xtype: 'button'
  101. ,id: 'modx-filter-clear'
  102. ,cls: 'x-form-filter-clear'
  103. ,text: _('filter_clear')
  104. ,listeners: {
  105. 'click': {fn: this.clearFilter, scope: this},
  106. 'mouseout': { fn: function(evt){
  107. this.removeClass('x-btn-focus');
  108. }
  109. }
  110. }
  111. }]
  112. });
  113. MODx.grid.FCSet.superclass.constructor.call(this,config);
  114. };
  115. Ext.extend(MODx.grid.FCSet,MODx.grid.Grid,{
  116. getMenu: function() {
  117. var r = this.getSelectionModel().getSelected();
  118. var p = r.data.perm;
  119. var m = [];
  120. if (this.getSelectionModel().getCount() > 1) {
  121. m.push({
  122. text: _('selected_activate')
  123. ,handler: this.activateSelected
  124. });
  125. m.push({
  126. text: _('selected_deactivate')
  127. ,handler: this.deactivateSelected
  128. });
  129. m.push('-');
  130. m.push({
  131. text: _('selected_remove')
  132. ,handler: this.removeSelected
  133. });
  134. } else {
  135. if (p.indexOf('pedit') != -1) {
  136. m.push({
  137. text: _('edit')
  138. ,handler: this.updateSet
  139. });
  140. m.push({
  141. text: _('duplicate')
  142. ,handler: this.duplicateSet
  143. });
  144. m.push({
  145. text: _('export')
  146. ,handler: this.exportSet
  147. });
  148. m.push('-');
  149. if (r.data.active) {
  150. m.push({
  151. text: _('deactivate')
  152. ,handler: this.deactivateSet
  153. });
  154. } else {
  155. m.push({
  156. text: _('activate')
  157. ,handler: this.activateSet
  158. });
  159. }
  160. }
  161. if (p.indexOf('premove') != -1) {
  162. m.push('-',{
  163. text: _('remove')
  164. ,handler: this.confirm.createDelegate(this,['security/forms/set/remove','set_remove_confirm'])
  165. });
  166. }
  167. }
  168. if (m.length > 0) {
  169. this.addContextMenuItem(m);
  170. }
  171. }
  172. ,search: function(tf,newValue,oldValue) {
  173. var nv = newValue || tf;
  174. this.getStore().baseParams.search = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  175. this.getBottomToolbar().changePage(1);
  176. //this.refresh();
  177. return true;
  178. }
  179. ,clearFilter: function() {
  180. this.getStore().baseParams = {
  181. action: 'security/forms/set/getList'
  182. ,profile: MODx.request.id
  183. };
  184. Ext.getCmp('modx-fcs-search').reset();
  185. this.getBottomToolbar().changePage(1);
  186. //this.refresh();
  187. }
  188. ,exportSet: function(btn,e) {
  189. var id = this.menu.record.id;
  190. MODx.Ajax.request({
  191. url: this.config.url
  192. ,params: {
  193. action: 'security/forms/set/export'
  194. ,id: id
  195. }
  196. ,listeners: {
  197. 'success': {fn:function(r) {
  198. location.href = this.config.url+'?action=security/forms/set/export&download='+r.message+'&id='+id+'&HTTP_MODAUTH='+MODx.siteId;
  199. },scope:this}
  200. }
  201. });
  202. }
  203. ,importSet: function(btn,e) {
  204. var r = {
  205. profile: MODx.request.id
  206. };
  207. if (!this.windows.impset) {
  208. this.windows.impset = MODx.load({
  209. xtype: 'modx-window-fc-set-import'
  210. ,record: r
  211. ,listeners: {
  212. 'success': {fn:function(o) {
  213. this.refresh();
  214. },scope:this}
  215. }
  216. });
  217. }
  218. this.windows.impset.reset();
  219. this.windows.impset.setValues(r);
  220. this.windows.impset.show(e.target);
  221. }
  222. ,createSet: function(btn,e) {
  223. var r = {
  224. profile: MODx.request.id
  225. ,active: true
  226. };
  227. if (!this.windows.cset) {
  228. this.windows.cset = MODx.load({
  229. xtype: 'modx-window-fc-set-create'
  230. ,record: r
  231. ,listeners: {
  232. 'success': {fn:function(r) {
  233. this.refresh();
  234. },scope:this}
  235. }
  236. });
  237. }
  238. this.windows.cset.reset();
  239. this.windows.cset.setValues(r);
  240. this.windows.cset.show(e.target);
  241. }
  242. ,updateSet: function(btn,e) {
  243. var r = this.menu.record;
  244. location.href = '?a=security/forms/set/update&id='+r.id;
  245. }
  246. ,duplicateSet: function(btn,e) {
  247. MODx.Ajax.request({
  248. url: this.config.url
  249. ,params: {
  250. action: 'security/forms/set/duplicate'
  251. ,id: this.menu.record.id
  252. }
  253. ,listeners: {
  254. 'success': {fn:this.refresh,scope:this}
  255. }
  256. });
  257. }
  258. ,activateSet: function(btn,e) {
  259. MODx.Ajax.request({
  260. url: this.config.url
  261. ,params: {
  262. action: 'security/forms/set/activate'
  263. ,id: this.menu.record.id
  264. }
  265. ,listeners: {
  266. 'success': {fn:this.refresh,scope:this}
  267. }
  268. });
  269. }
  270. ,activateSelected: function() {
  271. var cs = this.getSelectedAsList();
  272. if (cs === false) return false;
  273. MODx.Ajax.request({
  274. url: this.config.url
  275. ,params: {
  276. action: 'security/forms/set/activateMultiple'
  277. ,sets: cs
  278. }
  279. ,listeners: {
  280. 'success': {fn:function(r) {
  281. this.getSelectionModel().clearSelections(true);
  282. this.refresh();
  283. },scope:this}
  284. }
  285. });
  286. return true;
  287. }
  288. ,deactivateSet: function(btn,e) {
  289. MODx.Ajax.request({
  290. url: this.config.url
  291. ,params: {
  292. action: 'security/forms/set/deactivate'
  293. ,id: this.menu.record.id
  294. }
  295. ,listeners: {
  296. 'success': {fn:this.refresh,scope:this}
  297. }
  298. });
  299. }
  300. ,deactivateSelected: function() {
  301. var cs = this.getSelectedAsList();
  302. if (cs === false) return false;
  303. MODx.Ajax.request({
  304. url: this.config.url
  305. ,params: {
  306. action: 'security/forms/set/deactivateMultiple'
  307. ,sets: cs
  308. }
  309. ,listeners: {
  310. 'success': {fn:function(r) {
  311. this.getSelectionModel().clearSelections(true);
  312. this.refresh();
  313. },scope:this}
  314. }
  315. });
  316. return true;
  317. }
  318. ,removeSelected: function() {
  319. var cs = this.getSelectedAsList();
  320. if (cs === false) return false;
  321. MODx.msg.confirm({
  322. title: _('set_remove_multiple')
  323. ,text: _('set_remove_multiple_confirm')
  324. ,url: this.config.url
  325. ,params: {
  326. action: 'security/forms/set/removeMultiple'
  327. ,sets: cs
  328. }
  329. ,listeners: {
  330. 'success': {fn:function(r) {
  331. this.getSelectionModel().clearSelections(true);
  332. this.refresh();
  333. },scope:this}
  334. }
  335. });
  336. return true;
  337. }
  338. });
  339. Ext.reg('modx-grid-fc-set',MODx.grid.FCSet);
  340. MODx.window.CreateFCSet = function(config) {
  341. config = config || {};
  342. Ext.applyIf(config,{
  343. title: _('set_create')
  344. ,url: MODx.config.connector_url
  345. ,action: 'security/forms/set/create'
  346. // ,height: 150
  347. ,width: 600
  348. ,fields: [{
  349. xtype: 'hidden'
  350. ,name: 'profile'
  351. ,value: MODx.request.id
  352. },{
  353. xtype: 'hidden'
  354. ,fieldLabel: _('constraint_class')
  355. ,name: 'constraint_class'
  356. ,anchor: '100%'
  357. ,allowBlank: true
  358. ,value: 'modResource'
  359. },{
  360. layout: 'column'
  361. ,border: false
  362. ,defaults: {
  363. layout: 'form'
  364. ,labelAlign: 'top'
  365. ,anchor: '100%'
  366. ,border: false
  367. }
  368. ,items: [{
  369. columnWidth: .5
  370. ,items: [{
  371. fieldLabel: _('action')
  372. ,name: 'action_id'
  373. ,hiddenName: 'action_id'
  374. ,id: 'modx-fcsc-action'
  375. ,xtype: 'modx-combo-fc-action'
  376. ,editable: false
  377. ,allowBlank: false
  378. ,anchor: '100%'
  379. },{
  380. xtype: 'textarea'
  381. ,name: 'description'
  382. ,fieldLabel: _('description')
  383. ,id: 'modx-fcsc-description'
  384. ,anchor: '100%'
  385. },{
  386. xtype: 'xcheckbox'
  387. ,boxLabel: _('active')
  388. ,hideLabel: true
  389. ,name: 'active'
  390. ,inputValue: 1
  391. ,value: 1
  392. ,checked: true
  393. ,anchor: '100%'
  394. ,allowBlank: true
  395. }]
  396. },{
  397. columnWidth: .5
  398. ,items: [{
  399. xtype: 'modx-combo-template'
  400. ,name: 'template'
  401. ,hiddenName: 'template'
  402. ,fieldLabel: _('template')
  403. ,description: MODx.expandHelp ? '' : _('set_template_desc')
  404. ,id: 'modx-fcsc-template'
  405. ,anchor: '100%'
  406. ,baseParams: { action: 'element/template/getList', combo: true }
  407. },{
  408. xtype: MODx.expandHelp ? 'label' : 'hidden'
  409. ,forId: 'modx-fcsc-template'
  410. ,html: _('set_template_desc')
  411. ,cls: 'desc-under'
  412. },{
  413. xtype: 'textfield'
  414. ,fieldLabel: _('constraint_field')
  415. ,description: MODx.expandHelp ? '' : _('set_constraint_field_desc')
  416. ,name: 'constraint_field'
  417. ,id: 'modx-fcsc-constraint-field'
  418. ,anchor: '100%'
  419. ,allowBlank: true
  420. },{
  421. xtype: MODx.expandHelp ? 'label' : 'hidden'
  422. ,forId: 'modx-fcsc-constraint-field'
  423. ,html: _('set_constraint_field_desc')
  424. ,cls: 'desc-under'
  425. },{
  426. xtype: 'textfield'
  427. ,fieldLabel: _('constraint')
  428. ,description: MODx.expandHelp ? '' : _('set_constraint_desc')
  429. ,name: 'constraint'
  430. ,id: 'modx-fcsc-constraint'
  431. ,anchor: '100%'
  432. ,allowBlank: true
  433. },{
  434. xtype: MODx.expandHelp ? 'label' : 'hidden'
  435. ,forId: 'modx-fcsc-constraint'
  436. ,html: _('set_constraint_desc')
  437. ,cls: 'desc-under'
  438. }]
  439. }]
  440. }]
  441. ,keys: []
  442. });
  443. MODx.window.CreateFCSet.superclass.constructor.call(this,config);
  444. };
  445. Ext.extend(MODx.window.CreateFCSet,MODx.Window);
  446. Ext.reg('modx-window-fc-set-create',MODx.window.CreateFCSet);
  447. MODx.window.ImportFCSet = function(config) {
  448. config = config || {};
  449. Ext.applyIf(config,{
  450. title: _('import_from_xml')
  451. ,id: 'modx-window-fc-set-import'
  452. ,url: MODx.config.connector_url
  453. ,action: 'security/forms/set/import'
  454. ,fileUpload: true
  455. ,saveBtnText: _('import')
  456. ,fields: [{
  457. xtype: 'hidden'
  458. ,name: 'profile'
  459. ,value: MODx.request.id
  460. },{
  461. html: _('set_import_msg')
  462. ,id: 'modx-impset-desc'
  463. ,xtype: 'modx-description'
  464. ,style: 'margin-bottom: 10px;'
  465. },{
  466. xtype: 'fileuploadfield'
  467. ,fieldLabel: _('file')
  468. ,buttonText: _('upload.buttons.upload')
  469. ,name: 'file'
  470. ,id: 'modx-impset-file'
  471. ,anchor: '100%'
  472. // ,inputType: 'file'
  473. }]
  474. });
  475. MODx.window.ImportFCSet.superclass.constructor.call(this,config);
  476. };
  477. Ext.extend(MODx.window.ImportFCSet,MODx.Window);
  478. Ext.reg('modx-window-fc-set-import',MODx.window.ImportFCSet);