diff --git a/src/calendar.js b/src/calendar.js index 181dd88..c88c130 100644 --- a/src/calendar.js +++ b/src/calendar.js @@ -35,6 +35,7 @@ angular.module('ui.calendar', []) }; var eventSerialId = 1; + var resourceSerialId = 1; // @return {String} fingerprint of the event object and its properties this.eventFingerprint = function(e) { if (!e._id) { @@ -50,6 +51,16 @@ angular.module('ui.calendar', []) (e.allDay || '') + (e.className || '') + extraSignature; }; + // @return {String} fingerprint of the event object and its properties + this.resourceFingerprint = function(r) { + if (!r._id) { + r._id = resourceSerialId++; + } + + // This extracts all the information we need from the resource. http://jsperf.com/angular-calendar-events-fingerprint/3 + return r.id; + }; + var sourceSerialId = 1, sourceEventsSerialId = 1; // @return {String} fingerprint of the source object and its events array this.sourceFingerprint = function(source) { @@ -98,6 +109,7 @@ angular.module('ui.calendar', []) this.changeWatcher = function(arraySource, tokenFn) { var self; var getTokens = function() { + // console.log(arraySource); var array = angular.isFunction(arraySource) ? arraySource() : arraySource; var result = [], token, el; for (var i = 0, n = array.length; i < n; i++) { @@ -214,15 +226,16 @@ angular.module('ui.calendar', []) .directive('uiCalendar', ['uiCalendarConfig', function(uiCalendarConfig) { return { restrict: 'A', - scope: {eventSources:'=ngModel',calendarWatchEvent: '&'}, + scope: {eventSources:'=ngModel',calendarWatchEvent: '&', resources: '='}, controller: 'uiCalendarCtrl', link: function(scope, elm, attrs, controller) { - var sources = scope.eventSources, + evResources = scope.resources, sourcesChanged = false, calendar, eventSourcesWatcher = controller.changeWatcher(sources, controller.sourceFingerprint), eventsWatcher = controller.changeWatcher(controller.allEvents, controller.eventFingerprint), + resourceWatcher = controller.changeWatcher(scope.resources, controller.resourceFingerprint), options = null; function getOptions(){ @@ -233,7 +246,8 @@ angular.module('ui.calendar', []) var localeFullCalendarConfig = controller.getLocaleConfig(fullCalendarConfig); angular.extend(localeFullCalendarConfig, fullCalendarConfig); - options = { eventSources: sources }; + options = { eventSources: sources, + resources: evResources }; angular.extend(options, localeFullCalendarConfig); //remove calendars from options options.calendars = null; @@ -265,6 +279,7 @@ angular.module('ui.calendar', []) calendar.fullCalendar(options); if(attrs.calendar) { uiCalendarConfig.calendars[attrs.calendar] = calendar; + window.calendar = calendar; } }; scope.$on('$destroy', function() { @@ -299,7 +314,7 @@ angular.module('ui.calendar', []) eventsWatcher.onAdded = function(event) { if (calendar && calendar.fullCalendar) { - calendar.fullCalendar('renderEvent', event, (event.stick ? true : false)); + calendar.fullCalendar('renderEvent', event, true); } }; @@ -309,6 +324,18 @@ angular.module('ui.calendar', []) } }; + resourceWatcher.onAdded = function(resource) { + if (calendar && calendar.fullCalendar) { + calendar.fullCalendar('addResource', resource); + } + }; + + resourceWatcher.onRemoved = function(resource) { + if (calendar && calendar.fullCalendar) { + calendar.fullCalendar('removeResource', resource); + } + }; + eventsWatcher.onChanged = function(event) { if (calendar && calendar.fullCalendar) { var clientEvents = calendar.fullCalendar('clientEvents', event._id); @@ -320,6 +347,7 @@ angular.module('ui.calendar', []) } }; + resourceWatcher.subscribe(scope); eventSourcesWatcher.subscribe(scope); eventsWatcher.subscribe(scope, function() { if (sourcesChanged === true) {