Przeglądaj źródła

constraint system prefers to use business hours footprints

Adam Shaw 8 lat temu
rodzic
commit
c9495fc028
2 zmienionych plików z 34 dodań i 19 usunięć
  1. 20 4
      src/Calendar.business.js
  2. 14 15
      src/Calendar.constraints.js

+ 20 - 4
src/Calendar.business.js

@@ -9,19 +9,35 @@ var BUSINESS_HOUR_EVENT_DEFAULTS = {
 
 
 
 
 /*
 /*
-See note on buildBusinessInstanceGroup about return value.
+returns ComponentFootprint[]
+`businessHourDef` is optional. Use Calendar's setting if omitted.
 */
 */
-Calendar.prototype.buildCurrentBusinessInstanceGroup = function(wholeDay) {
+Calendar.prototype.buildCurrentBusinessFootprints = function(wholeDay, businessHourDef) {
 	var eventPeriod = this.eventManager.currentPeriod;
 	var eventPeriod = this.eventManager.currentPeriod;
+	var businessDefInput;
+	var businessInstanceGroup;
 
 
 	if (eventPeriod) {
 	if (eventPeriod) {
-		return this.buildBusinessInstanceGroup(
+
+		if (arguments.length < 2) {
+			businessDefInput = this.opt('businessHours');
+		}
+
+		businessInstanceGroup = this.buildBusinessInstanceGroup(
 			wholeDay,
 			wholeDay,
-			this.opt('businessHours'),
+			businessDefInput,
 			eventPeriod.start,
 			eventPeriod.start,
 			eventPeriod.end
 			eventPeriod.end
 		);
 		);
+
+		if (businessInstanceGroup) {
+			return this.eventInstancesToFootprints( // in Calendar.constraints.js
+				businessInstanceGroup.eventInstances
+			);
+		}
 	}
 	}
+
+	return [];
 };
 };
 
 
 
 

+ 14 - 15
src/Calendar.constraints.js

@@ -132,27 +132,28 @@ Calendar.prototype.isFootprintWithinConstraints = function(componentFootprint, c
 
 
 
 
 Calendar.prototype.constraintValToFootprints = function(constraintVal, isAllDay) {
 Calendar.prototype.constraintValToFootprints = function(constraintVal, isAllDay) {
-	var eventInstanceGroup;
-	var eventRanges = [];
-
 	if (constraintVal === 'businessHours') {
 	if (constraintVal === 'businessHours') {
-		eventInstanceGroup = this.buildCurrentBusinessInstanceGroup(isAllDay);
-
-		if (eventInstanceGroup) {
-			eventRanges = eventInstanceGroup.getAllEventRanges();
-		}
+		return this.buildCurrentBusinessFootprints(isAllDay);
 	}
 	}
 	else if (typeof constraintVal === 'object') {
 	else if (typeof constraintVal === 'object') {
-		eventRanges = this.parseEventDefToEventRanges(constraintVal);
+		return this.eventInstancesToFootprints(
+			this.parseEventDefToInstances(constraintVal)
+		);
 	}
 	}
 	else if (constraintVal != null) { // an ID
 	else if (constraintVal != null) { // an ID
-		eventRanges = eventInstancesToEventRanges(
+		return this.eventInstancesToFootprints(
 			this.eventManager.getEventInstancesWithId(constraintVal)
 			this.eventManager.getEventInstancesWithId(constraintVal)
 		);
 		);
 	}
 	}
+};
+
 
 
+// conversion util
+Calendar.prototype.eventInstancesToFootprints = function(eventInstances) {
 	return eventFootprintsToComponentFootprints(
 	return eventFootprintsToComponentFootprints(
-		this.eventRangesToEventFootprints(eventRanges)
+		this.eventRangesToEventFootprints(
+			eventInstancesToEventRanges(eventInstances)
+		)
 	);
 	);
 };
 };
 
 
@@ -241,14 +242,12 @@ function isOverlapEventInstancesAllowed(overlapEventFootprints, subjectEventInst
 // this more DRY.
 // this more DRY.
 
 
 
 
-Calendar.prototype.parseEventDefToEventRanges = function(eventInput) {
+Calendar.prototype.parseEventDefToInstances = function(eventInput) {
 	var eventPeriod = this.eventManager.currentPeriod;
 	var eventPeriod = this.eventManager.currentPeriod;
 	var eventDef = EventDefParser.parse(eventInput, new EventSource(this));
 	var eventDef = EventDefParser.parse(eventInput, new EventSource(this));
 
 
 	if (eventPeriod && eventDef) {
 	if (eventPeriod && eventDef) {
-		return eventInstancesToEventRanges(
-			eventDef.buildInstances(eventPeriod.start, eventPeriod.end)
-		);
+		return eventDef.buildInstances(eventPeriod.start, eventPeriod.end);
 	}
 	}
 	else {
 	else {
 		return [];
 		return [];