开发者

Good way to enable auto refresh of events on the fullCalendar jquery plugin?

Is there a good way to have the fullCalendar jquery plugin auto-refresh its events?

I am able to simply call 'refetchEvents' using a timer, but that presents issues if the user is currently dragging an 开发者_开发技巧event (throwing javascript errors during the refresh while the event is dragged). Is there a better way?


Good solution... but is not enough:

var calE = {
        url: 'calendarEvents.do',
        type: 'POST',
        data: {
            siteId: $("#siteId").val()
        },
        error: function() {
            alert('there was an error while fetching events!');
        }
};

function loadCal(){
        $('#calendar').fullCalendar({
                theme: true,
                events: calE,
                editable: false,            
                eventDrop: function(event, delta) {
                        alert(event.title + ' was moved ' + delta + ' days\n' +
                                '(should probably update your database)');
                },          
                loading: function(bool) {
                        if (bool) $('#loading').show();
                        else $('#loading').hide();
                },
                viewDisplay: function(viewObj) {}           
        });

}

function reloadCalendar(){
    $('#calendar').fullCalendar('removeEventSource', calEvent );
    var source = {
            url: 'calendarEvents.do',
            type: 'POST',
            data: {
                siteId: $("#siteId").val()
            },
            error: function() {
                alert('there was an error while fetching events!');
            }
        };
    $('#calendar').fullCalendar('removeEvents');
    $('#calendar').fullCalendar('addEventSource', source );
    $('#calendar').fullCalendar('rerenderEvents');
    calE = source;
}

By using this you'll keep the original algorithm to fetch the data.


you'd just need to keep track of a flag, whether auto-refreshing should happen. it should be true by default, but set to false when dragging or resizing. you can set it based on the eventDragStart, eventDragStop, eventResizeStart, and eventResizeStop.

see http://arshaw.com/fullcalendar/docs/event_ui/ for a list of mouse-related triggers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜