Browse Source

more separation of Grid.js

Adam Shaw 8 năm trước cách đây
mục cha
commit
da6f74f278
4 tập tin đã thay đổi với 168 bổ sung159 xóa
  1. 8 1
      src.json
  2. 45 0
      src/common/Grid.day-click.js
  3. 113 0
      src/common/Grid.day-selection.js
  4. 2 158
      src/common/Grid.js

+ 8 - 1
src.json

@@ -22,8 +22,15 @@
     "common/MouseFollower.js",
     "common/ChronoComponent.js",
     "common/Grid.js",
+    "common/Grid.day-click.js",
+    "common/Grid.day-selection.js",
+    "common/Grid.business-hours.js",
+    "common/Grid.event-rendering.js",
+    "common/Grid.event-interaction.js",
+    "common/Grid.event-dragging.js",
+    "common/Grid.event-resizing.js",
+    "common/Grid.external-dropping.js",
     "common/Grid.fill.js",
-    "common/Grid.events.js",
     "common/DayTableMixin.js",
     "common/DayGrid.js",
     "common/DayGrid.events.js",

+ 45 - 0
src/common/Grid.day-click.js

@@ -0,0 +1,45 @@
+
+Grid.mixin({
+
+	// Creates a listener that tracks the user's drag across day elements, for day clicking.
+	buildDayClickListener: function() {
+		var _this = this;
+		var dayClickHit; // null if invalid dayClick
+
+		var dragListener = new HitDragListener(this, {
+			scroll: this.opt('dragScroll'),
+			interactionStart: function() {
+				dayClickHit = dragListener.origHit;
+			},
+			hitOver: function(hit, isOrig, origHit) {
+				// if user dragged to another cell at any point, it can no longer be a dayClick
+				if (!isOrig) {
+					dayClickHit = null;
+				}
+			},
+			hitOut: function() { // called before mouse moves to a different hit OR moved out of all hits
+				dayClickHit = null;
+			},
+			interactionEnd: function(ev, isCancelled) {
+				var componentFootprint;
+
+				if (!isCancelled && dayClickHit) {
+					componentFootprint = _this.getSafeHitFootprint(dayClickHit);
+
+					if (componentFootprint) {
+						_this.view.triggerDayClick(componentFootprint, _this.getHitEl(dayClickHit), ev);
+					}
+				}
+			}
+		});
+
+		// because dayClickListener won't be called with any time delay, "dragging" will begin immediately,
+		// which will kill any touchmoving/scrolling. Prevent this.
+		dragListener.shouldCancelTouchScroll = false;
+
+		dragListener.scrollAlwaysKills = true;
+
+		return dragListener;
+	}
+
+});

+ 113 - 0
src/common/Grid.day-selection.js

@@ -0,0 +1,113 @@
+
+Grid.mixin({
+
+	// Creates a listener that tracks the user's drag across day elements, for day selecting.
+	buildDaySelectListener: function() {
+		var _this = this;
+		var selectionFootprint; // null if invalid selection
+
+		var dragListener = new HitDragListener(this, {
+			scroll: this.opt('dragScroll'),
+			interactionStart: function() {
+				selectionFootprint = null;
+			},
+			dragStart: function() {
+				_this.view.unselect(); // since we could be rendering a new selection, we want to clear any old one
+			},
+			hitOver: function(hit, isOrig, origHit) {
+				var origHitFootprint;
+				var hitFootprint;
+
+				if (origHit) { // click needs to have started on a hit
+
+					origHitFootprint = _this.getSafeHitFootprint(origHit);
+					hitFootprint = _this.getSafeHitFootprint(hit);
+
+					if (origHitFootprint && hitFootprint) {
+						selectionFootprint = _this.computeSelection(origHitFootprint, hitFootprint);
+					}
+					else {
+						selectionFootprint = null;
+					}
+
+					if (selectionFootprint) {
+						_this.renderSelectionFootprint(selectionFootprint);
+					}
+					else if (selectionFootprint === false) {
+						disableCursor();
+					}
+				}
+			},
+			hitOut: function() { // called before mouse moves to a different hit OR moved out of all hits
+				selectionFootprint = null;
+				_this.unrenderSelection();
+			},
+			hitDone: function() { // called after a hitOut OR before a dragEnd
+				enableCursor();
+			},
+			interactionEnd: function(ev, isCancelled) {
+				if (!isCancelled && selectionFootprint) {
+					// the selection will already have been rendered. just report it
+					_this.view.reportSelection(selectionFootprint, ev);
+				}
+			}
+		});
+
+		return dragListener;
+	},
+
+
+	// 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)
+	renderSelectionFootprint: function(componentFootprint) {
+		this.renderHighlight(componentFootprint);
+	},
+
+
+	// Unrenders any visual indications of a selection. Will unrender a highlight by default.
+	unrenderSelection: function() {
+		this.unrenderHighlight();
+	},
+
+
+	// Given the first and last date-spans of a selection, returns another date-span object.
+	// Subclasses can override and provide additional data in the span object. Will be passed to renderSelectionFootprint().
+	// 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.
+	computeSelection: function(footprint0, footprint1) {
+		var wholeFootprint = this.computeSelectionFootprint(footprint0, footprint1);
+
+		if (wholeFootprint && !this.isSelectionFootprintAllowed(wholeFootprint)) {
+			return false;
+		}
+
+		return wholeFootprint;
+	},
+
+
+	// Given two spans, must return the combination of the two.
+	// TODO: do this separation of concerns (combining VS validation) for event dnd/resize too.
+	// Assumes both footprints are non-open-ended.
+	computeSelectionFootprint: function(footprint0, footprint1) {
+		var ms = [
+			footprint0.unzonedRange.startMs,
+			footprint0.unzonedRange.endMs,
+			footprint1.unzonedRange.startMs,
+			footprint1.unzonedRange.endMs
+		];
+
+		ms.sort(compareNumbers);
+
+		return new ComponentFootprint(
+			new UnzonedRange(ms[0], ms[3]),
+			footprint0.isAllDay
+		);
+	},
+
+
+	isSelectionFootprintAllowed: function(componentFootprint) {
+		return this.view.validUnzonedRange.containsRange(componentFootprint.unzonedRange) &&
+			this.view.calendar.isSelectionFootprintAllowed(componentFootprint);
+	}
+
+});

+ 2 - 158
src/common/Grid.js

@@ -2,10 +2,10 @@
 /* An abstract class comprised of a "grid" of areas that each represent a specific datetime
 ----------------------------------------------------------------------------------------------------------------------
 Contains:
-- day click
-- selection
 - hit system
 - range->footprint->seg pipeline
+- initializing day click
+- initializing selection system
 - initializing mouse/touch handlers for everything
 - initializing event rendering-related options
 */
@@ -250,104 +250,6 @@ var Grid = FC.Grid = ChronoComponent.extend({
 	},
 
 
-	// Creates a listener that tracks the user's drag across day elements, for day clicking.
-	buildDayClickListener: function() {
-		var _this = this;
-		var dayClickHit; // null if invalid dayClick
-
-		var dragListener = new HitDragListener(this, {
-			scroll: this.opt('dragScroll'),
-			interactionStart: function() {
-				dayClickHit = dragListener.origHit;
-			},
-			hitOver: function(hit, isOrig, origHit) {
-				// if user dragged to another cell at any point, it can no longer be a dayClick
-				if (!isOrig) {
-					dayClickHit = null;
-				}
-			},
-			hitOut: function() { // called before mouse moves to a different hit OR moved out of all hits
-				dayClickHit = null;
-			},
-			interactionEnd: function(ev, isCancelled) {
-				var componentFootprint;
-
-				if (!isCancelled && dayClickHit) {
-					componentFootprint = _this.getSafeHitFootprint(dayClickHit);
-
-					if (componentFootprint) {
-						_this.view.triggerDayClick(componentFootprint, _this.getHitEl(dayClickHit), ev);
-					}
-				}
-			}
-		});
-
-		// because dayClickListener won't be called with any time delay, "dragging" will begin immediately,
-		// which will kill any touchmoving/scrolling. Prevent this.
-		dragListener.shouldCancelTouchScroll = false;
-
-		dragListener.scrollAlwaysKills = true;
-
-		return dragListener;
-	},
-
-
-	// Creates a listener that tracks the user's drag across day elements, for day selecting.
-	buildDaySelectListener: function() {
-		var _this = this;
-		var selectionFootprint; // null if invalid selection
-
-		var dragListener = new HitDragListener(this, {
-			scroll: this.opt('dragScroll'),
-			interactionStart: function() {
-				selectionFootprint = null;
-			},
-			dragStart: function() {
-				_this.view.unselect(); // since we could be rendering a new selection, we want to clear any old one
-			},
-			hitOver: function(hit, isOrig, origHit) {
-				var origHitFootprint;
-				var hitFootprint;
-
-				if (origHit) { // click needs to have started on a hit
-
-					origHitFootprint = _this.getSafeHitFootprint(origHit);
-					hitFootprint = _this.getSafeHitFootprint(hit);
-
-					if (origHitFootprint && hitFootprint) {
-						selectionFootprint = _this.computeSelection(origHitFootprint, hitFootprint);
-					}
-					else {
-						selectionFootprint = null;
-					}
-
-					if (selectionFootprint) {
-						_this.renderSelectionFootprint(selectionFootprint);
-					}
-					else if (selectionFootprint === false) {
-						disableCursor();
-					}
-				}
-			},
-			hitOut: function() { // called before mouse moves to a different hit OR moved out of all hits
-				selectionFootprint = null;
-				_this.unrenderSelection();
-			},
-			hitDone: function() { // called after a hitOut OR before a dragEnd
-				enableCursor();
-			},
-			interactionEnd: function(ev, isCancelled) {
-				if (!isCancelled && selectionFootprint) {
-					// the selection will already have been rendered. just report it
-					_this.view.reportSelection(selectionFootprint, ev);
-				}
-			}
-		});
-
-		return dragListener;
-	},
-
-
 	// Kills all in-progress dragging.
 	// Useful for when public API methods that result in re-rendering are invoked during a drag.
 	// Also useful for when touch devices misbehave and don't fire their touchend.
@@ -367,64 +269,6 @@ var Grid = FC.Grid = ChronoComponent.extend({
 	},
 
 
-	/* Selection
-	------------------------------------------------------------------------------------------------------------------*/
-
-
-	// 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)
-	renderSelectionFootprint: function(componentFootprint) {
-		this.renderHighlight(componentFootprint);
-	},
-
-
-	// Unrenders any visual indications of a selection. Will unrender a highlight by default.
-	unrenderSelection: function() {
-		this.unrenderHighlight();
-	},
-
-
-	// Given the first and last date-spans of a selection, returns another date-span object.
-	// Subclasses can override and provide additional data in the span object. Will be passed to renderSelectionFootprint().
-	// 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.
-	computeSelection: function(footprint0, footprint1) {
-		var wholeFootprint = this.computeSelectionFootprint(footprint0, footprint1);
-
-		if (wholeFootprint && !this.isSelectionFootprintAllowed(wholeFootprint)) {
-			return false;
-		}
-
-		return wholeFootprint;
-	},
-
-
-	// Given two spans, must return the combination of the two.
-	// TODO: do this separation of concerns (combining VS validation) for event dnd/resize too.
-	// Assumes both footprints are non-open-ended.
-	computeSelectionFootprint: function(footprint0, footprint1) {
-		var ms = [
-			footprint0.unzonedRange.startMs,
-			footprint0.unzonedRange.endMs,
-			footprint1.unzonedRange.startMs,
-			footprint1.unzonedRange.endMs
-		];
-
-		ms.sort(compareNumbers);
-
-		return new ComponentFootprint(
-			new UnzonedRange(ms[0], ms[3]),
-			footprint0.isAllDay
-		);
-	},
-
-
-	isSelectionFootprintAllowed: function(componentFootprint) {
-		return this.view.validUnzonedRange.containsRange(componentFootprint.unzonedRange) &&
-			this.view.calendar.isSelectionFootprintAllowed(componentFootprint);
-	},
-
-
 	/* Highlight
 	------------------------------------------------------------------------------------------------------------------*/