Adam Shaw 9 лет назад
Родитель
Сommit
7ff4f92aa2
4 измененных файлов с 29 добавлено и 15 удалено
  1. 1 1
      src/Calendar.js
  2. 12 10
      src/common/View.date-range.js
  3. 1 1
      src/util.js
  4. 15 3
      tests/automated-better/toolbar/prev-button.js

+ 1 - 1
src/Calendar.js

@@ -76,7 +76,7 @@ var Calendar = FC.Calendar = Class.extend({
 		var i;
 		var spec;
 
-		if ($.inArray(unit, intervalUnits) != -1) {
+		if ($.inArray(unit, unitsDesc) != -1) {
 
 			// put views that have buttons first. there will be duplicates, but oh well
 			viewTypes = this.header.getViewsWithButtons(); // TODO: include footer as well?

+ 12 - 10
src/common/View.date-range.js

@@ -87,14 +87,15 @@ View.mixin({
 	// Builds a structure holding dates/ranges for rendering around the given date.
 	// Optional direction param indicates whether the date is being incremented/decremented
 	// from its previous value. decremented = -1, incremented = 1 (default).
-	buildRangeInfo: function(date, direction) {
+	buildRangeInfo: function(givenDate, direction) {
 		var validRange = this.buildValidRange();
+		var constrainedDate = constrainDate(givenDate, validRange);
 		var currentInfo;
 		var renderRange;
 		var activeRange;
-		var isActiveRangeValid;
+		var isValid;
 
-		currentInfo = this.buildCurrentRangeInfo(date, direction);
+		currentInfo = this.buildCurrentRangeInfo(constrainedDate, direction);
 		renderRange = this.buildRenderRange(currentInfo.range, currentInfo.unit);
 		activeRange = cloneRange(renderRange);
 
@@ -102,12 +103,13 @@ View.mixin({
 			activeRange = constrainRange(activeRange, currentInfo.range);
 		}
 
-		isActiveRangeValid = doRangesIntersect(activeRange, validRange);
-		if (isActiveRangeValid) {
-			activeRange = constrainRange(activeRange, validRange);
-		}
+		activeRange = constrainRange(activeRange, validRange);
+		constrainedDate = constrainDate(constrainedDate, activeRange);
 
-		date = constrainDate(date, activeRange);
+		// it's invalid if the originally requested date is not contained,
+		// or if the range is completely outside of the valid range.
+		isValid = isDateWithinRange(givenDate, currentInfo.range) &&
+			doRangesIntersect(currentInfo.range, validRange);
 
 		return {
 			validRange: validRange,
@@ -115,8 +117,8 @@ View.mixin({
 			currentRangeUnit: currentInfo.unit,
 			activeRange: activeRange,
 			renderRange: renderRange,
-			isValid: isActiveRangeValid,
-			date: date,
+			isValid: isValid,
+			date: constrainedDate,
 			dateIncrement: this.buildDateIncrement(currentInfo.duration)
 				// pass a fallback (might be null) ^
 		};

+ 1 - 1
src/util.js

@@ -723,7 +723,7 @@ function isDateWithinRange(date, range) {
 // constraintRange can have unspecified start/end, an open-ended range.
 function doRangesIntersect(subjectRange, constraintRange) {
 	return (!constraintRange.start || subjectRange.end >= constraintRange.start) &&
-		(!constrainRange.end || subjectRange.start < constrainRange.end);
+		(!constraintRange.end || subjectRange.start < constraintRange.end);
 }
 
 

+ 15 - 3
tests/automated-better/toolbar/prev-button.js

@@ -7,7 +7,6 @@ SEE ALSO:
 */
 describe('prev button', function() {
 	pushOptions({
-		header: { left: 'prev' },
 		defaultView: 'agendaWeek',
 		defaultDate: '2017-06-08',
 		dateIncrement: { years: 1 } // prev range is 2016-06-05 - 2016-06-12
@@ -16,7 +15,7 @@ describe('prev button', function() {
 	describe('when there is no specified validRange', function() {
 		it('is enabled', function() {
 			initCalendar();
-			ToolbarUtils.expectButtonEnabled('next', true);
+			ToolbarUtils.expectButtonEnabled('prev', true);
 		});
 	});
 
@@ -26,7 +25,20 @@ describe('prev button', function() {
 		});
 		it('is disabled', function() {
 			initCalendar();
-			ToolbarUtils.expectButtonEnabled('next', false);
+			ToolbarUtils.expectButtonEnabled('prev', false);
+		});
+	});
+
+	describe('when month view', function() {
+		pushOptions({
+			defaultView: 'month',
+			defaultDate: '2017-03-01',
+			validRange: { start: '2017-02-07' }
+		});
+
+		it('when prev date range is partially before validRange', function() {
+			initCalendar();
+			ToolbarUtils.expectButtonEnabled('prev', false);
 		});
 	});
 });