PoDuck
PoDuck

Reputation: 1454

How to stop fullcalendar from interrupting dragging and resizing when polled

I have been trying to get fullcalendar to react to polling for new events, but whenever it calls refetchEvents, if I am dragging or resizing something, it stops me, as if I have released the mouse at the position I am in, which moves or resizes the event respectively to the wrong spot.

I have a jsfiddle, to show this in action.

Here is the code, if it helps:

$(document).ready(function() {

  /* initialize the calendar
  -----------------------------------------------------------------*/

  $('#calendar').fullCalendar({
    header: {
      left: 'prev,next today',
      center: 'title',
      right: 'month,agendaWeek,agendaDay'
    },
    editable: true,
    events: [{
      title: 'event1',
      start: '2017-01-26T08:00:00',
    end: '2017-01-26T10:00:00'
    }, {
      title: 'event2',
      start: '2017-01-05',
      end: '2017-01-07'
    }, {
      title: 'event3',
      start: '2017-01-09T06:30:00',
    end: '2017-01-09T09:30:00',
    }]
  });
});
setInterval(function() {
  $('#calendar').fullCalendar('refetchEvents');
  console.log('refetchEvents called');
}, 5000);

Upvotes: 1

Views: 307

Answers (1)

Searching
Searching

Reputation: 2279

May be not the most efficient, using fetchEventsLock reference on eventDragStart and eventDragStop and fetch events only when released === false.

var fetchEventsLock = false;
$(document).ready(function () {

    /* initialize the calendar
    -----------------------------------------------------------------*/

    function toggleLock() {
        fetchEventsLock = !fetchEventsLock;
        console.log('Set To ' + fetchEventsLock)
    }
    $('#calendar').fullCalendar({        
        eventDragStart: toggleLock,
        eventDragStop: toggleLock,
        /* Other option removed */

    });
});
setInterval(function () { 
    if (fetchEventsLock === false) {
        $('#calendar').fullCalendar('refetchEvents');
        console.log('refetchEvents called');
    }
}, 5000);

Upvotes: 1

Related Questions