MDL-8522 Add role reset button into role definition form; fixed single button css

This commit is contained in:
skodak 2007-03-03 22:30:35 +00:00
parent 3562486b7d
commit a83addc5e5
5 changed files with 148 additions and 65 deletions

View file

@ -4,9 +4,6 @@
case 'add':
$submitlabel = get_string('addrole', 'role');
break;
case 'view':
$submitlabel = get_string('listallroles', 'role');
break;
case 'edit':
default:
$submitlabel = get_string('savechanges');
@ -14,9 +11,6 @@
if ($action == 'view') {
?>
<div class="duplicaterole">
<a href="manage.php?roleid=<?php p($roleid); ?>&amp;action=duplicate"><?php print_string('duplicaterole', 'role'); ?></a>
</div>
<?php
}
?>
@ -27,36 +21,41 @@
<input type="hidden" name="action" value="<?php if ($action != 'view') { echo p($action); } ?>" />
</fieldset>
<table cellpadding="9" cellspacing="0" align="center">
<?php if ($action == 'view') { ?>
<tr valign="top">
<td align="right"><?php print_string('name') ?>:</td>
<td><?php p($role->name); ?></td>
</tr>
<tr valign="top">
<td align="right"><?php print_string('shortname') ?>:</td>
<td><?php p($role->shortname); ?></td>
</tr>
<tr valign="top">
<td align="right"><?php print_string('description') ?>:</td>
<td><?php p($role->description); $usehtmleditor = false; ?></td>
</tr>
<?php } else { ?>
<tr valign="top">
<td align="right"><label for="name"><?php print_string('name') ?></label></td>
<td><?php
if ($action == 'view') {
p($role->name);
} else {
echo '<input type="text" id="name" name="name" maxlength="254" size="50" value="'.s($role->name).'" />';
if (isset($errors["name"])) formerr($errors["name"]);
} ?></td>
?></td>
</tr>
<tr valign="top">
<td align="right"><label for="shortname"><?php print_string('shortname') ?></label></td>
<td><?php
if ($action == 'view') {
p($role->shortname);
} else {
echo '<input type="text" id="shortname" name="shortname" maxlength="20" size="15" value="'.s($role->shortname).'" />';
if (isset($errors["shortname"])) formerr($errors["shortname"]);
} ?></td>
?></td>
</tr>
<tr valign="top">
<td align="right"><label for="edit-description"><?php print_string('description') ?></label></td>
<td><?php
if ($action == 'view') {
p($role->description);
$usehtmleditor = false;
} else {
print_textarea($usehtmleditor, 10, 50, 50, 10, 'description', $role->description);
} ?></td>
?></td>
</tr>
<?php } ?>
</table>
<?php
@ -193,11 +192,11 @@ foreach ($capabilities as $capability) {
<?php } ?>
</table>
<div class="submit" align="center">
<input type="submit" value="<?php p($submitlabel) ?>" />
<?php if ($action != 'view') { ?>
<div class="submit buttons">
<input type="submit" value="<?php p($submitlabel) ?>" />
<input type="submit" name="cancel" value="<?php print_string('cancel') ?>" />
<?php } ?>
</div>
<?php } ?>
</form>

View file

@ -245,7 +245,28 @@
redirect('manage.php');
break;
case 'duplicate':
if (!array_key_exists($roleid, $roles)) {
redirect('manage.php');
}
if ($confirm and data_submitted() and confirm_sesskey()) {
//ok - lets duplicate!
} else {
// show confirmation
admin_externalpage_print_header($adminroot);
$optionsyes = array('action'=>'duplicate', 'roleid'=>$roleid, 'sesskey'=>sesskey(), 'confirm'=>1);
$optionsno = array('action'=>'view', 'roleid'=>$roleid);
$a = new object();
$a->id = $roleid;
$a->name = $roles[$roleid]->name;
$a->shortname = $roles[$roleid]->shortname;
notice_yesno(get_string('duplicaterolesure', 'role', $a), 'manage.php', 'manage.php', $optionsyes, $optionsno, 'post', 'get');
admin_externalpage_print_footer($adminroot);
die;
}
// duplicate current role
$sourcerole = get_record('role','id',$roleid);
@ -279,6 +300,49 @@
}
redirect('manage.php');
break;
case 'reset':
if (!array_key_exists($roleid, $roles)) {
redirect('manage.php');
}
if ($confirm and data_submitted() and confirm_sesskey()) {
$legacyroles = get_legacy_roles();
$defaultcaps = array();
foreach($legacyroles as $ltype=>$lcap) {
$localoverride = get_local_override($roleid, $sitecontext->id, $lcap);
if (!empty($localoverride->permission) and $localoverride->permission == CAP_ALLOW) {
//choose first selected legacy capability
$defaultcaps = get_default_capabilities($ltype);
break;
}
}
delete_records('role_capabilities', 'roleid', $roleid);
if (!empty($defaultcaps)) {
foreach($defaultcaps as $cap=>$permission) {
assign_capability($cap, $permission, $roleid, $sitecontext->id);
}
}
redirect('manage.php?action=view&amp;roleid='.$roleid);
} else {
// show confirmation
admin_externalpage_print_header($adminroot);
$optionsyes = array('action'=>'reset', 'roleid'=>$roleid, 'sesskey'=>sesskey(), 'confirm'=>1);
$optionsno = array('action'=>'view', 'roleid'=>$roleid);
$a = new object();
$a->id = $roleid;
$a->name = $roles[$roleid]->name;
$a->shortname = $roles[$roleid]->shortname;
notice_yesno(get_string('resetrolesure', 'role', $a), 'manage.php', 'manage.php', $optionsyes, $optionsno, 'post', 'get');
admin_externalpage_print_footer($adminroot);
die;
}
break;
default:
break;
}
@ -339,10 +403,18 @@
popup_form('manage.php?action=view&amp;roleid=', $roleoptions, 'switchrole', $roleid, '', '', '',
false, 'self', get_string('selectrole', 'role'));
echo '<div class="buttons">';
$options = array();
$options['roleid'] = $roleid;
$options['action'] = 'edit';
print_single_button('manage.php', $options, get_string('edit'));
$options['action'] = 'reset';
print_single_button('manage.php', $options, get_string('reset'));
$options['action'] = 'duplicate';
print_single_button('manage.php', $options, get_string('duplicaterole', 'role'));
print_single_button('manage.php', null, get_string('listallroles', 'role'));
echo '</div>';
}
echo '</div>';

View file

@ -49,7 +49,8 @@ $string['currentrole'] = 'Current role';
$string['defaultrole'] = 'Default role';
$string['defineroles'] = 'Define roles';
$string['deleterolesure'] = 'Are you sure that you want to delete role \"$a->name ($a->shortname)\"?</p><p>Currently this role is assigned to $a->count users.';
$string['duplicaterole'] = 'Duplicate this role';
$string['duplicaterolesure'] = 'Are you sure that you want to duplicate role \"$a->name ($a->shortname)\"?</p>';
$string['duplicaterole'] = 'Duplicate role';
$string['editrole'] = 'Edit role';
$string['errorbadrolename'] = 'Incorrect role name';
$string['errorbadroleshortname'] = 'Incorrect role name';
@ -79,6 +80,7 @@ $string['question:export'] = 'Export questions';
$string['question:import'] = 'Import questions';
$string['question:manage'] = 'Manage questions';
$string['question:managecategory'] = 'Manage question category';
$string['resetrolesure'] = 'Are you sure that you want to reset role \"$a->name ($a->shortname)\" to defaults?<p></p>The defaults are taken from the selected legacy capability.';
$string['risks'] = 'Risks';
$string['role:assign'] = 'Assign roles to users';
$string['role:manage'] = 'Create and manage roles';

View file

@ -1555,13 +1555,13 @@ function moodle_install_roles() {
*/
function get_legacy_roles() {
return array(
'guest' => 'moodle/legacy:guest',
'user' => 'moodle/legacy:user',
'student' => 'moodle/legacy:student',
'teacher' => 'moodle/legacy:teacher',
'editingteacher' => 'moodle/legacy:editingteacher',
'admin' => 'moodle/legacy:admin',
'coursecreator' => 'moodle/legacy:coursecreator',
'admin' => 'moodle/legacy:admin'
'editingteacher' => 'moodle/legacy:editingteacher',
'teacher' => 'moodle/legacy:teacher',
'student' => 'moodle/legacy:student',
'user' => 'moodle/legacy:user',
'guest' => 'moodle/legacy:guest'
);
}

View file

@ -131,6 +131,11 @@ img.grouppicture {
padding: 0;
}
.singlebutton form,
.singlebutton div {
display:inline;
}
.generalbox {
border-width:1px;
border-style:solid;
@ -775,14 +780,19 @@ body#admin-modules table.generaltable td.c0
margin-top: 1em;
}
#admin-roles-manage .duplicaterole {
text-align: right;
#admin-roles-manage .buttons {
margin: 20px;
text-align:center;
}
#admin-roles-manage .buttons .singlebutton {
display: inline;
}
#admin-roles-manage .singlebutton,
#admin-roles-allowoverride .singlebutton,
#admin-roles-allowassign .singlebutton {
padding: 10px;
padding: 5px;
text-align:center;
}