Commit cbd8641a authored by jun's avatar jun
Browse files

MDL-65994 question: Convert checkboxes to checkbox-toggleall element

parent 8d9614b3
......@@ -1259,7 +1259,14 @@ function question_category_select_menu($contexts, $top = false, $currentcat = 0,
$options[] = array($group => $opts);
}
echo html_writer::label(get_string('questioncategory', 'core_question'), 'id_movetocategory', false, array('class' => 'accesshide'));
$attrs = array('id' => 'id_movetocategory', 'class' => 'custom-select');
$attrs = array(
'id' => 'id_movetocategory',
'class' => 'custom-select',
'data-action' => 'toggle',
'data-togglegroup' => 'qbank',
'data-toggle' => 'action',
'disabled' => true,
);
echo html_writer::select($options, 'category', $selected, $choose, $attrs);
}
......
......@@ -166,14 +166,15 @@ class custom_view extends \core_question\bank\view {
// Add selected questions to the quiz.
$params = array(
'type' => 'submit',
'name' => 'add',
'class' => 'btn btn-primary',
'value' => get_string('addselectedquestionstoquiz', 'quiz'),
'type' => 'submit',
'name' => 'add',
'class' => 'btn btn-primary',
'value' => get_string('addselectedquestionstoquiz', 'quiz'),
'data-action' => 'toggle',
'data-togglegroup' => 'qbank',
'data-toggle' => 'action',
'disabled' => true,
);
if ($cmoptions->hasattempts) {
$params['disabled'] = 'disabled';
}
echo \html_writer::empty_tag('input', $params);
}
echo "</div>\n";
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
// 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/>.
/**
* A javascript module to handle question ajax actions.
*
* @module core_question/qbankmanager
* @class qbankmanager
* @package core_question
* @copyright 2018 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/pubsub', 'core/checkbox-toggleall'], function($, PubSub, ToggleAll) {
var registerListeners = function() {
PubSub.subscribe(ToggleAll.events.checkboxToggled, toggleButtonStates);
};
var toggleButtonStates = function(data) {
if ('qbank' !== data.toggleGroupName) {
return;
}
setButtonState(data.anyChecked);
};
var setButtonState = function(state) {
var buttons = $('.modulespecificbuttonscontainer').find('input, select, link');
buttons.attr('disabled', !state);
};
return {
/**
* Set up the Question Bank Manager.
*
* @method init
*/
init: function() {
setButtonState(false);
registerListeners();
},
};
});
......@@ -16,6 +16,8 @@
namespace core_question\bank;
use core\output\checkbox_toggleall;
/**
* A column with a checkbox for each question with name q{questionid}.
*
......@@ -23,37 +25,23 @@ namespace core_question\bank;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class checkbox_column extends column_base {
protected $strselect;
public function init() {
global $PAGE;
$PAGE->requires->js_call_amd('core/checkbox-toggleall', 'init');
}
public function get_name() {
return 'checkbox';
}
protected function get_title() {
$input = \html_writer::empty_tag('input', [
global $OUTPUT;
$mastercheckbox = new checkbox_toggleall('qbank', true, [
'id' => 'qbheadercheckbox',
'name' => 'qbheadercheckbox',
'type' => 'checkbox',
'value' => '1',
'data-action' => 'toggle',
'data-toggle' => 'master',
'data-togglegroup' => 'qbank',
'data-toggle-selectall' => get_string('selectall', 'moodle'),
'data-toggle-deselectall' => get_string('deselectall', 'moodle'),
'label' => get_string('selectall'),
'labelclasses' => 'accesshide',
]);
$label = \html_writer::tag('label', get_string('selectall', 'moodle'), [
'class' => 'accesshide',
'for' => 'qbheadercheckbox',
]);
return $input . $label;
return $OUTPUT->render($mastercheckbox);
}
protected function get_title_tip() {
......@@ -61,16 +49,17 @@ class checkbox_column extends column_base {
}
protected function display_content($question, $rowclasses) {
echo \html_writer::empty_tag('input', [
'title' => get_string('select'),
'type' => 'checkbox',
'name' => "q{$question->id}",
global $OUTPUT;
$checkbox = new checkbox_toggleall('qbank', false, [
'id' => "checkq{$question->id}",
'name' => "q{$question->id}",
'value' => '1',
'data-action' => 'toggle',
'data-toggle' => 'slave',
'data-togglegroup' => 'qbank',
'label' => get_string('select'),
'labelclasses' => 'accesshide',
]);
echo $OUTPUT->render($checkbox);
}
public function get_required_fields() {
......
......@@ -703,9 +703,6 @@ class view {
$category = $this->get_current_category($categoryandcontext);
$strselectall = get_string('selectall');
$strselectnone = get_string('deselectall');
list($categoryid, $contextid) = explode(',', $categoryandcontext);
$catcontext = \context::instance_by_id($contextid);
......@@ -764,8 +761,6 @@ class view {
}
echo '</div>';
$PAGE->requires->js_call_amd('core_question/qbankmanager', 'init');
$this->display_bottom_controls($totalnumber, $recurse, $category, $catcontext, $addcontexts);
echo '</fieldset>';
......@@ -791,11 +786,29 @@ class view {
// Print delete and move selected question.
if ($caneditall) {
echo '<input type="submit" class="btn btn-secondary" name="deleteselected" value="' . get_string('delete') . "\" />\n";
echo \html_writer::empty_tag('input', [
'type' => 'submit',
'class' => 'btn btn-secondary mr-1',
'name' => 'deleteselected',
'value' => get_string('delete'),
'data-action' => 'toggle',
'data-togglegroup' => 'qbank',
'data-toggle' => 'action',
'disabled' => true,
]);
}
if ($canmoveall && count($addcontexts)) {
echo '<input type="submit" class="btn btn-secondary" name="move" value="' . get_string('moveto', 'question') . "\" />\n";
echo \html_writer::empty_tag('input', [
'type' => 'submit',
'class' => 'btn btn-secondary mr-1',
'name' => 'move',
'value' => get_string('moveto', 'question'),
'data-action' => 'toggle',
'data-togglegroup' => 'qbank',
'data-toggle' => 'action',
'disabled' => true,
]);
question_category_select_menu($addcontexts, false, 0, "{$category->id},{$category->contextid}");
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment