mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 00:54:15 +01:00
- 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:
parent
25fb771435
commit
4e0fbfad9c
@ -283,6 +283,9 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e
|
||||
.css('top', '').css('left','')
|
||||
.appendTo(ui.helper);
|
||||
ui.helper.width(jQuery(this).width());
|
||||
|
||||
// Cancel drag to create, we're dragging an existing event
|
||||
planner._drag_create_end();
|
||||
});
|
||||
return true;
|
||||
},
|
||||
@ -1873,6 +1876,61 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e
|
||||
return new Date(this.date_helper.getValue());
|
||||
},
|
||||
|
||||
/**
|
||||
* Mousedown handler to support drag to create
|
||||
*
|
||||
* @param {jQuery.Event} event
|
||||
*/
|
||||
_mouse_down: function(event)
|
||||
{
|
||||
// Get time at mouse
|
||||
if(this.options.group_by === 'month')
|
||||
{
|
||||
var time = this._get_time_from_position(event.clientX, event.clientY);
|
||||
}
|
||||
else
|
||||
{
|
||||
var time = this._get_time_from_position(event.offsetX, event.offsetY);
|
||||
}
|
||||
if(!time) return false;
|
||||
|
||||
this.div.css('cursor', 'ew-resize');
|
||||
|
||||
// Find the correct row so we know the parent
|
||||
var row = event.target.closest('.calendar_plannerRowWidget');
|
||||
for(var i = 0; i < this._children.length && row; i++)
|
||||
{
|
||||
if(this._children[i].div[0] === row)
|
||||
{
|
||||
this.drag_create.parent = this._children[i];
|
||||
// Clear cached events for re-layout
|
||||
this._children[i]._cached_rows = [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return this._drag_create_start(jQuery.extend({},this.drag_create.parent.node.dataset,{date: time.toJSON()}));
|
||||
},
|
||||
|
||||
/**
|
||||
* Mouseup handler to support drag to create
|
||||
*
|
||||
* @param {jQuery.Event} event
|
||||
*/
|
||||
_mouse_up: function(event)
|
||||
{
|
||||
// Get time at mouse
|
||||
if(this.options.group_by === 'month')
|
||||
{
|
||||
var time = this._get_time_from_position(event.clientX, event.clientY);
|
||||
}
|
||||
else
|
||||
{
|
||||
var time = this._get_time_from_position(event.offsetX, event.offsetY);
|
||||
}
|
||||
|
||||
return this._drag_create_end({date: time.toJSON()});
|
||||
},
|
||||
|
||||
/**
|
||||
* Code for implementing et2_IDetachedDOM
|
||||
*
|
||||
@ -1914,4 +1972,4 @@ var et2_calendar_planner = (function(){ "use strict"; return et2_calendar_view.e
|
||||
this.rows.height(this.div.height() - this.headers.outerHeight());
|
||||
}
|
||||
});}).call(this);
|
||||
et2_register_widget(et2_calendar_planner, ["calendar-planner"]);
|
||||
et2_register_widget(et2_calendar_planner, ["calendar-planner"]);
|
||||
|
@ -1069,8 +1069,14 @@ var et2_calendar_timegrid = (function(){ "use strict"; return et2_calendar_view.
|
||||
var event = event.iface.getWidget();
|
||||
var timegrid = target.iface.getWidget() || false;
|
||||
if(event === timegrid || !event || !timegrid ||
|
||||
!event.options || !event.options.value.participants || !timegrid.options.owner ) return false;
|
||||
!event.options || !event.options.value.participants || !timegrid.options.owner
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var owner_match = false;
|
||||
var own_timegrid = event.getParent().getParent() === timegrid && !timegrid.daily_owner;
|
||||
|
||||
for(var id in event.options.value.participants)
|
||||
{
|
||||
if(!timegrid.daily_owner)
|
||||
@ -1089,11 +1095,15 @@ var et2_calendar_timegrid = (function(){ "use strict"; return et2_calendar_view.
|
||||
if(col.div.has(timegrid.gridHover).length || col.header.has(timegrid.gridHover).length)
|
||||
{
|
||||
owner_match = owner_match || col.options.owner.indexOf(id) !== -1;
|
||||
own_timegrid = (col === event.getParent());
|
||||
}
|
||||
}, this, et2_calendar_daycol);
|
||||
}
|
||||
}
|
||||
var enabled = !owner_match;
|
||||
var enabled = !owner_match &&
|
||||
// Not inside its own timegrid
|
||||
!own_timegrid;
|
||||
|
||||
widget_object.getActionLink('invite').enabled = enabled;
|
||||
widget_object.getActionLink('change_participant').enabled = enabled;
|
||||
|
||||
|
@ -383,6 +383,181 @@ var et2_calendar_view = (function(){ "use strict"; return et2_valueWidget.extend
|
||||
result.widget_id = 'event_' + widget_id.join('');
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
/**
|
||||
* Starting (mousedown) handler to support drag to create
|
||||
*
|
||||
* Extending classes need to set this.drag_create.parent, which is the
|
||||
* parent container (child of extending class) that will directly hold the
|
||||
* event.
|
||||
*
|
||||
* @param {String} start Date string (JSON format)
|
||||
*/
|
||||
_drag_create_start: function(start)
|
||||
{
|
||||
this.drag_create.start = jQuery.extend({},start);
|
||||
if(!this.drag_create.start.date)
|
||||
{
|
||||
this.drag_create.start = null;
|
||||
}
|
||||
this.drag_create.end = start;
|
||||
|
||||
// Clear some stuff, if last time did not complete
|
||||
if(this.drag_create.event)
|
||||
{
|
||||
if(this.drag_create.event.destroy)
|
||||
{
|
||||
this.drag_create.event.destroy();
|
||||
}
|
||||
this.drag_create.event = null;
|
||||
}
|
||||
// Wait a bit before adding an "event", it may be just a click
|
||||
window.setTimeout(jQuery.proxy(function() {
|
||||
// Create event
|
||||
this._drag_create_event();
|
||||
}, this), 250);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create or update an event used for feedback while dragging on empty space,
|
||||
* so user can see something is happening
|
||||
*/
|
||||
_drag_create_event: function()
|
||||
{
|
||||
if(!this.drag_create.parent || !this.drag_create.start)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!this.drag_create.event)
|
||||
{
|
||||
this.date_helper.set_value(this.drag_create.start.date);
|
||||
var value = jQuery.extend({},
|
||||
this.drag_create.start,
|
||||
this.drag_create.end,
|
||||
{
|
||||
start: this.drag_create.start.date,
|
||||
end: this.drag_create.end && this.drag_create.end.date || this.drag_create.start.date,
|
||||
date: ""+this.date_helper.get_year()+
|
||||
sprintf("%02d",this.date_helper.get_month())+
|
||||
sprintf("%02d",this.date_helper.get_date()),
|
||||
title: '',
|
||||
description: '',
|
||||
owner: this.options.owner,
|
||||
participants: this.options.owner,
|
||||
app: 'calendar',
|
||||
whole_day_on_top: this.drag_create.start.whole_day
|
||||
}
|
||||
);
|
||||
this.drag_create.event = et2_createWidget('calendar-event',{
|
||||
id:'event_drag',
|
||||
value: value
|
||||
},this.drag_create.parent);
|
||||
this.drag_create.event._values_check(value);
|
||||
this.drag_create.event.doLoadingFinished();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
_drag_update_event: function()
|
||||
{
|
||||
if(!this.drag_create.event || !this.drag_create.start || !this.drag_create.end
|
||||
|| !this.drag_create.parent || !this.drag_create.event._type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (this.drag_create.end)
|
||||
{
|
||||
this.drag_create.event.options.value.end = this.drag_create.end.date;
|
||||
this.drag_create.event._values_check(this.drag_create.event.options.value);
|
||||
}
|
||||
this.drag_create.event._update()
|
||||
this.drag_create.parent.position_event(this.drag_create.event);
|
||||
},
|
||||
|
||||
/**
|
||||
* Ending (mouseup) handler to support drag to create
|
||||
*
|
||||
* @param {String} end Date string (JSON format)
|
||||
*/
|
||||
_drag_create_end: function(end)
|
||||
{
|
||||
this.div.css('cursor','');
|
||||
if(typeof end === 'undefined')
|
||||
{
|
||||
end = {};
|
||||
}
|
||||
|
||||
if(this.drag_create.start && end.date &&
|
||||
JSON.stringify(this.drag_create.start.date) !== JSON.stringify(end.date))
|
||||
{
|
||||
// Drag from start to end, open dialog
|
||||
var options = {
|
||||
start: this.drag_create.start.date < end.date ? this.drag_create.start.date : end.date,
|
||||
end: this.drag_create.start.date < end.date ? end.date : this.drag_create.start.date
|
||||
};
|
||||
|
||||
// Whole day needs to go from 00:00 to 23:59
|
||||
if(end.whole_day || this.drag_create.start.whole_day)
|
||||
{
|
||||
var start = new Date(options.start);
|
||||
start.setUTCHours(0);
|
||||
start.setUTCMinutes(0);
|
||||
options.start = start.toJSON();
|
||||
|
||||
var end = new Date(options.end);
|
||||
end.setUTCHours(23);
|
||||
end.setUTCMinutes(59);
|
||||
options.end = end.toJSON();
|
||||
}
|
||||
|
||||
// Add anything else that was set, but not date
|
||||
jQuery.extend(options,this.drag_create.start, end);
|
||||
delete(options.date);
|
||||
|
||||
// Make sure parent is set, if needed
|
||||
if (this.drag_create.parent && this.drag_create.parent.options.owner !== app.calendar.state.owner && !options.owner)
|
||||
{
|
||||
options.owner = this.drag_create.parent.options.owner;
|
||||
}
|
||||
|
||||
// Remove empties
|
||||
for(var key in options)
|
||||
{
|
||||
if(!options[key]) delete options[key];
|
||||
}
|
||||
this.egw().open(null, 'calendar', 'add', options, '_blank');
|
||||
|
||||
// Wait a bit, having these stops the click
|
||||
window.setTimeout(jQuery.proxy(function() {
|
||||
this.drag_create.start = null;
|
||||
this.drag_create.end = null;
|
||||
this.drag_create.parent = null;
|
||||
if(this.drag_create.event)
|
||||
{
|
||||
if(this.drag_create.event.destroy)
|
||||
{
|
||||
this.drag_create.event.destroy();
|
||||
}
|
||||
this.drag_create.event = null;
|
||||
}
|
||||
},this),100);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
this.drag_create.start = null;
|
||||
this.drag_create.end = null;
|
||||
this.drag_create.parent = null;
|
||||
if(this.drag_create.event)
|
||||
{
|
||||
if(this.drag_create.event.destroy)
|
||||
{
|
||||
this.drag_create.event.destroy();
|
||||
}
|
||||
this.drag_create.event = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
});}).call(this);
|
||||
@ -455,4 +630,4 @@ jQuery.extend(et2_calendar_view,
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user