- Fix drag & drop an event inside a group or consolidated calendar asked to move or invite

- Fix some drag to create bugs throwing errors
This commit is contained in:
nathangray 2016-07-11 15:23:11 -06:00
parent 4e0fbfad9c
commit 23edb3cc5a
2 changed files with 139 additions and 1 deletions

View File

@ -230,6 +230,21 @@ var et2_calendar_timegrid = (function(){ "use strict"; return et2_calendar_view.
} }
}, },
/**
* If dragging to resize an event, abort drag to create
*
* @param {jQuery.Event} event
* @param {Object} ui
*/
start: function(event, ui)
{
if(timegrid.drag_create.start)
{
// Abort drag to create, we're dragging to resize
timegrid._drag_create_end({});
}
},
/** /**
* Triggered at the end of resizing the calEvent. * Triggered at the end of resizing the calEvent.
* *
@ -306,6 +321,10 @@ var et2_calendar_timegrid = (function(){ "use strict"; return et2_calendar_view.
.css('top', '').css('left','') .css('top', '').css('left','')
.appendTo(ui.helper); .appendTo(ui.helper);
ui.helper.width(jQuery(this).width()); ui.helper.width(jQuery(this).width());
// Cancel drag to create, we're dragging an existing event
timegrid.drag_create.start = null;
timegrid._drag_create_end();
}) })
.on('mousemove', function(event) { .on('mousemove', function(event) {
timegrid._get_time_from_position(event.clientX, event.clientY); timegrid._get_time_from_position(event.clientX, event.clientY);
@ -315,7 +334,9 @@ var et2_calendar_timegrid = (function(){ "use strict"; return et2_calendar_view.
{ {
timegrid.gridHover.hide(); timegrid.gridHover.hide();
} }
}); })
.on('mousedown', jQuery.proxy(this._mouse_down, this))
.on('mouseup', jQuery.proxy(this._mouse_up, this));
return true; return true;
}, },
@ -1762,6 +1783,9 @@ var et2_calendar_timegrid = (function(){ "use strict"; return et2_calendar_view.
{ {
var result = true; var result = true;
// Drag to create in progress
if(this.drag_create.start !== null) return;
// Is this click in the event stuff, or in the header? // Is this click in the event stuff, or in the header?
if(_ev.target.dataset.id || jQuery(_ev.target).parents('.calendar_calEvent').length) if(_ev.target.dataset.id || jQuery(_ev.target).parents('.calendar_calEvent').length)
{ {
@ -1840,6 +1864,110 @@ var et2_calendar_timegrid = (function(){ "use strict"; return et2_calendar_view.
} }
}, },
/**
* Mousedown handler to support drag to create
*
* @param {jQuery.Event} event
*/
_mouse_down: function(event)
{
var start = jQuery.extend({},this.gridHover[0].dataset);
if(start.date)
{
// Set parent for event
if(this.daily_owner)
{
// Each 'day' is the same date, different user
// Find the correct row so we know the parent
var col = event.target.closest('.calendar_calDayCol');
for(var i = 0; i < this._children.length && col; i++)
{
if(this._children[i].node === col)
{
this.drag_create.parent = this._children[i];
break;
}
}
}
else
{
this.drag_create.parent = this.getWidgetById(start.date);
}
// Format date
this.date_helper.set_year(start.date.substring(0,4));
this.date_helper.set_month(start.date.substring(4,6));
this.date_helper.set_date(start.date.substring(6,8));
if(start.hour)
{
this.date_helper.set_hours(start.hour);
}
if(start.minute)
{
this.date_helper.set_minutes(start.minute);
}
start.date = this.date_helper.get_value();
this.gridHover.css('cursor', 'ns-resize');
// Start update
var timegrid = this;
this.div.on('mousemove.dragcreate', function()
{
if(timegrid.drag_create.event && timegrid.drag_create.parent && timegrid.drag_create.end)
{
var end = jQuery.extend({}, timegrid.gridHover[0].dataset);
if(end.date)
{
timegrid.date_helper.set_year(end.date.substring(0,4));
timegrid.date_helper.set_month(end.date.substring(4,6));
timegrid.date_helper.set_date(end.date.substring(6,8));
if(end.hour)
{
timegrid.date_helper.set_hours(end.hour);
}
if(end.minute)
{
timegrid.date_helper.set_minutes(end.minute);
}
timegrid.drag_create.end.date = timegrid.date_helper.get_value();
}
timegrid._drag_update_event();
}
});
}
return this._drag_create_start(start);
},
/**
* Mouseup handler to support drag to create
*
* @param {jQuery.Event} event
*/
_mouse_up: function(event)
{
var end = jQuery.extend({}, this.gridHover[0].dataset);
if(end.date)
{
this.date_helper.set_year(end.date.substring(0,4));
this.date_helper.set_month(end.date.substring(4,6));
this.date_helper.set_date(end.date.substring(6,8));
if(end.hour)
{
this.date_helper.set_hours(end.hour);
}
if(end.minute)
{
this.date_helper.set_minutes(end.minute);
}
end.date = this.date_helper.get_value();
}
this.div.off('mousemove.dragcreate');
this.gridHover.css('cursor', '');
return this._drag_create_end(end);
},
/** /**
* Get time from position for drag and drop * Get time from position for drag and drop
* *
@ -1888,6 +2016,8 @@ var et2_calendar_timegrid = (function(){ "use strict"; return et2_calendar_view.
height: $node.css('padding-bottom') height: $node.css('padding-bottom')
}); });
day = node; day = node;
this.gridHover
.attr('data-non_blocking','true');
break; break;
} }
if($node.hasClass('calendar_calDayCol')) if($node.hasClass('calendar_calDayCol'))

View File

@ -57,6 +57,14 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
this.loader = jQuery('<div class="egw-loading-prompt-container ui-front loading"></div>'); this.loader = jQuery('<div class="egw-loading-prompt-container ui-front loading"></div>');
this.update_timer = null; this.update_timer = null;
// Used to support dragging on empty space to create an event
this.drag_create = {
start: null,
end: null,
parent: null,
event: null
};
}, },
destroy: function destroy() { destroy: function destroy() {