From 615074d4b8efa491d8d602eadfcb00ad6027f770 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Thu, 19 Sep 2019 14:44:19 +1200 Subject: [PATCH] Change to using single_select API. --- renderer.php | 50 ++++++++++++++++-------------- tests/behat/extra_features.feature | 4 +-- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/renderer.php b/renderer.php index b66a4e4..2993cd7 100644 --- a/renderer.php +++ b/renderer.php @@ -599,23 +599,23 @@ class mod_attendance_renderer extends plugin_renderer_base { } /** - * Render statusdropdown + * get statusdropdown * - * @param string $preference - * @return string + * @return \single_select */ - private function render_statusdropdown($preference) { - if ($preference == 'unselected') { - return " "; - } else { - return " "; + private function statusdropdown() { + $pref = get_user_preferences('mod_attendance_statusdropdown'); + if (empty($pref)) { + $pref = 'unselected'; } + $options = array('all' => get_string('statusall', 'attendance'), + 'unselected' => get_string('statusunselected', 'attendance')); + + $select = new \single_select(new \moodle_url('/'), 'setallstatus-select', $options, + $pref, null, 'setallstatus-select'); + $select->label = get_string('setallstatuses', 'attendance'); + + return $select; } /** @@ -653,7 +653,14 @@ class mod_attendance_renderer extends plugin_renderer_base { $PAGE->requires->js_amd_inline(" require(['jquery'], function($) { $('#checkstatus".$st->id."').click(function(e) { - $('#attendancetakeform').find('.st".$st->id."').prop('checked', true); + if ($('select[name=\"setallstatus-select\"] option:selected').val() == 'all') { + $('#attendancetakeform').find('.st".$st->id."').prop('checked', true); + M.util.set_user_preference('mod_attendance_statusdropdown','all'); + } + else { + $('#attendancetakeform').find('input:indeterminate.st".$st->id."').prop('checked', true); + M.util.set_user_preference('mod_attendance_statusdropdown','unselected'); + } e.preventDefault(); }); });"); @@ -672,9 +679,7 @@ class mod_attendance_renderer extends plugin_renderer_base { $row->cells[] = ''; } - $selectmenu = $this->render_statusdropdown(get_user_preferences('mod_attendance_statusdropdown')); - $cell = new html_table_cell(html_writer::div(get_string('setallstatuses', 'attendance'). - $selectmenu, 'setallstatuses')); + $cell = new html_table_cell(html_writer::div($this->output->render($this->statusdropdown()), 'setallstatuses')); $cell->colspan = 2; $row->cells[] = $cell; foreach ($takedata->statuses as $st) { @@ -690,7 +695,7 @@ class mod_attendance_renderer extends plugin_renderer_base { $PAGE->requires->js_amd_inline(" require(['jquery'], function($) { $('#radiocheckstatus".$st->id."').click(function(e) { - if ($('#setallstatus-select').val() == 'all') { + if ($('select[name=\"setallstatus-select\"] option:selected').val() == 'all') { $('#attendancetakeform').find('.st".$st->id."').prop('checked', true); M.util.set_user_preference('mod_attendance_statusdropdown','all'); } @@ -756,11 +761,8 @@ class mod_attendance_renderer extends plugin_renderer_base { $table->attributes['class'] = 'generaltable takegrid'; $table->headspan = $takedata->pageparams->gridcols; - $selectmenu = $this->render_statusdropdown(get_user_preferences('mod_attendance_statusdropdown')); - $head = array(); - $head[] = html_writer::div(get_string('setallstatuses', 'attendance'). - $selectmenu, 'setallstatuses'); + $head[] = html_writer::div($this->output->render($this->statusdropdown()), 'setallstatuses'); foreach ($takedata->statuses as $st) { $head[] = html_writer::link("#", $st->acronym, array('id' => 'checkstatus'.$st->id, 'title' => get_string('setallstatusesto', 'attendance', $st->description))); @@ -768,7 +770,7 @@ class mod_attendance_renderer extends plugin_renderer_base { $PAGE->requires->js_amd_inline(" require(['jquery'], function($) { $('#checkstatus".$st->id."').click(function(e) { - if ($('#setallstatus-select').val() == 'unselected') { + if ($('select[name=\"setallstatus-select\"] option:selected').val() == 'unselected') { $('#attendancetakeform').find('input:indeterminate.st".$st->id."').prop('checked', true); M.util.set_user_preference('mod_attendance_statusdropdown','unselected'); } diff --git a/tests/behat/extra_features.feature b/tests/behat/extra_features.feature index ab9d4c2..9fab01d 100644 --- a/tests/behat/extra_features.feature +++ b/tests/behat/extra_features.feature @@ -202,8 +202,8 @@ Feature: Test the various new features in the attendance module | id_addmultiply | 0 | And I click on "submitbutton" "button" And I click on "Take attendance" "link" - - When I click on "setallstatuses" "field" in the ".takelist tbody td.c4" "css_element" + And I set the field "Set status for" to "all" + When I click on "setallstatuses" "field" in the ".takelist tbody td.c3" "css_element" And I press "Save attendance" And I follow "Report" Then "L" "text" should exist in the "Student 1" "table_row"