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 |
* The activity header component.
|
|
|
18 |
*
|
|
|
19 |
* @module core_courseformat/local/content/activity_header
|
|
|
20 |
* @class core_courseformat/local/content/activity_header
|
|
|
21 |
* @copyright 2021 Ferran Recio <ferran@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
import {BaseComponent} from 'core/reactive';
|
|
|
26 |
import {getCurrentCourseEditor} from 'core_courseformat/courseeditor';
|
|
|
27 |
import * as CourseEvents from 'core_course/events';
|
|
|
28 |
|
|
|
29 |
// Global page selectors.
|
|
|
30 |
const SELECTORS = {
|
|
|
31 |
ACTIVITY_HEADER: `[data-for='page-activity-header']`,
|
|
|
32 |
};
|
|
|
33 |
|
|
|
34 |
export default class Component extends BaseComponent {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Constructor hook.
|
|
|
38 |
*/
|
|
|
39 |
create() {
|
|
|
40 |
// Optional component name for debugging.
|
|
|
41 |
this.name = 'activity_header';
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Static method to create a component instance form the mustache template.
|
|
|
46 |
*
|
|
|
47 |
* @param {string} target optional altentative DOM main element CSS selector
|
|
|
48 |
* @param {object} selectors optional css selector overrides
|
|
|
49 |
* @return {Component}
|
|
|
50 |
*/
|
|
|
51 |
static init(target, selectors) {
|
|
|
52 |
const elementselector = (target) ? target : SELECTORS.ACTIVITY_HEADER;
|
|
|
53 |
return new Component({
|
|
|
54 |
element: document.querySelector(elementselector),
|
|
|
55 |
reactive: getCurrentCourseEditor(),
|
|
|
56 |
selectors
|
|
|
57 |
});
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Initial state ready method.
|
|
|
62 |
*/
|
|
|
63 |
stateReady() {
|
|
|
64 |
// Capture completion events.
|
|
|
65 |
this.addEventListener(
|
|
|
66 |
this.element,
|
|
|
67 |
CourseEvents.manualCompletionToggled,
|
|
|
68 |
this._completionHandler
|
|
|
69 |
);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* Activity manual completion listener.
|
|
|
74 |
*
|
|
|
75 |
* @param {Event} event the custom event
|
|
|
76 |
* @param {object} event.detail the event details
|
|
|
77 |
*/
|
|
|
78 |
_completionHandler({detail}) {
|
|
|
79 |
if (detail === undefined) {
|
|
|
80 |
return;
|
|
|
81 |
}
|
|
|
82 |
this.reactive.dispatch('cmCompletion', [detail.cmid], detail.completed);
|
|
|
83 |
}
|
|
|
84 |
}
|