From ed99d8991aadb7d35d700c956558110521607d30 Mon Sep 17 00:00:00 2001 From: JeanMichel FRANCOIS Date: Tue, 23 Jun 2015 16:50:03 +0200 Subject: [PATCH 1/3] fix: update calendar settings keep the current view name and start date --- src/calendar.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calendar.js b/src/calendar.js index 694269c..b6670e2 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -244,6 +244,7 @@ angular.module('ui.calendar', []) scope.destroy = function(){ if(calendar && calendar.fullCalendar){ + scope.lastView = calendar.fullCalendar('getView'); calendar.fullCalendar('destroy'); } if(attrs.calendar) { @@ -257,7 +258,12 @@ angular.module('ui.calendar', []) calendar.fullCalendar(options); if(attrs.calendar) { uiCalendarConfig.calendars[attrs.calendar] = calendar; - } + } + if(scope.lastView) { + calendar.fullCalendar('changeView', scope.lastView.name); + calendar.fullCalendar('gotoDate', scope.lastView.start); + scope.lastView = undefined; + } }; eventSourcesWatcher.onAdded = function(source) { From b24e527c1111e6eca4128b65eb632b241a665a1c Mon Sep 17 00:00:00 2001 From: JeanMichel FRANCOIS Date: Mon, 12 Oct 2015 16:58:24 +0200 Subject: [PATCH 2/3] refactor: call init with params only if needed --- src/calendar.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/calendar.js b/src/calendar.js index b6670e2..9cb5e10 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -244,7 +244,6 @@ angular.module('ui.calendar', []) scope.destroy = function(){ if(calendar && calendar.fullCalendar){ - scope.lastView = calendar.fullCalendar('getView'); calendar.fullCalendar('destroy'); } if(attrs.calendar) { @@ -254,15 +253,16 @@ angular.module('ui.calendar', []) } }; - scope.init = function(){ + scope.init = function(changeView, gotoDate){ calendar.fullCalendar(options); if(attrs.calendar) { uiCalendarConfig.calendars[attrs.calendar] = calendar; } - if(scope.lastView) { - calendar.fullCalendar('changeView', scope.lastView.name); - calendar.fullCalendar('gotoDate', scope.lastView.start); - scope.lastView = undefined; + if(changeView) { + calendar.fullCalendar('changeView', changeView); + } + if (gotoDate) { + calendar.fullCalendar('gotoDate', gotoDate); } }; @@ -309,7 +309,19 @@ angular.module('ui.calendar', []) scope.$watch(getOptions, function(newO,oldO){ scope.destroy(); - scope.init(); + + //if settings has not changeView, then keep the current one; + var changeView, gotoDate; + if (calendar && calendar.fullCalendar) { + var lastView = calendar.fullCalendar('getView'); + if (lastView) { + if (newO.defaultView === oldO.defaultView) { + changeView = lastView.name; + } + gotoDate = lastView.ntervalStart; + } + } + scope.init(changeView, gotoDate); }); } }; From 57b901658f17426dd7ee8026c0467ee9aa1239e0 Mon Sep 17 00:00:00 2001 From: JeanMichel FRANCOIS Date: Mon, 12 Oct 2015 17:00:14 +0200 Subject: [PATCH 3/3] fix typo --- src/calendar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calendar.js b/src/calendar.js index 9cb5e10..c6e5600 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -318,7 +318,7 @@ angular.module('ui.calendar', []) if (newO.defaultView === oldO.defaultView) { changeView = lastView.name; } - gotoDate = lastView.ntervalStart; + gotoDate = lastView.intervalStart; } } scope.init(changeView, gotoDate);