Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 27... Línea 27...
27
import DndCmItem from 'core_courseformat/local/courseeditor/dndcmitem';
27
import DndCmItem from 'core_courseformat/local/courseeditor/dndcmitem';
28
import Templates from 'core/templates';
28
import Templates from 'core/templates';
29
import Prefetch from 'core/prefetch';
29
import Prefetch from 'core/prefetch';
30
import Config from 'core/config';
30
import Config from 'core/config';
31
import Pending from "core/pending";
31
import Pending from "core/pending";
-
 
32
import log from "core/log";
Línea 32... Línea 33...
32
 
33
 
33
// Prefetch the completion icons template.
34
// Prefetch the completion icons template.
34
const completionTemplate = 'core_courseformat/local/courseindex/cmcompletion';
35
const completionTemplate = 'core_courseformat/local/courseindex/cmcompletion';
Línea 44... Línea 45...
44
        this.name = 'courseindex_cm';
45
        this.name = 'courseindex_cm';
45
        // Default query selectors.
46
        // Default query selectors.
46
        this.selectors = {
47
        this.selectors = {
47
            CM_NAME: `[data-for='cm_name']`,
48
            CM_NAME: `[data-for='cm_name']`,
48
            CM_COMPLETION: `[data-for='cm_completion']`,
49
            CM_COMPLETION: `[data-for='cm_completion']`,
-
 
50
            DND_ALLOWED: `[data-courseindexdndallowed='true']`,
49
        };
51
        };
50
        // Default classes to toggle on refresh.
52
        // Default classes to toggle on refresh.
51
        this.classes = {
53
        this.classes = {
52
            CMHIDDEN: 'dimmed',
54
            CMHIDDEN: 'dimmed',
53
            LOCKED: 'editinprogress',
55
            LOCKED: 'editinprogress',
Línea 65... Línea 67...
65
     * @param {element|string} target the DOM main element or its ID
67
     * @param {element|string} target the DOM main element or its ID
66
     * @param {object} selectors optional css selector overrides
68
     * @param {object} selectors optional css selector overrides
67
     * @return {Component}
69
     * @return {Component}
68
     */
70
     */
69
    static init(target, selectors) {
71
    static init(target, selectors) {
-
 
72
        let element = document.querySelector(target);
-
 
73
        // TODO Remove this if condition as part of MDL-83851.
-
 
74
        if (!element) {
-
 
75
            log.debug('Init component with id is deprecated, use a query selector instead.');
-
 
76
            element = document.getElementById(target);
-
 
77
        }
70
        return new this({
78
        return new this({
71
            element: document.getElementById(target),
79
            element,
72
            selectors,
80
            selectors,
73
        });
81
        });
74
    }
82
    }
Línea 75... Línea 83...
75
 
83
 
76
    /**
84
    /**
77
     * Initial state ready method.
85
     * Initial state ready method.
78
     *
86
     *
79
     * @param {Object} state the course state.
87
     * @param {Object} state the course state.
80
     */
88
     */
-
 
89
    stateReady(state) {
81
    stateReady(state) {
90
        if (document.querySelector(this.selectors.DND_ALLOWED)) {
-
 
91
            this.configDragDrop(this.id);
82
        this.configDragDrop(this.id);
92
        }
83
        const cm = state.cm.get(this.id);
93
        const cm = state.cm.get(this.id);
84
        const course = state.course;
94
        const course = state.course;
85
        // Refresh completion icon.
95
        // Refresh completion icon.
86
        this._refreshCompletion({
96
        this._refreshCompletion({
Línea 100... Línea 110...
100
            this.reactive.dispatch('setPageItem', 'cm', this.id, true);
110
            this.reactive.dispatch('setPageItem', 'cm', this.id, true);
101
            this.element.scrollIntoView({block: "center"});
111
            this.element.scrollIntoView({block: "center"});
102
        }
112
        }
103
        // Add anchor logic if the element is not user visible or the element hasn't URL.
113
        // Add anchor logic if the element is not user visible or the element hasn't URL.
104
        if (!cm.uservisible || !cm.url) {
114
        if (!cm.uservisible || !cm.url) {
-
 
115
            const element = this.getElement(this.selectors.CM_NAME);
105
            this.addEventListener(
116
            this.addEventListener(
106
                this.getElement(this.selectors.CM_NAME),
117
                element,
107
                'click',
118
                'click',
108
                this._activityAnchor,
119
                this._activityAnchor,
109
            );
120
            );
-
 
121
            // If the element is not user visible we also need to update the anchor link including the section page.
-
 
122
            if (!document.getElementById(cm.anchor)) {
-
 
123
                element.setAttribute('href', this._getActivitySectionURL(cm));
-
 
124
            }
110
        }
125
        }
111
    }
126
    }
Línea 112... Línea 127...
112
 
127
 
113
    /**
128
    /**
Línea 170... Línea 185...
170
        if (this.reactive.isEditing || !element.istrackeduser) {
185
        if (this.reactive.isEditing || !element.istrackeduser) {
171
            return;
186
            return;
172
        }
187
        }
173
        // Check if the completion value has changed.
188
        // Check if the completion value has changed.
174
        const completionElement = this.getElement(this.selectors.CM_COMPLETION);
189
        const completionElement = this.getElement(this.selectors.CM_COMPLETION);
175
        if (completionElement.dataset.value == element.completionstate) {
190
        if (!completionElement || completionElement.dataset.value == element.completionstate) {
176
            return;
191
            return;
177
        }
192
        }
Línea 178... Línea 193...
178
 
193
 
179
        // Collect section information from the state.
194
        // Collect section information from the state.
Línea 204... Línea 219...
204
                pendingAnchor.resolve();
219
                pendingAnchor.resolve();
205
            }, 50);
220
            }, 50);
206
            return;
221
            return;
207
        }
222
        }
208
        // If the element is not present in the page we need to go to the specific section.
223
        // If the element is not present in the page we need to go to the specific section.
-
 
224
        event.preventDefault();
209
        const course = this.reactive.get('course');
225
        window.location = this._getActivitySectionURL(cm);
-
 
226
    }
-
 
227
 
-
 
228
    /**
-
 
229
     * Get the anchor link in section page for the cm.
-
 
230
     *
-
 
231
     * @param {Object} cm the course module data.
-
 
232
     * @return {String} the anchor link.
-
 
233
     */
-
 
234
    _getActivitySectionURL(cm) {
210
        const section = this.reactive.get('section', cm.sectionid);
235
        let section = this.reactive.get('section', cm.sectionid);
-
 
236
 
-
 
237
        // If the section is delegated get its parent section if it has one.
-
 
238
        if (section.component && section.parentsectionid) {
-
 
239
            section = this.reactive.get('section', section.parentsectionid);
-
 
240
        }
-
 
241
 
211
        if (!section) {
242
        if (!section) {
212
            return;
243
            return '#';
213
        }
244
        }
-
 
245
 
214
        const url = `${course.baseurl}&section=${section.number}#${cm.anchor}`;
246
        const sectionurl = section.sectionurl.split("#")[0];
215
        event.preventDefault();
-
 
216
        window.location = url;
247
        return `${sectionurl}#${cm.anchor}`;
217
    }
248
    }
218
}
249
}