Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Course index section title component.
18
 *
19
 * This component is used to control specific course section interactions like drag and drop.
20
 *
21
 * @module     core_courseformat/local/courseindex/sectiontitle
22
 * @class      core_courseformat/local/courseindex/sectiontitle
23
 * @copyright  2021 Ferran Recio <ferran@moodle.com>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
import DndSectionItem from 'core_courseformat/local/courseeditor/dndsectionitem';
1441 ariadna 28
import log from "core/log";
1 efrain 29
 
30
export default class Component extends DndSectionItem {
31
 
32
    /**
33
     * Constructor hook.
34
     *
35
     * @param {Object} descriptor
36
     */
37
    create(descriptor) {
38
        // Optional component name for debugging.
39
        this.name = 'courseindex_sectiontitle';
40
 
41
        this.id = descriptor.id;
42
        this.section = descriptor.section;
43
        this.course = descriptor.course;
44
        this.fullregion = descriptor.fullregion;
45
 
1441 ariadna 46
        // Prevent topic zero and delegated sections from being draggable.
47
        if (this.section.number > 0 && this.section.component === null) {
1 efrain 48
            this.getDraggableData = this._getDraggableData;
49
        }
50
    }
51
 
52
    /**
53
     * Static method to create a component instance form the mustahce template.
54
     *
55
     * @param {element|string} target the DOM main element or its ID
56
     * @param {object} selectors optional css selector overrides
57
     * @return {Component}
58
     */
59
    static init(target, selectors) {
1441 ariadna 60
        let element = document.querySelector(target);
61
        // TODO Remove this if condition as part of MDL-83851.
62
        if (!element) {
63
            log.debug('Init component with id is deprecated, use a query selector instead.');
64
            element = document.getElementById(target);
65
        }
1 efrain 66
        return new this({
1441 ariadna 67
            element,
1 efrain 68
            selectors,
69
        });
70
    }
71
 
72
    /**
73
     * Initial state ready method.
74
     *
75
     * @param {Object} state the initial state
76
     */
77
    stateReady(state) {
1441 ariadna 78
        this.configDragDrop(this.id, state, this.fullregion, !!document.querySelector(`[data-courseindexdndallowed="true"]`));
1 efrain 79
    }
80
}