Kaynağa Gözat

fixes related to gcal

Adam Shaw 8 yıl önce
ebeveyn
işleme
eb55fdd4db

+ 12 - 11
src/gcal/GcalEventSource.js

@@ -2,6 +2,7 @@
 var GcalEventSource = EventSource.extend({
 
 	// TODO: eventually remove "googleCalendar" prefix (API-breaking)
+	googleCalendarApiKey: null,
 	googleCalendarId: null,
 	googleCalendarError: null, // optional function
 	ajaxSettings: null,
@@ -98,6 +99,7 @@ var GcalEventSource = EventSource.extend({
 
 	buildRequestParams: function(start, end, timezone) {
 		var apiKey = this.googleCalendarApiKey || this.calendar.opt('googleCalendarApiKey');
+		var params;
 
 		if (!apiKey) {
 			this.reportError("Specify a googleCalendarApiKey. See http://fullcalendar.io/docs/google_calendar/");
@@ -115,25 +117,23 @@ var GcalEventSource = EventSource.extend({
 			end = end.clone().utc().add(1, 'day');
 		}
 
-		if (timezone === 'local') {
-			timezone = null;
-		}
-		else if (timezone) {
-			// when sending timezone names to Google, only accepts underscores, not spaces
-			timezone = timezone.replace(' ', '_');
-		}
-
-		return $.extend(
+		params = $.extend(
 			this.ajaxSettings.data || {},
 			{
 				key: apiKey,
 				timeMin: start.format(),
 				timeMax: end.format(),
-				timeZone: timezone,
 				singleEvents: true,
 				maxResults: 9999
 			}
 		);
+
+		if (timezone && timezone !== 'local') {
+			// when sending timezone names to Google, only accepts underscores, not spaces
+			params.timeZone = timezone.replace(' ', '_');
+		}
+
+		return params;
 	},
 
 
@@ -175,7 +175,7 @@ GcalEventSource.parse = function(rawInput, calendar) {
 		url = rawInput;
 		rawProps = {};
 	}
-	else if (typeof rawInput.url === 'string') {
+	else if (typeof rawInput === 'object') {
 		rawProps = $.extend({}, rawInput); // clone
 		url = pluckProp(rawProps, 'url');
 		googleCalendarId = pluckProp(rawProps, 'googleCalendarId');
@@ -189,6 +189,7 @@ GcalEventSource.parse = function(rawInput, calendar) {
 		source = EventSource.parseAndPluck.call(this, rawProps, calendar);
 
 		source.googleCalendarId = googleCalendarId;
+		source.googleCalendarApiKey = pluckProp(rawProps, 'googleCalendarApiKey');
 		source.googleCalendarError = pluckProp(rawProps, 'googleCalendarError');
 		source.ajaxSettings = rawProps; // remainder
 

+ 12 - 6
src/models/EventManager.js

@@ -128,9 +128,10 @@ var EventManager = Class.extend(EmitterMixin, ListenerMixin, {
 		var sources = this.otherSources;
 		var i, source;
 
-		// given an proper event source object
+		// given a proper event source object
 		for (i = 0; i < sources.length; i++) {
 			source = sources[i];
+
 			if (source === matchInput) {
 				return [ source ];
 			}
@@ -142,9 +143,14 @@ var EventManager = Class.extend(EmitterMixin, ListenerMixin, {
 			return [ source ];
 		}
 
-		return $.grep(sources, function(source) {
-			return isSourcesEquivalent(matchInput, source);
-		});
+		// parse as an event source
+		matchInput = EventSourceParser.parse(matchInput);
+		if (matchInput) {
+
+			return $.grep(sources, function(source) {
+				return isSourcesEquivalent(matchInput, source);
+			});
+		}
 	},
 
 
@@ -329,6 +335,6 @@ var EventManager = Class.extend(EmitterMixin, ListenerMixin, {
 });
 
 
-function isSourcesEquivalent(source1, source2) {
-	return source1 && source2 && source1.getPrimitive() == source2.getPrimitive();
+function isSourcesEquivalent(source0, source1) {
+	return source0.getPrimitive() == source1.getPrimitive();
 }

+ 7 - 0
src/models/EventPeriod.js

@@ -64,6 +64,13 @@ var EventPeriod = Class.extend(EmitterMixin, {
 				request.eventDefs = eventDefs;
 
 				_this.addEventDefs(eventDefs);
+				_this.pendingCnt--;
+				_this.tryRelease();
+			}
+		}, function() { // failure
+			if (request.status !== 'cancelled') {
+				request.status = 'failed';
+
 				_this.pendingCnt--;
 				_this.tryRelease();
 			}

+ 1 - 1
src/models/event-source/EventSourceParser.js

@@ -5,7 +5,7 @@ var EventSourceParser = {
 
 
 	registerClass: function(EventSourceClass) {
-		this.sourceClasses.push(EventSourceClass);
+		this.sourceClasses.unshift(EventSourceClass); // give highest priority
 	},