modx.grid.user.settings.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * Loads a grid of User Settings
  3. *
  4. * @class MODx.grid.UserSettings
  5. * @extends MODx.grid.Grid
  6. * @param {Object} config An object of options.
  7. * @xtype modx-grid-user-settings
  8. */
  9. MODx.grid.UserSettings = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config,{
  12. title: _('user_settings')
  13. ,id: 'modx-grid-user-settings'
  14. ,url: MODx.config.connector_url
  15. ,baseParams: {
  16. action: 'security/user/setting/getList'
  17. ,user: config.user
  18. }
  19. ,saveParams: {
  20. user: config.user
  21. }
  22. ,save_action: 'security/user/setting/updatefromgrid'
  23. ,fk: config.user
  24. ,tbar: [{
  25. text: _('create_new')
  26. ,cls: 'primary-button'
  27. ,scope: this
  28. ,handler: {
  29. xtype: 'modx-window-setting-create'
  30. ,url: MODx.config.connector_url
  31. ,baseParams: {
  32. action: 'security/user/setting/create'
  33. }
  34. ,keyField: {
  35. xtype: 'modx-combo-setting-key'
  36. ,fieldLabel: _('key')
  37. ,name: 'key'
  38. ,id: 'modx-cs-key'
  39. ,maxLength: 100
  40. ,anchor: '100%'
  41. ,listeners: {
  42. 'render': {
  43. fn: function(key) {
  44. key.getStore().baseParams.namespace = Ext.getCmp('modx-cs-namespace').getValue();
  45. Ext.getCmp('modx-cs-namespace').on('select', function(combo, item) {
  46. key.getStore().baseParams.namespace = item.data.name;
  47. key.getStore().load();
  48. }, this);
  49. }
  50. ,scope: this
  51. }
  52. }
  53. }
  54. ,fk: config.user
  55. }
  56. }]
  57. });
  58. MODx.grid.UserSettings.superclass.constructor.call(this,config);
  59. };
  60. Ext.extend(MODx.grid.UserSettings,MODx.grid.SettingsGrid, {
  61. _showMenu: function(g,ri,e) {
  62. e.stopEvent();
  63. e.preventDefault();
  64. this.menu.record = this.getStore().getAt(ri).data;
  65. if (!this.getSelectionModel().isSelected(ri)) {
  66. this.getSelectionModel().selectRow(ri);
  67. }
  68. this.menu.removeAll();
  69. var m = [];
  70. if (this.menu.record.menu) {
  71. m = this.menu.record.menu;
  72. } else {
  73. m.push({
  74. text: _('setting_update')
  75. ,handler: this.updateSetting
  76. },'-',{
  77. text: _('setting_remove')
  78. ,handler: this.remove.createDelegate(this,['setting_remove_confirm', 'security/user/setting/remove'])
  79. });
  80. }
  81. if (m.length > 0) {
  82. this.addContextMenuItem(m);
  83. this.menu.showAt(e.xy);
  84. }
  85. }
  86. ,updateSetting: function(btn,e) {
  87. var r = this.menu.record;
  88. r.fk = Ext.isDefined(this.config.fk) ? this.config.fk : 0;
  89. var uss = MODx.load({
  90. xtype: 'modx-window-setting-update'
  91. ,action: 'security/user/setting/update'
  92. ,record: r
  93. ,grid: this
  94. ,listeners: {
  95. 'success': {fn:function(r) {
  96. this.refresh();
  97. },scope:this}
  98. }
  99. });
  100. uss.reset();
  101. uss.setValues(r);
  102. uss.show(e.target);
  103. }
  104. });
  105. Ext.reg('modx-grid-user-settings',MODx.grid.UserSettings);