Browse Source

Change to using single_select API.

MOODLE_37_STABLE
Dan Marsden 5 years ago
parent
commit
295d9f3292
  1. 48
      renderer.php
  2. 4
      tests/behat/extra_features.feature

48
renderer.php

@ -599,23 +599,23 @@ class mod_attendance_renderer extends plugin_renderer_base {
} }
/** /**
* Render statusdropdown * get statusdropdown
* *
* @param string $preference * @return \single_select
* @return string
*/ */
private function render_statusdropdown($preference) { private function statusdropdown() {
if ($preference == 'unselected') { $pref = get_user_preferences('mod_attendance_statusdropdown');
return " <select id='setallstatus-select'> if (empty($pref)) {
<option value='all'>".get_string('statusall', 'attendance')."</option> $pref = 'unselected';
<option selected value='unselected'>".get_string('statusunselected', 'attendance')."</option>
</select>";
} else {
return " <select id='setallstatus-select'>
<option selected value='all'>".get_string('statusall', 'attendance')."</option>
<option value='unselected'>".get_string('statusunselected', 'attendance')."</option>
</select>";
} }
$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(" $PAGE->requires->js_amd_inline("
require(['jquery'], function($) { require(['jquery'], function($) {
$('#checkstatus".$st->id."').click(function(e) { $('#checkstatus".$st->id."').click(function(e) {
if ($('select[name=\"setallstatus-select\"] option:selected').val() == 'all') {
$('#attendancetakeform').find('.st".$st->id."').prop('checked', true); $('#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(); e.preventDefault();
}); });
});"); });");
@ -672,9 +679,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$row->cells[] = ''; $row->cells[] = '';
} }
$selectmenu = $this->render_statusdropdown(get_user_preferences('mod_attendance_statusdropdown')); $cell = new html_table_cell(html_writer::div($this->output->render($this->statusdropdown()), 'setallstatuses'));
$cell = new html_table_cell(html_writer::div(get_string('setallstatuses', 'attendance').
$selectmenu, 'setallstatuses'));
$cell->colspan = 2; $cell->colspan = 2;
$row->cells[] = $cell; $row->cells[] = $cell;
foreach ($takedata->statuses as $st) { foreach ($takedata->statuses as $st) {
@ -690,7 +695,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$PAGE->requires->js_amd_inline(" $PAGE->requires->js_amd_inline("
require(['jquery'], function($) { require(['jquery'], function($) {
$('#radiocheckstatus".$st->id."').click(function(e) { $('#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); $('#attendancetakeform').find('.st".$st->id."').prop('checked', true);
M.util.set_user_preference('mod_attendance_statusdropdown','all'); 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->attributes['class'] = 'generaltable takegrid';
$table->headspan = $takedata->pageparams->gridcols; $table->headspan = $takedata->pageparams->gridcols;
$selectmenu = $this->render_statusdropdown(get_user_preferences('mod_attendance_statusdropdown'));
$head = array(); $head = array();
$head[] = html_writer::div(get_string('setallstatuses', 'attendance'). $head[] = html_writer::div($this->output->render($this->statusdropdown()), 'setallstatuses');
$selectmenu, 'setallstatuses');
foreach ($takedata->statuses as $st) { foreach ($takedata->statuses as $st) {
$head[] = html_writer::link("#", $st->acronym, array('id' => 'checkstatus'.$st->id, $head[] = html_writer::link("#", $st->acronym, array('id' => 'checkstatus'.$st->id,
'title' => get_string('setallstatusesto', 'attendance', $st->description))); 'title' => get_string('setallstatusesto', 'attendance', $st->description)));
@ -768,7 +770,7 @@ class mod_attendance_renderer extends plugin_renderer_base {
$PAGE->requires->js_amd_inline(" $PAGE->requires->js_amd_inline("
require(['jquery'], function($) { require(['jquery'], function($) {
$('#checkstatus".$st->id."').click(function(e) { $('#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); $('#attendancetakeform').find('input:indeterminate.st".$st->id."').prop('checked', true);
M.util.set_user_preference('mod_attendance_statusdropdown','unselected'); M.util.set_user_preference('mod_attendance_statusdropdown','unselected');
} }

4
tests/behat/extra_features.feature

@ -202,8 +202,8 @@ Feature: Test the various new features in the attendance module
| id_addmultiply | 0 | | id_addmultiply | 0 |
And I click on "submitbutton" "button" And I click on "submitbutton" "button"
And I click on "Take attendance" "link" And I click on "Take attendance" "link"
And I set the field "Set status for" to "all"
When I click on "setallstatuses" "field" in the ".takelist tbody td.c4" "css_element" When I click on "setallstatuses" "field" in the ".takelist tbody td.c3" "css_element"
And I press "Save attendance" And I press "Save attendance"
And I follow "Report" And I follow "Report"
Then "L" "text" should exist in the "Student 1" "table_row" Then "L" "text" should exist in the "Student 1" "table_row"

Loading…
Cancel
Save