window.location = 'index.php?id='+args.courseid+'&category='+args.category+'&aggregationtype='+selectmenu.get('value')+'&sesskey='+args.sesskey;
}
+/**
+ * The weight override checkboxes toggle the disabled status of their associated weight fields.
+ */
+YUI().use('node', 'delegate', function(Y) {
+ Y.on('domready', function() {
+ Y.delegate('click', function(e) {
+ var t = e.currentTarget,
+ itemid = t.get('id').split('_')[1];
+ Y.one('input[name=weight_' + itemid + ']').set('disabled', t.get('checked') ? false : true);
+ }, Y.config.doc.body, 'input.weightoverride');
+ });
+});
/* TODO: finish and rewrite for YUI3...
Y.YUI2.namespace('grade_edit_tree');
// Convert weight to aggregation coef2.
$aggcoef = $grade_item->get_coefstring();
if ($aggcoef == 'aggregationcoefextraweightsum') {
+ // The field 'weight' should only be sent when the checkbox 'weighoverride' is checked,
+ // so there is not need to set weightoverride here, it is done below.
$value = $value / 100.0;
- if (round($grade_item->aggregationcoef2, 4) != round($value, 4)) {
- $grade_item->weightoverride = 1;
- }
$grade_item->aggregationcoef2 = $value;
} else if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoefextraweight') {
$grade_item->aggregationcoef = $value;
$grade_item->update();
+ $recreatetree = true;
+
+ // Grade item checkbox inputs.
+ } elseif (preg_match('/^(weightoverride)_([0-9]+)$/', $key, $matches)) {
+ $param = $matches[1];
+ $aid = $matches[2];
+ $value = clean_param($value, PARAM_BOOL);
+
+ $grade_item = grade_item::fetch(array('id' => $aid, 'courseid' => $courseid));
+ $grade_item->$param = $value;
+
+ $grade_item->update();
+
$recreatetree = true;
}
}
'<input type="text" size="6" id="weight_'.$item->id.'" name="weight_'.$item->id.'"
value="'.grade_edit_tree::format_number($item->aggregationcoef).'" />';
} else if ($aggcoef == 'aggregationcoefextraweightsum') {
- $label = '';
- if ($item->weightoverride && $parent_category->aggregation == GRADE_AGGREGATE_SUM) {
- $label = ' '.get_string('adjusted', 'grades');
- }
+
+ $checkboxname = 'weightoverride_' . $item->id;
+ $checkboxlbl = html_writer::tag('label', get_string('overrideweight', 'grades'),
+ array('for' => $checkboxname, 'class' => 'accesshide'));
+ $checkbox = html_writer::empty_tag('input', array('name' => $checkboxname,
+ 'type' => 'hidden', 'value' => 0));
+ $checkbox .= html_writer::empty_tag('input', array('name' => $checkboxname,
+ 'type' => 'checkbox', 'value' => 1, 'id' => $checkboxname, 'class' => 'weightoverride',
+ 'checked' => ($item->weightoverride ? 'checked' : null)));
$name = 'weight_' . $item->id;
$hiddenlabel = html_writer::tag(
'size' => 6,
'id' => $name,
'name' => $name,
- 'value' => grade_edit_tree::format_number($item->aggregationcoef2 * 100.0)
+ 'value' => grade_edit_tree::format_number($item->aggregationcoef2 * 100.0),
+ 'disabled' => ($item->weightoverride ? null : 'disabled')
)
);
- $str .= $hiddenlabel . $input . $label;
+ $str .= $checkboxlbl . $checkbox . $hiddenlabel . $input;
if ($item->aggregationcoef > 0) {
$str .= ' ' . html_writer::tag('abbr', get_string('aggregationcoefextrasumabbr', 'grades'),
$string['addoutcome'] = 'Add an outcome';
$string['addoutcomeitem'] = 'Add outcome item';
$string['addscale'] = 'Add a scale';
-$string['adjusted'] = 'Adjusted';
$string['adjustedweight'] = 'Weight adjusted';
$string['aggregateextracreditmean'] = 'Mean of grades (with extra credits)';
$string['aggregatemax'] = 'Highest grade';
$string['overriddennotice'] = 'Your final grade from this activity was manually adjusted.';
$string['overridesitedefaultgradedisplaytype'] = 'Override site defaults';
$string['overridesitedefaultgradedisplaytype_help'] = 'If ticked, grade letters and boundaries for the course may be set, rather than using the site defaults.';
+$string['overrideweight'] = 'Override weight';
$string['parentcategory'] = 'Parent category';
$string['pctoftotalgrade'] = '% of total grade';
$string['percent'] = 'Percent';