Permalink
Browse files

ENHANCEMENT Using ListboxField/chosen.js to assign roles in Group->ge…

…tCMSFields(). Improved explanation of groups in the user interface.
  • Loading branch information...
1 parent 5d565dc commit ad5cf1ebf11f0e730bf89ae3b219d9d53a5b2b96 @chillu chillu committed Mar 5, 2012
Showing with 21 additions and 27 deletions.
  1. +0 −15 admin/code/SecurityAdmin.php
  2. +2 −2 lang/en_US.php
  3. +19 −10 security/Group.php
@@ -63,21 +63,6 @@ public function getEditForm($id = null, $fields = null) {
)
)
);
- if(Permission::check('APPLY_ROLES')) {
- $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')
- )
- )
- );
- }
// Filter permissions
$permissionField = $form->Fields()->dataFieldByName('Permissions');
View
@@ -281,7 +281,7 @@
PR_MEDIUM,
'One group has one parent group'
);
-$lang['en_US']['Group']['RolesAddEditLink'] = 'Add/edit roles';
+$lang['en_US']['Group']['RolesAddEditLink'] = 'Manage roles';
$lang['en_US']['Group']['SINGULARNAME'] = array(
'Group',
50,
@@ -730,7 +730,7 @@
$lang['en_US']['SecurityAdmin']['NEWGROUP'] = 'New Group';
$lang['en_US']['SecurityAdmin']['PERMISSIONS'] = 'Permissions';
$lang['en_US']['SecurityAdmin']['ROLES'] = 'Roles';
-$lang['en_US']['SecurityAdmin']['ROLESDESCRIPTION'] = 'This section allows you to add roles to this group. Roles are logical groupings of permissions, which can be editied in the Roles tab';
+$lang['en_US']['SecurityAdmin']['ROLESDESCRIPTION'] = 'Roles are predefined sets of permissions, and can be assigned to groups.<br />They are inherited from parent groups if required.';
$lang['en_US']['SecurityAdmin']['SGROUPS'] = 'Security Groups';
$lang['en_US']['SecurityAdmin']['TABIMPORT'] = 'Import';
$lang['en_US']['SecurityAdmin']['TABROLES'] = 'Roles';
View
@@ -123,9 +123,17 @@ public function getCMSFields() {
new LiteralField(
"",
"<p>" .
- _t('SecurityAdmin.ROLESDESCRIPTION',
- "This section allows you to add roles to this group. Roles are logical groupings of permissions, which can be editied in the Roles tab"
- ) .
+ _t(
+ 'SecurityAdmin.ROLESDESCRIPTION',
+ "Roles are predefined sets of permissions, and can be assigned to groups.<br />They are inherited from parent groups if required."
+ ) . '<br />' .
+ sprintf(
+ '<a href="%s" class="add-role">%s</a>',
+ singleton('SecurityAdmin')->Link('show/root#Root_Roles'),
+ // 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', 'Manage roles')
+ ) .
"</p>"
)
);
@@ -139,13 +147,14 @@ public function getCMSFields() {
$ancestorRoles = $ancestor->Roles();
if($ancestorRoles) $inheritedRoles->merge($ancestorRoles);
}
- $fields->findOrMakeTab('Root.Roles', 'Root.' . _t('SecurityAdmin.ROLES', 'Roles'));
- $fields->addFieldToTab(
- 'Root.Roles',
- $rolesField = new CheckboxSetField('Roles', 'Roles', $allRoles)
- );
- $rolesField->setDefaultItems($inheritedRoles->column('ID'));
- $rolesField->setDisabledItems($inheritedRoles->column('ID'));
+ $groupRoleIDs = $groupRoles->column('ID') + $inheritedRoles->column('ID');
+ $rolesField = Object::create('ListboxField', 'Roles', false, $allRoles->map()->toArray())
+ ->setMultiple(true)
+ ->setDefaultItems($groupRoleIDs)
+ ->setAttribute('data-placeholder', _t('Group.AddRole', 'Add a role for this group'))
+ ->setDisabledItems($inheritedRoles->column('ID'));
+ if(!$allRoles->Count()) $rolesField->setAttribute('data-placeholder', _t('Group.NoRoles', 'No roles found'));
+ $fields->addFieldToTab('Root.Roles', $rolesField);
}
$fields->push($idField = new HiddenField("ID"));

0 comments on commit ad5cf1e

Please sign in to comment.