Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

updating an event by dragging/dropping fullcalendar- Javascript

I'm using Fullcalendar for a project I'm developing ... I have only one feature left to be implemented, which is when an existing event is dragged from it's original position to another time or date. I would like to know how I get the current object information (title, new start time, old start time, id, url, etc), so I can update the database with the newer information ... which property from the Fullcalendar object do I use? I implemented the drop property;

    drop  : function(date, allDay) {
            // retrieve the dropped element's stored event object
            var originalEventObject = $(this).data('eventObject');
            // we need to copy it, so that multiple events don't 
            // have a reference object
            var copiedEventObject   = $.extend({}, originalEventObject);
            // assign it the date that was reported
            copiedEventObject.start = date;
            copiedEventObject.allDay = allDay;

            // render the event on the calendar
            // the last `true` argument determines if the event `sticks`
            $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);

            // if the 'remove after drop' checkbox checked?
            if ($('#drop-remove').is(':checked')) {
                // if so remove the element from the "Draggable Events"
                $(this).remove();
            }
    },

but it's not doing what I wanted ...

like image 372
cybertextron Avatar asked Oct 17 '13 18:10

cybertextron


1 Answers

Take a look at the Event Dragging and Resizing http://arshaw.com/fullcalendar/docs/event_ui/

I think what you are looking for the eventDrop callback.

Triggered when dragging stops and the event has moved to a different day/time.

http://arshaw.com/fullcalendar/docs/event_ui/eventDrop/

Example from arshaw's site:

$('#calendar').fullCalendar({
    events: [
        // events here
    ],
    editable: true,
    eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {

        alert(
            event.title + " was moved " +
            dayDelta + " days and " +
            minuteDelta + " minutes."
        );

        if (allDay) {
            alert("Event is now all-day");
        }else{
            alert("Event has a time-of-day");
        }

        if (!confirm("Are you sure about this change?")) {
            revertFunc();
        }

    }
});
like image 66
MarCrazyness Avatar answered Sep 22 '22 07:09

MarCrazyness