Browse Source

Issue #405 Convert shift click functionality to drop down menu.

Use user preferences to remember the value of the drop-down
nwp90-nwp90-allsessionsreport
M 5 years ago
committed by Dan Marsden
parent
commit
40d6885875
  1. 2
      lang/en/attendance.php
  2. 42
      renderer.php
  3. 14
      tests/behat/extra_features.feature

2
lang/en/attendance.php

@ -463,6 +463,8 @@ $string['statusdeleted'] = 'Status deleted';
$string['statuses'] = 'Statuses'; $string['statuses'] = 'Statuses';
$string['statusset'] = 'Status set {$a}'; $string['statusset'] = 'Status set {$a}';
$string['statussetsettings'] = 'Status set'; $string['statussetsettings'] = 'Status set';
$string['statusall'] = 'all';
$string['statusunselected'] = 'unselected';
$string['strftimedm'] = '%b %d'; $string['strftimedm'] = '%b %d';
$string['strftimedmy'] = '%d %b %Y'; $string['strftimedmy'] = '%d %b %Y';
$string['strftimedmyhm'] = '%d %b %Y %I.%M%p'; // Line added to allow multiple sessions in the same day. $string['strftimedmyhm'] = '%d %b %Y %I.%M%p'; // Line added to allow multiple sessions in the same day.

42
renderer.php

@ -28,6 +28,7 @@ require_once(dirname(__FILE__).'/locallib.php');
require_once(dirname(__FILE__).'/renderables.php'); require_once(dirname(__FILE__).'/renderables.php');
require_once(dirname(__FILE__).'/renderhelpers.php'); require_once(dirname(__FILE__).'/renderhelpers.php');
require_once($CFG->libdir.'/tablelib.php'); require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->libdir.'/moodlelib.php');
/** /**
* Attendance module renderer class * Attendance module renderer class
@ -414,6 +415,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
* @return string * @return string
*/ */
protected function render_attendance_take_data(attendance_take_data $takedata) { protected function render_attendance_take_data(attendance_take_data $takedata) {
user_preference_allow_ajax_update('mod_attendance_statusdropdown', PARAM_RAW);
$controls = $this->render_attendance_take_controls($takedata); $controls = $this->render_attendance_take_controls($takedata);
$table = html_writer::start_div('no-overflow'); $table = html_writer::start_div('no-overflow');
if ($takedata->pageparams->viewmode == mod_attendance_take_page_params::SORTED_LIST) { if ($takedata->pageparams->viewmode == mod_attendance_take_page_params::SORTED_LIST) {
@ -595,6 +598,26 @@ class mod_attendance_renderer extends plugin_renderer_base {
return $controls; return $controls;
} }
/**
* Render statusdropdown
*
* @param string $preference
* @return string
*/
private function render_statusdropdown($preference) {
if ($preference == 'unselected') {
return " <select id='setallstatus-select'>
<option value='all'>".get_string('statusall', 'attendance')."</option>
<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>";
}
}
/** /**
* Render take list. * Render take list.
* *
@ -649,7 +672,11 @@ class mod_attendance_renderer extends plugin_renderer_base {
foreach ($extrasearchfields as $field) { foreach ($extrasearchfields as $field) {
$row->cells[] = ''; $row->cells[] = '';
} }
$row->cells[] = html_writer::div(get_string('setallstatuses', 'attendance'), 'setallstatuses');
$selectmenu = $this->render_statusdropdown(get_user_preferences('mod_attendance_statusdropdown'));
$row->cells[] = html_writer::div(get_string('setallstatuses', 'attendance').
$selectmenu, 'setallstatuses');
foreach ($takedata->statuses as $st) { foreach ($takedata->statuses as $st) {
$attribs = array( $attribs = array(
'id' => 'radiocheckstatus'.$st->id, 'id' => 'radiocheckstatus'.$st->id,
@ -663,11 +690,13 @@ 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 (e.shiftKey) { if ($('#setallstatus-select').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 { else {
$('#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');
} }
}); });
});"); });");
@ -726,7 +755,12 @@ 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').
$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)));
@ -734,11 +768,13 @@ 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 (e.shiftKey) { if ($('#setallstatus-select').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');
} }
else { else {
$('#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');
} }
e.preventDefault(); e.preventDefault();
}); });

14
tests/behat/extra_features.feature

@ -182,16 +182,16 @@ Feature: Test the various new features in the attendance module
And I click on "submitbutton" "button" And I click on "submitbutton" "button"
When I click on "Take attendance" "link" in the "10AM" "table_row" When I click on "Take attendance" "link" in the "10AM" "table_row"
Then "Set status for all users to «Present»" "link" should exist Then "Set status to «Present»" "link" should exist
And "Set status for all users to «Late»" "link" should exist And "Set status to «Late»" "link" should exist
And "Set status for all users to «Excused»" "link" should exist And "Set status to «Excused»" "link" should exist
And "Set status for all users to «Absent»" "link" should exist And "Set status to «Absent»" "link" should exist
When I follow "Sessions" When I follow "Sessions"
And I click on "Take attendance" "link" in the "12PM" "table_row" And I click on "Take attendance" "link" in the "12PM" "table_row"
Then "Set status for all users to «Great»" "link" should exist Then "Set status to «Great»" "link" should exist
And "Set status for all users to «OK»" "link" should exist And "Set status to «OK»" "link" should exist
And "Set status for all users to «Bad»" "link" should exist And "Set status to «Bad»" "link" should exist
Scenario: A teacher can use the radio buttons to set attendance values for all users Scenario: A teacher can use the radio buttons to set attendance values for all users
Given I log in as "teacher1" Given I log in as "teacher1"

Loading…
Cancel
Save