1441 |
ariadna |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
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.
|
|
|
7 |
//
|
|
|
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.
|
|
|
12 |
//
|
|
|
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/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* The category root component.
|
|
|
18 |
*
|
|
|
19 |
* @module qbank_managecategories/categoryroot
|
|
|
20 |
* @class qbank_managecategories/categoryroot
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
import {BaseComponent} from 'core/reactive';
|
|
|
24 |
import {categorymanager} from 'qbank_managecategories/categorymanager';
|
|
|
25 |
|
|
|
26 |
export default class extends BaseComponent {
|
|
|
27 |
|
|
|
28 |
create(descriptor) {
|
|
|
29 |
this.name = descriptor.element.id;
|
|
|
30 |
this.classes = {
|
|
|
31 |
SHOWDESCRIPTIONS: 'showdescriptions',
|
|
|
32 |
};
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Static method to create a component instance.
|
|
|
37 |
*
|
|
|
38 |
* @param {string} target the DOM main element or its ID
|
|
|
39 |
* @param {object} selectors optional css selector overrides
|
|
|
40 |
* @return {Component}
|
|
|
41 |
*/
|
|
|
42 |
static init(target, selectors) {
|
|
|
43 |
return new this({
|
|
|
44 |
element: document.querySelector(target),
|
|
|
45 |
selectors,
|
|
|
46 |
reactive: categorymanager,
|
|
|
47 |
});
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Watch for changes to the page state.
|
|
|
52 |
*
|
|
|
53 |
* @return {Array} A list of watchers.
|
|
|
54 |
*/
|
|
|
55 |
getWatchers() {
|
|
|
56 |
return [
|
|
|
57 |
// Watch for descriptions being toggled.
|
|
|
58 |
{watch: `page.showdescriptions:updated`, handler: this.toggleDescriptions}
|
|
|
59 |
];
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Show or hide descriptions when the flag in the state is changed.
|
|
|
64 |
*
|
|
|
65 |
* @param {Object} args
|
|
|
66 |
* @param {Object} args.element The updated page state.
|
|
|
67 |
*/
|
|
|
68 |
toggleDescriptions({element}) {
|
|
|
69 |
if (element.showdescriptions) {
|
|
|
70 |
this.getElement().classList.add(this.classes.SHOWDESCRIPTIONS);
|
|
|
71 |
} else {
|
|
|
72 |
this.getElement().classList.remove(this.classes.SHOWDESCRIPTIONS);
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
}
|