From d68a9ece8616508b798b34bc59b1654b70edaa11 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 16 Aug 2016 17:41:14 +0800 Subject: [PATCH] MDL-55584 core_grades: Convert part of set-up screen to template Part of MDL-55071 --- grade/edit/tree/index.php | 44 ++++++------- grade/edit/tree/lib.php | 63 +++++-------------- grade/templates/edit_tree.mustache | 47 ++++++++++++++ grade/templates/weight_field.mustache | 23 +++++++ .../templates/weight_override_field.mustache | 29 +++++++++ 5 files changed, 131 insertions(+), 75 deletions(-) create mode 100644 grade/templates/edit_tree.mustache create mode 100644 grade/templates/weight_field.mustache create mode 100644 grade/templates/weight_override_field.mustache diff --git a/grade/edit/tree/index.php b/grade/edit/tree/index.php index ac912f7cde7..bcdbbb82184 100644 --- a/grade/edit/tree/index.php +++ b/grade/edit/tree/index.php @@ -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 '
'; -echo '
'; -echo ''; - //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 '
'; -if (!$moving) { - echo ''; -} - -// 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 '

'; - echo ''; - $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 '
- -
'; -} - -echo '
'; - -echo '
'; +echo $OUTPUT->render_from_template('core_grades/edit_tree', $tpldata); echo $OUTPUT->box_end(); diff --git a/grade/edit/tree/lib.php b/grade/edit/tree/lib.php index 8b9e101fe19..a7b7d064b75 100644 --- a/grade/edit/tree/lib.php +++ b/grade/edit/tree/lib.php @@ -400,59 +400,24 @@ class grade_edit_tree { $str = ''; if ($aggcoef == 'aggregationcoefweight' || $aggcoef == 'aggregationcoef' || $aggcoef == 'aggregationcoefextraweight') { - return '' . - 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; diff --git a/grade/templates/edit_tree.mustache b/grade/templates/edit_tree.mustache new file mode 100644 index 00000000000..551dae6793c --- /dev/null +++ b/grade/templates/edit_tree.mustache @@ -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 . +}} +{{! + Edit tree. +}} + +
+
+ + {{#notification}} + {{>core/notification_info}} + {{/notification}} + {{{table}}} +
+ {{#showsave}} + + {{/showsave}} + {{#showbulkmove}} +

+ + + +
+ +
+ {{/showbulkmove}} +
+
+
diff --git a/grade/templates/weight_field.mustache b/grade/templates/weight_field.mustache new file mode 100644 index 00000000000..1bf4f7c8dd1 --- /dev/null +++ b/grade/templates/weight_field.mustache @@ -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 . +}} +{{! + Weight field. +}} + + diff --git a/grade/templates/weight_override_field.mustache b/grade/templates/weight_override_field.mustache new file mode 100644 index 00000000000..91f6f950253 --- /dev/null +++ b/grade/templates/weight_override_field.mustache @@ -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 . +}} +{{! + Weight override field. +}} + + + + + +