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 |
* This module is responsible for handle calendar day and upcoming view.
|
|
|
18 |
*
|
|
|
19 |
* @module core_calendar/calendar_view
|
|
|
20 |
* @copyright 2017 Simey Lameze <simey@moodle.com>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
define([
|
|
|
24 |
'jquery',
|
|
|
25 |
'core/notification',
|
|
|
26 |
'core_calendar/selectors',
|
|
|
27 |
'core_calendar/events',
|
|
|
28 |
'core_calendar/view_manager',
|
|
|
29 |
'core_calendar/crud'
|
|
|
30 |
],
|
|
|
31 |
function(
|
|
|
32 |
$,
|
|
|
33 |
Notification,
|
|
|
34 |
CalendarSelectors,
|
|
|
35 |
CalendarEvents,
|
|
|
36 |
CalendarViewManager,
|
|
|
37 |
CalendarCrud
|
|
|
38 |
) {
|
|
|
39 |
|
|
|
40 |
var registerEventListeners = function(root, type) {
|
|
|
41 |
var body = $('body');
|
|
|
42 |
|
|
|
43 |
CalendarCrud.registerRemove(root);
|
|
|
44 |
|
|
|
45 |
var reloadFunction = 'reloadCurrent' + type.charAt(0).toUpperCase() + type.slice(1);
|
|
|
46 |
|
|
|
47 |
body.on(CalendarEvents.created, function() {
|
|
|
48 |
CalendarViewManager[reloadFunction](root);
|
|
|
49 |
});
|
|
|
50 |
body.on(CalendarEvents.deleted, function() {
|
|
|
51 |
CalendarViewManager[reloadFunction](root);
|
|
|
52 |
});
|
|
|
53 |
body.on(CalendarEvents.updated, function() {
|
|
|
54 |
CalendarViewManager[reloadFunction](root);
|
|
|
55 |
});
|
|
|
56 |
|
|
|
57 |
root.on('change', CalendarSelectors.courseSelector, function() {
|
|
|
58 |
var selectElement = $(this);
|
|
|
59 |
var courseId = selectElement.val();
|
|
|
60 |
const courseName = $("option:selected", selectElement).text();
|
|
|
61 |
CalendarViewManager[reloadFunction](root, courseId, null)
|
|
|
62 |
.then(function() {
|
|
|
63 |
// We need to get the selector again because the content has changed.
|
|
|
64 |
return root.find(CalendarSelectors.courseSelector).val(courseId);
|
|
|
65 |
})
|
|
|
66 |
.then(function() {
|
|
|
67 |
CalendarViewManager.updateUrl('?view=' + type + '&course=' + courseId);
|
|
|
68 |
CalendarViewManager.handleCourseChange(Number(courseId), courseName);
|
|
|
69 |
return;
|
|
|
70 |
})
|
|
|
71 |
.fail(Notification.exception);
|
|
|
72 |
});
|
|
|
73 |
|
|
|
74 |
body.on(CalendarEvents.filterChanged, function(e, data) {
|
|
|
75 |
var daysWithEvent = root.find(CalendarSelectors.eventType[data.type]);
|
|
|
76 |
if (data.hidden == true) {
|
|
|
77 |
daysWithEvent.addClass('hidden');
|
|
|
78 |
} else {
|
|
|
79 |
daysWithEvent.removeClass('hidden');
|
|
|
80 |
}
|
|
|
81 |
CalendarViewManager.foldDayEvents(root);
|
|
|
82 |
});
|
|
|
83 |
|
|
|
84 |
var eventFormPromise = CalendarCrud.registerEventFormModal(root);
|
|
|
85 |
CalendarCrud.registerEditListeners(root, eventFormPromise);
|
|
|
86 |
};
|
|
|
87 |
|
|
|
88 |
return {
|
11 |
efrain |
89 |
init: function(root, type, isCalendarBlock = false) {
|
1 |
efrain |
90 |
root = $(root);
|
|
|
91 |
|
11 |
efrain |
92 |
CalendarViewManager.init(root, type, isCalendarBlock);
|
|
|
93 |
registerEventListeners(root, type, isCalendarBlock);
|
1 |
efrain |
94 |
}
|
|
|
95 |
};
|
|
|
96 |
});
|