modx.grid.role.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * Loads a grid of roles.
  3. *
  4. * @class MODx.grid.Role
  5. * @extends MODx.grid.Grid
  6. * @constructor
  7. * @param {Object} config An object of options.
  8. * @xtype grid-role
  9. */
  10. MODx.grid.Role = function(config) {
  11. config = config || {};
  12. Ext.applyIf(config,{
  13. title: _('roles')
  14. ,id: 'modx-grid-role'
  15. ,url: MODx.config.connector_url
  16. ,baseParams: {
  17. action: 'security/role/getlist'
  18. }
  19. ,fields: ['id','name','description','authority','perm']
  20. ,paging: true
  21. ,autosave: true
  22. ,save_action: 'security/role/updatefromgrid'
  23. ,columns: [{
  24. header: _('id')
  25. ,dataIndex: 'id'
  26. ,width: 50
  27. ,sortable: true
  28. },{
  29. header: _('name')
  30. ,dataIndex: 'name'
  31. ,width: 150
  32. ,sortable: true
  33. ,editor: { xtype: 'textfield' }
  34. },{
  35. header: _('description')
  36. ,dataIndex: 'description'
  37. ,width: 350
  38. ,editor: { xtype: 'textfield' }
  39. },{
  40. header: _('authority')
  41. ,dataIndex: 'authority'
  42. ,width: 60
  43. ,editor: { xtype: 'textfield' }
  44. ,sortable: true
  45. }]
  46. ,tbar: [{
  47. text: _('create_new')
  48. ,cls:'primary-button'
  49. ,handler: this.createRole
  50. ,scope: this
  51. }]
  52. });
  53. MODx.grid.Role.superclass.constructor.call(this,config);
  54. this.on('beforeedit',this.checkEditable,this);
  55. };
  56. Ext.extend(MODx.grid.Role,MODx.grid.Grid,{
  57. checkEditable: function(o) {
  58. var p = o.record.data.perm || '';
  59. return p.indexOf('edit') != -1;
  60. }
  61. ,getMenu: function() {
  62. var r = this.getSelectionModel().getSelected();
  63. var p = r.data.perm || '';
  64. var m = [];
  65. if (p.indexOf('remove') != -1) {
  66. m.push({
  67. text: _('role_remove')
  68. ,handler: this.remove.createDelegate(this,['role_remove_confirm', 'security/role/remove'])
  69. });
  70. }
  71. return m;
  72. }
  73. ,createRole: function(btn,e) {
  74. this.loadWindow(btn,e,{
  75. xtype: 'modx-window-role-create'
  76. ,listeners: {
  77. 'success': {fn: function() {
  78. this.refresh();
  79. },scope:this}
  80. }
  81. });
  82. }
  83. });
  84. Ext.reg('modx-grid-role',MODx.grid.Role);
  85. MODx.window.CreateRole = function(config) {
  86. config = config || {};
  87. this.ident = config.ident || 'crole'+Ext.id();
  88. Ext.applyIf(config,{
  89. title: _('role_create')
  90. // ,height: 150
  91. // ,width: 400
  92. ,url: MODx.config.connector_url
  93. ,action: 'security/role/create'
  94. ,fields: [{
  95. name: 'name'
  96. ,fieldLabel: _('name')+'<span class="required">*</span>'
  97. ,id: 'modx-'+this.ident+'-name'
  98. ,xtype: 'textfield'
  99. ,allowBlank: false
  100. ,anchor: '100%'
  101. },{
  102. xtype: MODx.expandHelp ? 'label' : 'hidden'
  103. ,forId: 'modx-'+this.ident+'-name'
  104. ,html: _('role_desc_name')
  105. ,cls: 'desc-under'
  106. },{
  107. name: 'authority'
  108. ,fieldLabel: _('authority')
  109. ,xtype: 'textfield'
  110. ,id: 'modx-'+this.ident+'-authority'
  111. ,allowBlank: false
  112. ,allowNegative: false
  113. ,value: 0
  114. // ,width: 75
  115. ,anchor: '100%'
  116. },{
  117. xtype: MODx.expandHelp ? 'label' : 'hidden'
  118. ,forId: 'modx-'+this.ident+'-authority'
  119. ,html: _('role_desc_authority')
  120. ,cls: 'desc-under'
  121. },{
  122. name: 'description'
  123. ,fieldLabel: _('description')
  124. ,id: 'modx-'+this.ident+'-description'
  125. ,xtype: 'textarea'
  126. ,anchor: '100%'
  127. ,grow: true
  128. },{
  129. xtype: MODx.expandHelp ? 'label' : 'hidden'
  130. ,forId: 'modx-'+this.ident+'-description'
  131. ,html: _('role_desc_description')
  132. ,cls: 'desc-under'
  133. }]
  134. ,keys: []
  135. });
  136. MODx.window.CreateRole.superclass.constructor.call(this,config);
  137. };
  138. Ext.extend(MODx.window.CreateRole,MODx.Window);
  139. Ext.reg('modx-window-role-create',MODx.window.CreateRole);