MDL-55584 core_grades: Convert part of set-up screen to template
authorFrederic Massart <fred@moodle.com>
Tue, 16 Aug 2016 09:41:14 +0000 (17:41 +0800)
committerDan Poltawski <dan@moodle.com>
Fri, 23 Sep 2016 09:53:56 +0000 (10:53 +0100)
Part of MDL-55071

grade/edit/tree/index.php
grade/edit/tree/lib.php
grade/templates/edit_tree.mustache [new file with mode: 0644]
grade/templates/weight_field.mustache [new file with mode: 0644]
grade/templates/weight_override_field.mustache [new file with mode: 0644]

index ac912f7..bcdbbb8 100644 (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');
-}
-
-echo 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>';
+    $notification = new \core\output\notification(get_string('weightsadjusted', 'grades'), \core\output\notification::NOTIFY_INFO);
+    $tpldata->notification = $notification->export_for_template($OUTPUT);
 }
 
-echo '</div>';
+$tpldata->table = html_writer::table($grade_edit_tree->table);
 
-echo '</div></form>';
+echo $OUTPUT->render_from_template('core_grades/edit_tree', $tpldata);
 
 echo $OUTPUT->box_end();
 
index 8b9e101..a7b7d06 100644 (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),
-                ]);
 
-        } 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,
+            return $OUTPUT->render_from_template('core_grades/weight_field', [
+                'id' => $item->id,
+                'itemname' => $itemname,
+                'value' => self::format_number($item->aggregationcoef)
             ]);
 
-            $checkbox .= html_writer::empty_tag('input', [
-                'name' => $checkboxname,
-                'type' => 'checkbox',
-                'value' => 1,
-                'id' => $checkboxname,
-                'class' => 'weightoverride',
-                'checked' => ($item->weightoverride ? 'checked' : null),
-            ]);
+        } else if ($aggcoef == 'aggregationcoefextraweightsum') {
+
+            $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);
 
-            $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 (file)
index 0000000..551dae6
--- /dev/null
@@ -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>
diff --git a/grade/templates/weight_field.mustache b/grade/templates/weight_field.mustache
new file mode 100644 (file)
index 0000000..1bf4f7c
--- /dev/null
@@ -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">
diff --git a/grade/templates/weight_override_field.mustache b/grade/templates/weight_override_field.mustache
new file mode 100644 (file)
index 0000000..91f6f95
--- /dev/null
@@ -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}}>