Browse Source

fixes for businesshours

Adam Shaw 8 years ago
parent
commit
47844413c0
3 changed files with 22 additions and 17 deletions
  1. 16 15
      src/Calendar.business.js
  2. 1 0
      src/Calendar.constraints.js
  3. 5 2
      src/common/Grid.events.js

+ 16 - 15
src/Calendar.business.js

@@ -13,36 +13,37 @@ var BUSINESS_HOUR_EVENT_DEFAULTS = {
 // Abuse of our event system :(
 Calendar.prototype.buildCurrentBusinessFootprints = function(wholeDay) {
 	var activeRange = this.getView().activeRange;
-
-	return this.eventInstanceGroupToFootprints(
-		this.buildBusinessGroup(
-			wholeDay,
-			this.opt('businessHours'),
-			activeRange.start,
-			activeRange.end
-		)
+	var eventInstances = this.buildBusinessInstances(
+		wholeDay,
+		this.opt('businessHours'),
+		activeRange.start,
+		activeRange.end
 	);
+
+	var eventRanges = this.eventInstancesToEventRanges(eventInstances);
+
+	return this.eventRangesToEventFootprints(eventRanges);
 };
 
 
 // Given a raw input value from options, return events objects for business hours within the current view.
-Calendar.prototype.buildBusinessGroup = function(wholeDay, input, rangeStart, rangeEnd) {
+Calendar.prototype.buildBusinessInstances = function(wholeDay, input, rangeStart, rangeEnd) {
 	if (input === true) {
-		return this._buildBusinessGroup(wholeDay, [ {} ], false, rangeStart, rangeEnd);
+		return this._buildBusinessInstances(wholeDay, [ {} ], false, rangeStart, rangeEnd);
 	}
 	else if ($.isPlainObject(input)) {
-		return this._buildBusinessGroup(wholeDay, [ input ], false, rangeStart, rangeEnd);
+		return this._buildBusinessInstances(wholeDay, [ input ], false, rangeStart, rangeEnd);
 	}
 	else if ($.isArray(input)) {
-		return this._buildBusinessGroup(wholeDay, input, true, rangeStart, rangeEnd);
+		return this._buildBusinessInstances(wholeDay, input, true, rangeStart, rangeEnd);
 	}
 	else {
-		return new EventInstanceGroup([]);
+		return [];
 	}
 };
 
 
-Calendar.prototype._buildBusinessGroup = function(wholeDay, rawDefs, ignoreNoDow, rangeStart, rangeEnd) {
+Calendar.prototype._buildBusinessInstances = function(wholeDay, rawDefs, ignoreNoDow, rangeStart, rangeEnd) {
 	var rawDef;
 	var fullRawDef;
 	var eventDef;
@@ -69,5 +70,5 @@ Calendar.prototype._buildBusinessGroup = function(wholeDay, rawDefs, ignoreNoDow
 		);
 	}
 
-	return new EventInstanceGroup(eventInstances);
+	return eventInstances;
 };

+ 1 - 0
src/Calendar.constraints.js

@@ -259,6 +259,7 @@ function isOverlapEventInstancesAllowed(overlapEventFootprints, subjectEventInst
 
 // Conversion: eventDefs -> eventInstances -> eventRanges -> eventFootprints -> componentFootprints
 // ------------------------------------------------------------------------------------------------
+// TODO: this is not DRY with Grid
 
 
 Calendar.prototype.eventDefsToInstances = function(eventDefs) {

+ 5 - 2
src/common/Grid.events.js

@@ -142,6 +142,7 @@ Grid.mixin({
 	buildBusinessHourRanges: function(wholeDay, businessHours) {
 		var calendar = this.view.calendar;
 		var events;
+		var group;
 
 		if (businessHours == null) {
 			// fallback
@@ -149,12 +150,14 @@ Grid.mixin({
 			businessHours = calendar.opt('businessHours');
 		}
 
-		return calendar.buildBusinessGroup(
+		group = new EventInstanceGroup(calendar.buildBusinessInstances(
 			wholeDay,
 			businessHours,
 			this.start,
 			this.end
-		).buildRenderRanges(
+		));
+
+		return group.buildRenderRanges(
 			new UnzonedRange(this.start, this.end),
 			calendar
 		);