Adam Shaw пре 8 година
родитељ
комит
78770261b6
4 измењених фајлова са 47 додато и 57 уклоњено
  1. 27 0
      src/Calendar.moment.js
  2. 12 23
      src/common/Grid.events.js
  3. 4 16
      src/common/Grid.js
  4. 4 18
      src/models/event/EventDefDateMutation.js

+ 27 - 0
src/Calendar.moment.js

@@ -133,6 +133,33 @@ Calendar.mixin({
 	},
 
 
+	footprintToDateProfile: function(componentFootprint, ignoreEnd) {
+		var start = FC.moment.utc(componentFootprint.dateRange.startMs);
+		var end;
+
+		if (!ignoreEnd) {
+			end = FC.moment.utc(componentFootprint.dateRange.endMs);
+		}
+
+		if (componentFootprint.isAllDay) {
+			start.stripTime();
+
+			if (end) {
+				end.stripTime();
+			}
+		}
+		else {
+			start = this.applyTimezone(start);
+
+			if (end) {
+				end = this.applyTimezone(end);
+			}
+		}
+
+		return new EventDateProfile(start, end);
+	},
+
+
 	// Returns a moment for the current date, as defined by the client's computer or from the `now` option.
 	// Will return an moment with an ambiguous timezone.
 	getNow: function() {

+ 12 - 23
src/common/Grid.events.js

@@ -650,39 +650,28 @@ Grid.mixin({
 	// DOES NOT consider overlap/constraint.
 	computeExternalDrop: function(componentFootprint, meta) {
 		var calendar = this.view.calendar;
-		var isAllDay = componentFootprint.isAllDay;
 		var start = FC.moment.utc(componentFootprint.dateRange.startMs).stripZone();
 		var end;
 		var eventDef;
 
-		// if dropped on an all-day span, and element's metadata specified a time, set it
-		if (meta.startTime && isAllDay) {
-			start.time(meta.startTime);
-			isAllDay = false;
+		if (componentFootprint.isAllDay) {
+			// if dropped on an all-day span, and element's metadata specified a time, set it
+			if (meta.startTime) {
+				start.time(meta.startTime);
+			}
+			else {
+				start.stripTime();
+			}
 		}
 
 		if (meta.duration) {
 			end = start.clone().add(meta.duration);
 		}
 
-		// TODO: make DRY with fabricateEventFootprint!
-		if (isAllDay) {
-			start.stripTime();
-			if (end) {
-				end.stripTime();
-			}
-		}
-		else if (calendar.opt('timezone') === 'local') {
-			start.local();
-			if (end) {
-				end.local();
-			}
-		}
-		else if (calendar.opt('timezone') === 'UTC') {
-			start.utc();
-			if (end) {
-				end.utc();
-			}
+		start = calendar.applyTimezone(start);
+
+		if (end) {
+			end = calendar.applyTimezone(end);
 		}
 
 		eventDef = SingleEventDef.parse(

+ 4 - 16
src/common/Grid.js

@@ -467,25 +467,13 @@ var Grid = FC.Grid = ChronoComponent.extend({
 
 	fabricateEventFootprint: function(componentFootprint) {
 		var calendar = this.view.calendar;
+		var eventDateProfile = calendar.footprintToDateProfile(componentFootprint);
 		var dummyEvent = new SingleEventDef(new EventSource(calendar));
 		var dummyInstance;
 
-		dummyEvent.start = FC.moment.utc(componentFootprint.dateRange.startMs).stripZone();
-		dummyEvent.end = FC.moment.utc(componentFootprint.dateRange.endMs).stripZone();
-
-		// TODO: make DRY with computeExternalDrop!
-		if (componentFootprint.isAllDay) {
-			dummyEvent.start.stripTime();
-			dummyEvent.end.stripTime();
-		}
-		else if (calendar.opt('timezone') === 'local') {
-			dummyEvent.start.local();
-			dummyEvent.end.local();
-		}
-		else if (calendar.opt('timezone') === 'UTC') {
-			dummyEvent.start.utc();
-			dummyEvent.end.utc();
-		}
+		// TODO: have SingleEventDef leverage EventDateProfile and kill EventStartEndMixin?
+		dummyEvent.start = eventDateProfile.start;
+		dummyEvent.end = eventDateProfile.end;
 
 		dummyInstance = dummyEvent.buildInstances()[0];
 

+ 4 - 18
src/models/event/EventDefDateMutation.js

@@ -75,25 +75,11 @@ var EventDefDateMutation = Class.extend({
 			start.add(this.startDelta);
 		}
 
-		// TODO: make more DRY
 		if (shouldRezone) {
-			if (calendar.opt('timezone') === 'UTC') {
-				start.utc();
-				if (end) {
-					end.utc();
-				}
-			}
-			else if (calendar.opt('timezone') === 'local') {
-				start.local();
-				if (end) {
-					end.local();
-				}
-			}
-			else {
-				start.stripZone();
-				if (end) {
-					end.stripZone();
-				}
+			start = calendar.applyTimezone(start);
+
+			if (end) {
+				end = calendar.applyTimezone(end);
 			}
 		}