Adam Shaw 11 lat temu
rodzic
commit
2b5da3d019

+ 40 - 3
src/EventManager.js

@@ -592,7 +592,8 @@ function EventManager(options) { // assumed to be a calendar
 
 
 	// If the given event is a recurring event, break it down into an array of individual instances.
 	// If the given event is a recurring event, break it down into an array of individual instances.
 	// If not a recurring event, return an array with the single original event.
 	// If not a recurring event, return an array with the single original event.
-	function expandEvent(abstractEvent) {
+	// `_rangeStart` and `_rangeEnd` and are HACKS for when the no events have been requested yet.
+	function expandEvent(abstractEvent, _rangeStart, _rangeEnd) {
 		var events = [];
 		var events = [];
 		var dowHash;
 		var dowHash;
 		var dow;
 		var dow;
@@ -602,6 +603,10 @@ function EventManager(options) { // assumed to be a calendar
 		var start, end;
 		var start, end;
 		var event;
 		var event;
 
 
+		// hack
+		_rangeStart = _rangeStart || rangeStart;
+		_rangeEnd = _rangeEnd || rangeEnd;
+
 		if (abstractEvent._recurring) {
 		if (abstractEvent._recurring) {
 
 
 			// make a boolean hash as to whether the event occurs on each day-of-week
 			// make a boolean hash as to whether the event occurs on each day-of-week
@@ -613,8 +618,8 @@ function EventManager(options) { // assumed to be a calendar
 			}
 			}
 
 
 			// iterate through every day in the current range
 			// iterate through every day in the current range
-			date = rangeStart.clone().stripTime(); // holds the date of the current day
-			while (date.isBefore(rangeEnd)) {
+			date = _rangeStart.clone().stripTime(); // holds the date of the current day
+			while (date.isBefore(_rangeEnd)) { // QUESTION: is this kosher with an ambiguous date?
 
 
 				if (!dowHash || dowHash[date.day()]) { // if everyday, or this particular day-of-week
 				if (!dowHash || dowHash[date.day()]) { // if everyday, or this particular day-of-week
 
 
@@ -823,6 +828,38 @@ function EventManager(options) { // assumed to be a calendar
 		};
 		};
 	}
 	}
 
 
+
+	/* Business Hours
+	-----------------------------------------------------------------------------------------*/
+
+	t.getBusinessHoursEvents = function(view) {
+		var optionVal = options.businessHours;
+		var defaultVal = {
+			id: '_businessHours',
+			className: 'fc-nonbusiness',
+			start: '09:00',
+			end: '17:00',
+			dow: [ 1, 2, 3, 4, 5 ],
+			rendering: 'inverse-background'
+		};
+		var eventInput;
+
+		if (optionVal) {
+			if (typeof optionVal === 'object') {
+				eventInput = $.extend({}, defaultVal, optionVal);
+			}
+			else {
+				eventInput = defaultVal;
+			}
+		}
+
+		if (eventInput) {
+			return expandEvent(buildEventFromInput(eventInput), view.start, view.end);
+		}
+
+		return [];
+	};
+
 }
 }
 
 
 
 

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

@@ -136,6 +136,11 @@ $.extend(Grid.prototype, {
 	},
 	},
 
 
 
 
+	businessHoursSegClasses: function(seg) {
+		return this.bgEventSegClasses(seg);
+	},
+
+
 	// Returns additional CSS properties (as a string) to be applied to a background event segment.
 	// Returns additional CSS properties (as a string) to be applied to a background event segment.
 	// Gets called by each subclass' fill-rendering system.
 	// Gets called by each subclass' fill-rendering system.
 	// TODO: merge with getEventSkinCss() somehow
 	// TODO: merge with getEventSkinCss() somehow

+ 18 - 6
src/common/TimeGrid.js

@@ -39,10 +39,18 @@ $.extend(TimeGrid.prototype, {
 
 
 		this.computeSlatTops();
 		this.computeSlatTops();
 
 
+		this.renderBusinessHours();
+
 		Grid.prototype.render.call(this); // call the super-method
 		Grid.prototype.render.call(this); // call the super-method
 	},
 	},
 
 
 
 
+	renderBusinessHours: function() {
+		var events = this.view.calendar.getBusinessHoursEvents(this.view);
+		this.renderFill('businessHours', this.eventsToSegs(events), 'bgevent');
+	},
+
+
 	// Renders the basic HTML skeleton for the grid
 	// Renders the basic HTML skeleton for the grid
 	renderHtml: function() {
 	renderHtml: function() {
 		return '' +
 		return '' +
@@ -409,11 +417,11 @@ $.extend(TimeGrid.prototype, {
 
 
 	// Renders a set of rectangles over the given time segments.
 	// Renders a set of rectangles over the given time segments.
 	// The `type` is used for destroying later. Also allows for special-cased behavior via strategically-named methods.
 	// The `type` is used for destroying later. Also allows for special-cased behavior via strategically-named methods.
-	renderFill: function(type, segs) {
+	// `classNameStr` is a HACK
+	renderFill: function(type, segs, classNameStr) {
 		var view = this.view;
 		var view = this.view;
 		var extraClassesMethod = this[type + 'SegClasses']; // TODO: better system for this
 		var extraClassesMethod = this[type + 'SegClasses']; // TODO: better system for this
 		var extraStylesMethod = this[type + 'SegStyles']; //
 		var extraStylesMethod = this[type + 'SegStyles']; //
-		var typeLower = type.toLowerCase();
 		var cellHtml = '';
 		var cellHtml = '';
 		var segCols;
 		var segCols;
 		var col, colSegs;
 		var col, colSegs;
@@ -426,15 +434,19 @@ $.extend(TimeGrid.prototype, {
 		var segEls;
 		var segEls;
 		var j;
 		var j;
 
 
+		if (!segs.length) return;
+
 		segCols = this.groupSegCols(segs); // group into sub-arrays, and assigns 'col' to each seg
 		segCols = this.groupSegCols(segs); // group into sub-arrays, and assigns 'col' to each seg
 
 
+		classNameStr = classNameStr || type.toLowerCase();
+
 		for (col = 0; col < segCols.length; col++) {
 		for (col = 0; col < segCols.length; col++) {
 			colSegs = segCols[col];
 			colSegs = segCols[col];
 
 
 			cellHtml += '<td>';
 			cellHtml += '<td>';
 
 
 			if (colSegs.length) {
 			if (colSegs.length) {
-				cellHtml += '<div class="fc-' + typeLower + '-container">';
+				cellHtml += '<div class="fc-' + classNameStr + '-container">';
 
 
 				for (i = 0; i < colSegs.length; i++) {
 				for (i = 0; i < colSegs.length; i++) {
 					seg = colSegs[i];
 					seg = colSegs[i];
@@ -449,7 +461,7 @@ $.extend(TimeGrid.prototype, {
 					extraStyles = extraStylesMethod ? extraStylesMethod.call(this, seg) : '';
 					extraStyles = extraStylesMethod ? extraStylesMethod.call(this, seg) : '';
 
 
 					cellHtml += '<div' +
 					cellHtml += '<div' +
-						' class="fc-' + typeLower + ' ' + extraClasses + '"' +
+						' class="fc-' + classNameStr + ' ' + extraClasses + '"' +
 						' style="top:' + top + 'px;bottom:-' + bottom + 'px;' + extraStyles + '"' +
 						' style="top:' + top + 'px;bottom:-' + bottom + 'px;' + extraStyles + '"' +
 						'/>';
 						'/>';
 				}
 				}
@@ -463,7 +475,7 @@ $.extend(TimeGrid.prototype, {
 		cellHtml = this.bookendCells(cellHtml, type);
 		cellHtml = this.bookendCells(cellHtml, type);
 
 
 		el = $(
 		el = $(
-			'<div class="fc-' + typeLower + '-skeleton">' +
+			'<div class="fc-' + classNameStr + '-skeleton">' +
 				'<table>' +
 				'<table>' +
 					'<tr>' +
 					'<tr>' +
 						cellHtml +
 						cellHtml +
@@ -473,7 +485,7 @@ $.extend(TimeGrid.prototype, {
 		);
 		);
 
 
 		// assign each segment's el. TODO: there's gotta be a better way
 		// assign each segment's el. TODO: there's gotta be a better way
-		segEls = el.find('.fc-' + typeLower);
+		segEls = el.find('.fc-' + classNameStr);
 		j = 0;
 		j = 0;
 		for (col = 0; col < segCols.length; col++) {
 		for (col = 0; col < segCols.length; col++) {
 			colSegs = segCols[col];
 			colSegs = segCols[col];

+ 5 - 0
src/common/common.css

@@ -61,6 +61,11 @@ body .fc { /* extra precedence to overcome jqui */
 	filter: alpha(opacity=30); /* for IE */
 	filter: alpha(opacity=30); /* for IE */
 }
 }
 
 
+.fc-nonbusiness { /* default look for non-business-hours areas */
+	/* will inherit .fc-bgevent's styles */
+	background: #ccc;
+}
+
 
 
 /* Icons (inline elements with styled text that mock arrow icons)
 /* Icons (inline elements with styled text that mock arrow icons)
 --------------------------------------------------------------------------------------------------*/
 --------------------------------------------------------------------------------------------------*/