Skip to content

Commit

Permalink
MDL-63944 Questions Bank: Select all checkbox should be checked
Browse files Browse the repository at this point in the history
When checkbox item be chosen then "Select All" be chosen.
When "Select All" be chosen then all checkbox item be chosen.
  • Loading branch information
lethevinh authored and VinhLe committed Feb 15, 2019
1 parent 1249995 commit b65bc97
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 442 deletions.
1 change: 1 addition & 0 deletions question/amd/build/qbankmanager.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 128 additions & 0 deletions question/amd/src/qbankmanager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// 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/str', 'core/notification'], function($, str, notification) {

return {
/**
* A reference to the header checkbox.
*
* @property _strings
* @type Node
* @private
*/
_strings: null,

/**
* A reference to the add to quiz button.
*
* @property _buttons
* @type Node
* @private
*/
_buttons: null,

/**
* Set up the Question Bank Manager.
*
* @method init
*/
init: function() {
// Find the header checkbox, and set the initial values.
var header = $('#qbheadercheckbox');
if (header.length == 0) {
return;
}
var self = this;
str.get_strings([
{key: 'selectall', component: 'moodle'},
{key: 'deselectall', component: 'moodle'},
]).then(function(strings) {
self._strings = strings;
header.attr({
disabled: false,
checked: self._getSizeChecked() != 0,
title: strings[0]
});
header.click(self, self._headerClick);

self._buttons = $(".modulespecificbuttonscontainer input, .modulespecificbuttonscontainer select," +
" .modulespecificbuttonscontainer link, .modulespecificbuttonscontainer link");

self._buttons.attr('disabled', self._getSizeChecked() == 0);

if (self._buttons.length > 0) {
$('.categoryquestionscontainer')
.delegate('td.checkbox input[type="checkbox"]', 'change', self, self._questionClick);
}
return;
}).fail(notification.exception);
},

/**
* Handle toggling of the header checkbox.
*
* @method _headerClick
* @param {Event} event of element.
* @private
*/
_headerClick: function(event) {
var self = event.data;
var header = $('#qbheadercheckbox');
var isCheckedHeader = header.is(':checked');
var indexStringTitle = isCheckedHeader ? 1 : 0;

$("#categoryquestions tbody [type=checkbox]").prop("checked", isCheckedHeader);
self._buttons.attr('disabled', self._getSizeChecked() === 0);
header.attr('title', self._strings[indexStringTitle]);
},

/**
* Handle toggling of a question checkbox.
*
* @method _questionClick
* @param {Event} event of element.
* @private
*/
_questionClick: function(event) {
var self = event.data;
var header = $('#qbheadercheckbox');
var areChecked = self._getSizeChecked();
var lengthCheckbox = $("#categoryquestions tbody [type=checkbox]").length;
var ischeckboxHeader = (areChecked != 0) && areChecked == lengthCheckbox;

header.prop('checked', ischeckboxHeader);
self._buttons.attr('disabled', (areChecked === 0));
},
/**
* Get size all row checked of table.
* @method _getSizeChecked
* @return {Number}
* @private
*/
_getSizeChecked: function() {
return $('#categoryquestions td.checkbox input[type="checkbox"]:checked').length;
}
};
});
5 changes: 3 additions & 2 deletions question/classes/bank/checkbox_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ public function get_name() {
}

protected function get_title() {
return '<input type="checkbox" disabled="disabled" id="qbheadercheckbox" />';
return '<input type="checkbox" disabled="disabled" id="qbheadercheckbox" name="qbheadercheckbox" />' .
'<label class="accesshide" for="qbheadercheckbox">' . get_string('selectall', 'moodle') . '</label>';
}

protected function get_title_tip() {
global $PAGE;
$PAGE->requires->strings_for_js(array('selectall', 'deselectall'), 'moodle');
$PAGE->requires->yui_module('moodle-question-qbankmanager', 'M.question.qbankmanager.init');
$PAGE->requires->js_call_amd('core_question/qbankmanager', 'init');
return get_string('selectquestionsforbulk', 'question');

}
Expand Down
56 changes: 56 additions & 0 deletions question/tests/behat/select_questions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@core @core_question
Feature: The questions in the question bank can be selected in various ways
In selected to do something for questions
As a teacher
I want to choose them to move, delete it.

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | weeks |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | user | questiontext |
| Test questions | essay | A question 1 name | admin | Question 1 text |
| Test questions | essay | B question 2 name | teacher1 | Question 2 text |
| Test questions | numerical | C question 3 name | teacher1 | Question 3 text |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I navigate to "Questions" node in "Course administration > Question bank"

@javascript
Scenario: The question text can be chosen all in the list of questions
Given the field "Select all" matches value ""
When I click on "Select all" "checkbox"
Then the field "A question 1 name" matches value "1"
And the field "B question 2 name" matches value "1"
And the field "C question 3 name" matches value "1"
When I click on "Select all" "checkbox"
Then the field "A question 1 name" matches value ""
And the field "B question 2 name" matches value ""
And the field "C question 3 name" matches value ""

@javascript
Scenario: The question text can be chosen in the list of questions
Given the field "Select all" matches value ""
When I click on "A question 1 name" "checkbox"
Then the field "Select all" matches value ""
When I click on "B question 2 name" "checkbox"
And I click on "C question 3 name" "checkbox"
Then the field "Select all" matches value "1"

@javascript
Scenario: The action button can be disabled when the question not be chosen in the list of questions
Given the "Delete" "button" should be disabled
And the "Move to >>" "button" should be disabled
When I click on "Select all" "checkbox"
Then the "Delete" "button" should be enabled
And the "Move to >>" "button" should be enabled

This file was deleted.

This file was deleted.

Loading

0 comments on commit b65bc97

Please sign in to comment.