Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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 show descriptions toggle component.
18
 *
19
 * @module     qbank_managecategories/showdescriptions
20
 * @class      qbank_managecategories/showdescriptions
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.selectors = {
31
            TOGGLE: '#showdescriptions-toggle',
32
        };
33
    }
34
 
35
    stateReady() {
36
        this.addEventListener(this.getElement(this.selectors.TOGGLE), 'change', this.updateShowDescriptions);
37
    }
38
 
39
    /**
40
     * Static method to create a component instance.
41
     *
42
     * @param {string} target the DOM main element or its ID
43
     * @param {object} selectors optional css selector overrides
44
     * @return {Component}
45
     */
46
    static init(target, selectors) {
47
        const targetElement = document.querySelector(target);
48
        return new this({
49
            element: targetElement,
50
            selectors,
51
            reactive: categorymanager,
52
        });
53
    }
54
 
55
    /**
56
     * Dispatch a mutation to toggle the showDescriptions setting.
57
     *
58
     * @param {Event} event The toggle change event.
59
     * @return {Promise<void>}
60
     */
61
    async updateShowDescriptions(event) {
62
        const checked = event.target.checked;
63
        this.reactive.dispatch('toggleDescriptions', checked);
64
    }
65
}