Jelajahi Sumber

start with killing View::currentRange

Adam Shaw 8 tahun lalu
induk
melakukan
c81ab13acd

+ 1 - 1
src/Calendar.toolbar.js

@@ -68,7 +68,7 @@ Calendar.mixin({
 		var nextInfo = view.buildNextDateProfile(this.currentDate);
 
 		this.toolbarsManager.proxyCall(
-			(todayInfo.isValid && !isDateWithinRange(now, view.currentRange)) ?
+			(todayInfo.isValid && !view.currentUnzonedRange.containsDate(now)) ?
 				'enableButton' :
 				'disableButton',
 			'today'

+ 5 - 0
src/basic/MonthView.js

@@ -36,6 +36,11 @@ var MonthView = FC.MonthView = BasicView.extend({
 
 	isFixedWeeks: function() {
 		return this.opt('fixedWeekCount');
+	},
+
+
+	isDateInOtherMonth: function(date) {
+		return date.month() !== moment.utc(this.currentUnzonedRange.startMs).month(); // TODO: optimize
 	}
 
 });

+ 3 - 6
src/common/ChronoComponent.js

@@ -503,10 +503,10 @@ var ChronoComponent = Model.extend({
 	// Utility for formatting a range. Accepts a range object, formatting string, and optional separator.
 	// Displays all-day ranges naturally, with an inclusive end. Takes the current isRTL into account.
 	// The timezones of the dates within `range` will be respected.
-	formatRange: function(range, formatStr, separator) {
+	formatRange: function(range, isAllDay, formatStr, separator) {
 		var end = range.end;
 
-		if (!end.hasTime()) { // all-day?
+		if (isAllDay) {
 			end = end.clone().subtract(1); // convert to inclusive. last ms of previous day
 		}
 
@@ -531,10 +531,7 @@ var ChronoComponent = Model.extend({
 		else {
 			classes.push('fc-' + dayIDs[date.day()]);
 
-			if (
-				view.currentRangeAs('months') == 1 && // TODO: somehow get into MonthView
-				date.month() != view.currentRange.start.month()
-			) {
+			if (view.isDateInOtherMonth(date)) { // TODO: use ChronoComponent subclass somehow
 				classes.push('fc-other-month');
 			}
 

+ 1 - 1
src/common/Grid.events.js

@@ -896,7 +896,7 @@ Grid.mixin({
 
 		if (this.displayEventTime && range.start.hasTime()) {
 			if (displayEnd && range.end) {
-				return this.view.formatRange(range, formatStr);
+				return this.view.formatRange(range, false, formatStr); // allDay=false
 			}
 			else {
 				return range.start.format(formatStr);

+ 22 - 7
src/common/View.date-range.js

@@ -3,9 +3,11 @@ View.mixin({
 
 	// range the view is formally responsible for.
 	// for example, a month view might have 1st-31st, excluding padded dates
-	currentRange: null,
+	currentUnzonedRange: null,
 	currentRangeUnit: null, // name of largest unit being displayed, like "month" or "week"
 
+	isRangeAllDay: false,
+
 	// date range with a rendered skeleton
 	// includes not-active days that need some sort of DOM
 	renderRange: null,
@@ -27,8 +29,8 @@ View.mixin({
 	// DEPRECATED
 	start: null, // use activeRange.start
 	end: null, // use activeRange.end
-	intervalStart: null, // use currentRange.start
-	intervalEnd: null, // use currentRange.end
+	intervalStart: null, // use currentUnzonedRange.getStart
+	intervalEnd: null, // use currentUnzonedRange.getEnd
 
 
 	/* Date Range Computation
@@ -36,8 +38,9 @@ View.mixin({
 
 
 	setDateProfileForRendering: function(dateProfile) {
-		this.currentRange = dateProfile.currentRange;
+		this.currentUnzonedRange = new UnzonedRange(dateProfile.currentRange.start, dateProfile.currentRange.end);
 		this.currentRangeUnit = dateProfile.currentRangeUnit;
+		this.isRangeAllDay = dateProfile.isRangeAllDay;
 		this.renderRange = dateProfile.renderRange;
 		this.activeRange = dateProfile.activeRange;
 		this.validRange = dateProfile.validRange;
@@ -108,6 +111,7 @@ View.mixin({
 			validRange: validRange,
 			currentRange: currentInfo.range,
 			currentRangeUnit: currentInfo.unit,
+			isRangeAllDay: /^(year|month|week|day)$/.test(currentInfo.unit),
 			activeRange: activeRange,
 			renderRange: renderRange,
 			minTime: minTime,
@@ -285,7 +289,7 @@ View.mixin({
 
 
 	// Builds a normalized range object for the "visible" range,
-	// which is a way to define the currentRange and activeRange at the same time.
+	// which is a way to define the currentUnzonedRange and activeRange at the same time.
 	buildCustomVisibleRange: function(date) {
 		var visibleRange = this.getRangeOption(
 			'visibleRange',
@@ -341,8 +345,19 @@ View.mixin({
 	// Compute the number of the give units in the "current" range.
 	// Will return a floating-point number. Won't round.
 	currentRangeAs: function(unit) {
-		var currentRange = this.currentRange;
-		return currentRange.end.diff(currentRange.start, unit, true);
+		var currentUnzonedRange = this.currentUnzonedRange;
+
+		return moment.utc(currentUnzonedRange.endMs).diff(
+			moment.utc(currentUnzonedRange.startMs),
+			unit,
+			true
+		);
+	},
+
+
+	// For ChronoComponent::getDayClasses
+	isDateInOtherMonth: function(date) {
+		return false;
 	},
 
 

+ 4 - 2
src/common/View.js

@@ -149,7 +149,7 @@ var View = FC.View = ChronoComponent.extend({
 
 		// for views that span a large unit of time, show the proper interval, ignoring stray days before and after
 		if (/^(year|month)$/.test(this.currentRangeUnit)) {
-			range = this.currentRange;
+			range = this.currentUnzonedRange.getRange();
 		}
 		else { // for day units or smaller, use the actual day range
 			range = this.activeRange;
@@ -157,10 +157,12 @@ var View = FC.View = ChronoComponent.extend({
 
 		return this.formatRange(
 			{
-				// in case currentRange has a time, make sure timezone is correct
+				// in case currentRange has a time, make sure timezone is correct.
+				// TODO: make a utility for zoning an unzoned range.
 				start: this.calendar.applyTimezone(range.start),
 				end: this.calendar.applyTimezone(range.end)
 			},
+			this.isRangeAllDay,
 			this.opt('titleFormat') || this.computeTitleFormat(),
 			this.opt('titleRangeSeparator')
 		);

+ 8 - 0
src/models/UnzonedRange.js

@@ -67,6 +67,14 @@ var UnzonedRange = FC.UnzonedRange = Class.extend({
 	},
 
 
+	containsDate: function(mom) { // TODO: rename
+		var ms = mom.valueOf();
+
+		return (this.startMs === null || ms >= this.startMs) &&
+			(this.endMs === null || ms < this.endMs);
+	},
+
+
 	intersectsWith: function(otherRange) {
 		return (this.endMs === null || otherRange.startMs === null || this.endMs > otherRange.startMs) &&
 			(this.startMs === null || otherRange.endMs === null || this.startMs < otherRange.endMs);