MDL-9040: Enabled disabling of any buttons that always lead to errors. Javascript dynamically displays/hides buttons depending on which groupings/groups are selected. This required a number of extensive modifications, but degrades nicely without JS.

This commit is contained in:
nicolasconnault 2007-03-27 04:03:02 +00:00
parent 3c58497b82
commit bd52a0145e
4 changed files with 161 additions and 106 deletions

View file

@ -76,9 +76,6 @@ if ($success) {
*/ */
$success = (bool)$groupid = groups_create_group($courseid); //$groupsettings); $success = (bool)$groupid = groups_create_group($courseid); //$groupsettings);
if ($groupingid != GROUP_NOT_IN_GROUPING) {
$success = groups_add_group_to_grouping($groupid, $groupingid);
}
} }
elseif ($groupingid != $newgrouping) { //OK, move group. elseif ($groupingid != $newgrouping) { //OK, move group.
// Allow groups to be created outside of groupings // Allow groups to be created outside of groupings
@ -159,109 +156,112 @@ if ($success) {
"-> $strgroups", '', '', true, '', user_login_string($course, $USER)); "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
$usehtmleditor = false; $usehtmleditor = false;
?>
<h3 class="main"><?php echo $strheading ?></h3>
<form action="group.php" method="post" enctype="multipart/form-data" class="mform notmform" id="groupform"> echo '<h3 class="main">' . $strheading . '</h3>'."\n";
echo '<form action="group.php" method="post" enctype="multipart/form-data" class="mform notmform" id="groupform">'."\n";
echo '<div>'."\n";
echo '<input type="hidden" name="sesskey" value="' . s(sesskey()) . '" />'."\n";
echo '<input type="hidden" name="courseid" value="' . s($courseid) . '" />'."\n";
echo '<input type="hidden" name="grouping" value="' . s($groupingid) . '" />'."\n";
<input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
<input type="hidden" name="courseid" value="<?php p($courseid); ?>" />
<input type="hidden" name="grouping" value="<?php p($groupingid); ?>" />
<?php
if ($groupid) { if ($groupid) {
echo '<input type="hidden" name="group" value="'. $groupid .'" />'; echo '<input type="hidden" name="group" value="'. $groupid .'" />'."\n";
} }
if ($delete) { if ($delete) {
/*echo 'Are you sure you want to delete group X ?'; /*echo 'Are you sure you want to delete group X ?';
choose_from_menu_yesno('confirmdelete', false, '', true);*/ choose_from_menu_yesno('confirmdelete', false, '', true);*/
?>
<p><?php print_string('deletegroupconfirm', 'group', $strname); ?></p> echo '<p>' . get_string('deletegroupconfirm', 'group', $strname) . '</p>'."\n";
<input type="hidden" name="delete" value="1" /> echo '<input type="hidden" name="delete" value="1" />'."\n";
<input type="submit" name="confirmdelete" value="<?php print_string('yes'); ?>" /> echo '<input type="submit" name="confirmdelete" value="' . get_string('yes') . '" />'."\n";
<input type="submit" name="cancel" value="<?php print_string('no'); ?>" /> echo '<input type="submit" name="cancel" value="' . get_string('no') . '" />'."\n";
<?php
} else { } else {
?> echo '<div class="fitem">'."\n";
echo '<p><label for="groupname">' . get_string('groupname', 'group');
<div class="fitem"> if (isset($err['name'])) {
<p><label for="groupname"><?php echo ' ';
print_string('groupname', 'group'); formerr($err['name']);
if (isset($err['name'])) {
echo' ';
formerr($err['name']);
} ?>&nbsp; </label></p>
<p class="felement"><input id="groupname" name="name" type="text" size="40" value="<?php echo $strname; ?>" /></p>
</div>
<p><label for="edit-description"><?php print_string('groupdescription', 'group'); ?>&nbsp;</label></p>
<p><?php print_textarea($usehtmleditor, 5, 45, 200, 400, 'description', $strdesc); ?></p>
<p><label for="enrolmentkey"><?php print_string('enrolmentkey', 'group'); ?>&nbsp;</label></p>
<p><input id="enrolmentkey" name="enrolmentkey" type="text" size="25" /></p>
<?php if ($printuploadpicture) { ?>
<p><label for="menuhidepicture"><?php print_string('hidepicture', 'group'); ?>&nbsp;</label></p>
<p><?php $options = array();
$options[0] = get_string('no');
$options[1] = get_string('yes');
choose_from_menu($options, 'hidepicture', isset($group)? $group->hidepicture: 1, '');?></p>
<p><label ><?php /* for="imagefile" */ print_string('newpicture', 'group');
helpbutton('picture', get_string('helppicture'));
print_string('maxsize', '', display_size($maxbytes), 'group');
if (isset($err['imagefile'])) formerr($err['imagefile']);
?>&nbsp;</label></p>
<p><?php upload_print_form_fragment(1, array('imagefile'), null,false,null,0,0,false); ?></p>
<?php
}
if ($groupid) { //OK, editing - option to move grouping.
?>
<p><label for="groupings"><?php print_string('addgroupstogrouping', 'group'); ?></label></p>
<select name="newgrouping" id="groupings" class="select">
<?php
$groupingids = groups_get_groupings($courseid);
if (GROUP_NOT_IN_GROUPING == $groupingid) {
$groupingids[] = GROUP_NOT_IN_GROUPING;
}
if ($groupingids) {
// Put the groupings into a hash and sort them
foreach($groupingids as $id) {
$listgroupings[$id] = groups_get_grouping_displayname($id, $courseid);
} }
natcasesort($listgroupings);
// Print out the HTML echo '&nbsp; </label></p>'."\n";
$count = 1; echo '<p class="felement"><input id="groupname" name="name" type="text" size="40" value="' . $strname . '" /></p>'."\n";
foreach($listgroupings as $id => $name) { echo '</div>'."\n";
$select = '';
if ($groupingid == $id) { echo '<p><label for="edit-description">' . get_string('groupdescription', 'group') . '&nbsp;</label></p>'."\n";
$select = ' selected="selected"'; echo '<p>' . print_textarea($usehtmleditor, 5, 45, 200, 400, 'description', $strdesc, 0, true) . '</p>'."\n";
echo '<p><label for="enrolmentkey">' . get_string('enrolmentkey', 'group') . '&nbsp;</label></p>'."\n";
echo '<p><input id="enrolmentkey" name="enrolmentkey" type="text" size="25" /></p>'."\n";
if ($printuploadpicture) {
echo '<p><label for="menuhidepicture">' . get_string('hidepicture', 'group') . '&nbsp;</label></p>'."\n";
echo '<p>';
$options = array();
$options[0] = get_string('no');
$options[1] = get_string('yes');
choose_from_menu($options, 'hidepicture', isset($group)? $group->hidepicture: 1, '');
echo '</p>'."\n";
echo '<p><label >' . get_string('newpicture', 'group');
helpbutton('picture', get_string('helppicture'));
echo get_string('maxsize', '', display_size($maxbytes), 'group');
if (isset($err['imagefile'])) {
formerr($err['imagefile']);
} }
echo "<option value=\"$id\"$select>$name</option>\n";
$count++; echo '&nbsp;</label></p>'."\n";
echo '<p>' . upload_print_form_fragment(1, array('imagefile'), null,false,null,0,0,true) . '</p>'."\n";
} }
}
?>
</select>
<?php } //IF($groupid) ?>
<p class="fitem"> if ($groupid) { //OK, editing - option to move grouping.
<label for="id_submit">&nbsp;</label>
<span class="f--element fsubmit">
<input type="submit" name="update" id="id_submit" value="<?php echo $strbutton; ?>" />
<input type="submit" name="cancel" value="<?php print_string('cancel', 'group'); ?>" />
</span>
</p>
<?php } //IF($delete) ?> echo '<p><label for="groupings">' . get_string('addgroupstogrouping', 'group'). '</label></p>'."\n";
echo '<select name="newgrouping" id="groupings" class="select">'."\n";
<span class="clearer">&nbsp;</span> $groupingids = groups_get_groupings($courseid);
if (GROUP_NOT_IN_GROUPING == $groupingid) {
$groupingids[] = GROUP_NOT_IN_GROUPING;
}
if ($groupingids) {
// Put the groupings into a hash and sort them
foreach($groupingids as $id) {
$listgroupings[$id] = groups_get_grouping_displayname($id, $courseid);
}
natcasesort($listgroupings);
// Print out the HTML
$count = 1;
foreach($listgroupings as $id => $name) {
$select = '';
if ($groupingid == $id) {
$select = ' selected="selected"';
}
echo "<option value=\"$id\"$select>$name</option>\n";
$count++;
}
}
echo '</select>'."\n";
} //IF($groupid)
echo '<p class="fitem">'."\n";
echo '<label for="id_submit">&nbsp;</label>'."\n";
echo '<span class="f--element fsubmit">'."\n";
echo '<input type="submit" name="update" id="id_submit" value="' . $strbutton . '" />'."\n";
echo '<input type="submit" name="cancel" value="' . get_string('cancel', 'group') . '" />'."\n";
echo '</span>'."\n";
echo '</p>'."\n";
} //IF($delete)
echo '<span class="clearer">&nbsp;</span>'."\n";
echo '</div>';
echo '</form>'."\n";
</form>
<?php
print_footer($course); print_footer($course);
} }

View file

@ -123,6 +123,9 @@ if ($success) {
*/ */
redirect(groups_group_edit_url($courseid, null, $groupingid, false)); redirect(groups_group_edit_url($courseid, null, $groupingid, false));
break; break;
case 'showcreateorphangroupform':
redirect(groups_group_edit_url($courseid, null, null, false));
break;
case 'addgroupstogroupingform': case 'addgroupstogroupingform':
break; break;
case 'updategroups': //Currently reloading. case 'updategroups': //Currently reloading.
@ -154,8 +157,36 @@ if ($success) {
"-> $strgroups", '', '', true, '', user_login_string($course, $USER)); "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
$usehtmleditor = false; $usehtmleditor = false;
//TODO: eventually we'll implement all buttons, meantime hide the ones we haven't finised. //TODO: eventually we'll implement all buttons, meantime hide the ones we haven't finished.
$shownotdone = false; $shownotdone = false;
$disabled = 'disabled="disabled"';
// Pre-disable buttons based on URL variables
if (isset($groupingid) && $groupingid > -1) {
$showeditgroupsettingsform_disabled = '';
$showeditgroupingsettingsform_disabled = '';
$deletegroup_disabled = '';
$deletegrouping_disabled = '';
$printerfriendly_disabled = '';
$showcreategroupform_disabled = '';
} else {
$showeditgroupsettingsform_disabled = $disabled;
$showeditgroupingsettingsform_disabled = $disabled;
$deletegroup_disabled = $disabled;
$deletegrouping_disabled = $disabled;
$printerfriendly_disabled = $disabled;
$showcreategroupform_disabled = $disabled;
}
if (isset($groupid)) {
$showaddmembersform_disabled = '';
$showeditgroupsettingsform_disabled = '';
$deletegroup_disabled = '';
} else {
$deletegroup_disabled = $disabled;
$showeditgroupsettingsform_disabled = $disabled;
$showaddmembersform_disabled = $disabled;
}
print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3); print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3);
echo '<form id="groupeditform" action="index.php" method="post">'."\n"; echo '<form id="groupeditform" action="index.php" method="post">'."\n";
@ -201,29 +232,30 @@ if ($success) {
} }
echo '</select>'."\n"; echo '</select>'."\n";
echo '<p><input type="submit" name="act_updategroups" id="updategroups" value="' echo '<p><input type="submit" name="act_updategroups" id="updategroups" value="'
. get_string('showgroupsingrouping', 'group') . '" /></p>'."\n"; . get_string('showgroupsingrouping', 'group') . '" /></p>'."\n";
echo '<p><input type="submit" name="act_showgroupingsettingsform" id="showeditgroupingsettingsform" value="' echo '<p><input type="submit" ' . $showeditgroupingsettingsform_disabled . ' name="act_showgroupingsettingsform" id="showeditgroupingsettingsform" value="'
. get_string('editgroupingsettings', 'group') . '" /></p>'."\n"; . get_string('editgroupingsettings', 'group') . '" /></p>'."\n";
if ($shownotdone) { if ($shownotdone) {
echo '<p><input type="submit" disabled="disabled" name="act_showgroupingpermsform" ' echo '<p><input type="submit" '.$disabled.' name="act_showgroupingpermsform" '
. 'id="showeditgroupingpermissionsform" value="' . 'id="showeditgroupingpermissionsform" value="'
. get_string('editgroupingpermissions', 'group') . '" /></p>'."\n"; . get_string('editgroupingpermissions', 'group') . '" /></p>'."\n";
} }
echo '<p><input type="submit" name="act_deletegrouping" id="deletegrouping" value="' echo '<p><input type="submit" ' . $deletegrouping_disabled . ' name="act_deletegrouping" id="deletegrouping" value="'
. get_string('deletegrouping', 'group') . '" /></p>'."\n"; . get_string('deletegrouping', 'group') . '" /></p>'."\n";
echo '<p><input type="submit" name="act_showcreategroupingform" id="showcreategroupingform" value="' echo '<p><input type="submit" name="act_showcreategroupingform" id="showcreategroupingform" value="'
. get_string('creategrouping', 'group') . '" /></p>'."\n"; . get_string('creategrouping', 'group') . '" /></p>'."\n";
if ($shownotdone) { if ($shownotdone) {
echo '<p><input type="submit" disabled="disabled" name="act_createautomaticgroupingform" ' echo '<p><input type="submit" '.$disabled.' name="act_createautomaticgroupingform" '
. 'id="showcreateautomaticgroupingform" value="' . 'id="showcreateautomaticgroupingform" value="'
. get_string('createautomaticgrouping', 'group') . '" /></p>'."\n"; . get_string('createautomaticgrouping', 'group') . '" /></p>'."\n";
} }
echo '<p><input type="submit" name="act_printerfriendly" id="printerfriendly" value="' echo '<p><input type="submit" ' . $printerfriendly_disabled . ' name="act_printerfriendly" id="printerfriendly" value="'
. get_string('printerfriendly', 'group') . '" /></p>'."\n"; . get_string('printerfriendly', 'group') . '" /></p>'."\n";
echo "</td>\n<td>\n"; echo "</td>\n<td>\n";
echo '<p><label for="groups" id="groupslabel">' .get_string('groupsinselectedgrouping', 'group') . '</label></p>'."\n"; echo '<p><label for="groups" id="groupslabel">' .get_string('groupsinselectedgrouping', 'group') . '</label></p>'."\n";
@ -257,21 +289,24 @@ if ($success) {
echo '</select>'."\n"; echo '</select>'."\n";
echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="' echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="'
. get_string('showmembersforgroup', 'group') . '" /></p>'."\n"; . get_string('showmembersforgroup', 'group') . '" /></p>'."\n";
echo '<p><input type="submit" name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="' echo '<p><input type="submit" '. $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="'
. get_string('editgroupsettings', 'group') . '" /></p>'."\n"; . get_string('editgroupsettings', 'group') . '" /></p>'."\n";
echo '<p><input type="submit" name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="' echo '<p><input type="submit" '. $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="'
. get_string('deleteselectedgroup', 'group') . '" /></p>'."\n"; . get_string('deleteselectedgroup', 'group') . '" /></p>'."\n";
if ($shownotdone) { if ($shownotdone) {
echo '<p><input type="submit" disabled="disabled" name="act_removegroup" ' echo '<p><input type="submit" '.$disabled.' name="act_removegroup" '
. 'id="removegroup" value="' . get_string('removegroupfromselectedgrouping', 'group') . '" /></p>'."\n"; . 'id="removegroup" value="' . get_string('removegroupfromselectedgrouping', 'group') . '" /></p>'."\n";
} }
echo '<p><input type="submit" name="act_showcreategroupform" id="showcreategroupform" value="' echo '<p><input type="submit" ' . $showcreategroupform_disabled . ' name="act_showcreategroupform" id="showcreategroupform" value="'
. get_string('creategroupinselectedgrouping', 'group') . '" /></p>'."\n"; . get_string('creategroupinselectedgrouping', 'group') . '" /></p>'."\n";
echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="'
. get_string('createorphangroup', 'group') . '" /></p>'."\n";
if ($shownotdone) { if ($shownotdone) {
echo '<p><input type="submit" disabled="disabled" name="act_addgroupstogroupingform" ' echo '<p><input type="submit" '.$disabled.' name="act_addgroupstogroupingform" '
. 'id="showaddgroupstogroupingform" value="' . get_string('addgroupstogrouping', 'group') . '" /></p>'."\n"; . 'id="showaddgroupstogroupingform" value="' . get_string('addgroupstogrouping', 'group') . '" /></p>'."\n";
} }
@ -298,11 +333,11 @@ if ($success) {
echo '</select>'."\n"; echo '</select>'."\n";
if ($shownotdone) { if ($shownotdone) {
echo '<p><input type="submit" disabled="disabled" name="act_removemembers" ' echo '<p><input type="submit" '.$disabled.' name="act_removemembers" '
. 'id="removemembers" value="' . get_string('removeselectedusers', 'group') . '"/></p>'."\n"; . 'id="removemembers" value="' . get_string('removeselectedusers', 'group') . '"/></p>'."\n";
} }
echo '<p><input type="submit" name="act_showaddmembersform" ' echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" '
. 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n"; . 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n";
echo '</td>'."\n"; echo '</td>'."\n";
echo '</tr>'."\n"; echo '</tr>'."\n";

View file

@ -80,6 +80,20 @@ UpdatableGroupsCombo.prototype.refreshGroups = function (groupingId) {
} }
} }
if (groupingId > -1) {
document.getElementById("showaddmembersform").disabled = true;
document.getElementById("showeditgroupingsettingsform").disabled = false;
document.getElementById("deletegrouping").disabled = false;
document.getElementById("printerfriendly").disabled = false;
document.getElementById("showeditgroupsettingsform").disabled = true;
document.getElementById("deletegroup").disabled = true;
document.getElementById("showcreategroupform").disabled = false;
} else {
document.getElementById("showeditgroupingsettingsform").disabled = true;
document.getElementById("deletegrouping").disabled = true;
document.getElementById("showcreategroupform").disabled = true;
}
var sUrl = this.wwwRoot+"/group/index.php?id="+this.courseId+"&grouping="+groupingId+"&act_ajax_getgroupsingrouping"; var sUrl = this.wwwRoot+"/group/index.php?id="+this.courseId+"&grouping="+groupingId+"&act_ajax_getgroupsingrouping";
YAHOO.util.Connect.asyncRequest('GET', sUrl, this.connectCallback, null); YAHOO.util.Connect.asyncRequest('GET', sUrl, this.connectCallback, null);
}; };
@ -127,6 +141,8 @@ function UpdatableMembersCombo(wwwRoot, courseId) {
/** /**
* When a group is selected, we need to update the members. * When a group is selected, we need to update the members.
* The Add/Remove Users button also needs to be disabled/enabled
* depending on whether or not a group is selected
*/ */
UpdatableMembersCombo.prototype.refreshMembers = function (groupId) { UpdatableMembersCombo.prototype.refreshMembers = function (groupId) {
// Add the loader gif image. // Add the loader gif image.
@ -140,6 +156,9 @@ UpdatableMembersCombo.prototype.refreshMembers = function (groupId) {
} }
} }
document.getElementById("showaddmembersform").disabled = false;
document.getElementById("showeditgroupsettingsform").disabled = false;
document.getElementById("deletegroup").disabled = false;
var sUrl = this.wwwRoot+"/group/index.php?id="+this.courseId+"&group="+groupId+"&act_ajax_getmembersingroup"; var sUrl = this.wwwRoot+"/group/index.php?id="+this.courseId+"&group="+groupId+"&act_ajax_getmembersingroup";
YAHOO.util.Connect.asyncRequest("GET", sUrl, this.connectCallback, null); YAHOO.util.Connect.asyncRequest("GET", sUrl, this.connectCallback, null);
}; };

View file

@ -67,6 +67,7 @@ $string['selectnumberofgroups'] = 'Select number of groups';
$string['numberofgroups'] = 'Number of groups'; $string['numberofgroups'] = 'Number of groups';
$string['creategrouping'] = 'Create grouping'; $string['creategrouping'] = 'Create grouping';
$string['creategroup'] = 'Create group'; $string['creategroup'] = 'Create group';
$string['createorphangroup'] = 'Create Orphan group';
$string['groupname'] = 'Group name'; $string['groupname'] = 'Group name';
$string['defaultgroupname'] = 'Group'; $string['defaultgroupname'] = 'Group';