From 40d68858758aa20eacf357a5f454839fc1914482 Mon Sep 17 00:00:00 2001
From: M <12033826+maksudr@users.noreply.github.com>
Date: Mon, 29 Jul 2019 22:08:27 +0100
Subject: [PATCH] Issue #405 Convert shift click functionality to drop down
menu.
Use user preferences to remember the value of the drop-down
---
lang/en/attendance.php | 2 ++
renderer.php | 42 +++++++++++++++++++++++++++---
tests/behat/extra_features.feature | 14 +++++-----
3 files changed, 48 insertions(+), 10 deletions(-)
diff --git a/lang/en/attendance.php b/lang/en/attendance.php
index dbc5d30..93abce7 100644
--- a/lang/en/attendance.php
+++ b/lang/en/attendance.php
@@ -463,6 +463,8 @@ $string['statusdeleted'] = 'Status deleted';
$string['statuses'] = 'Statuses';
$string['statusset'] = 'Status set {$a}';
$string['statussetsettings'] = 'Status set';
+$string['statusall'] = 'all';
+$string['statusunselected'] = 'unselected';
$string['strftimedm'] = '%b %d';
$string['strftimedmy'] = '%d %b %Y';
$string['strftimedmyhm'] = '%d %b %Y %I.%M%p'; // Line added to allow multiple sessions in the same day.
diff --git a/renderer.php b/renderer.php
index 834546e..c5e3a67 100644
--- a/renderer.php
+++ b/renderer.php
@@ -28,6 +28,7 @@ require_once(dirname(__FILE__).'/locallib.php');
require_once(dirname(__FILE__).'/renderables.php');
require_once(dirname(__FILE__).'/renderhelpers.php');
require_once($CFG->libdir.'/tablelib.php');
+require_once($CFG->libdir.'/moodlelib.php');
/**
* Attendance module renderer class
@@ -414,6 +415,8 @@ class mod_attendance_renderer extends plugin_renderer_base {
* @return string
*/
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);
$table = html_writer::start_div('no-overflow');
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;
}
+ /**
+ * Render statusdropdown
+ *
+ * @param string $preference
+ * @return string
+ */
+ private function render_statusdropdown($preference) {
+ if ($preference == 'unselected') {
+ return " ";
+ } else {
+ return " ";
+ }
+ }
+
/**
* Render take list.
*
@@ -649,7 +672,11 @@ class mod_attendance_renderer extends plugin_renderer_base {
foreach ($extrasearchfields as $field) {
$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) {
$attribs = array(
'id' => 'radiocheckstatus'.$st->id,
@@ -663,11 +690,13 @@ class mod_attendance_renderer extends plugin_renderer_base {
$PAGE->requires->js_amd_inline("
require(['jquery'], function($) {
$('#radiocheckstatus".$st->id."').click(function(e) {
- if (e.shiftKey) {
+ if ($('#setallstatus-select').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');
}
});
});");
@@ -726,7 +755,12 @@ 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');
foreach ($takedata->statuses as $st) {
$head[] = html_writer::link("#", $st->acronym, array('id' => 'checkstatus'.$st->id,
'title' => get_string('setallstatusesto', 'attendance', $st->description)));
@@ -734,11 +768,13 @@ class mod_attendance_renderer extends plugin_renderer_base {
$PAGE->requires->js_amd_inline("
require(['jquery'], function($) {
$('#checkstatus".$st->id."').click(function(e) {
- if (e.shiftKey) {
+ if ($('#setallstatus-select').val() == 'unselected') {
$('#attendancetakeform').find('input:indeterminate.st".$st->id."').prop('checked', true);
+ M.util.set_user_preference('mod_attendance_statusdropdown','unselected');
}
else {
$('#attendancetakeform').find('.st".$st->id."').prop('checked', true);
+ M.util.set_user_preference('mod_attendance_statusdropdown','all');
}
e.preventDefault();
});
diff --git a/tests/behat/extra_features.feature b/tests/behat/extra_features.feature
index db7c77c..ab9d4c2 100644
--- a/tests/behat/extra_features.feature
+++ b/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"
When I click on "Take attendance" "link" in the "10AM" "table_row"
- Then "Set status for all users to «Present»" "link" should exist
- And "Set status for all users to «Late»" "link" should exist
- And "Set status for all users to «Excused»" "link" should exist
- And "Set status for all users to «Absent»" "link" should exist
+ Then "Set status to «Present»" "link" should exist
+ And "Set status to «Late»" "link" should exist
+ And "Set status to «Excused»" "link" should exist
+ And "Set status to «Absent»" "link" should exist
When I follow "Sessions"
And I click on "Take attendance" "link" in the "12PM" "table_row"
- Then "Set status for all users to «Great»" "link" should exist
- And "Set status for all users to «OK»" "link" should exist
- And "Set status for all users to «Bad»" "link" should exist
+ Then "Set status to «Great»" "link" should exist
+ And "Set status to «OK»" "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
Given I log in as "teacher1"