MDL-60546 mod_choice: Fixed select all functionality

Fixed the functionality which ticks or unticks all checkboxes when
clicking the Select all or Deselect all elements when viewing the
responses.

Caused by deprecating checkall and checknone functions in
MDL-57490.
This commit is contained in:
Marcus Fabriczy 2017-11-14 22:12:41 +10:30
parent 4275ea4a43
commit f32ee5c54e
3 changed files with 48 additions and 6 deletions

View File

@ -0,0 +1 @@
define(["jquery","core/str"],function(a,b){return{init:function(){a(".selectallnone a").on("click",function(c){c.preventDefault();var d=!1,e=a(this).text();b.get_string("selectall","core").done(function(b){e===b&&(d=!0),a("#attemptsform").find("input:checkbox").prop("checked",d)})})}}});

View File

@ -0,0 +1,42 @@
// 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 <http://www.gnu.org/licenses/>.
/**
* Ticks or unticks all checkboxes when clicking the Select all or Deselect all elements when viewing the response overview.
*
* @module mod_choice/select_all_choices
* @copyright 2017 Marcus Fabriczy <marcus.fabriczy@blackboard.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/str'], function($, str) {
return {
init: function () {
$('.selectallnone a').on('click', function(e) {
e.preventDefault();
var flag = false;
var selectedtext = $(this).text();
str.get_string('selectall', 'core').done(function(string) {
if (selectedtext === string) {
flag = true;
}
$('#attemptsform').find('input:checkbox').prop('checked', flag);
});
});
}
};
});

View File

@ -267,13 +267,9 @@ class mod_choice_renderer extends plugin_renderer_base {
$selecturl = new moodle_url('#');
$actiondata .= html_writer::start_div('selectallnone');
$selectallactions = new component_action('click',"checkall");
$selectall = new action_link($selecturl, get_string('selectall'), $selectallactions);
$actiondata .= $this->output->render($selectall) . ' / ';
$actiondata .= html_writer::link($selecturl, get_string('selectall')) . ' / ';
$deselectallactions = new component_action('click',"checknone");
$deselectall = new action_link($selecturl, get_string('deselectall'), $deselectallactions);
$actiondata .= $this->output->render($deselectall);
$actiondata .= html_writer::link($selecturl, get_string('deselectall'));
$actiondata .= html_writer::end_div();
@ -287,6 +283,9 @@ class mod_choice_renderer extends plugin_renderer_base {
$select = new single_select($actionurl, 'action', $actionoptions, null,
array('' => get_string('chooseaction', 'choice')), 'attemptsform');
$select->set_label(get_string('withselected', 'choice'));
$PAGE->requires->js_call_amd('mod_choice/select_all_choices', 'init');
$actiondata .= $this->output->render($select);
}
$html .= html_writer::tag('div', $actiondata, array('class'=>'responseaction'));