fix(calendar(js)): swap start-end dates when delta is negative

When creating an event by drag'n'dropping from bottom to top, the
original coordinate become the start date.
This commit is contained in:
Francis Lachapelle
2019-10-30 13:46:07 -04:00
parent 060dea3818
commit 8b45f2c731
2 changed files with 11 additions and 1 deletions
@@ -222,16 +222,19 @@
// Adjust component or create new component through drag'n'drop
function updateComponentFromGhost($event) {
var component, pointerHandler, coordinates, delta, params, calendarNumber, activeCalendars;
var component, pointerHandler, originalCoordinates, coordinates, delta, params, calendarNumber, activeCalendars;
component = Component.$ghost.component;
pointerHandler = Component.$ghost.pointerHandler;
if (component.isNew) {
originalCoordinates = pointerHandler.originalEventCoordinates;
coordinates = pointerHandler.currentEventCoordinates;
component.summary = '';
if (component.isAllDay)
coordinates.duration -= 96;
if (coordinates.start < originalCoordinates.start)
coordinates.duration *= -1;
component.setDelta(coordinates.duration * 15);
newComponent(null, 'appointment', component)
.catch()
@@ -759,6 +759,13 @@
* @param {number} delta - the number of minutes
*/
Component.prototype.setDelta = function(delta) {
if (delta < 0) {
var start = new Date(this.start.getTime());
start.setMinutes(Math.round(start.getMinutes()/15)*15);
start.addMinutes(delta);
this.start = start;
delta *= -1;
}
this.delta = delta;
this.end = new Date(this.start.getTime());
this.end.setMinutes(Math.round(this.end.getMinutes()/15)*15);