I want to be able to drag external elements and drop them on my fullcalendar. In the drop callback I request a page that returns the calculated return time (for example: “2012-03-03 08:00:00”) for the event reason type. The date is received and applied to the .end property of the event. And the event is added to the calendar but the event defaults to 2 hours length causing the event to have the wrong endtime (should stretch to next “08:00”). If I switch to weekview the correct endtime is displayed and also if I switch back. Also if I drag the event having thw wrong siplayed endtime to a new position on the calendar, it is rerendered with the correct endtime (“08:00”).
So, does anyone know how to simluate a dragEventStop or whatever is needed for it to rerender correctly?
The code:
drop: function(date, allDay) { // this function is called when something is dropped
// retrieve the dropped element's stored Event Object
var originalEventObject = jQuery(this).data('eventObject');
// we need to copy it, so that multiple events don't have a reference to the same object
var copiedEventObject = jQuery.extend({}, originalEventObject);
// assign it the date that was reported
copiedEventObject.start = date;
//Fetch endtime from loadReturntime
var opt = {session: '<%= GetVariable('session') %>', cmd: 'hv_get_returntime', reasoncode_id: ''+jQuery(this).attr('custom:reasoncode')+'', fromtime: ISODateString(date)};
jQuery.get('engine.wsc', opt, function(data) {
copiedEventObject.end = new Date(data);
});
copiedEventObject.allDay = false;
// render the event on the calendar
jQuery('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
},
I found out that the answer is that the callback of jQuery.get() is handled after (of course) the remaining lines of the function drop. Therefor the event is rendered before the callback is handled and setting the end date to the correct one. The solution is to add the rendering in the callback of get(). For example: