Prechádzať zdrojové kódy

get external dropping to work

Adam Shaw 8 rokov pred
rodič
commit
04184a45f4
2 zmenil súbory, kde vykonal 48 pridanie a 25 odobranie
  1. 39 20
      src/common/Grid.events.js
  2. 9 5
      src/common/View.js

+ 39 - 20
src/common/Grid.events.js

@@ -555,7 +555,7 @@ Grid.mixin({
 		var _this = this;
 		var view = this.view;
 		var meta = getDraggedElMeta(el); // extra data about event drop, including possible event to create
-		var dropLocation; // a null value signals an unsuccessful drag
+		var singleEventDef; // a null value signals an unsuccessful drag
 
 		// listener that tracks mouse movement over date-associated pixel regions
 		var dragListener = _this.externalDragListener = new HitDragListener(this, {
@@ -564,36 +564,44 @@ Grid.mixin({
 			},
 			hitOver: function(hit) {
 				var isAllowed = true;
-				var hitSpan = hit.component.getSafeHitSpan(hit); // hit might not belong to this grid
+				var hitFootprint = hit.component.getSafeHitFootprint(hit); // hit might not belong to this grid
 
-				if (hitSpan) {
-					dropLocation = _this.computeExternalDrop(hitSpan, meta);
-					isAllowed = dropLocation && _this.isExternalLocationAllowed(dropLocation, meta.eventProps);
+				if (hitFootprint) {
+					singleEventDef = _this.computeExternalDrop(hitFootprint, meta);
+					isAllowed = Boolean(singleEventDef); // TODO --- && _this.isExternalLocationAllowed(singleEventDef, meta.eventProps);
 				}
 				else {
 					isAllowed = false;
 				}
 
 				if (!isAllowed) {
-					dropLocation = null;
+					singleEventDef = null;
 					disableCursor();
 				}
 
-				if (dropLocation) {
-					_this.renderDrag(dropLocation); // called without a seg parameter
+				if (singleEventDef) {
+					_this.renderDrag( // called without a seg parameter
+						new EventInstanceGroup(singleEventDef.buildInstances())
+							.buildRenderRanges(
+								new UnzonedRange(_this.start, _this.end),
+								view.calendar
+							)
+					);
 				}
 			},
 			hitOut: function() {
-				dropLocation = null; // signal unsuccessful
+				singleEventDef = null; // signal unsuccessful
 			},
 			hitDone: function() { // Called after a hitOut OR before a dragEnd
 				enableCursor();
 				_this.unrenderDrag();
 			},
 			interactionEnd: function(ev) {
-				if (dropLocation) { // element was dropped on a valid hit
-					view.reportExternalDrop(meta, dropLocation, el, ev, ui);
+
+				if (singleEventDef) { // element was dropped on a valid hit
+					view.reportExternalDrop(meta, singleEventDef, el, ev, ui);
 				}
+
 				_this.isDraggingExternal = false;
 				_this.externalDragListener = null;
 			}
@@ -607,23 +615,34 @@ Grid.mixin({
 	// returns the zoned start/end dates for the event that would result from the hypothetical drop. end might be null.
 	// Returning a null value signals an invalid drop hit.
 	// DOES NOT consider overlap/constraint.
-	computeExternalDrop: function(span, meta) {
+	computeExternalDrop: function(componentFootprint, meta) {
 		var calendar = this.view.calendar;
-		var dropLocation = {
-			start: calendar.applyTimezone(span.start), // simulate a zoned event start date
-			end: null
-		};
+		var start = calendar.moment(componentFootprint.dateRange.startMs);
+		var end;
+		var eventDef;
 
 		// if dropped on an all-day span, and element's metadata specified a time, set it
-		if (meta.startTime && !dropLocation.start.hasTime()) {
-			dropLocation.start.time(meta.startTime);
+		if (meta.startTime && componentFootprint.isAllDay) {
+			start.time(meta.startTime);
 		}
 
 		if (meta.duration) {
-			dropLocation.end = dropLocation.start.clone().add(meta.duration);
+			end = start.clone().add(meta.duration);
 		}
 
-		return dropLocation;
+		if (componentFootprint.isAllDay) {
+			start.stripTime();
+
+			if (end) {
+				end.stripTime();
+			}
+		}
+
+		eventDef = new SingleEventDefinition();
+		eventDef.start = start;
+		eventDef.end = end;
+
+		return eventDef;
 	},
 
 

+ 9 - 5
src/common/View.js

@@ -736,26 +736,30 @@ var View = FC.View = ChronoComponent.extend({
 	// Must be called when an external element, via jQuery UI, has been dropped onto the calendar.
 	// `meta` is the parsed data that has been embedded into the dragging event.
 	// `dropLocation` is an object that contains the new zoned start/end/allDay values for the event.
-	reportExternalDrop: function(meta, dropLocation, el, ev, ui) {
+	reportExternalDrop: function(meta, singleEventDef, el, ev, ui) {
 		var eventProps = meta.eventProps;
 		var eventInput;
 		var event;
 
 		// Try to build an event object and render it. TODO: decouple the two
+		// TODO: use singleEventDef directly without reparsing. but meta's props inside the def beforehand.
 		if (eventProps) {
-			eventInput = $.extend({}, eventProps, dropLocation);
+			eventInput = $.extend({}, eventProps, {
+				start: singleEventDef.start,
+				end: singleEventDef.end
+			});
 			event = this.calendar.renderEvent(eventInput, meta.stick)[0]; // renderEvent returns an array
 		}
 
-		this.triggerExternalDrop(event, dropLocation, el, ev, ui);
+		this.triggerExternalDrop(event, singleEventDef, el, ev, ui);
 	},
 
 
 	// Triggers external-drop handlers that have subscribed via the API
-	triggerExternalDrop: function(event, dropLocation, el, ev, ui) {
+	triggerExternalDrop: function(event, singleEventDef, el, ev, ui) {
 
 		// trigger 'drop' regardless of whether element represents an event
-		this.publiclyTrigger('drop', el[0], dropLocation.start, ev, ui);
+		this.publiclyTrigger('drop', el[0], singleEventDef.start, ev, ui);
 
 		if (event) {
 			this.publiclyTrigger('eventReceive', null, event); // signal an external event landed