modx.grid.role.user.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * Loads a grid of Role and User pairs.
  3. *
  4. * @deprecated
  5. *
  6. * @class MODx.grid.AccessResourceGroup
  7. * @extends MODx.grid.Grid
  8. * @param {Object} config An object of options.
  9. * @xtype modx-grid-roleuser
  10. */
  11. MODx.grid.RoleUser = function(config) {
  12. config = config || {};
  13. Ext.applyIf(config,{
  14. title: _('role_users')
  15. ,url: MODx.config.connector_url
  16. ,fields: ['id','username','fullname','email']
  17. ,baseParams: {
  18. action: 'security/role/getUsers'
  19. ,role: config.role
  20. }
  21. ,autosave: true
  22. ,paging: true
  23. ,columns: [
  24. { header: _('id') ,dataIndex: 'id' ,width: 40 }
  25. ,{ header: _('username') ,dataIndex: 'username' ,width: 175 }
  26. ,{ header: _('name') ,dataIndex: 'fullname' ,width: 175 }
  27. ,{ header: _('email') ,dataIndex: 'email' ,width: 200 }
  28. ]
  29. ,tbar: this.getToolbar()
  30. });
  31. MODx.grid.RoleUser.superclass.constructor.call(this,config);
  32. };
  33. Ext.extend(MODx.grid.RoleUser,MODx.grid.Grid,{
  34. combos: {}
  35. /**
  36. * Runs a confirm dialog, and if proceeding, removes the modUser.
  37. */
  38. ,removeUser: function() {
  39. MODx.msg.confirm({
  40. title: _('role_user_remove')
  41. ,text: _('role_user_confirm_remove')
  42. ,url: this.config.url
  43. ,params: {
  44. action: 'security/role/removeUser'
  45. ,user: this.menu.record.id
  46. ,role: this.config.role
  47. }
  48. ,listeners: {
  49. 'success': {fn:this.refresh,scope:this}
  50. }
  51. });
  52. }
  53. /**
  54. * Adds a user to the role based upon the combobox value.
  55. */
  56. ,addUser: function(btn,e) {
  57. var user = Ext.getCmp('rugrid-combo-user').getValue();
  58. MODx.Ajax.request({
  59. url: this.config.url
  60. ,params: {
  61. action: 'security/role/addUser'
  62. ,role: this.config.role
  63. ,user: user
  64. }
  65. ,listeners: {
  66. 'success': {fn:function(r) {
  67. this.getStore().baseParams = {
  68. action: 'security/role/getUsers'
  69. ,role: this.config.role
  70. };
  71. Ext.getCmp('rugrid-combo-usergroup').setValue('');
  72. this.refresh();
  73. },scope:this}
  74. }
  75. });
  76. }
  77. /**
  78. * Loads the context menu for the user-role pairing.
  79. */
  80. ,_loadMenu: function() {
  81. this.menu = new Ext.menu.Menu({ defaultAlign: 'tl-b?' });
  82. this.menu.add({
  83. text: _('role_user_remove')
  84. ,handler: this.removeUser
  85. ,scope: this
  86. });
  87. }
  88. /**
  89. * Returns the custom toolbar for the grid.
  90. */
  91. ,getToolbar: function() {
  92. return [
  93. _('role_user_add')+': '
  94. ,{
  95. xtype: 'modx-combo-user'
  96. ,id: 'rugrid-combo-user'
  97. },{
  98. xtype: 'button'
  99. ,text: 'Add'
  100. ,scope: this
  101. ,handler: this.addUser
  102. }
  103. ,'->'
  104. ,_('group')+': '
  105. ,{
  106. xtype: 'modx-combo-usergroup'
  107. ,id: 'rugrid-combo-usergroup'
  108. ,listeners: {
  109. 'select': {fn:function(btn,e) {
  110. this.store.baseParams = {
  111. action: 'security/role/getUsers'
  112. ,role: this.config.role
  113. ,group: Ext.getCmp('rugrid-combo-usergroup').getValue()
  114. };
  115. this.refresh();
  116. },scope:this}
  117. }
  118. },{
  119. xtype: 'button'
  120. ,text: _('clear_filter')
  121. ,scope: this
  122. ,handler: function(btn,e) {
  123. this.getStore().baseParams = {
  124. action: 'security/role/getUsers'
  125. ,role: this.config.role
  126. };
  127. Ext.getCmp('rugrid-combo-usergroup').setValue('');
  128. this.getStore().load();
  129. }
  130. }
  131. ];
  132. }
  133. });
  134. Ext.reg('modx-grid-roleuser',MODx.grid.RoleUser);