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(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 YAHOO.util.Event.addListener(question_bank.headercheckbox, 'change', 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.
70 init: function(Y, boxid) {
71 // Find the radio buttons.
72 qtype_chooser.radiobuttons = YAHOO.util.Dom.getElementsBy(
73 function(el) { return el.type == 'radio'; }, 'input' , boxid);
74 qtype_chooser.labels = YAHOO.util.Dom.getElementsByClassName('qtypeoption', 'div', boxid);
76 // Find the submit button.
77 qtype_chooser.submitbutton = document.getElementById(boxid + '_submit');
78 qtype_chooser.enable_disable_submit();
80 // Add the event handlers.
81 YAHOO.util.Event.addListener(boxid, 'click', qtype_chooser.enable_disable_submit);
82 YAHOO.util.Event.addListener(boxid, 'key_down', qtype_chooser.enable_disable_submit);
83 YAHOO.util.Event.addListener(boxid, 'key_up', qtype_chooser.enable_disable_submit);
84 YAHOO.util.Event.addListener(boxid, 'dblclick', function(e) {
85 if (!qtype_chooser.submitbutton.disabled) {
86 M.core_scroll_manager.save_scroll_pos(Y, Y.one(qtype_chooser.submitbutton));
87 qtype_chooser.submitbutton.form.submit();
91 YAHOO.util.Event.onDOMReady(qtype_chooser.init_container);
92 Y.on('submit', function(e) {
93 M.core_scroll_manager.save_scroll_pos(Y, Y.one(qtype_chooser.submitbutton));
94 }, qtype_chooser.submitbutton.form);
97 enable_disable_submit: function() {
99 for (var i = 0; i < qtype_chooser.radiobuttons.length; i++) {
100 if (qtype_chooser.radiobuttons[i].checked) {
102 YAHOO.util.Dom.addClass(qtype_chooser.labels[i], 'selected');
104 YAHOO.util.Dom.removeClass(qtype_chooser.labels[i], 'selected');
107 qtype_chooser.submitbutton.disabled = !ok;
110 init_container: function() {
111 if (!document.getElementById('qtypechoicecontainer')) {
114 var qtypechoicecontainer = document.getElementById('qtypechoicecontainer');
115 qtypechoicecontainer.style.display = 'block';
116 qtypechoicecontainer.parentNode.removeChild(qtypechoicecontainer);
117 document.body.appendChild(qtypechoicecontainer);
118 qtype_chooser.container = new YAHOO.widget.Dialog(qtypechoicecontainer, {
119 constraintoviewport: true,
129 qtype_chooser.container.render();
131 YAHOO.util.Event.addListener('chooseqtypecancel', 'click', qtype_chooser.cancel_popup);
133 var addforms = YAHOO.util.Dom.getElementsBy(function(el) {
134 return /question\/addquestion\.php/.test(el.action); }, 'form', document.body);
135 for (var i = 0; i < addforms.length; i++) {
136 YAHOO.util.Event.addListener(addforms[i], 'submit', qtype_chooser.add_button_click);
140 add_button_click: function(e) {
141 var form = document.getElementById('qtypeformdiv');
143 var oldhidden = YAHOO.util.Dom.getElementsBy(
144 function(el) { return el.type == 'hidden'; }, 'input', form);
145 for (var i = 0; i < oldhidden.length; i++) {
146 oldhidden[i].parentNode.removeChild(oldhidden[i]);
149 var wantedhidden = YAHOO.util.Dom.getElementsBy(
150 function(el) { return el.type == 'hidden'; }, 'input', this);
151 for (i = 0; i < wantedhidden.length; i++) {
152 form.appendChild(wantedhidden[i].cloneNode(true));
155 qtype_chooser.container.show();
156 YAHOO.util.Event.preventDefault(e);
159 cancel_popup: function(e) {
160 qtype_chooser.container.hide();
161 YAHOO.util.Event.preventDefault(e);