ソースを参照

revive selection

Adam Shaw 8 年 前
コミット
b6682b5470
3 ファイル変更68 行追加53 行削除
  1. 6 3
      src/Calendar.js
  2. 38 30
      src/common/Grid.js
  3. 24 20
      src/common/View.js

+ 6 - 3
src/Calendar.js

@@ -207,7 +207,7 @@ var Calendar = FC.Calendar = Class.extend(EmitterMixin, {
 	// this public method receives start/end dates in any format, with any timezone
 	// this public method receives start/end dates in any format, with any timezone
 	select: function(zonedStartInput, zonedEndInput) {
 	select: function(zonedStartInput, zonedEndInput) {
 		this.view.select(
 		this.view.select(
-			this.buildSelectSpan.apply(this, arguments)
+			this.buildSelectFootprint.apply(this, arguments)
 		);
 		);
 	},
 	},
 
 
@@ -220,7 +220,7 @@ var Calendar = FC.Calendar = Class.extend(EmitterMixin, {
 
 
 
 
 	// Given arguments to the select method in the API, returns a span (unzoned start/end and other info)
 	// Given arguments to the select method in the API, returns a span (unzoned start/end and other info)
-	buildSelectSpan: function(zonedStartInput, zonedEndInput) {
+	buildSelectFootprint: function(zonedStartInput, zonedEndInput) {
 		var start = this.moment(zonedStartInput).stripZone();
 		var start = this.moment(zonedStartInput).stripZone();
 		var end;
 		var end;
 
 
@@ -234,7 +234,10 @@ var Calendar = FC.Calendar = Class.extend(EmitterMixin, {
 			end = start.clone().add(this.defaultAllDayEventDuration);
 			end = start.clone().add(this.defaultAllDayEventDuration);
 		}
 		}
 
 
-		return { start: start, end: end };
+		return new ComponentFootprint(
+			new UnzonedRange(start, end),
+			!start.hasTime()
+		);
 	},
 	},
 
 
 
 

+ 38 - 30
src/common/Grid.js

@@ -340,13 +340,13 @@ var Grid = FC.Grid = ChronoComponent.extend({
 				dayClickHit = null;
 				dayClickHit = null;
 			},
 			},
 			interactionEnd: function(ev, isCancelled) {
 			interactionEnd: function(ev, isCancelled) {
-				var hitSpan;
+				var componentFootprint;
 
 
 				if (!isCancelled && dayClickHit) {
 				if (!isCancelled && dayClickHit) {
-					hitSpan = _this.getSafeHitSpan(dayClickHit);
+					componentFootprint = _this.getSafeHitFootprint(dayClickHit);
 
 
-					if (hitSpan) {
-						_this.view.triggerDayClick(hitSpan, _this.getHitEl(dayClickHit), ev);
+					if (componentFootprint) {
+						_this.view.triggerDayClick(componentFootprint, _this.getHitEl(dayClickHit), ev);
 					}
 					}
 				}
 				}
 			}
 			}
@@ -365,51 +365,51 @@ var Grid = FC.Grid = ChronoComponent.extend({
 	// Creates a listener that tracks the user's drag across day elements, for day selecting.
 	// Creates a listener that tracks the user's drag across day elements, for day selecting.
 	buildDaySelectListener: function() {
 	buildDaySelectListener: function() {
 		var _this = this;
 		var _this = this;
-		var selectionSpan; // null if invalid selection
+		var selectionFootprint; // null if invalid selection
 
 
 		var dragListener = new HitDragListener(this, {
 		var dragListener = new HitDragListener(this, {
 			scroll: this.opt('dragScroll'),
 			scroll: this.opt('dragScroll'),
 			interactionStart: function() {
 			interactionStart: function() {
-				selectionSpan = null;
+				selectionFootprint = null;
 			},
 			},
 			dragStart: function() {
 			dragStart: function() {
 				_this.view.unselect(); // since we could be rendering a new selection, we want to clear any old one
 				_this.view.unselect(); // since we could be rendering a new selection, we want to clear any old one
 			},
 			},
 			hitOver: function(hit, isOrig, origHit) {
 			hitOver: function(hit, isOrig, origHit) {
-				var origHitSpan;
-				var hitSpan;
+				var origHitFootprint;
+				var hitFootprint;
 
 
 				if (origHit) { // click needs to have started on a hit
 				if (origHit) { // click needs to have started on a hit
 
 
-					origHitSpan = _this.getSafeHitSpan(origHit);
-					hitSpan = _this.getSafeHitSpan(hit);
+					origHitFootprint = _this.getSafeHitFootprint(origHit);
+					hitFootprint = _this.getSafeHitFootprint(hit);
 
 
-					if (origHitSpan && hitSpan) {
-						selectionSpan = _this.computeSelection(origHitSpan, hitSpan);
+					if (origHitFootprint && hitFootprint) {
+						selectionFootprint = _this.computeSelection(origHitFootprint, hitFootprint);
 					}
 					}
 					else {
 					else {
-						selectionSpan = null;
+						selectionFootprint = null;
 					}
 					}
 
 
-					if (selectionSpan) {
-						_this.renderSelection(selectionSpan);
+					if (selectionFootprint) {
+						_this.renderSelection(selectionFootprint);
 					}
 					}
-					else if (selectionSpan === false) {
+					else if (selectionFootprint === false) {
 						disableCursor();
 						disableCursor();
 					}
 					}
 				}
 				}
 			},
 			},
 			hitOut: function() { // called before mouse moves to a different hit OR moved out of all hits
 			hitOut: function() { // called before mouse moves to a different hit OR moved out of all hits
-				selectionSpan = null;
+				selectionFootprint = null;
 				_this.unrenderSelection();
 				_this.unrenderSelection();
 			},
 			},
 			hitDone: function() { // called after a hitOut OR before a dragEnd
 			hitDone: function() { // called after a hitOut OR before a dragEnd
 				enableCursor();
 				enableCursor();
 			},
 			},
 			interactionEnd: function(ev, isCancelled) {
 			interactionEnd: function(ev, isCancelled) {
-				if (!isCancelled && selectionSpan) {
+				if (!isCancelled && selectionFootprint) {
 					// the selection will already have been rendered. just report it
 					// the selection will already have been rendered. just report it
-					_this.view.reportSelection(selectionSpan, ev);
+					_this.view.reportSelection(selectionFootprint, ev);
 				}
 				}
 			}
 			}
 		});
 		});
@@ -493,8 +493,8 @@ var Grid = FC.Grid = ChronoComponent.extend({
 
 
 	// Renders a visual indication of a selection. Will highlight by default but can be overridden by subclasses.
 	// Renders a visual indication of a selection. Will highlight by default but can be overridden by subclasses.
 	// Given a span (unzoned start/end and other misc data)
 	// Given a span (unzoned start/end and other misc data)
-	renderSelection: function(span) {
-		this.renderHighlight(span);
+	renderSelection: function(componentFootprint) {
+		this.renderHighlight(componentFootprint);
 	},
 	},
 
 
 
 
@@ -508,25 +508,33 @@ var Grid = FC.Grid = ChronoComponent.extend({
 	// Subclasses can override and provide additional data in the span object. Will be passed to renderSelection().
 	// Subclasses can override and provide additional data in the span object. Will be passed to renderSelection().
 	// Will return false if the selection is invalid and this should be indicated to the user.
 	// Will return false if the selection is invalid and this should be indicated to the user.
 	// Will return null/undefined if a selection invalid but no error should be reported.
 	// Will return null/undefined if a selection invalid but no error should be reported.
-	computeSelection: function(span0, span1) {
-		var span = this.computeSelectionSpan(span0, span1);
+	computeSelection: function(footprint0, footprint1) {
+		var wholeFootprint = this.computeSelectionFootprint(footprint0, footprint1);
 
 
 		if (span && !this.view.calendar.isSelectionSpanAllowed(span)) {
 		if (span && !this.view.calendar.isSelectionSpanAllowed(span)) {
 			return false;
 			return false;
 		}
 		}
 
 
-		return span;
+		return wholeFootprint;
 	},
 	},
 
 
 
 
 	// Given two spans, must return the combination of the two.
 	// Given two spans, must return the combination of the two.
 	// TODO: do this separation of concerns (combining VS validation) for event dnd/resize too.
 	// TODO: do this separation of concerns (combining VS validation) for event dnd/resize too.
-	computeSelectionSpan: function(span0, span1) {
-		var dates = [ span0.start, span0.end, span1.start, span1.end ];
-
-		dates.sort(compareNumbers); // sorts chronologically. works with Moments
-
-		return { start: dates[0].clone(), end: dates[3].clone() };
+	computeSelectionFootprint: function(footprint0, footprint1) {
+		var ms = [
+			footprint0.dateRange.startMs,
+			footprint0.dateRange.endMs,
+			footprint1.dateRange.startMs,
+			footprint1.dateRange.endMs
+		];
+
+		ms.sort(compareNumbers);
+
+		return new ComponentFootprint(
+			new UnzonedRange(ms[0], ms[3]),
+			footprint0.isAllDay
+		);
 	},
 	},
 
 
 
 

+ 24 - 20
src/common/View.js

@@ -794,29 +794,32 @@ var View = FC.View = ChronoComponent.extend({
 
 
 	// Selects a date span on the view. `start` and `end` are both Moments.
 	// Selects a date span on the view. `start` and `end` are both Moments.
 	// `ev` is the native mouse event that begin the interaction.
 	// `ev` is the native mouse event that begin the interaction.
-	select: function(span, ev) {
+	select: function(footprint, ev) {
 		this.unselect(ev);
 		this.unselect(ev);
-		this.renderSelection(span);
-		this.reportSelection(span, ev);
+		this.renderSelection(footprint);
+		this.reportSelection(footprint, ev);
 	},
 	},
 
 
 
 
 	// Called when a new selection is made. Updates internal state and triggers handlers.
 	// Called when a new selection is made. Updates internal state and triggers handlers.
-	reportSelection: function(span, ev) {
+	reportSelection: function(footprint, ev) {
 		this.isSelected = true;
 		this.isSelected = true;
-		this.triggerSelect(span, ev);
+		this.triggerSelect(footprint, ev);
 	},
 	},
 
 
 
 
 	// Triggers handlers to 'select'
 	// Triggers handlers to 'select'
-	triggerSelect: function(span, ev) {
-		this.publiclyTrigger(
-			'select',
-			null,
-			this.calendar.applyTimezone(span.start), // convert to calendar's tz for external API
-			this.calendar.applyTimezone(span.end), // "
-			ev
-		);
+	triggerSelect: function(footprint, ev) {
+		var calendar = this.calendar;
+		var start = calendar.moment(footprint.dateRange.getStart());
+		var end = calendar.moment(footprint.dateRange.getEnd());
+
+		if (footprint.isAllDay) {
+			start.stripTime();
+			end.stripTime();
+		}
+
+		this.publiclyTrigger('select', null, start, end, ev);
 	},
 	},
 
 
 
 
@@ -914,13 +917,14 @@ var View = FC.View = ChronoComponent.extend({
 
 
 	// Triggers handlers to 'dayClick'
 	// Triggers handlers to 'dayClick'
 	// Span has start/end of the clicked area. Only the start is useful.
 	// Span has start/end of the clicked area. Only the start is useful.
-	triggerDayClick: function(span, dayEl, ev) {
-		this.publiclyTrigger(
-			'dayClick',
-			dayEl,
-			this.calendar.applyTimezone(span.start), // convert to calendar's timezone for external API
-			ev
-		);
+	triggerDayClick: function(footprint, dayEl, ev) {
+		var date = this.calendar.moment(footprint.dateRange.getStart()); // need the calendar's timezone
+
+		if (footprint.isAllDay) {
+			date.stripTime();
+		}
+
+		this.publiclyTrigger('dayClick', dayEl, date, ev);
 	}
 	}
 
 
 });
 });