Browse Source

fall back to parseFootprints

Adam Shaw 8 years ago
parent
commit
f6f1956985
1 changed files with 21 additions and 7 deletions
  1. 21 7
      src/Calendar.constraints.js

+ 21 - 7
src/Calendar.constraints.js

@@ -137,18 +137,25 @@ Calendar.prototype.isFootprintWithinConstraints = function(componentFootprint, c
 
 
 Calendar.prototype.constraintValToFootprints = function(constraintVal, isAllDay) {
+	var eventInstances;
+
 	if (constraintVal === 'businessHours') {
 		return this.buildCurrentBusinessFootprints(isAllDay);
 	}
 	else if (typeof constraintVal === 'object') {
-		return this.eventInstancesToFootprints(
-			this.parseEventDefToInstances(constraintVal)
-		);
+		eventInstances = this.parseEventDefToInstances(constraintVal); // handles recurring events
+
+		if (!eventInstances) { // invalid input. fallback to parsing footprint directly
+			return this.parseFootprints(constraintVal);
+		}
+		else {
+			return this.eventInstancesToFootprints(eventInstances);
+		}
 	}
 	else if (constraintVal != null) { // an ID
-		return this.eventInstancesToFootprints(
-			this.eventManager.getEventInstancesWithId(constraintVal)
-		);
+		eventInstances = this.eventManager.getEventInstancesWithId(constraintVal);
+
+		return this.eventInstancesToFootprints(eventInstances);
 	}
 };
 
@@ -247,11 +254,18 @@ function isOverlapEventInstancesAllowed(overlapEventFootprints, subjectEventInst
 // this more DRY.
 
 
+/*
+Returns false on invalid input.
+*/
 Calendar.prototype.parseEventDefToInstances = function(eventInput) {
 	var eventPeriod = this.eventManager.currentPeriod;
 	var eventDef = EventDefParser.parse(eventInput, new EventSource(this));
 
-	if (eventPeriod && eventDef) {
+	if (!eventDef) { // invalid
+		return false;
+	}
+
+	if (eventPeriod) {
 		return eventDef.buildInstances(eventPeriod.start, eventPeriod.end);
 	}
 	else {