Merge branch 'MDL-61010-master' of git://github.com/andrewnicols/moodle
[moodle.git] / question / yui / build / moodle-question-qbankmanager / moodle-question-qbankmanager-debug.js
CommitLineData
0b98f8e8
AN
1YUI.add('moodle-question-qbankmanager', function (Y, NAME) {
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/*
19 * Question Bank Management.
20 *
21 * @package question
22 * @copyright 2014 Andrew Nicols
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26/**
27 * Questionbank Management.
28 *
29 * @module moodle-question-qbankmanager
30 */
31
32/**
33 * Question Bank Management.
34 *
35 * @class M.question.qbankmanager
36 */
37
38var manager = {
39 /**
40 * A reference to the header checkbox.
41 *
42 * @property _header
43 * @type Node
44 * @private
45 */
46 _header: null,
47
4bfcdfed
LB
48 /**
49 * A reference to the add to quiz button.
50 *
51 * @property _addbutton
52 * @type Node
53 * @private
54 */
55 _addbutton: null,
56
0b98f8e8
AN
57 /**
58 * The ID of the first checkbox on the page.
59 *
e1a2d0d9
CC
60 * @property _firstCheckbox
61 * @type Node
0b98f8e8
AN
62 * @private
63 */
e1a2d0d9 64 _firstCheckbox: null,
0b98f8e8
AN
65
66 /**
67 * Set up the Question Bank Manager.
68 *
69 * @method init
0b98f8e8 70 */
e1a2d0d9 71 init: function() {
0b98f8e8
AN
72 // Find the header checkbox, and set the initial values.
73 this._header = Y.one('#qbheadercheckbox');
e1a2d0d9
CC
74 if (!this._header) {
75 return;
76 }
0b98f8e8
AN
77 this._header.setAttrs({
78 disabled: false,
79 title: M.util.get_string('selectall', 'moodle')
80 });
81
82 this._header.on('click', this._headerClick, this);
4bfcdfed
LB
83
84 this._addbutton = Y.one('.modulespecificbuttonscontainer input[name="add"]');
1a43d6de
DM
85 // input[name="add"] is not always available.
86 if (this._addbutton) {
87 this._addbutton.setAttrs({
88 disabled: true
89 });
4bfcdfed 90
1a43d6de
DM
91 this._header.on('click', this._questionClick, this);
92 Y.one('.categoryquestionscontainer').delegate('change', this._questionClick,
93 'td.checkbox input[type="checkbox"]', this);
94 }
0b98f8e8
AN
95
96 // Store the first checkbox details.
e1a2d0d9
CC
97 var table = this._header.ancestor('table');
98 this._firstCheckbox = table.one('tbody tr td.checkbox input');
0b98f8e8
AN
99 },
100
101 /**
102 * Handle toggling of the header checkbox.
103 *
104 * @method _headerClick
105 * @private
106 */
107 _headerClick: function() {
108 // Get the list of questions we affect.
109 var categoryQuestions = Y.one('#categoryquestions')
110 .all('[type=checkbox],[type=radio]');
111
112 // We base the state of all of the questions on the state of the first.
e1a2d0d9 113 if (this._firstCheckbox.get('checked')) {
0b98f8e8
AN
114 categoryQuestions.set('checked', false);
115 this._header.setAttribute('title', M.util.get_string('selectall', 'moodle'));
116 } else {
117 categoryQuestions.set('checked', true);
118 this._header.setAttribute('title', M.util.get_string('deselectall', 'moodle'));
119 }
120
121 this._header.set('checked', false);
4bfcdfed
LB
122 },
123
124 /**
125 * Handle toggling of a question checkbox.
126 *
127 * @method _questionClick
128 * @private
129 */
130 _questionClick: function() {
131 var areChecked = Y.all('td.checkbox input[type="checkbox"]:checked').size();
132 this._addbutton.setAttrs({
133 disabled: (areChecked === 0)
134 });
0b98f8e8
AN
135 }
136};
137
138M.question = M.question || {};
139M.question.qbankmanager = M.question.qbankmanager || manager;
140
141
142}, '@VERSION@', {"requires": ["node", "selector-css3"]});