From ec3857fee26fd355311841cc423be511793434c2 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Tue, 16 Aug 2016 17:40:07 +0800 Subject: [PATCH] MDL-55584 gradereport_singleview: Convert some elements to template Part of MDL-55071 --- .../classes/local/screen/tablelike.php | 6 +- .../classes/local/ui/bulk_insert.php | 69 +++++-------------- .../classes/local/ui/dropdown_attribute.php | 33 +++++---- .../classes/local/ui/text_attribute.php | 38 ++++------ .../singleview/templates/bulk_insert.mustache | 34 +++++++++ .../singleview/templates/button.mustache | 20 ++++++ .../templates/dropdown_attribute.mustache | 25 +++++++ .../templates/text_attribute.mustache | 22 ++++++ 8 files changed, 151 insertions(+), 96 deletions(-) create mode 100644 grade/report/singleview/templates/bulk_insert.mustache create mode 100644 grade/report/singleview/templates/button.mustache create mode 100644 grade/report/singleview/templates/dropdown_attribute.mustache create mode 100644 grade/report/singleview/templates/text_attribute.mustache diff --git a/grade/report/singleview/classes/local/screen/tablelike.php b/grade/report/singleview/classes/local/screen/tablelike.php index 5e5054fbd92..9c5f025315b 100644 --- a/grade/report/singleview/classes/local/screen/tablelike.php +++ b/grade/report/singleview/classes/local/screen/tablelike.php @@ -230,10 +230,12 @@ abstract class tablelike extends screen { * @return array */ public function buttons() { - $save = html_writer::empty_tag('input', array( + global $OUTPUT; + + $save = $OUTPUT->render_from_template('gradereport_singleview/button', [ 'type' => 'submit', 'value' => get_string('save', 'gradereport_singleview'), - )); + ]); return array($save); } diff --git a/grade/report/singleview/classes/local/ui/bulk_insert.php b/grade/report/singleview/classes/local/ui/bulk_insert.php index 24b715e496c..2eb173f8969 100644 --- a/grade/report/singleview/classes/local/ui/bulk_insert.php +++ b/grade/report/singleview/classes/local/ui/bulk_insert.php @@ -85,62 +85,25 @@ class bulk_insert extends element { * @return string HTML */ public function html() { - $insertvalue = get_string('bulkinsertvalue', 'gradereport_singleview'); - $insertappliesto = get_string('bulkappliesto', 'gradereport_singleview'); + global $OUTPUT; - $insertoptions = array( - 'all' => get_string('all_grades', 'gradereport_singleview'), - 'blanks' => get_string('blanks', 'gradereport_singleview') - ); - - $selectlabel = html_writer::label( - $insertappliesto, - 'menu' . $this->selectname - ); - $select = html_writer::select( - $insertoptions, - $this->selectname, - 'blanks', - false, - array( - 'id' => 'menu' . $this->selectname - ) - ); - - $textlabel = html_writer::label( - $insertvalue, - $this->insertname - ); $text = new text_attribute($this->insertname, "0", 'bulk'); + $context = (object) [ + 'label' => get_string('bulklegend', 'gradereport_singleview'), + 'applylabel' => get_string('bulkperform', 'gradereport_singleview'), + 'applyname' => $this->applyname, + 'menuname' => $this->selectname, + 'menulabel' => get_string('bulkappliesto', 'gradereport_singleview'), + 'menuoptions' => [ + ['value' => 'all', 'name' => get_string('all_grades', 'gradereport_singleview')], + ['value' => 'blanks', 'name' => get_string('blanks', 'gradereport_singleview'), 'selected' => true], + ], + 'valuename' => $this->insertname, + 'valuelabel' => get_string('bulkinsertvalue', 'gradereport_singleview'), + 'valuefield' => $text->html() + ]; - $inner = implode(' ', array( - $selectlabel, - $select, - $textlabel, - $text->html() - )); - - $fieldset = html_writer::tag( - 'fieldset', - html_writer::tag( - 'legend', - get_string('bulklegend', 'gradereport_singleview'), - array( - 'class' => 'accesshide' - ) - ) . - $inner - ); - - $apply = html_writer::checkbox( - $this->applyname, - 1, - false, - get_string('bulkperform', 'gradereport_singleview') - ); - $applydiv = html_writer::div($apply, 'enable'); - - return $applydiv . $fieldset; + return $OUTPUT->render_from_template('gradereport_singleview/bulk_insert', $context); } /** diff --git a/grade/report/singleview/classes/local/ui/dropdown_attribute.php b/grade/report/singleview/classes/local/ui/dropdown_attribute.php index 19bc80c6f8e..50f1ce99667 100644 --- a/grade/report/singleview/classes/local/ui/dropdown_attribute.php +++ b/grade/report/singleview/classes/local/ui/dropdown_attribute.php @@ -77,22 +77,25 @@ class dropdown_attribute extends element { * @return string */ public function html() { - $old = array( - 'type' => 'hidden', - 'name' => 'old' . $this->name, - 'value' => $this->selected + global $OUTPUT; + + $options = $this->options; + $selected = $this->selected; + + $context = array( + 'name' => $this->name, + 'value' => $this->selected, + 'tabindex' => 1, + 'disabled' => !empty($this->isdisabled), + 'options' => array_map(function($option) use ($options, $selected) { + return [ + 'name' => $options[$option], + 'value' => $option, + 'selected' => $selected == $option + ]; + }, array_keys($options)) ); - $attributes = array('tabindex' => '1'); - - if (!empty($this->isdisabled)) { - $attributes['disabled'] = 'DISABLED'; - } - - $select = html_writer::select( - $this->options, $this->name, $this->selected, false, $attributes - ); - - return ($select . html_writer::empty_tag('input', $old)); + return $OUTPUT->render_from_template('gradereport_singleview/dropdown_attribute', $context); } } diff --git a/grade/report/singleview/classes/local/ui/text_attribute.php b/grade/report/singleview/classes/local/ui/text_attribute.php index 01021993f69..652ae616a81 100644 --- a/grade/report/singleview/classes/local/ui/text_attribute.php +++ b/grade/report/singleview/classes/local/ui/text_attribute.php @@ -65,38 +65,24 @@ class text_attribute extends element { * @return string The HTML. */ public function html() { - $attributes = array( - 'type' => 'text', + global $OUTPUT; + + $context = (object) [ + 'id' => $this->name, 'name' => $this->name, 'value' => $this->value, - 'id' => $this->name - ); + 'disabled' => $this->isdisabled, + ]; - if ($this->isdisabled) { - $attributes['disabled'] = 'DISABLED'; - } - - $hidden = array( - 'type' => 'hidden', - 'name' => 'old' . $this->name, - 'value' => $this->value - ); - - $label = ''; + $context->label = ''; if (preg_match("/^feedback/", $this->name)) { - $labeltitle = get_string('feedbackfor', 'gradereport_singleview', $this->label); - $attributes['tabindex'] = '2'; - $label = html_writer::tag('label', $labeltitle, array('for' => $this->name, 'class' => 'accesshide')); + $context->label = get_string('feedbackfor', 'gradereport_singleview', $this->label); + $context->tabindex = '2'; } else if (preg_match("/^finalgrade/", $this->name)) { - $labeltitle = get_string('gradefor', 'gradereport_singleview', $this->label); - $attributes['tabindex'] = '1'; - $label = html_writer::tag('label', $labeltitle, array('for' => $this->name, 'class' => 'accesshide')); + $context->label = get_string('gradefor', 'gradereport_singleview', $this->label); + $context->tabindex = '1'; } - return ( - $label . - html_writer::empty_tag('input', $attributes) . - html_writer::empty_tag('input', $hidden) - ); + return $OUTPUT->render_from_template('gradereport_singleview/text_attribute', $context); } } diff --git a/grade/report/singleview/templates/bulk_insert.mustache b/grade/report/singleview/templates/bulk_insert.mustache new file mode 100644 index 00000000000..ad4b6574424 --- /dev/null +++ b/grade/report/singleview/templates/bulk_insert.mustache @@ -0,0 +1,34 @@ +{{! + 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 . +}} +{{! + Bulk insert attribute. +}} +
+ + +
+
+ {{label}} + + + + {{{valuefield}}} +
diff --git a/grade/report/singleview/templates/button.mustache b/grade/report/singleview/templates/button.mustache new file mode 100644 index 00000000000..a922e89b8d1 --- /dev/null +++ b/grade/report/singleview/templates/button.mustache @@ -0,0 +1,20 @@ +{{! + 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 . +}} +{{! + Button. +}} + diff --git a/grade/report/singleview/templates/dropdown_attribute.mustache b/grade/report/singleview/templates/dropdown_attribute.mustache new file mode 100644 index 00000000000..e6388ca809e --- /dev/null +++ b/grade/report/singleview/templates/dropdown_attribute.mustache @@ -0,0 +1,25 @@ +{{! + 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 . +}} +{{! + Dropdown attribute. +}} + + diff --git a/grade/report/singleview/templates/text_attribute.mustache b/grade/report/singleview/templates/text_attribute.mustache new file mode 100644 index 00000000000..3b93780129b --- /dev/null +++ b/grade/report/singleview/templates/text_attribute.mustache @@ -0,0 +1,22 @@ +{{! + 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 . +}} +{{! + Text attribute. +}} + + +