MDL-55584 core_grades: Convert part of set-up screen to template

Part of MDL-55071
This commit is contained in:
Frederic Massart 2016-08-16 17:41:14 +08:00 committed by Dan Poltawski
parent ec3857fee2
commit d68a9ece86
5 changed files with 131 additions and 75 deletions

View File

@ -237,42 +237,34 @@ print_grade_page_head($courseid, 'settings', 'setup', get_string('gradebooksetup
// Print Table of categories and items
echo $OUTPUT->box_start('gradetreebox generalbox');
echo '<form id="gradetreeform" method="post" action="'.$returnurl.'">';
echo '<div>';
echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
//did we update something in the db and thus invalidate $grade_edit_tree?
if ($recreatetree) {
$grade_edit_tree = new grade_edit_tree($gtree, $movingeid, $gpr);
}
$bulkmoveoptions = ['' => get_string('choosedots')] + $grade_edit_tree->categories;
$tpldata = (object) [
'actionurl' => $returnurl,
'sesskey' => sesskey(),
'showsave' => !$moving,
'showbulkmove' => !$moving && count($grade_edit_tree->categories) > 1,
'bulkmoveoptions' => array_map(function($option) use ($bulkmoveoptions) {
return [
'name' => $bulkmoveoptions[$option],
'value' => $option
];
}, array_keys($bulkmoveoptions))
];
// Check to see if we have a normalisation message to send.
if ($weightsadjusted) {
echo $OUTPUT->notification(get_string('weightsadjusted', 'grades'), 'notifymessage');
$notification = new \core\output\notification(get_string('weightsadjusted', 'grades'), \core\output\notification::NOTIFY_INFO);
$tpldata->notification = $notification->export_for_template($OUTPUT);
}
echo html_writer::table($grade_edit_tree->table);
$tpldata->table = html_writer::table($grade_edit_tree->table);
echo '<div id="gradetreesubmit">';
if (!$moving) {
echo '<input class="advanced" type="submit" value="'.get_string('savechanges').'" />';
}
// We don't print a bulk move menu if there are no other categories than course category
if (!$moving && count($grade_edit_tree->categories) > 1) {
echo '<br /><br />';
echo '<input type="hidden" name="bulkmove" value="0" id="bulkmoveinput" />';
$attributes = array('id'=>'menumoveafter', 'class' => 'ignoredirty singleselect');
echo html_writer::label(get_string('moveselectedto', 'grades'), 'menumoveafter');
echo html_writer::select($grade_edit_tree->categories, 'moveafter', '', array(''=>'choosedots'), $attributes);
echo '<div id="noscriptgradetreeform" class="hiddenifjs">
<input type="submit" value="'.get_string('go').'" />
</div>';
}
echo '</div>';
echo '</div></form>';
echo $OUTPUT->render_from_template('core_grades/edit_tree', $tpldata);
echo $OUTPUT->box_end();

View File

@ -400,59 +400,24 @@ class grade_edit_tree {
$str = '';
if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef' || $aggcoef == 'aggregationcoefextraweight') {
return '<label class="accesshide" for="weight_'.$item->id.'">' .
get_string('extracreditvalue', 'grades', $itemname).'</label>' .
html_writer::empty_tag('input', [
'type' => 'text',
'size' => 6,
'id' => 'weight_' . $item->id,
'name' => 'weight_' . $item->id,
'value' => self::format_number($item->aggregationcoef),
]);
return $OUTPUT->render_from_template('core_grades/weight_field', [
'id' => $item->id,
'itemname' => $itemname,
'value' => self::format_number($item->aggregationcoef)
]);
} else if ($aggcoef == 'aggregationcoefextraweightsum') {
$checkboxname = 'weightoverride_' . $item->id;
$checkboxlbl = html_writer::tag('label', get_string('overrideweightofa', 'grades', $itemname),
array('for' => $checkboxname, 'class' => 'accesshide'));
$checkbox = html_writer::empty_tag('input', [
'name' => $checkboxname,
'type' => 'hidden',
'value' => 0,
]);
$tpldata = [
'id' => $item->id,
'itemname' => $itemname,
'value' => grade_edit_tree::format_number($item->aggregationcoef2 * 100.0),
'checked' => $item->weightoverride,
'disabled' => !$item->weightoverride
];
$str .= $OUTPUT->render_from_template('core_grades/weight_override_field', $tpldata);
$checkbox .= html_writer::empty_tag('input', [
'name' => $checkboxname,
'type' => 'checkbox',
'value' => 1,
'id' => $checkboxname,
'class' => 'weightoverride',
'checked' => ($item->weightoverride ? 'checked' : null),
]);
$name = 'weight_' . $item->id;
$hiddenlabel = html_writer::tag(
'label',
get_string('weightofa', 'grades', $itemname),
array(
'class' => 'accesshide',
'for' => $name
)
);
$input = html_writer::empty_tag(
'input',
array(
'type' => 'text',
'size' => 6,
'id' => $name,
'name' => $name,
'value' => grade_edit_tree::format_number($item->aggregationcoef2 * 100.0),
'disabled' => ($item->weightoverride ? null : 'disabled')
)
);
$str .= $checkboxlbl . $checkbox . $hiddenlabel . $input;
}
return $str;

View File

@ -0,0 +1,47 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
Edit tree.
}}
<form id="gradetreeform" method="post" action="{{actionurl}}">
<div>
<input type="hidden" name="sesskey" value="{{sesskey}}">
{{#notification}}
{{>core/notification_info}}
{{/notification}}
{{{table}}}
<div id="gradetreesubmit">
{{#showsave}}
<input class="advanced" type="submit" value={{#quote}}{{#str}}savechanges{{/str}}{{/quote}}>
{{/showsave}}
{{#showbulkmove}}
<br><br>
<input type="hidden" name="bulkmove" value="0" id="bulkmoveinput">
<label for="menumoveafter">{{#str}}moveselectedto, grades{{/str}}</label>
<select name="moveafter" id="menumoveafter" class="ignoredirty singleselect select">
{{#bulkmoveoptions}}
<option value="{{value}}">{{name}}</option>
{{/bulkmoveoptions}}
</select>
<div id="noscriptgradetreeform" class="hiddenifjs">
<input type="submit" name={{#quote}}{{#str}}go{{/str}}{{/quote}}>
</div>
{{/showbulkmove}}
</div>
</div>
</form>

View File

@ -0,0 +1,23 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
Weight field.
}}
<label class="accesshide" for="weight_{{id}}">
{{#str}}extracreditvalue, grades, {{itemname}}{{/str}}
</label>
<input type="text" name="weight_{{id}}" id="weight_{{id}}" value="{{value}}" size="6">

View File

@ -0,0 +1,29 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
Weight override field.
}}
<label class="accesshide" for="weightoverride_{{id}}">
{{#str}}overrideweightofa, grades, {{itemname}}{{/str}}
</label>
<input type="hidden" name="weightoverride_{{id}}" value="0">
<input type="checkbox" name="weightoverride_{{id}}" id="weightoverride_{{id}}" value="1" class="weightoverride" {{#checked}}checked{{/checked}}>
<label class="accesshide" for="weight_{{id}}">
{{#str}}weightofa, grades, {{itemname}}{{/str}}
</label>
<input type="text" name="weight_{{id}}" id="weight_{{id}}" value="{{value}}" size="6" {{#disabled}}disabled{{/disabled}}>