Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

update calendar settings keep the current view name and start date #285

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,20 @@ angular.module('ui.calendar', [])
}
};

scope.initCalendar = function(){
scope.initCalendar = function(changeView, gotoDate){
if (!calendar) {
calendar = angular.element(elm).html('');
}
calendar.fullCalendar(options);
if(attrs.calendar) {
uiCalendarConfig.calendars[attrs.calendar] = calendar;
}
}
if(changeView) {
calendar.fullCalendar('changeView', changeView);
}
if (gotoDate) {
calendar.fullCalendar('gotoDate', gotoDate);
}
};
scope.$on('$destroy', function() {
scope.destroyCalendar();
Expand Down Expand Up @@ -330,12 +336,26 @@ angular.module('ui.calendar', [])
});

scope.$watch(getOptions, function(newValue, oldValue) {
if(newValue !== oldValue) {
scope.destroyCalendar();
scope.initCalendar();
} else if((newValue && angular.isUndefined(calendar))) {
scope.initCalendar();
}
function _initCalendar() {
//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 (newValue.defaultView === oldValue.defaultView) {
changeView = lastView.name;
}
gotoDate = lastView.intervalStart;
}
}
scope.initCalendar(changeView, gotoDate);
}
if(newValue !== oldValue) {
scope.destroyCalendar();
_initCalendar();
} else if((newValue && angular.isUndefined(calendar))) {
_initCalendar();
}
});
}
};
Expand Down