From 13ee9391bfb8844b24fefae89b0ae9e58537c618 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 10 Mar 2010 02:59:24 +0000 Subject: [PATCH] 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 --- code/PermissionRoleAdmin.php | 46 ----------------------------- code/SecurityAdmin.php | 36 +++++++++++++++++++++++ javascript/MemberTableField.js | 53 ++++++++++++++++++---------------- 3 files changed, 64 insertions(+), 71 deletions(-) delete mode 100644 code/PermissionRoleAdmin.php diff --git a/code/PermissionRoleAdmin.php b/code/PermissionRoleAdmin.php deleted file mode 100644 index 1f4aed6c..00000000 --- a/code/PermissionRoleAdmin.php +++ /dev/null @@ -1,46 +0,0 @@ -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; - } -} - -?> diff --git a/code/SecurityAdmin.php b/code/SecurityAdmin.php index 7d8797fd..ef86b03d 100644 --- a/code/SecurityAdmin.php +++ b/code/SecurityAdmin.php @@ -81,6 +81,20 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { ) ) ); + + $fields->addFieldToTab( + 'Root.Roles', + new LiteralField( + 'RolesAddEditLink', + sprintf( + '

%s

', + $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')) ); diff --git a/javascript/MemberTableField.js b/javascript/MemberTableField.js index f9ca0b49..1663c2d4 100755 --- a/javascript/MemberTableField.js +++ b/javascript/MemberTableField.js @@ -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)); \ No newline at end of file