mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 09:05:53 +00:00
ENHANCEMENT Better editing of roles through SecurityAdmin instead of a new "Roles" tab. Removed (previously unreleased) PermissionRoleAdmin. (see #4757)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@100776 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
131c271f9c
commit
13ee9391bf
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Admin interface for Permission Roles.
|
||||
*/
|
||||
class PermissionRoleAdmin extends ModelAdmin {
|
||||
static $managed_models = array(
|
||||
'PermissionRole'
|
||||
);
|
||||
|
||||
public static $collection_controller_class = "PermissionRoleAdmin_CollectionController";
|
||||
public static $record_controller_class = "PermissionRoleAdmin_RecordController";
|
||||
|
||||
static $url_segment = 'roles';
|
||||
static $menu_title = 'Roles';
|
||||
}
|
||||
|
||||
/**
|
||||
* Customized controller for hiding permissions on AddForm
|
||||
*/
|
||||
class PermissionRoleAdmin_CollectionController extends ModelAdmin_CollectionController {
|
||||
public function AddForm() {
|
||||
$form = parent::AddForm();
|
||||
if ( $this->modelClass=='PermissionRole' ) {
|
||||
$permissionField = $form->Fields()->dataFieldByName('Codes');
|
||||
if($permissionField) $permissionField->setHiddenPermissions(SecurityAdmin::$hidden_permissions);
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Customized controller for hiding permissions on EditForm
|
||||
*/
|
||||
class PermissionRoleAdmin_RecordController extends ModelAdmin_RecordController {
|
||||
public function EditForm() {
|
||||
$form = parent::EditForm();
|
||||
if ( $this->parentController->modelClass=='PermissionRole' ) {
|
||||
$permissionField = $form->Fields()->dataFieldByName('Codes');
|
||||
if($permissionField) $permissionField->setHiddenPermissions(SecurityAdmin::$hidden_permissions);
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -81,6 +81,20 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$fields->addFieldToTab(
|
||||
'Root.Roles',
|
||||
new LiteralField(
|
||||
'RolesAddEditLink',
|
||||
sprintf(
|
||||
'<p class="add-role"><a href="%s">%s</a></p>',
|
||||
$this->Link('show/root'),
|
||||
// TODO This should include #Root_Roles to switch directly to the tab,
|
||||
// but tabstrip.js doesn't display tabs when directly adressed through a URL pragma
|
||||
_t('Group.RolesAddEditLink', 'Add/edit roles')
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$actions = new FieldSet(
|
||||
@ -147,6 +161,28 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
||||
// necessary for tree node selection in LeftAndMain.EditForm.js
|
||||
new HiddenField('ID', false, 0)
|
||||
);
|
||||
|
||||
// Add roles editing interface
|
||||
if(Permission::check('APPLY_ROLES')) {
|
||||
$rolesCTF = new ComplexTableField(
|
||||
$this,
|
||||
'Roles',
|
||||
'PermissionRole'
|
||||
);
|
||||
// Necessary to make Permission code checkboxes behave consistently
|
||||
$rolesCTF->requirementsForPopupCallback = create_function(
|
||||
'$popup',
|
||||
'Requirements::javascript(CMS_DIR . "/javascript/MemberTableField.js");'
|
||||
);
|
||||
|
||||
$rolesTab = $fields->findOrMakeTab('Root.Roles', _t('SecurityAdmin.TABROLES', 'Roles'));
|
||||
$rolesTab->push(new LiteralField(
|
||||
'RolesDescription',
|
||||
''
|
||||
));
|
||||
$rolesTab->push($rolesCTF);
|
||||
}
|
||||
|
||||
$actions = new FieldSet(
|
||||
new FormAction('addmember',_t('SecurityAdmin.ADDMEMBER','Add Member'))
|
||||
);
|
||||
|
@ -281,36 +281,39 @@ Behaviour.register({
|
||||
});
|
||||
|
||||
(function($) {
|
||||
var checkboxBehaviour = {
|
||||
initialize: function() {
|
||||
this.toggleCheckboxes();
|
||||
},
|
||||
onclick: function(e) {
|
||||
this.toggleCheckboxes();
|
||||
},
|
||||
toggleCheckboxes: function() {
|
||||
var checkboxes = $(this).parents('.field:eq(0)').find('.checkbox').not(this);
|
||||
|
||||
if($(this).is(':checked')) {
|
||||
checkboxes.each(function() {
|
||||
$(this).data('SecurityAdmin.oldChecked', $(this).attr('checked'));
|
||||
$(this).data('SecurityAdmin.oldDisabled', $(this).attr('disabled'));
|
||||
$(this).attr('disabled', 'disabled');
|
||||
$(this).attr('checked', 'checked');
|
||||
});
|
||||
} else {
|
||||
checkboxes.each(function() {
|
||||
$(this).attr('checked', $(this).data('SecurityAdmin.oldChecked'));
|
||||
$(this).attr('disabled', $(this).data('SecurityAdmin.oldDisabled'));
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Behaviour.register({
|
||||
/**
|
||||
* Automatically check and disable all checkboxes if ADMIN permissions are selected.
|
||||
* As they're disabled, any changes won't be submitted (which is intended behaviour),
|
||||
* checking all boxes is purely presentational.
|
||||
*/
|
||||
'#Permissions .valADMIN input': {
|
||||
initialize: function() {
|
||||
this.toggleCheckboxes();
|
||||
},
|
||||
onclick: function(e) {
|
||||
this.toggleCheckboxes();
|
||||
},
|
||||
toggleCheckboxes: function() {
|
||||
var checkboxes = $(this).parents('.field:eq(0)').find('.checkbox').not(this);
|
||||
|
||||
if($(this).is(':checked')) {
|
||||
checkboxes.each(function() {
|
||||
$(this).data('SecurityAdmin.oldChecked', $(this).attr('checked'));
|
||||
$(this).data('SecurityAdmin.oldDisabled', $(this).attr('disabled'));
|
||||
$(this).attr('disabled', 'disabled');
|
||||
$(this).attr('checked', 'checked');
|
||||
});
|
||||
} else {
|
||||
checkboxes.each(function() {
|
||||
$(this).attr('checked', $(this).data('SecurityAdmin.oldChecked'));
|
||||
$(this).attr('disabled', $(this).data('SecurityAdmin.oldDisabled'));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
'#Permissions .valADMIN input': checkboxBehaviour,
|
||||
'#Codes .valADMIN input': checkboxBehaviour
|
||||
});
|
||||
}(jQuery));
|
Loading…
x
Reference in New Issue
Block a user