mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
MDL-63944 Questions Bank: Select all checkbox should be checked
When checkbox item be chosen then "Select All" be chosen. When "Select All" be chosen then all checkbox item be chosen.
This commit is contained in:
parent
124999563a
commit
b65bc972e6
1
question/amd/build/qbankmanager.min.js
vendored
Normal file
1
question/amd/build/qbankmanager.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
define(["jquery","core/str","core/notification"],function(a,b,c){return{_strings:null,_buttons:null,init:function(){var d=a("#qbheadercheckbox");if(0!=d.length){var e=this;b.get_strings([{key:"selectall",component:"moodle"},{key:"deselectall",component:"moodle"}]).then(function(b){e._strings=b,d.attr({disabled:!1,checked:0!=e._getSizeChecked(),title:b[0]}),d.click(e,e._headerClick),e._buttons=a(".modulespecificbuttonscontainer input, .modulespecificbuttonscontainer select, .modulespecificbuttonscontainer link, .modulespecificbuttonscontainer link"),e._buttons.attr("disabled",0==e._getSizeChecked()),e._buttons.length>0&&a(".categoryquestionscontainer").delegate('td.checkbox input[type="checkbox"]',"change",e,e._questionClick)}).fail(c.exception)}},_headerClick:function(b){var c=b.data,d=a("#qbheadercheckbox"),e=d.is(":checked"),f=e?1:0;a("#categoryquestions tbody [type=checkbox]").prop("checked",e),c._buttons.attr("disabled",0===c._getSizeChecked()),d.attr("title",c._strings[f])},_questionClick:function(b){var c=b.data,d=a("#qbheadercheckbox"),e=c._getSizeChecked(),f=a("#categoryquestions tbody [type=checkbox]").length,g=0!=e&&e==f;d.prop("checked",g),c._buttons.attr("disabled",0===e)},_getSizeChecked:function(){return a('#categoryquestions td.checkbox input[type="checkbox"]:checked').length}}});
|
128
question/amd/src/qbankmanager.js
Executable file
128
question/amd/src/qbankmanager.js
Executable file
@ -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;
|
||||
}
|
||||
};
|
||||
});
|
@ -34,13 +34,14 @@ class checkbox_column extends column_base {
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
}
|
||||
|
56
question/tests/behat/select_questions.feature
Normal file
56
question/tests/behat/select_questions.feature
Normal file
@ -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
|
@ -1,142 +0,0 @@
|
||||
YUI.add('moodle-question-qbankmanager', function (Y, NAME) {
|
||||
|
||||
// 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/>.
|
||||
|
||||
/*
|
||||
* Question Bank Management.
|
||||
*
|
||||
* @package question
|
||||
* @copyright 2014 Andrew Nicols
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Questionbank Management.
|
||||
*
|
||||
* @module moodle-question-qbankmanager
|
||||
*/
|
||||
|
||||
/**
|
||||
* Question Bank Management.
|
||||
*
|
||||
* @class M.question.qbankmanager
|
||||
*/
|
||||
|
||||
var manager = {
|
||||
/**
|
||||
* A reference to the header checkbox.
|
||||
*
|
||||
* @property _header
|
||||
* @type Node
|
||||
* @private
|
||||
*/
|
||||
_header: null,
|
||||
|
||||
/**
|
||||
* A reference to the add to quiz button.
|
||||
*
|
||||
* @property _addbutton
|
||||
* @type Node
|
||||
* @private
|
||||
*/
|
||||
_addbutton: null,
|
||||
|
||||
/**
|
||||
* The ID of the first checkbox on the page.
|
||||
*
|
||||
* @property _firstCheckbox
|
||||
* @type Node
|
||||
* @private
|
||||
*/
|
||||
_firstCheckbox: null,
|
||||
|
||||
/**
|
||||
* Set up the Question Bank Manager.
|
||||
*
|
||||
* @method init
|
||||
*/
|
||||
init: function() {
|
||||
// Find the header checkbox, and set the initial values.
|
||||
this._header = Y.one('#qbheadercheckbox');
|
||||
if (!this._header) {
|
||||
return;
|
||||
}
|
||||
this._header.setAttrs({
|
||||
disabled: false,
|
||||
title: M.util.get_string('selectall', 'moodle')
|
||||
});
|
||||
|
||||
this._header.on('click', this._headerClick, this);
|
||||
|
||||
this._addbutton = Y.one('.modulespecificbuttonscontainer input[name="add"]');
|
||||
// input[name="add"] is not always available.
|
||||
if (this._addbutton) {
|
||||
this._addbutton.setAttrs({
|
||||
disabled: true
|
||||
});
|
||||
|
||||
this._header.on('click', this._questionClick, this);
|
||||
Y.one('.categoryquestionscontainer').delegate('change', this._questionClick,
|
||||
'td.checkbox input[type="checkbox"]', this);
|
||||
}
|
||||
|
||||
// Store the first checkbox details.
|
||||
var table = this._header.ancestor('table');
|
||||
this._firstCheckbox = table.one('tbody tr td.checkbox input');
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle toggling of the header checkbox.
|
||||
*
|
||||
* @method _headerClick
|
||||
* @private
|
||||
*/
|
||||
_headerClick: function() {
|
||||
// Get the list of questions we affect.
|
||||
var categoryQuestions = Y.one('#categoryquestions')
|
||||
.all('[type=checkbox],[type=radio]');
|
||||
|
||||
// We base the state of all of the questions on the state of the first.
|
||||
if (this._firstCheckbox.get('checked')) {
|
||||
categoryQuestions.set('checked', false);
|
||||
this._header.setAttribute('title', M.util.get_string('selectall', 'moodle'));
|
||||
} else {
|
||||
categoryQuestions.set('checked', true);
|
||||
this._header.setAttribute('title', M.util.get_string('deselectall', 'moodle'));
|
||||
}
|
||||
|
||||
this._header.set('checked', false);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle toggling of a question checkbox.
|
||||
*
|
||||
* @method _questionClick
|
||||
* @private
|
||||
*/
|
||||
_questionClick: function() {
|
||||
var areChecked = Y.all('td.checkbox input[type="checkbox"]:checked').size();
|
||||
this._addbutton.setAttrs({
|
||||
disabled: (areChecked === 0)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
M.question = M.question || {};
|
||||
M.question.qbankmanager = M.question.qbankmanager || manager;
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["node", "selector-css3"]});
|
@ -1 +0,0 @@
|
||||
YUI.add("moodle-question-qbankmanager",function(e,t){var n={_header:null,_addbutton:null,_firstCheckbox:null,init:function(){this._header=e.one("#qbheadercheckbox");if(!this._header)return;this._header.setAttrs({disabled:!1,title:M.util.get_string("selectall","moodle")}),this._header.on("click",this._headerClick,this),this._addbutton=e.one('.modulespecificbuttonscontainer input[name="add"]'),this._addbutton&&(this._addbutton.setAttrs({disabled:!0}),this._header.on("click",this._questionClick,this),e.one(".categoryquestionscontainer").delegate("change",this._questionClick,'td.checkbox input[type="checkbox"]',this));var t=this._header.ancestor("table");this._firstCheckbox=t.one("tbody tr td.checkbox input")},_headerClick:function(){var t=e.one("#categoryquestions").all("[type=checkbox],[type=radio]");this._firstCheckbox.get("checked")?(t.set("checked",!1),this._header.setAttribute("title",M.util.get_string("selectall","moodle"))):(t.set("checked",!0),this._header.setAttribute("title",M.util.get_string("deselectall","moodle"))),this._header.set("checked",!1)},_questionClick:function(){var t=e.all('td.checkbox input[type="checkbox"]:checked').size();this._addbutton.setAttrs({disabled:t===0})}};M.question=M.question||{},M.question.qbankmanager=M.question.qbankmanager||n},"@VERSION@",{requires:["node","selector-css3"]});
|
@ -1,142 +0,0 @@
|
||||
YUI.add('moodle-question-qbankmanager', function (Y, NAME) {
|
||||
|
||||
// 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/>.
|
||||
|
||||
/*
|
||||
* Question Bank Management.
|
||||
*
|
||||
* @package question
|
||||
* @copyright 2014 Andrew Nicols
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Questionbank Management.
|
||||
*
|
||||
* @module moodle-question-qbankmanager
|
||||
*/
|
||||
|
||||
/**
|
||||
* Question Bank Management.
|
||||
*
|
||||
* @class M.question.qbankmanager
|
||||
*/
|
||||
|
||||
var manager = {
|
||||
/**
|
||||
* A reference to the header checkbox.
|
||||
*
|
||||
* @property _header
|
||||
* @type Node
|
||||
* @private
|
||||
*/
|
||||
_header: null,
|
||||
|
||||
/**
|
||||
* A reference to the add to quiz button.
|
||||
*
|
||||
* @property _addbutton
|
||||
* @type Node
|
||||
* @private
|
||||
*/
|
||||
_addbutton: null,
|
||||
|
||||
/**
|
||||
* The ID of the first checkbox on the page.
|
||||
*
|
||||
* @property _firstCheckbox
|
||||
* @type Node
|
||||
* @private
|
||||
*/
|
||||
_firstCheckbox: null,
|
||||
|
||||
/**
|
||||
* Set up the Question Bank Manager.
|
||||
*
|
||||
* @method init
|
||||
*/
|
||||
init: function() {
|
||||
// Find the header checkbox, and set the initial values.
|
||||
this._header = Y.one('#qbheadercheckbox');
|
||||
if (!this._header) {
|
||||
return;
|
||||
}
|
||||
this._header.setAttrs({
|
||||
disabled: false,
|
||||
title: M.util.get_string('selectall', 'moodle')
|
||||
});
|
||||
|
||||
this._header.on('click', this._headerClick, this);
|
||||
|
||||
this._addbutton = Y.one('.modulespecificbuttonscontainer input[name="add"]');
|
||||
// input[name="add"] is not always available.
|
||||
if (this._addbutton) {
|
||||
this._addbutton.setAttrs({
|
||||
disabled: true
|
||||
});
|
||||
|
||||
this._header.on('click', this._questionClick, this);
|
||||
Y.one('.categoryquestionscontainer').delegate('change', this._questionClick,
|
||||
'td.checkbox input[type="checkbox"]', this);
|
||||
}
|
||||
|
||||
// Store the first checkbox details.
|
||||
var table = this._header.ancestor('table');
|
||||
this._firstCheckbox = table.one('tbody tr td.checkbox input');
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle toggling of the header checkbox.
|
||||
*
|
||||
* @method _headerClick
|
||||
* @private
|
||||
*/
|
||||
_headerClick: function() {
|
||||
// Get the list of questions we affect.
|
||||
var categoryQuestions = Y.one('#categoryquestions')
|
||||
.all('[type=checkbox],[type=radio]');
|
||||
|
||||
// We base the state of all of the questions on the state of the first.
|
||||
if (this._firstCheckbox.get('checked')) {
|
||||
categoryQuestions.set('checked', false);
|
||||
this._header.setAttribute('title', M.util.get_string('selectall', 'moodle'));
|
||||
} else {
|
||||
categoryQuestions.set('checked', true);
|
||||
this._header.setAttribute('title', M.util.get_string('deselectall', 'moodle'));
|
||||
}
|
||||
|
||||
this._header.set('checked', false);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle toggling of a question checkbox.
|
||||
*
|
||||
* @method _questionClick
|
||||
* @private
|
||||
*/
|
||||
_questionClick: function() {
|
||||
var areChecked = Y.all('td.checkbox input[type="checkbox"]:checked').size();
|
||||
this._addbutton.setAttrs({
|
||||
disabled: (areChecked === 0)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
M.question = M.question || {};
|
||||
M.question.qbankmanager = M.question.qbankmanager || manager;
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["node", "selector-css3"]});
|
@ -1,10 +0,0 @@
|
||||
{
|
||||
"name": "moodle-question-qbankmanager",
|
||||
"builds": {
|
||||
"moodle-question-qbankmanager": {
|
||||
"jsfiles": [
|
||||
"qbankmanager.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
137
question/yui/src/qbankmanager/js/qbankmanager.js
vendored
137
question/yui/src/qbankmanager/js/qbankmanager.js
vendored
@ -1,137 +0,0 @@
|
||||
// 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/>.
|
||||
|
||||
/*
|
||||
* Question Bank Management.
|
||||
*
|
||||
* @package question
|
||||
* @copyright 2014 Andrew Nicols
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Questionbank Management.
|
||||
*
|
||||
* @module moodle-question-qbankmanager
|
||||
*/
|
||||
|
||||
/**
|
||||
* Question Bank Management.
|
||||
*
|
||||
* @class M.question.qbankmanager
|
||||
*/
|
||||
|
||||
var manager = {
|
||||
/**
|
||||
* A reference to the header checkbox.
|
||||
*
|
||||
* @property _header
|
||||
* @type Node
|
||||
* @private
|
||||
*/
|
||||
_header: null,
|
||||
|
||||
/**
|
||||
* A reference to the add to quiz button.
|
||||
*
|
||||
* @property _addbutton
|
||||
* @type Node
|
||||
* @private
|
||||
*/
|
||||
_addbutton: null,
|
||||
|
||||
/**
|
||||
* The ID of the first checkbox on the page.
|
||||
*
|
||||
* @property _firstCheckbox
|
||||
* @type Node
|
||||
* @private
|
||||
*/
|
||||
_firstCheckbox: null,
|
||||
|
||||
/**
|
||||
* Set up the Question Bank Manager.
|
||||
*
|
||||
* @method init
|
||||
*/
|
||||
init: function() {
|
||||
// Find the header checkbox, and set the initial values.
|
||||
this._header = Y.one('#qbheadercheckbox');
|
||||
if (!this._header) {
|
||||
return;
|
||||
}
|
||||
this._header.setAttrs({
|
||||
disabled: false,
|
||||
title: M.util.get_string('selectall', 'moodle')
|
||||
});
|
||||
|
||||
this._header.on('click', this._headerClick, this);
|
||||
|
||||
this._addbutton = Y.one('.modulespecificbuttonscontainer input[name="add"]');
|
||||
// input[name="add"] is not always available.
|
||||
if (this._addbutton) {
|
||||
this._addbutton.setAttrs({
|
||||
disabled: true
|
||||
});
|
||||
|
||||
this._header.on('click', this._questionClick, this);
|
||||
Y.one('.categoryquestionscontainer').delegate('change', this._questionClick,
|
||||
'td.checkbox input[type="checkbox"]', this);
|
||||
}
|
||||
|
||||
// Store the first checkbox details.
|
||||
var table = this._header.ancestor('table');
|
||||
this._firstCheckbox = table.one('tbody tr td.checkbox input');
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle toggling of the header checkbox.
|
||||
*
|
||||
* @method _headerClick
|
||||
* @private
|
||||
*/
|
||||
_headerClick: function() {
|
||||
// Get the list of questions we affect.
|
||||
var categoryQuestions = Y.one('#categoryquestions')
|
||||
.all('[type=checkbox],[type=radio]');
|
||||
|
||||
// We base the state of all of the questions on the state of the first.
|
||||
if (this._firstCheckbox.get('checked')) {
|
||||
categoryQuestions.set('checked', false);
|
||||
this._header.setAttribute('title', M.util.get_string('selectall', 'moodle'));
|
||||
} else {
|
||||
categoryQuestions.set('checked', true);
|
||||
this._header.setAttribute('title', M.util.get_string('deselectall', 'moodle'));
|
||||
}
|
||||
|
||||
this._header.set('checked', false);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle toggling of a question checkbox.
|
||||
*
|
||||
* @method _questionClick
|
||||
* @private
|
||||
*/
|
||||
_questionClick: function() {
|
||||
var areChecked = Y.all('td.checkbox input[type="checkbox"]:checked').size();
|
||||
this._addbutton.setAttrs({
|
||||
disabled: (areChecked === 0)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
M.question = M.question || {};
|
||||
M.question.qbankmanager = M.question.qbankmanager || manager;
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"moodle-question-qbankmanager": {
|
||||
"requires": [
|
||||
"node",
|
||||
"selector-css3"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user