From c4a228ab996c10ceb85c52382d819f5d8e8c0a6d Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Tue, 4 Nov 2014 14:50:05 +0100 Subject: [PATCH] Avoid flickering of calendar view when refetching all events (#3405) --- plugins/calendar/calendar_ui.js | 12 ++++++------ plugins/calendar/lib/js/fullcalendar.js | 9 +++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js index 3be3a9dd..a5a78381 100644 --- a/plugins/calendar/calendar_ui.js +++ b/plugins/calendar/calendar_ui.js @@ -3105,6 +3105,9 @@ function rcube_calendar_ui(settings) } } + // remove temp events + fc.fullCalendar('removeEvents', function(e){ return e.temp; }); + if (source && (p.refetch || (p.update && !source.active))) { // activate event source if new event was added to an invisible calendar if (this.quickview_active) { @@ -3115,7 +3118,7 @@ function rcube_calendar_ui(settings) return false; } }); - fc.fullCalendar('refetchEvents', source); + fc.fullCalendar('refetchEvents', source, true); } else if (!source.active) { source.active = true; @@ -3123,7 +3126,7 @@ function rcube_calendar_ui(settings) $('#rcmlical' + source.id + ' input').prop('checked', true); } else - fc.fullCalendar('refetchEvents', source); + fc.fullCalendar('refetchEvents', source, true); fetch_counts(); } @@ -3147,12 +3150,9 @@ function rcube_calendar_ui(settings) } // refetch all calendars else if (p.refetch) { - fc.fullCalendar('refetchEvents'); + fc.fullCalendar('refetchEvents', undefined, true); fetch_counts(); } - - // remove temp events - fc.fullCalendar('removeEvents', function(e){ return e.temp; }); }; // modify query parameters for refresh requests diff --git a/plugins/calendar/lib/js/fullcalendar.js b/plugins/calendar/lib/js/fullcalendar.js index a417a25b..33893995 100644 --- a/plugins/calendar/lib/js/fullcalendar.js +++ b/plugins/calendar/lib/js/fullcalendar.js @@ -259,6 +259,7 @@ function Calendar(element, options, eventSources) { var ignoreWindowResize = 0; var date = new Date(); var events = []; + var lazyRendering = false; var _dragElement; @@ -509,8 +510,8 @@ function Calendar(element, options, eventSources) { // TODO: going forward, most of this stuff should be directly handled by the view - function refetchEvents(source) { // can be called as an API method - clearEvents(); + function refetchEvents(source, lazy) { // can be called as an API method + lazyRendering = lazy || false; fetchAndRenderEvents(source); } @@ -556,6 +557,10 @@ function Calendar(element, options, eventSources) { // called when event data arrives function reportEvents(_events) { + if (lazyRendering) { + clearEvents(); + lazyRendering = false; + } events = _events; renderEvents(); }