1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 * JavaScript belonging to question_bank_view.
19 * This script is included by question_bank_view and other parts of question/editlib.php.
22 * @subpackage questionbank
23 * @copyright 2009 Tim Hunt
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 init_checkbox_column: function(Y, strselectall, strdeselectall, firstcbid) {
35 question_bank.strselectall = strselectall;
36 question_bank.strdeselectall = strdeselectall;
38 // Find the header checkbox, and initialise it.
39 question_bank.headercheckbox = document.getElementById('qbheadercheckbox');
40 question_bank.headercheckbox.disabled = false;
41 question_bank.headercheckbox.title = strselectall;
43 // Find the first real checkbox.
44 question_bank.firstcheckbox = document.getElementById(firstcbid);
46 // Add the event handler.
47 Y.YUI2.util.Event.addListener(question_bank.headercheckbox, 'click', question_bank.header_checkbox_click);
50 header_checkbox_click: function() {
51 if (question_bank.firstcheckbox.checked) {
52 select_all_in_element_with_id('categoryquestions', '');
53 question_bank.headercheckbox.title = question_bank.strselectall;
55 select_all_in_element_with_id('categoryquestions', 'checked');
56 question_bank.headercheckbox.title = question_bank.strdeselectall;
58 question_bank.headercheckbox.checked = false;
62 // JavaScript to make the list of question types pop-up when you click an add
63 // add question button.
71 init: function(Y, boxid) {
73 qtype_chooser.yui3 = Y;
74 // Find the radio buttons.
75 qtype_chooser.radiobuttons = Y.YUI2.util.Dom.getElementsBy(
76 function(el) { return el.type == 'radio'; }, 'input' , boxid);
77 qtype_chooser.labels = Y.YUI2.util.Dom.getElementsByClassName('qtypeoption', 'div', boxid);
79 // Find the submit button.
80 qtype_chooser.submitbutton = document.getElementById(boxid + '_submit');
81 qtype_chooser.enable_disable_submit();
83 // Add the event handlers.
84 Y.YUI2.util.Event.addListener(boxid, 'click', qtype_chooser.enable_disable_submit);
85 Y.YUI2.util.Event.addListener(boxid, 'key_down', qtype_chooser.enable_disable_submit);
86 Y.YUI2.util.Event.addListener(boxid, 'key_up', qtype_chooser.enable_disable_submit);
87 Y.YUI2.util.Event.addListener(boxid, 'dblclick', function(e) {
88 if (!qtype_chooser.submitbutton.disabled) {
89 M.core_scroll_manager.save_scroll_pos(Y, Y.one(qtype_chooser.submitbutton));
90 qtype_chooser.submitbutton.form.submit();
94 Y.YUI2.util.Event.onDOMReady(qtype_chooser.init_container);
95 Y.on('submit', function(e) {
96 M.core_scroll_manager.save_scroll_pos(Y, Y.one(qtype_chooser.submitbutton));
97 }, qtype_chooser.submitbutton.form);
100 enable_disable_submit: function() {
101 var Y = qtype_chooser.yui3;
103 for (var i = 0; i < qtype_chooser.radiobuttons.length; i++) {
104 if (qtype_chooser.radiobuttons[i].checked) {
106 Y.YUI2.util.Dom.addClass(qtype_chooser.labels[i], 'selected');
108 Y.YUI2.util.Dom.removeClass(qtype_chooser.labels[i], 'selected');
111 qtype_chooser.submitbutton.disabled = !ok;
114 init_container: function() {
115 var Y = qtype_chooser.yui3;
116 if (!document.getElementById('qtypechoicecontainer')) {
119 var qtypechoicecontainer = document.getElementById('qtypechoicecontainer');
120 qtypechoicecontainer.style.display = 'block';
121 qtypechoicecontainer.parentNode.removeChild(qtypechoicecontainer);
122 document.body.appendChild(qtypechoicecontainer);
123 qtype_chooser.container = new Y.YUI2.widget.Dialog(qtypechoicecontainer, {
124 constraintoviewport: true,
134 qtype_chooser.container.render();
136 Y.YUI2.util.Event.addListener('chooseqtypecancel', 'click', qtype_chooser.cancel_popup);
138 var addforms = Y.YUI2.util.Dom.getElementsBy(function(el) {
139 return /question\/addquestion\.php/.test(el.action); }, 'form', document.body);
140 for (var i = 0; i < addforms.length; i++) {
141 Y.YUI2.util.Event.addListener(addforms[i], 'submit', qtype_chooser.add_button_click);
145 add_button_click: function(e) {
146 var Y = qtype_chooser.yui3;
147 var form = document.getElementById('qtypeformdiv');
149 var oldhidden = Y.YUI2.util.Dom.getElementsBy(
150 function(el) { return el.type == 'hidden'; }, 'input', form);
151 for (var i = 0; i < oldhidden.length; i++) {
152 oldhidden[i].parentNode.removeChild(oldhidden[i]);
155 var wantedhidden = Y.YUI2.util.Dom.getElementsBy(
156 function(el) { return el.type == 'hidden'; }, 'input', this);
157 for (i = 0; i < wantedhidden.length; i++) {
158 form.appendChild(wantedhidden[i].cloneNode(true));
161 qtype_chooser.container.show();
162 Y.YUI2.util.Event.preventDefault(e);
165 cancel_popup: function(e) {
166 var Y = qtype_chooser.yui3;
167 qtype_chooser.container.hide();
168 Y.YUI2.util.Event.preventDefault(e);