I am using fullCalendar-2.9.1 along with fullcalendar-scheduler-1.4.0. In my current project I have external elements which I need to drag and drop into full calendar. While dragging the element into the full calendar, a highlighting portion is displayed which shows the selected portion that the dragged element is hovering. I have set the defaultTimedEventDuration as '00:30:00', so that the default duration of an event should be 30 minutes if the end is not specified.
I have events, which has duration as 10 minutes. I am dragging these fullcalender events to the external element box and again dragging it back to the fullcalendar. I have set the start and end time of the event in data(‘event’).
Now my problem is, when I am dragging an external element into the fullcalendar the highlighting portion is equivalent to 30 minutes always, because of the defaultTimedEventDuration I guess. I need to control the height of the highlighting portion which should match the duration of the dragging element.
How can I control the highlighting portions height according to the event duration?
$('#external-events .fc-event').each(function() {
$(this).data('event', {
title: $.trim($(this).text()),
stick: true
});
$(this).draggable({
zIndex: 999,
revert: true,
revertDuration: 0
});
});
function makeEventsDraggable () {
$('.fc-draggable').each(function() {
$(this).data('event', {
title: $.trim($(this).text()),
stick: true
});
$(this).draggable({
appendTo: ".calander_container",
helper: function(ev) {
return '<div id="draggableHelper" class="fc-event " style="width:'+$(this).parent().width()+'px; height:'+$(this).height()+'px;">'+ $(this).html() +'</div>';
},
zIndex: 9999,
revert: true,
revertDuration: 0
});
});
}
var sDate = null;
var resource_id = null;
$('#calendar').fullCalendar({
defaultView: 'agendaDay',
defaultDate: '2016-09-07',
editable: true,
selectable: true,
eventLimit: true,
droppable: true,
minTime: '07:00:00',
maxTime: '22:00:00',
slotDuration: '00:05:00',
scrollTime: sTime,
slotLabelInterval: {hours:1},
allDaySlot: false,
disableDragging: false,
selectable: false,
selectHelper: true,
defaultTimedEventDuration: '00:30:00',
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
views: {
},
allDaySlot: false,
resources: [
{ id: 'a', title: 'Room A' },
{ id: 'b', title: 'Room B', eventColor: 'green' },
{ id: 'c', title: 'Room C', eventColor: 'orange' },
{ id: 'd', title: 'Room D', eventColor: 'red' }
],
events: [
{ id: '1', resourceId: 'a', start: '2016-09-06', end: '2016-09-08', title: 'event 1' },
{ id: '2', resourceId: 'a', start: '2016-09-07T09:00:00', end: '2016-09-07T14:00:00', title: 'event 2' },
{ id: '3', resourceId: 'b', start: '2016-09-07T12:00:00', end: '2016-09-08T12:10:00', title: 'event 3' },
{ id: '4', resourceId: 'c', start: '2016-09-07T07:30:00', end: '2016-09-07T07:05:00', title: 'event 4' },
{ id: '5', resourceId: 'd', start: '2016-09-07T10:00:00', end: '2016-09-07T10:20:00', title: 'event 5' }
],
viewRender: function(view, element) {
element.on('dblclick',function(e) {
var defaultDuration = moment.duration($('#calendar').fullCalendar('option', 'defaultTimedEventDuration'));
var eDate = slotDate.clone().add(defaultDuration);
$('#calendar').fullCalendar( 'select', slotDate, eDate, resource_id);
});
},
select: function(start, end, jsEvent, view, resource) {
},
dayClick: function(date, jsEvent, view, resource) {
sDate = date;
resource_id = resource.id;
},
drop: function(date, jsEvent, ui, resourceId) {
var oEventObject = $(this).data('event');
var duration = null;
if((oEventObject.start)&&(oEventObject.end)){
duration = moment.duration(oEventObject.end.diff(oEventObject.start));
}
var cEventObject = $.extend({}, oEventObject);
cEventObject.start = date;
var defaultDuration = null;
if(duration) {
defaultDuration = duration;
} else {
defaultDuration = moment.duration($('#calendar').fullCalendar('option', 'defaultTimedEventDuration'));
}
cEventObject.end = date.clone().add(defaultDuration);
cEventObject.resourceId = resourceId;
$('#calendar').fullCalendar('renderEvent', cEventObject, true);
if ($('#drop-remove').is(':checked')) {
$(this).remove();
}
makeEventsDraggable();
},
eventReceive: function(event) {
console.log('eventReceive', event);
makeEventsDraggable();
},
eventDrop: function(event) {
if(isEventOverDiv(jsEvent.clientX, jsEvent.clientY)) {
$('#calendar').fullCalendar('removeEvents', event._id);
var el = $( "<div class='fc-event'>" ).appendTo( '#external-events-listing' ).text( event.title );
el.data('event', { title: event.title, id: event._id, start: event.start, end: event.end, stick: true });
el.draggable({
helper: function(event) {
return $(event.target).clone().css({
width: $(event.target).width()
});
},
zIndex: 999,
revert: true,
revertDuration: 0
});
}
makeEventsDraggable();
}
});
Got answer. We need to include the duration in el.data('event', { title: event.title, id: event._id, start: event.start, end: event.end, stick: true }). ie, el.data('event', { title: event.title, id: event._id, start: event.start, end: event.end, duration: '00:10:00', stick: true })