فهرست منبع

buildBusinessHourSegs. render fully non-business-hour region

Adam Shaw 9 سال پیش
والد
کامیت
e50eb19d22
4فایلهای تغییر یافته به همراه46 افزوده شده و 7 حذف شده
  1. 1 3
      src/common/DayGrid.js
  2. 29 0
      src/common/Grid.events.js
  3. 3 4
      src/common/TimeGrid.js
  4. 13 0
      tests/automated/businessHours.js

+ 1 - 3
src/common/DayGrid.js

@@ -63,9 +63,7 @@ var DayGrid = FC.DayGrid = Grid.extend(DayTableMixin, {
 
 
 	renderBusinessHours: function() {
-		var events = this.view.calendar.getCurrentBusinessHourEvents(true); // wholeDay=true
-		var segs = this.eventsToSegs(events);
-
+		var segs = this.buildBusinessHourSegs(true); // wholeDay=true
 		this.renderFill('businessHours', segs, 'bgevent');
 	},
 

+ 29 - 0
src/common/Grid.events.js

@@ -170,6 +170,35 @@ Grid.mixin({
 	},
 
 
+	/* Business Hours
+	------------------------------------------------------------------------------------------------------------------*/
+
+
+	// Compute business hour segs for the grid's current date range.
+	// Caller must ask if whole-day business hours are needed.
+	buildBusinessHourSegs: function(wholeDay) {
+		var events = this.view.calendar.getCurrentBusinessHourEvents(wholeDay);
+
+		// HACK. Eventually refactor business hours "events" system.
+		// If no events are given, but businessHours is activated, this means the entire visible range should be
+		// marked as *not* business-hours, via inverse-background rendering.
+		if (
+			!events.length &&
+			this.view.calendar.options.businessHours // don't access view option. doesn't update with dynamic options
+		) {
+			events = [
+				$.extend({}, BUSINESS_HOUR_EVENT_DEFAULTS, {
+					start: this.view.end, // guaranteed out-of-range
+					end: this.view.end,   // "
+					dow: null
+				})
+			];
+		}
+
+		return this.eventsToSegs(events);
+	},
+
+
 	/* Handlers
 	------------------------------------------------------------------------------------------------------------------*/
 

+ 3 - 4
src/common/TimeGrid.js

@@ -423,10 +423,9 @@ var TimeGrid = FC.TimeGrid = Grid.extend(DayTableMixin, {
 
 
 	renderBusinessHours: function() {
-		var events = this.view.calendar.getCurrentBusinessHourEvents();
-		var segs = this.eventsToSegs(events);
-
-		this.renderBusinessSegs(segs);
+		this.renderBusinessSegs(
+			this.buildBusinessHourSegs()
+		);
 	},
 
 

+ 13 - 0
tests/automated/businessHours.js

@@ -168,6 +168,19 @@ describe('businessHours', function() {
 	});
 
 
+	it('will grey-out a totally non-business-hour view', function() {
+		$('#cal').fullCalendar({
+			defaultDate: '2016-07-23', // sat
+			defaultView: 'agendaDay',
+			businessHours: true
+		});
+
+		// timed area
+		expect(isTimeGridNonBusinessSegsRendered([
+			{ start: '2016-07-23T00:00', end: '2016-07-24T00:00' }
+		])).toBe(true);
+	});
+
 
 	function queryNonBusinessSegs() {
 		return $('.fc-nonbusiness');