MDL-60065 calendar: Update side calendar when on CRUD events

This commit is contained in:
Andrew Nicols
2017-09-18 12:04:48 +08:00
parent f58424c70c
commit b9ff690eb6
2 changed files with 40 additions and 1 deletions
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core_calendar/selectors","core_calendar/events","core_calendar/view_manager"],function(a,b,c,d){var e=function(d){a("body").on(c.filterChanged,function(a,c){var e=d.find(b.eventType[c.type]);e.toggleClass("calendar_event_"+c.type,!c.hidden)})};return{init:function(b){b=a(b),d.init(b),e(b)}}});
define(["jquery","core_calendar/selectors","core_calendar/events","core_calendar/view_manager"],function(a,b,c,d){var e=function(b){var d=a("body"),e="."+b.attr("id");d.on(c.created+e,b,f),d.on(c.deleted+e,b,f),d.on(c.updated+e,b,f),d.on(c.eventMoved+e,b,f)},f=function(b){var e=b.data,f=a("body"),g="."+e.attr("id");e.is(":visible")?d.reloadCurrentMonth(e):(f.on(c.created+g),f.on(c.deleted+g),f.on(c.updated+g),f.on(c.eventMoved+g))},g=function(d){a("body").on(c.filterChanged,function(a,c){var e=d.find(b.eventType[c.type]);e.toggleClass("calendar_event_"+c.type,!c.hidden)})};return{init:function(b){b=a(b),d.init(b),g(b),e(b)}}});
+39
View File
@@ -38,6 +38,44 @@ function(
CalendarViewManager
) {
/**
* Listen to and handle any calendar events fired by the calendar UI.
*
* @method registerCalendarEventListeners
* @param {object} root The calendar root element
*/
var registerCalendarEventListeners = function(root) {
var body = $('body');
var namespace = '.' + root.attr('id');
body.on(CalendarEvents.created + namespace, root, reloadMonth);
body.on(CalendarEvents.deleted + namespace, root, reloadMonth);
body.on(CalendarEvents.updated + namespace, root, reloadMonth);
body.on(CalendarEvents.eventMoved + namespace, root, reloadMonth);
};
/**
* Reload the month view in this month.
*
* @param {EventFacade} e
*/
var reloadMonth = function(e) {
var root = e.data;
var body = $('body');
var namespace = '.' + root.attr('id');
if (root.is(':visible')) {
CalendarViewManager.reloadCurrentMonth(root);
} else {
// The root has been removed.
// Remove all events in the namespace.
body.on(CalendarEvents.created + namespace);
body.on(CalendarEvents.deleted + namespace);
body.on(CalendarEvents.updated + namespace);
body.on(CalendarEvents.eventMoved + namespace);
}
};
var registerEventListeners = function(root) {
$('body').on(CalendarEvents.filterChanged, function(e, data) {
var daysWithEvent = root.find(CalendarSelectors.eventType[data.type]);
@@ -52,6 +90,7 @@ function(
CalendarViewManager.init(root);
registerEventListeners(root);
registerCalendarEventListeners(root);
}
};
});