Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Role Authority Editability #16568

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update modx.grid.role.js
Formatting and code style fixes and optimizations
  • Loading branch information
smg6511 authored and opengeek committed Jul 5, 2024
commit 0bb0b9b16dc2503a301258adb668955893f35cd0
234 changes: 118 additions & 116 deletions manager/assets/modext/widgets/security/modx.grid.role.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,77 @@
* @param {Object} config An object of options.
* @xtype modx-grid-role
*/
MODx.grid.Role = function(config) {
config = config || {};
Ext.applyIf(config,{
title: _('roles')
,id: 'modx-grid-role'
,url: MODx.config.connector_url
,baseParams: {
MODx.grid.Role = function(config = {}) {
Ext.applyIf(config, {
title: _('roles'),
id: 'modx-grid-role',
url: MODx.config.connector_url,
baseParams: {
action: 'Security/Role/GetList'
}
,fields: ['id','name','description','authority','perm']
,paging: true
,autosave: true
,save_action: 'Security/Role/UpdateFromGrid'
,columns: [{
header: _('id')
,dataIndex: 'id'
,width: 50
,sortable: true
},{
header: _('name')
,dataIndex: 'name'
,width: 150
,sortable: true
,editor: {
},
fields: [
'id',
'name',
'description',
'authority',
'perm'
],
paging: true,
autosave: true,
save_action: 'Security/Role/UpdateFromGrid',
columns: [{
header: _('id'),
dataIndex: 'id',
width: 50,
sortable: true
}, {
header: _('name'),
dataIndex: 'name',
width: 150,
sortable: true,
editor: {
xtype: 'textfield'
}
,renderer: {
},
renderer: {
fn: function(value, metaData, record, rowIndex, colIndex, store) {
metaData.css = this.setEditableCellClasses(record);
return Ext.util.Format.htmlEncode(value);
},
scope: this
}
},{
header: _('description')
,dataIndex: 'description'
,width: 350
,editor: { xtype: 'textarea' }
,renderer: {
}, {
header: _('description'),
dataIndex: 'description',
width: 350,
editor: { xtype: 'textarea' },
renderer: {
fn: function(value, metaData, record, rowIndex, colIndex, store) {
metaData.css = this.setEditableCellClasses(record);
return Ext.util.Format.htmlEncode(value);
},
scope: this
}
},{
header: _('authority')
,dataIndex: 'authority'
,width: 60
,sortable: true
,editor: {
}, {
header: _('authority'),
dataIndex: 'authority',
width: 60,
sortable: true,
editor: {
xtype: 'numberfield',
allowNegative: false,
allowDecimals: false,
allowBlank: false,
blankText: _('role_err_ns_authority'),
maxValue: 9999
}
,renderer: {
},
renderer: {
fn: function(value, metaData, record, rowIndex, colIndex, store) {
metaData.css = this.setEditableCellClasses(record, [record.json.isAssigned]);
return value;
},
scope: this
}
,listeners: {
},
listeners: {
dblclick: {
fn: function(column, grid, rowIndex, e) {
const
Expand All @@ -92,99 +97,96 @@ MODx.grid.Role = function(config) {
scope: this
}
}
}]
,tbar: [{
text: _('create')
,cls:'primary-button'
,handler: this.createRole
,scope: this
}],
tbar: [{
text: _('create'),
cls: 'primary-button',
handler: this.createRole,
scope: this
}]
});
MODx.grid.Role.superclass.constructor.call(this,config);
MODx.grid.Role.superclass.constructor.call(this, config);
this.on('beforeedit', this.checkCellIsEditable, this);
};
Ext.extend(MODx.grid.Role,MODx.grid.Grid,{
Ext.extend(MODx.grid.Role, MODx.grid.Grid, {
getMenu: function() {
var r = this.getSelectionModel().getSelected();
var p = r.data.perm || '';
var m = [];
if (p.indexOf('remove') != -1) {
m.push({
text: _('delete')
,handler: this.remove.createDelegate(this,['role_remove_confirm', 'Security/Role/Remove'])
const
record = this.getSelectionModel().getSelected(),
permissions = record.data.perm || '',
menu = []
;
if (permissions.indexOf('remove') !== -1) {
menu.push({
text: _('delete'),
handler: this.remove.createDelegate(this, ['role_remove_confirm', 'Security/Role/Remove'])
});
}
return m;
}
return menu;
},

,createRole: function(btn,e) {
this.loadWindow(btn,e,{
xtype: 'modx-window-role-create'
,listeners: {
'success': {fn: function() {
this.refresh();
},scope:this}
createRole: function(btn, e) {
this.loadWindow(btn, e, {
xtype: 'modx-window-role-create',
listeners: {
success: {
fn: function() {
this.refresh();
},
scope: this
}
}
});
}
});
Ext.reg('modx-grid-role',MODx.grid.Role);
Ext.reg('modx-grid-role', MODx.grid.Role);

/**
* @class MODx.window.CreateRole
* @extends MODx.Window
* @param {Object} config An object of options.
* @xtype modx-window-role-create
*/
MODx.window.CreateRole = function(config) {
config = config || {};
this.ident = config.ident || 'crole'+Ext.id();
Ext.applyIf(config,{
title: _('create')
,url: MODx.config.connector_url
,action: 'Security/Role/Create'
,fields: [{
name: 'name'
,fieldLabel: _('name')
,id: 'modx-'+this.ident+'-name'
,xtype: 'textfield'
,allowBlank: false
,anchor: '100%'
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: 'modx-'+this.ident+'-name'
,html: _('role_desc_name')
,cls: 'desc-under'
},{
name: 'authority'
,fieldLabel: _('authority')
,xtype: 'textfield'
,id: 'modx-'+this.ident+'-authority'
,allowBlank: false
,allowNegative: false
,value: 0
,anchor: '100%'
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: 'modx-'+this.ident+'-authority'
,html: _('role_desc_authority')
,cls: 'desc-under'
},{
name: 'description'
,fieldLabel: _('description')
,id: 'modx-'+this.ident+'-description'
,xtype: 'textarea'
,anchor: '100%'
,grow: true
},{
xtype: MODx.expandHelp ? 'label' : 'hidden'
,forId: 'modx-'+this.ident+'-description'
,html: _('role_desc_description')
,cls: 'desc-under'
}]
,keys: []
MODx.window.CreateRole = function(config = {}) {
Ext.applyIf(config, {
title: _('create'),
url: MODx.config.connector_url,
action: 'Security/Role/Create',
formDefaults: {
allowBlank: false,
anchor: '100%'
},
fields: [{
name: 'name',
fieldLabel: _('name'),
xtype: 'textfield'
}, {
xtype: MODx.expandHelp ? 'box' : 'hidden',
html: _('role_desc_name'),
cls: 'desc-under'
}, {
name: 'authority',
fieldLabel: _('authority'),
xtype: 'textfield',
allowNegative: false,
value: 0
}, {
xtype: MODx.expandHelp ? 'box' : 'hidden',
html: _('role_desc_authority'),
cls: 'desc-under'
}, {
name: 'description',
fieldLabel: _('description'),
xtype: 'textarea',
allowBlank: true,
grow: true
}, {
xtype: MODx.expandHelp ? 'box' : 'hidden',
html: _('role_desc_description'),
cls: 'desc-under'
}],
keys: []
});
MODx.window.CreateRole.superclass.constructor.call(this,config);
MODx.window.CreateRole.superclass.constructor.call(this, config);
};
Ext.extend(MODx.window.CreateRole,MODx.Window);
Ext.reg('modx-window-role-create',MODx.window.CreateRole);
Ext.extend(MODx.window.CreateRole, MODx.Window);
Ext.reg('modx-window-role-create', MODx.window.CreateRole);