Ver código fonte

rig up constraint system

Adam Shaw 8 anos atrás
pai
commit
b1cc06387d
3 arquivos alterados com 85 adições e 41 exclusões
  1. 19 0
      src/EventManager.js
  2. 51 40
      src/common/Grid.events.js
  3. 15 1
      src/common/Grid.js

+ 19 - 0
src/EventManager.js

@@ -1259,6 +1259,25 @@ Calendar.prototype.buildMutatedEventInstanceGroup = function(eventId, eventMutat
 -----------------------------------------------------------------------------------------*/
 
 
+Calendar.prototype.isEventFootprintAllowed = function(eventFootprint) {
+	console.log('isEventFootprintAllowed', eventFootprint);
+	return true;
+};
+
+
+// when it's a completely anonymous external drag, no event.
+Calendar.prototype.isExternalFootprintAllowed = function(componentFootprint) {
+	console.log('isExternalFootprintAllowed', componentFootprint);
+	return true;
+};
+
+
+Calendar.prototype.isSelectionFootprintAllowed = function(componentFootprint) {
+	console.log('isSelectionFootprintAllowed', componentFootprint);
+	return true;
+};
+
+
 // Determines if the given event can be relocated to the given span (unzoned start/end with other misc data)
 Calendar.prototype.isEventSpanAllowed = function(span, event) {
 	var source = event.source || {};

+ 51 - 40
src/common/Grid.events.js

@@ -362,8 +362,14 @@ Grid.mixin({
 
 				if (origFootprint && footprint) {
 					eventMutation = _this.computeEventDropMutation(origFootprint, footprint);
-					eventInstanceGroup = view.calendar.buildMutatedEventInstanceGroup(event._id, eventMutation);
-					isAllowed = Boolean(eventMutation); // TODO && _this.isEventLocationAllowed(dropLocation, event);
+
+					if (eventMutation) {
+						eventInstanceGroup = view.calendar.buildMutatedEventInstanceGroup(event._id, eventMutation);
+						isAllowed = _this.isEventInstanceGroupAllowed(eventInstanceGroup);
+					}
+					else {
+						isAllowed = false;
+					}
 				}
 				else {
 					isAllowed = false;
@@ -565,10 +571,20 @@ Grid.mixin({
 			hitOver: function(hit) {
 				var isAllowed = true;
 				var hitFootprint = hit.component.getSafeHitFootprint(hit); // hit might not belong to this grid
+				var eventInstanceGroup;
 
 				if (hitFootprint) {
 					singleEventDef = _this.computeExternalDrop(hitFootprint, meta);
-					isAllowed = Boolean(singleEventDef); // TODO --- && _this.isExternalLocationAllowed(singleEventDef, meta.eventProps);
+
+					if (singleEventDef) {
+						eventInstanceGroup = new EventInstanceGroup(singleEventDef.buildInstances());
+						isAllowed = meta.eventProps ? // isEvent?
+							_this.isEventInstanceGroupAllowed(eventInstanceGroup) :
+							_this.isExternalInstanceGroupAllowed(eventInstanceGroup);
+					}
+					else {
+						isAllowed = false;
+					}
 				}
 				else {
 					isAllowed = false;
@@ -717,7 +733,7 @@ Grid.mixin({
 
 					if (resizeMutation) {
 						eventInstanceGroup = calendar.buildMutatedEventInstanceGroup(event._id, resizeMutation);
-						isAllowed = true; // TODO && _this.isEventLocationAllowed(resizeLocation, event);
+						isAllowed = _this.isEventInstanceGroupAllowed(eventInstanceGroup);
 					}
 					else {
 						isAllowed = false;
@@ -989,55 +1005,50 @@ Grid.mixin({
 	------------------------------------------------------------------------------------------------------------------*/
 
 
-	isEventLocationAllowed: function(eventLocation, event) {
-		if (this.isEventLocationInRange(eventLocation)) {
-			var calendar = this.view.calendar;
-			var eventSpans = this.eventToSpans(eventLocation);
-			var i;
+	// TODO: more DRY
+	isEventInstanceGroupAllowed: function(eventInstanceGroup) {
+		var calendar = this.view.calendar;
+		var eventRanges = eventInstanceGroup.buildEventRanges(null, calendar);
+		var eventFootprints = this.eventRangesToEventFootprints(eventRanges);
+		var i;
 
-			if (eventSpans.length) {
-				for (i = 0; i < eventSpans.length; i++) {
-					if (!calendar.isEventSpanAllowed(eventSpans[i], event)) {
-						return false;
-					}
-				}
+		for (i = 0; i < eventFootprints.length; i++) {
+			if (!this.isFootprintInRange(eventFootprints[i].componentFootprint)) {
+				return false;
+			}
+		}
 
-				return true;
+		for (i = 0; i < eventFootprints.length; i++) {
+			if (!calendar.isEventFootprintAllowed(eventFootprints[i])) {
+				return false;
 			}
 		}
 
-		return false;
+		return true;
 	},
 
 
-	isExternalLocationAllowed: function(eventLocation, metaProps) { // FOR the external element
-		if (this.isEventLocationInRange(eventLocation)) {
-			var calendar = this.view.calendar;
-			var eventSpans = this.eventToSpans(eventLocation);
-			var i;
-
-			if (eventSpans.length) {
-				for (i = 0; i < eventSpans.length; i++) {
-					if (!calendar.isExternalSpanAllowed(eventSpans[i], eventLocation, metaProps)) {
-						return false;
-					}
-				}
+	// TODO: more DRY
+	// when it's a completely anonymous external drag, no event.
+	isExternalInstanceGroupAllowed: function(eventInstanceGroup) {
+		var calendar = this.view.calendar;
+		var eventRanges = eventInstanceGroup.buildEventRanges(null, calendar);
+		var eventFootprints = this.eventRangesToEventFootprints(eventRanges);
+		var i;
 
-				return true;
+		for (i = 0; i < eventFootprints.length; i++) {
+			if (!this.isFootprintInRange(eventFootprints[i].componentFootprint)) {
+				return false;
 			}
 		}
 
-		return false;
-	},
-
-
-	isEventLocationInRange: function(eventLocation) {
-		return false;
+		for (i = 0; i < eventFootprints.length; i++) {
+			if (!calendar.isExternalFootprintAllowed(eventFootprints[i])) {
+				return false;
+			}
+		}
 
-		return isRangeWithinRange(
-			//this.eventToRawRange(eventLocation),
-			this.view.validRange
-		);
+		return true;
 	},
 
 

+ 15 - 1
src/common/Grid.js

@@ -488,7 +488,7 @@ var Grid = FC.Grid = ChronoComponent.extend({
 	computeSelection: function(footprint0, footprint1) {
 		var wholeFootprint = this.computeSelectionFootprint(footprint0, footprint1);
 
-		if (span && !this.view.calendar.isSelectionSpanAllowed(span)) {
+		if (wholeFootprint && !this.isSelectionFootprintAllowed(wholeFootprint)) {
 			return false;
 		}
 
@@ -515,6 +515,20 @@ var Grid = FC.Grid = ChronoComponent.extend({
 	},
 
 
+	isSelectionFootprintAllowed: function(componentFootprint) {
+		return this.isFootprintInRange(componentFootprint) &&
+			this.view.calendar.isSelectionFootprintAllowed(componentFootprint);
+	},
+
+
+	isFootprintInRange: function(componentFootprint) { // used by other things too
+		return isRangeWithinRange(
+			componentFootprint.dateRange.getRange(),
+			this.view.validRange
+		);
+	},
+
+
 	/* Highlight
 	------------------------------------------------------------------------------------------------------------------*/