modx.panel.fcprofile.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /**
  2. * @class MODx.panel.FCProfile
  3. * @extends MODx.FormPanel
  4. * @param {Object} config An object of configuration properties
  5. * @xtype modx-panel-fc-profile
  6. */
  7. MODx.panel.FCProfile = function(config) {
  8. config = config || {};
  9. Ext.applyIf(config,{
  10. url: MODx.config.connector_url
  11. ,baseParams: {
  12. action: 'security/forms/profile/get'
  13. }
  14. ,id: 'modx-panel-fc-profile'
  15. ,cls: 'container'
  16. ,class_key: 'modFormCustomizationProfile'
  17. ,bodyStyle: ''
  18. ,items: [{
  19. html: _('profile_new')
  20. ,id: 'modx-fcp-header'
  21. ,xtype: 'modx-header'
  22. },MODx.getPageStructure([{
  23. title: _('profile')
  24. ,defaults: { border: false ,msgTarget: 'side' }
  25. ,layout: 'form'
  26. ,id: 'modx-chunk-form'
  27. ,labelWidth: 150
  28. ,items: [{
  29. html: '<p>'+_('profile_msg')+'</p>'
  30. ,id: 'modx-fcp-msg'
  31. ,xtype: 'modx-description'
  32. },{
  33. xtype: 'panel'
  34. ,border: false
  35. ,cls:'main-wrapper'
  36. ,layout: 'form'
  37. ,items: [{
  38. xtype: 'hidden'
  39. ,name: 'id'
  40. ,id: 'modx-fcp-id'
  41. ,value: config.record.id || MODx.request.id
  42. },{
  43. xtype: 'textfield'
  44. ,fieldLabel: _('name')
  45. ,name: 'name'
  46. ,id: 'modx-fcp-name'
  47. ,anchor: '100%'
  48. ,maxLength: 255
  49. ,enableKeyEvents: true
  50. ,allowBlank: false
  51. ,value: config.record.name
  52. ,listeners: {
  53. 'keyup': {scope:this,fn:function(f,e) {
  54. Ext.getCmp('modx-fcp-header').getEl().update(_('profile')+': '+f.getValue());
  55. }}
  56. }
  57. },{
  58. xtype: 'textarea'
  59. ,fieldLabel: _('description')
  60. ,name: 'description'
  61. ,id: 'modx-fcp-description'
  62. ,anchor: '100%'
  63. ,maxLength: 255
  64. ,grow: false
  65. ,value: config.record.description
  66. },{
  67. xtype: 'xcheckbox'
  68. ,fieldLabel: _('active')
  69. ,name: 'active'
  70. ,id: 'modx-fcp-active'
  71. ,inputValue: true
  72. ,value: config.record.active ? true : false
  73. ,anchor: '100%'
  74. ,allowBlank: true
  75. }]
  76. },{
  77. xtype: 'modx-grid-fc-set'
  78. ,cls:'main-wrapper'
  79. ,baseParams: {
  80. action: 'security/forms/set/getList'
  81. ,profile: config.record.id
  82. }
  83. ,preventRender: true
  84. }]
  85. },{
  86. title: _('usergroups')
  87. ,layout: 'anchor'
  88. ,items: [{
  89. html: '<p>'+_('profile_usergroups_msg')+'</p>'
  90. ,xtype: 'modx-description'
  91. },{
  92. xtype: 'modx-grid-fc-profile-usergroups'
  93. ,cls:'main-wrapper'
  94. ,data: config.record.usergroups || []
  95. ,preventRender: true
  96. }]
  97. }],{
  98. id: 'modx-fc-profile-tabs'
  99. })]
  100. ,listeners: {
  101. 'setup': {fn:this.setup,scope:this}
  102. ,'success': {fn:this.success,scope:this}
  103. ,'beforeSubmit': {fn:this.beforeSubmit,scope:this}
  104. }
  105. });
  106. MODx.panel.FCProfile.superclass.constructor.call(this,config);
  107. };
  108. Ext.extend(MODx.panel.FCProfile,MODx.FormPanel,{
  109. initialized: false
  110. ,setup: function() {
  111. if (!this.initialized) { this.getForm().setValues(this.config.record); }
  112. if (!Ext.isEmpty(this.config.record.name)) {
  113. Ext.defer(function() {
  114. Ext.getCmp('modx-fcp-header').update(_('profile')+': '+this.config.record.name);
  115. }, 250, this);
  116. }
  117. this.fireEvent('ready',this.config.record);
  118. this.clearDirty();
  119. this.initialized = true;
  120. MODx.fireEvent('ready');
  121. return true;
  122. }
  123. ,beforeSubmit: function(o) {
  124. Ext.apply(o.form.baseParams,{
  125. usergroups: Ext.getCmp('modx-grid-fc-profile-usergroups').encode()
  126. });
  127. return this.fireEvent('save',{
  128. values: this.getForm().getValues()
  129. });
  130. }
  131. ,success: function(r) {
  132. Ext.getCmp('modx-grid-fc-profile-usergroups').getStore().commitChanges();
  133. this.getForm().setValues(r.result.object);
  134. }
  135. });
  136. Ext.reg('modx-panel-fc-profile',MODx.panel.FCProfile);
  137. MODx.grid.FCProfileUserGroups = function(config) {
  138. config = config || {};
  139. Ext.applyIf(config,{
  140. id: 'modx-grid-fc-profile-usergroups'
  141. ,fields: ['id','name']
  142. ,autoHeight: true
  143. ,stateful: false
  144. ,columns: [{
  145. header: _('name')
  146. ,dataIndex: 'name'
  147. }]
  148. ,tbar: [{
  149. text: _('usergroup_create')
  150. ,cls: 'primary-button'
  151. ,handler: this.addUserGroup
  152. ,scope: this
  153. }]
  154. });
  155. MODx.grid.FCProfileUserGroups.superclass.constructor.call(this,config);
  156. this.fcugRecord = Ext.data.Record.create(config.fields);
  157. };
  158. Ext.extend(MODx.grid.FCProfileUserGroups,MODx.grid.LocalGrid,{
  159. addUserGroup: function(btn,e) {
  160. this.loadWindow(btn,e,{
  161. xtype: 'modx-window-fc-profile-add-usergroup'
  162. ,listeners: {
  163. 'success': {fn:function(r) {
  164. var s = this.getStore();
  165. var rec = new this.fcugRecord(r);
  166. s.add(rec);
  167. },scope:this}
  168. }
  169. });
  170. }
  171. ,getMenu: function(g,ri) {
  172. return [{
  173. text: _('usergroup_remove')
  174. ,handler: this.removeUserGroup
  175. ,scope: this
  176. }];
  177. }
  178. ,removeUserGroup: function(btn,e) {
  179. var rec = this.getSelectionModel().getSelected();
  180. Ext.Msg.confirm(_('usergroup_remove'),_('usergroup_remove_confirm'),function(e) {
  181. if (e == 'yes') {
  182. this.getStore().remove(rec);
  183. }
  184. },this);
  185. }
  186. });
  187. Ext.reg('modx-grid-fc-profile-usergroups',MODx.grid.FCProfileUserGroups);
  188. MODx.window.AddGroupToProfile = function(config) {
  189. config = config || {};
  190. Ext.applyIf(config,{
  191. title: _('usergroup_create')
  192. // ,height: 150
  193. // ,width: 375
  194. ,fields: [{
  195. fieldLabel: _('user_group')
  196. ,name: 'usergroup'
  197. ,hiddenName: 'usergroup'
  198. ,id: 'modx-fcaug-usergroup'
  199. ,xtype: 'modx-combo-usergroup'
  200. ,editable: false
  201. ,allowBlank: false
  202. ,anchor: '100%'
  203. }]
  204. });
  205. MODx.window.AddGroupToProfile.superclass.constructor.call(this,config);
  206. };
  207. Ext.extend(MODx.window.AddGroupToProfile,MODx.Window,{
  208. submit: function() {
  209. var rec = {};
  210. rec.id = Ext.getCmp('modx-fcaug-usergroup').getValue();
  211. rec.name = Ext.getCmp('modx-fcaug-usergroup').getRawValue();
  212. var g = Ext.getCmp('modx-grid-fc-profile-usergroups');
  213. var s = g.getStore();
  214. var v = s.findExact('id',rec.id);
  215. if (v != '-1') {
  216. MODx.msg.alert(_('error'),_('profile_usergroup_err_ae'));
  217. return false;
  218. }
  219. this.fireEvent('success',rec);
  220. this.hide();
  221. return false;
  222. }
  223. });
  224. Ext.reg('modx-window-fc-profile-add-usergroup',MODx.window.AddGroupToProfile);