modx.grid.fcprofile.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. MODx.panel.FCProfiles = function(config) {
  2. config = config || {};
  3. Ext.applyIf(config,{
  4. id: 'modx-panel-fc-profiles'
  5. ,cls: 'container'
  6. ,defaults: { collapsible: false ,autoHeight: true }
  7. ,items: [{
  8. html: _('form_customization')
  9. ,id: 'modx-fcp-header'
  10. ,xtype: 'modx-header'
  11. },MODx.getPageStructure([{
  12. title: _('profiles')
  13. ,autoHeight: true
  14. ,layout: "form"
  15. ,items: [{
  16. html: '<p>'+_('form_customization_msg')+'</p>'
  17. ,xtype: 'modx-description'
  18. },{
  19. title: ''
  20. ,preventRender: true
  21. ,xtype: 'modx-grid-fc-profile'
  22. ,cls:'main-wrapper'
  23. }]
  24. }],{
  25. id: 'modx-form-customization-tabs'
  26. })]
  27. });
  28. MODx.panel.FCProfiles.superclass.constructor.call(this,config);
  29. };
  30. Ext.extend(MODx.panel.FCProfiles,MODx.FormPanel);
  31. Ext.reg('modx-panel-fc-profiles',MODx.panel.FCProfiles);
  32. MODx.grid.FCProfile = function(config) {
  33. config = config || {};
  34. this.sm = new Ext.grid.CheckboxSelectionModel();
  35. Ext.applyIf(config,{
  36. id: 'modx-grid-fc-profile'
  37. ,url: MODx.config.connector_url
  38. ,baseParams: {
  39. action: 'security/forms/profile/getlist'
  40. }
  41. ,fields: ['id','name','description','usergroups','active','rank','sets','perm']
  42. ,paging: true
  43. ,autosave: true
  44. ,save_action: 'security/forms/profile/updatefromgrid'
  45. ,sm: this.sm
  46. ,remoteSort: true
  47. ,columns: [this.sm,{
  48. header: _('id')
  49. ,dataIndex: 'id'
  50. ,width: 40
  51. ,sortable: true
  52. },{
  53. header: _('name')
  54. ,dataIndex: 'name'
  55. ,width: 200
  56. ,sortable: true
  57. ,editor: { xtype: 'textfield' }
  58. },{
  59. header: _('description')
  60. ,dataIndex: 'description'
  61. ,width: 250
  62. ,sortable: true
  63. ,editor: { xtype: 'textfield' }
  64. },{
  65. header: _('usergroups')
  66. ,dataIndex: 'usergroups'
  67. ,width: 150
  68. }]
  69. ,viewConfig: {
  70. forceFit:true
  71. ,enableRowBody:true
  72. ,scrollOffset: 0
  73. ,autoFill: true
  74. ,showPreview: true
  75. ,getRowClass : function(rec, ri, p){
  76. return rec.data.active ? 'grid-row-active' : 'grid-row-inactive';
  77. }
  78. }
  79. ,tbar: [{
  80. text: _('profile_create')
  81. ,scope: this
  82. ,handler: this.createProfile
  83. ,cls:'primary-button'
  84. },{
  85. text: _('bulk_actions')
  86. ,menu: [{
  87. text: _('selected_activate')
  88. ,handler: this.activateSelected
  89. ,scope: this
  90. },{
  91. text: _('selected_deactivate')
  92. ,handler: this.deactivateSelected
  93. ,scope: this
  94. },{
  95. text: _('selected_remove')
  96. ,handler: this.removeSelected
  97. ,scope: this
  98. }]
  99. },'->',{
  100. xtype: 'textfield'
  101. ,name: 'search'
  102. ,id: 'modx-fcp-search'
  103. ,cls: 'x-form-filter'
  104. ,emptyText: _('filter_by_search')
  105. ,listeners: {
  106. 'change': {fn: this.search, scope: this}
  107. ,'render': {fn: function(cmp) {
  108. new Ext.KeyMap(cmp.getEl(), {
  109. key: Ext.EventObject.ENTER
  110. ,fn: function() {
  111. this.fireEvent('change',this.getValue());
  112. this.blur();
  113. return true;}
  114. ,scope: cmp
  115. });
  116. },scope:this}
  117. }
  118. },{
  119. xtype: 'button'
  120. ,id: 'modx-filter-clear'
  121. ,cls: 'x-form-filter-clear'
  122. ,text: _('filter_clear')
  123. ,listeners: {
  124. 'click': {fn: this.clearFilter, scope: this},
  125. 'mouseout': { fn: function(evt){
  126. this.removeClass('x-btn-focus');
  127. }
  128. }
  129. }
  130. }]
  131. });
  132. MODx.grid.FCProfile.superclass.constructor.call(this,config);
  133. this.on('render',function() { this.getStore().reload(); },this);
  134. };
  135. Ext.extend(MODx.grid.FCProfile,MODx.grid.Grid,{
  136. getMenu: function() {
  137. var r = this.getSelectionModel().getSelected();
  138. var p = r.data.perm;
  139. var m = [];
  140. if (this.getSelectionModel().getCount() > 1) {
  141. m.push({
  142. text: _('selected_activate')
  143. ,handler: this.activateSelected
  144. });
  145. m.push({
  146. text: _('selected_deactivate')
  147. ,handler: this.deactivateSelected
  148. });
  149. m.push('-');
  150. m.push({
  151. text: _('selected_remove')
  152. ,handler: this.removeSelected
  153. });
  154. } else {
  155. if (p.indexOf('pedit') != -1) {
  156. m.push({
  157. text: _('edit')
  158. ,handler: this.updateProfile
  159. },{
  160. text: _('duplicate')
  161. ,handler: this.duplicateProfile
  162. },'-');
  163. if (r.data.active) {
  164. m.push({
  165. text: _('deactivate')
  166. ,handler: this.deactivateProfile
  167. });
  168. } else {
  169. m.push({
  170. text: _('activate')
  171. ,handler: this.activateProfile
  172. });
  173. }
  174. }
  175. if (p.indexOf('premove') != -1) {
  176. m.push('-',{
  177. text: _('remove')
  178. ,handler: this.confirm.createDelegate(this,['security/forms/profile/remove','profile_remove_confirm'])
  179. });
  180. }
  181. }
  182. if (m.length > 0) {
  183. this.addContextMenuItem(m);
  184. }
  185. }
  186. ,search: function(tf,newValue,oldValue) {
  187. var nv = newValue || tf;
  188. this.getStore().baseParams.search = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  189. this.getBottomToolbar().changePage(1);
  190. //this.refresh();
  191. return true;
  192. }
  193. ,clearFilter: function() {
  194. this.getStore().baseParams = {
  195. action: 'security/forms/profile/getlist'
  196. };
  197. Ext.getCmp('modx-fcp-search').reset();
  198. this.getBottomToolbar().changePage(1);
  199. }
  200. ,createProfile: function(btn,e) {
  201. if (!this.windows.cpro) {
  202. this.windows.cpro = MODx.load({
  203. xtype: 'modx-window-fc-profile-create'
  204. ,listeners: {
  205. 'success': {fn:function(r) {
  206. this.refresh();
  207. },scope:this}
  208. }
  209. });
  210. }
  211. this.windows.cpro.reset();
  212. this.windows.cpro.show(e.target);
  213. }
  214. ,updateProfile: function(btn,e) {
  215. var r = this.menu.record;
  216. location.href = '?a=security/forms/profile/update&id='+r.id;
  217. }
  218. ,duplicateProfile: function(btn,e) {
  219. MODx.Ajax.request({
  220. url: this.config.url
  221. ,params: {
  222. action: 'security/forms/profile/duplicate'
  223. ,id: this.menu.record.id
  224. }
  225. ,listeners: {
  226. 'success': {fn:this.refresh,scope:this}
  227. }
  228. });
  229. }
  230. ,activateProfile: function(btn,e) {
  231. MODx.Ajax.request({
  232. url: this.config.url
  233. ,params: {
  234. action: 'security/forms/profile/activate'
  235. ,id: this.menu.record.id
  236. }
  237. ,listeners: {
  238. 'success': {fn:this.refresh,scope:this}
  239. }
  240. });
  241. }
  242. ,activateSelected: function() {
  243. var cs = this.getSelectedAsList();
  244. if (cs === false) return false;
  245. MODx.Ajax.request({
  246. url: this.config.url
  247. ,params: {
  248. action: 'security/forms/profile/activateMultiple'
  249. ,profiles: cs
  250. }
  251. ,listeners: {
  252. 'success': {fn:function(r) {
  253. this.getSelectionModel().clearSelections(true);
  254. this.refresh();
  255. },scope:this}
  256. }
  257. });
  258. return true;
  259. }
  260. ,deactivateProfile: function(btn,e) {
  261. MODx.Ajax.request({
  262. url: this.config.url
  263. ,params: {
  264. action: 'security/forms/profile/deactivate'
  265. ,id: this.menu.record.id
  266. }
  267. ,listeners: {
  268. 'success': {fn:this.refresh,scope:this}
  269. }
  270. });
  271. }
  272. ,deactivateSelected: function() {
  273. var cs = this.getSelectedAsList();
  274. if (cs === false) return false;
  275. MODx.Ajax.request({
  276. url: this.config.url
  277. ,params: {
  278. action: 'security/forms/profile/deactivateMultiple'
  279. ,profiles: cs
  280. }
  281. ,listeners: {
  282. 'success': {fn:function(r) {
  283. this.getSelectionModel().clearSelections(true);
  284. this.refresh();
  285. },scope:this}
  286. }
  287. });
  288. return true;
  289. }
  290. ,removeSelected: function() {
  291. var cs = this.getSelectedAsList();
  292. if (cs === false) return false;
  293. MODx.msg.confirm({
  294. title: _('profile_remove_multiple')
  295. ,text: _('profile_remove_multiple_confirm')
  296. ,url: this.config.url
  297. ,params: {
  298. action: 'security/forms/profile/removeMultiple'
  299. ,profiles: cs
  300. }
  301. ,listeners: {
  302. 'success': {fn:function(r) {
  303. this.getSelectionModel().clearSelections(true);
  304. this.refresh();
  305. },scope:this}
  306. }
  307. });
  308. return true;
  309. }
  310. });
  311. Ext.reg('modx-grid-fc-profile',MODx.grid.FCProfile);
  312. MODx.window.CreateFCProfile = function(config) {
  313. config = config || {};
  314. Ext.applyIf(config,{
  315. title: _('profile_create')
  316. ,url: MODx.config.connector_url
  317. ,action: 'security/forms/profile/create'
  318. // ,height: 150
  319. // ,width: 375
  320. ,fields: [{
  321. xtype: 'textfield'
  322. ,name: 'name'
  323. ,fieldLabel: _('name')
  324. ,id: 'modx-fccp-name'
  325. ,allowBlank: false
  326. ,anchor: '100%'
  327. },{
  328. xtype: 'textarea'
  329. ,name: 'description'
  330. ,fieldLabel: _('description')
  331. ,id: 'modx-fccp-description'
  332. ,anchor: '100%'
  333. },{
  334. xtype: 'xcheckbox'
  335. ,boxLabel: _('active')
  336. ,hideLabel: true
  337. ,name: 'active'
  338. ,id: 'modx-fccp-active'
  339. ,inputValue: 1
  340. ,value: 1
  341. ,checked: true
  342. ,anchor: '100%'
  343. }]
  344. ,keys: []
  345. });
  346. MODx.window.CreateFCProfile.superclass.constructor.call(this,config);
  347. };
  348. Ext.extend(MODx.window.CreateFCProfile,MODx.Window);
  349. Ext.reg('modx-window-fc-profile-create',MODx.window.CreateFCProfile);