|
@@ -185,140 +185,121 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
|
|
|
|
|
|
|
|
|
|
|
|
|
resolveRangesForDate: function(date, direction) {
|
|
resolveRangesForDate: function(date, direction) {
|
|
|
- var validRange = this.buildValidRange() || {};
|
|
|
|
|
-
|
|
|
|
|
|
|
+ var validRange = this.buildValidRange();
|
|
|
var isDateValid = isDateWithinRange(date, validRange);
|
|
var isDateValid = isDateWithinRange(date, validRange);
|
|
|
-
|
|
|
|
|
- date = constrainDate(date, validRange);
|
|
|
|
|
-
|
|
|
|
|
- var customVisibleRange;
|
|
|
|
|
- var currentRangeDuration;
|
|
|
|
|
- var currentRangeUnit;
|
|
|
|
|
- var currentRange;
|
|
|
|
|
|
|
+ var currentInfo;
|
|
|
var renderRange;
|
|
var renderRange;
|
|
|
var visibleRange;
|
|
var visibleRange;
|
|
|
- var dateIncrementInput;
|
|
|
|
|
- var dateIncrement;
|
|
|
|
|
- var dayCount;
|
|
|
|
|
|
|
+ var isVisibleRangeValid;
|
|
|
|
|
|
|
|
- if (this.viewSpec.duration) {
|
|
|
|
|
- currentRangeDuration = this.viewSpec.duration;
|
|
|
|
|
- currentRangeUnit = this.viewSpec.durationUnit;
|
|
|
|
|
-
|
|
|
|
|
- // if the view displays a single day or smaller
|
|
|
|
|
- if (currentRangeDuration.as('days') <= 1) {
|
|
|
|
|
- if (this.isHiddenDay(date)) {
|
|
|
|
|
- date = this.skipHiddenDays(date, direction);
|
|
|
|
|
- date.startOf('day');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ date = constrainDate(date, validRange);
|
|
|
|
|
+ currentInfo = this.buildCurrentRangeInfo(date, direction);
|
|
|
|
|
+ renderRange = this.computeRenderRange(currentInfo.range, currentInfo.unit);
|
|
|
|
|
+ visibleRange = constrainRange(renderRange, validRange);
|
|
|
|
|
|
|
|
- currentRange = this.computeCurrentRange(date, currentRangeDuration, currentRangeUnit);
|
|
|
|
|
- currentRange = this.filterCurrentRange(currentRange, currentRangeUnit);
|
|
|
|
|
- renderRange = this.computeRenderRange(currentRange, currentRangeUnit);
|
|
|
|
|
- renderRange = this.trimHiddenDays(renderRange); // should computeRenderRange be responsible?
|
|
|
|
|
|
|
+ if (this.opt('disableNonCurrentDates')) {
|
|
|
|
|
+ visibleRange = constrainRange(visibleRange, currentInfo.range);
|
|
|
}
|
|
}
|
|
|
- else if ((dayCount = this.opt('dayCount'))) {
|
|
|
|
|
|
|
|
|
|
- currentRangeUnit = 'day';
|
|
|
|
|
|
|
+ date = constrainDate(date, visibleRange);
|
|
|
|
|
+ isVisibleRangeValid = Boolean(intersectRanges(visibleRange, currentInfo.range));
|
|
|
|
|
|
|
|
- if (this.isHiddenDay(date)) {
|
|
|
|
|
- date = this.skipHiddenDays(date, direction);
|
|
|
|
|
- date.startOf('day');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return {
|
|
|
|
|
+ validRange: validRange,
|
|
|
|
|
+ currentRange: currentInfo.range,
|
|
|
|
|
+ currentRangeUnit: currentInfo.unit,
|
|
|
|
|
+ visibleRange: visibleRange,
|
|
|
|
|
+ renderRange: renderRange,
|
|
|
|
|
+ isValid: isDateValid && isVisibleRangeValid,
|
|
|
|
|
+ date: date,
|
|
|
|
|
+ dateIncrement: this.computeDateIncrement(currentInfo.duration)
|
|
|
|
|
+ };
|
|
|
|
|
+ },
|
|
|
|
|
|
|
|
- var runningCount = 0;
|
|
|
|
|
- var end = date.clone().startOf('day');
|
|
|
|
|
|
|
|
|
|
- do {
|
|
|
|
|
- end.add(1, 'day');
|
|
|
|
|
- if (!this.isHiddenDay(end)) {
|
|
|
|
|
- runningCount++;
|
|
|
|
|
- }
|
|
|
|
|
- } while (runningCount < dayCount);
|
|
|
|
|
|
|
+ buildValidRange: function() {
|
|
|
|
|
+ return this.getRangeOption('validRange', this.calendar.getNow()) || {};
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ buildCurrentRangeInfo: function(date, direction) {
|
|
|
|
|
+ var duration = null;
|
|
|
|
|
+ var unit = null;
|
|
|
|
|
+ var range = null;
|
|
|
|
|
+ var dayCount;
|
|
|
|
|
|
|
|
- currentRange = { start: date.clone(), end: end };
|
|
|
|
|
- currentRange = this.filterCurrentRange(currentRange, currentRangeUnit); // needed here?
|
|
|
|
|
- renderRange = this.computeRenderRange(currentRange, currentRangeUnit);
|
|
|
|
|
- renderRange = this.trimHiddenDays(renderRange); // should computeRenderRange be responsible?
|
|
|
|
|
|
|
+ if (this.viewSpec.duration) {
|
|
|
|
|
+ duration = this.viewSpec.duration;
|
|
|
|
|
+ unit = this.viewSpec.durationUnit;
|
|
|
|
|
+ range = this.buildRangeFromDuration(date, direction, duration, unit);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if ((dayCount = this.opt('dayCount'))) {
|
|
|
|
|
+ unit = 'day';
|
|
|
|
|
+ range = this.buildRangeFromDayCount(date, direction, dayCount);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if ((range = this.buildCustomVisibleRange(date))) {
|
|
|
|
|
+ unit = computeIntervalUnit(range.start, range.end);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- customVisibleRange = this.buildCustomVisibleRange(date);
|
|
|
|
|
- if (customVisibleRange) {
|
|
|
|
|
-
|
|
|
|
|
- currentRangeUnit = computeIntervalUnit(
|
|
|
|
|
- customVisibleRange.start,
|
|
|
|
|
- customVisibleRange.end
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- currentRange = this.filterCurrentRange(customVisibleRange, currentRangeUnit);
|
|
|
|
|
- renderRange = currentRange;
|
|
|
|
|
- renderRange = this.trimHiddenDays(renderRange);
|
|
|
|
|
-
|
|
|
|
|
- // if the view displays a single day or smaller
|
|
|
|
|
- if (currentRange.end.diff(currentRange.start, 'days', true) <= 1) {
|
|
|
|
|
- if (this.isHiddenDay(date)) {
|
|
|
|
|
- date = this.skipHiddenDays(date, direction);
|
|
|
|
|
- date.startOf('day');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else { // lots of repeat code
|
|
|
|
|
- currentRangeDuration = moment.duration(1, 'day');
|
|
|
|
|
- currentRangeUnit = 'day';
|
|
|
|
|
-
|
|
|
|
|
- // if the view displays a single day or smaller
|
|
|
|
|
- if (currentRangeDuration.as('days') <= 1) {
|
|
|
|
|
- if (this.isHiddenDay(date)) {
|
|
|
|
|
- date = this.skipHiddenDays(date, direction);
|
|
|
|
|
- date.startOf('day');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- currentRange = this.computeCurrentRange(date, currentRangeDuration, currentRangeUnit);
|
|
|
|
|
- currentRange = this.filterCurrentRange(currentRange, currentRangeUnit);
|
|
|
|
|
- renderRange = this.computeRenderRange(currentRange, currentRangeUnit);
|
|
|
|
|
- renderRange = this.trimHiddenDays(renderRange); // should computeRenderRange be responsible?
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ unit = 'day';
|
|
|
|
|
+ duration = moment.duration({ days: 1 });
|
|
|
|
|
+ range = this.buildRangeFromDuration(date, direction, duration, unit);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- visibleRange = constrainRange(renderRange, validRange);
|
|
|
|
|
|
|
+ range = this.filterCurrentRange(range, unit);
|
|
|
|
|
|
|
|
- var isVisibleRangeValid = Boolean(intersectRanges(visibleRange, currentRange));
|
|
|
|
|
|
|
+ return { duration: duration, unit: unit, range: range };
|
|
|
|
|
+ },
|
|
|
|
|
|
|
|
- if (this.opt('disableNonCurrentDates')) {
|
|
|
|
|
- visibleRange = constrainRange(visibleRange, currentRange);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ buildRangeFromDuration: function(date, direction, duration, unit) {
|
|
|
|
|
+ var customAlignment = this.opt('dateAlignment');
|
|
|
|
|
+ var start = date.clone();
|
|
|
|
|
+ var end;
|
|
|
|
|
+
|
|
|
|
|
+ // if the view displays a single day or smaller
|
|
|
|
|
+ if (duration.as('days') <= 1) {
|
|
|
|
|
+ if (this.isHiddenDay(start)) {
|
|
|
|
|
+ start = this.skipHiddenDays(start, direction);
|
|
|
|
|
+ start.startOf('day');
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- date = constrainDate(date, visibleRange);
|
|
|
|
|
|
|
+ start.startOf(customAlignment || unit);
|
|
|
|
|
+ end = start.clone().add(duration);
|
|
|
|
|
|
|
|
- dateIncrementInput = this.opt('dateIncrement'); // TODO: util for getting date options
|
|
|
|
|
|
|
+ return { start: start, end: end };
|
|
|
|
|
+ },
|
|
|
|
|
|
|
|
- if (dateIncrementInput) {
|
|
|
|
|
- dateIncrement = moment.duration(dateIncrementInput);
|
|
|
|
|
- }
|
|
|
|
|
- else if (this.opt('dateAlignment')) {
|
|
|
|
|
- dateIncrement = moment.duration(1, this.opt('dateAlignment'));
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- dateIncrement = currentRangeDuration;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ buildRangeFromDayCount: function(date, direction, dayCount) {
|
|
|
|
|
+ var customAlignment = this.opt('dateAlignment');
|
|
|
|
|
+ var runningCount = 0;
|
|
|
|
|
+ var start = date.clone();
|
|
|
|
|
+ var end;
|
|
|
|
|
+
|
|
|
|
|
+ // if the view displays a single day or smaller
|
|
|
|
|
+ if (dayCount <= 1) {
|
|
|
|
|
+ if (this.isHiddenDay(start)) {
|
|
|
|
|
+ start = this.skipHiddenDays(start, direction);
|
|
|
|
|
+ start.startOf('day');
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return {
|
|
|
|
|
- validRange: validRange,
|
|
|
|
|
- currentRange: currentRange,
|
|
|
|
|
- currentRangeUnit: currentRangeUnit,
|
|
|
|
|
- visibleRange: visibleRange,
|
|
|
|
|
- isValid: isDateValid && isVisibleRangeValid,
|
|
|
|
|
- renderRange: renderRange,
|
|
|
|
|
- dateIncrement: dateIncrement,
|
|
|
|
|
- date: date // the revised date
|
|
|
|
|
- };
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ if (customAlignment) {
|
|
|
|
|
+ start.startOf(customAlignment);
|
|
|
|
|
+ }
|
|
|
|
|
+ start.startOf('day');
|
|
|
|
|
|
|
|
|
|
+ end = start.clone();
|
|
|
|
|
+ do {
|
|
|
|
|
+ end.add(1, 'day');
|
|
|
|
|
+ if (!this.isHiddenDay(end)) {
|
|
|
|
|
+ runningCount++;
|
|
|
|
|
+ }
|
|
|
|
|
+ } while (runningCount < dayCount);
|
|
|
|
|
|
|
|
- buildValidRange: function() {
|
|
|
|
|
- return this.getRangeOption('validRange', this.calendar.getNow());
|
|
|
|
|
|
|
+ return { start: start, end: end };
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
@@ -333,15 +314,6 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
- computeCurrentRange: function(date, duration, durationUnit) {
|
|
|
|
|
- var customAlignment = this.opt('dateAlignment');
|
|
|
|
|
- var start = date.clone().startOf(customAlignment || durationUnit);
|
|
|
|
|
- var end = start.clone().add(duration);
|
|
|
|
|
-
|
|
|
|
|
- return { start: start, end: end };
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
filterCurrentRange: function(currentRange, unit) {
|
|
filterCurrentRange: function(currentRange, unit) {
|
|
|
|
|
|
|
|
// normalize the range's time-ambiguity
|
|
// normalize the range's time-ambiguity
|
|
@@ -368,6 +340,24 @@ var View = FC.View = Class.extend(EmitterMixin, ListenerMixin, {
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ computeDateIncrement: function(fallback) {
|
|
|
|
|
+ var dateIncrementInput = this.opt('dateIncrement');
|
|
|
|
|
+
|
|
|
|
|
+ if (dateIncrementInput) {
|
|
|
|
|
+ return moment.duration(dateIncrementInput);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (this.opt('dateAlignment')) {
|
|
|
|
|
+ return moment.duration(1, this.opt('dateAlignment'));
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (fallback) {
|
|
|
|
|
+ return fallback;
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ return moment.duration(1, 'day');
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// Computes the new date when the user hits the prev button, given the current date
|
|
// Computes the new date when the user hits the prev button, given the current date
|
|
|
computePrevDate: function(date) {
|
|
computePrevDate: function(date) {
|
|
|
var ranges = this.computePrevRanges(date);
|
|
var ranges = this.computePrevRanges(date);
|