Sfoglia il codice sorgente

change the format of a 'hit'

Adam Shaw 10 anni fa
parent
commit
e784e70cbc

+ 4 - 4
src/agenda/AgendaView.js

@@ -275,14 +275,14 @@ var AgendaView = fc.AgendaView = View.extend({
 
 
 	getHitSpan: function(hit) {
-		// TODO: hit.grid is set as a hack to identify which grid the hit came from
-		return hit.grid.getHitSpan(hit);
+		// TODO: hit.component is set as a hack to identify where the hit came from
+		return hit.component.getHitSpan(hit);
 	},
 
 
 	getHitEl: function(hit) {
-		// TODO: hit.grid is set as a hack to identify which grid the hit came from
-		return hit.grid.getHitEl(hit);
+		// TODO: hit.component is set as a hack to identify where the hit came from
+		return hit.component.getHitEl(hit);
 	},
 
 

+ 5 - 4
src/common/DayGrid.js

@@ -226,12 +226,12 @@ var DayGrid = fc.DayGrid = Grid.extend($.extend({}, DayTableMixin, {
 
 
 	getHitSpan: function(hit) {
-		return this.getCellRange(hit.id[0], hit.id[1]);
+		return this.getCellRange(hit.row, hit.col);
 	},
 
 
 	getHitEl: function(hit) {
-		return this.getCellEl(hit.id[0], hit.id[1]);
+		return this.getCellEl(hit.row, hit.col);
 	},
 
 
@@ -242,8 +242,9 @@ var DayGrid = fc.DayGrid = Grid.extend($.extend({}, DayTableMixin, {
 
 	getCellHit: function(row, col) {
 		return {
-			grid: this, // needed unfortunately :(
-			id: [ row, col ], // TODO: move away from id array
+			row: row,
+			col: col,
+			component: this, // needed unfortunately :(
 			left: this.colCoordCache.getLeftOffset(col),
 			right: this.colCoordCache.getRightOffset(col),
 			top: this.rowCoordCache.getTopOffset(row),

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

@@ -286,8 +286,8 @@ Grid.mixin({
 
 				// since we are querying the parent view, might not belong to this grid
 				dropLocation = _this.computeEventDrop(
-					origHit.grid.getHitSpan(origHit),
-					hit.grid.getHitSpan(hit),
+					origHit.component.getHitSpan(origHit),
+					hit.component.getHitSpan(hit),
 					event
 				);
 
@@ -453,7 +453,7 @@ Grid.mixin({
 			},
 			hitOver: function(hit) {
 				dropLocation = _this.computeExternalDrop(
-					hit.grid.getHitSpan(hit), // since we are querying the parent view, might not belong to this grid
+					hit.component.getHitSpan(hit), // since we are querying the parent view, might not belong to this grid
 					meta
 				);
 				if (dropLocation) {

+ 10 - 14
src/common/HitDragListener.js

@@ -189,27 +189,23 @@ function isHitsEqual(hit0, hit1) {
 	}
 
 	if (hit0 && hit1) {
-		return hit0.grid === hit1.grid && // TODO: referencing a "grid" is bad. should be more general
-			isHitIdsEqual(hit0.id, hit1.id);
+		return hit0.component === hit1.component &&
+			isHitPropsWithin(hit0, hit1) &&
+			isHitPropsWithin(hit1, hit0); // ensures all props are identical
 	}
 
 	return false;
 }
 
 
-function isHitIdsEqual(id0, id1) {
-	id0 = [].concat(id0);
-	id1 = [].concat(id1);
-
-	if (id0.length !== id1.length) {
-		return false;
-	}
-
-	for (var i = 0; i < id0.length; i++) {
-		if (id0[i] !== id1[i]) {
-			return false;
+// Returns true if all of subHit's non-standard properties are within superHit
+function isHitPropsWithin(subHit, superHit) {
+	for (var propName in subHit) {
+		if (!/^(component|left|right|top|bottom)$/.test(propName)) {
+			if (subHit[propName] !== superHit[propName]) {
+				return false;
+			}
 		}
 	}
-
 	return true;
 }

+ 9 - 9
src/common/TimeGrid.js

@@ -215,8 +215,9 @@ var TimeGrid = fc.TimeGrid = Grid.extend($.extend({}, DayTableMixin, {
 			var snapBottom = slatTop + ((localSnapIndex + 1) / snapsPerSlot) * slatHeight;
 
 			return {
-				grid: this, // needed unfortunately :(
-				id: [ colIndex, snapIndex ], // TODO: move away from id index
+				col: colIndex,
+				snap: snapIndex,
+				component: this, // needed unfortunately :(
 				left: colCoordCache.getLeftOffset(colIndex),
 				right: colCoordCache.getRightOffset(colIndex),
 				top: snapTop,
@@ -227,21 +228,20 @@ var TimeGrid = fc.TimeGrid = Grid.extend($.extend({}, DayTableMixin, {
 
 
 	getHitSpan: function(hit) {
-		var colIndex = hit.id[0];
-		var snapIndex = hit.id[1];
-		var date = this.getCellDate(0, colIndex); // row=0
-		var time = this.computeSnapTime(snapIndex);
-
+		var date = this.getCellDate(0, hit.col); // row=0
+		var time = this.computeSnapTime(hit.snap); // pass in the snap-index
 		var start = this.view.calendar.rezoneDate(date); // gives it a 00:00 time
+		var end;
+
 		start.time(time);
-		var end = start.clone().add(this.snapDuration);
+		end = start.clone().add(this.snapDuration);
 
 		return { start: start, end: end };
 	},
 
 
 	getHitEl: function(hit) {
-		return this.colEls.eq(hit.id[0]);
+		return this.colEls.eq(hit.col);
 	},