Calendar: fix click on event in planner view created a new event

This commit is contained in:
nathan 2023-07-27 13:03:16 -06:00
parent 3d2f915037
commit 01c276c3ea
2 changed files with 61 additions and 11 deletions

View File

@ -319,13 +319,23 @@ export class et2_calendar_planner extends et2_calendar_view implements et2_IDeta
{
const formatDate = new Date(time.valueOf() + time.getTimezoneOffset() * 60 * 1000);
planner.vertical_bar
.html('<span>'+date(egw.preference('timeformat','calendar') == 12 ? 'h:ia' : 'H:i',formatDate)+'</span>')
.html('<span>' + date(egw.preference('timeformat', 'calendar') == 12 ? 'h:ia' : 'H:i', formatDate) + '</span>')
.show();
if(!planner.drag_create.event && planner.drag_create.start && time.toJSON() != planner.drag_create.start.date.toJSON())
{
planner._drag_create_start(planner.drag_create.start);
// Create the event immediately
planner._drag_create_event();
}
if(planner.drag_create.event && planner.drag_create.parent && planner.drag_create.end)
{
planner.drag_create.end.date = time.toJSON();
if(planner.drag_create.start?.date?.toJSON() == time.toJSON())
{
// Minimum drag size is time granularity or default
time.setUTCMinutes(time.getUTCMinutes() + parseInt(planner.egw().preference("defaultlength", "calendar")));
}
planner.drag_create.end.date = time;
planner._drag_update_event();
}
}
@ -2539,10 +2549,22 @@ export class et2_calendar_planner extends et2_calendar_view implements et2_IDeta
_mouse_down(event)
{
// Only left mouse button
if(event.which !== 1) return;
if(event.which !== 1)
{
return;
}
// Skip for events
if(event.target.closest(".calendar_calEvent"))
{
return;
}
// Ignore headers
if(this.headers.has(event.target).length !== 0) return false;
if(this.headers.has(event.target).length !== 0)
{
return false;
}
// Get time at mouse
if(this.options.group_by === 'month')
@ -2569,9 +2591,8 @@ export class et2_calendar_planner extends et2_calendar_view implements et2_IDeta
}
if(!this.drag_create.parent) return false;
this.drag_create.start = {date: time};
this.div.css('cursor', 'ew-resize');
return this._drag_create_start(jQuery.extend({},this.drag_create.parent.node.dataset,{date: time.toJSON()}));
}
/**
@ -2591,7 +2612,16 @@ export class et2_calendar_planner extends et2_calendar_view implements et2_IDeta
var time = this._get_time_from_position(event.offsetX, event.offsetY);
}
return this._drag_create_end(time ? {date: time.toJSON()} : false);
if(this.drag_create.end)
{
return this._drag_create_end(this.drag_create.end);
}
else if(this.drag_create.start)
{
// Not dragged enough to count, fake a click
event.stopImmediatePropagation();
}
this._drag_create_end();
}
/**

View File

@ -504,6 +504,12 @@ export class et2_calendar_view extends et2_valueWidget
widget_id = widget_id.split('event_');
widget_id.shift();
result.widget_id = 'event_' + widget_id.join('');
const widget = this.getWidgetById(result.widget_id);
if(widget)
{
result.title = widget.options.value.title;
}
}
return result;
}
@ -572,12 +578,16 @@ export class et2_calendar_view extends et2_valueWidget
whole_day_on_top: this.drag_create.start.whole_day
}
);
this.drag_create.event = <et2_calendar_event>et2_createWidget('calendar-event',{
id:'event_drag',
this.drag_create.event = <et2_calendar_event>et2_createWidget('calendar-event', {
id: 'event_drag',
value: value
},this.drag_create.parent);
}, this.drag_create.parent);
this.drag_create.event._values_check(value);
this.drag_create.event.doLoadingFinished();
if(this.drag_create.parent && typeof this.drag_create.parent.position_event == "function")
{
this.drag_create.parent.position_event(this.drag_create.event);
}
}
}
@ -665,6 +675,16 @@ export class et2_calendar_view extends et2_valueWidget
this.drag_create.parent = null;
if(this.drag_create.event)
{
try
{
if(this.drag_create.event.destroy)
{
this.drag_create.event.destroy();
}
}
catch(e)
{
}
this.drag_create.event = null;
}
},this),100);