如何在fullcalendar中限制每个时段的事件?

时间:2014-06-06 08:09:46

标签: jquery fullcalendar

是否可以限制FullCalendar-2仅在插槽间隔中添加事件并将其限制为2?

例如,用户只能在12:00:00 - 12:15:00之间添加活动,无法添加更长的活动(12:00:00 - 12:30:00),他可以添加只有有免费的'插槽。 Orage事件是正确的(时间段中最多2个事件),事件蓝色错误(超过2个事件)

这是一个例子

$(document).ready(function() {

    // page is now ready, initialize the calendar...

    $('#calendar').fullCalendar({
                    header: {
                            left: 'prev,next today',
                            center: 'title',
                            right: 'agendaDay'
                    },
                    defaultView: 'agendaDay',
                    allDaySlot: false,
                    scrollTime: moment().format('HH:mm:ss'),
                    slotDuration: '00:15:00',
                    minTime: '06:45:00',
                    maxTime: '23:15:00',
                editable: true,
            events: [
                {
                    title: 'Meeting',
                    start: '2014-06-06T10:30:00',
                    end: '2014-06-06T10:45:00'
                },
                {
                    title: 'Lunch',
                    start: '2014-06-06T10:30:00',
                    end: '2014-06-06T10:45:00'
                },
                {
                    title: 'Birthday Party',
                    start: '2014-06-06T10:30:00',
                    end: '2014-06-06T10:45:00'
                },
                {
                    title: 'Meeting',
                    start: '2014-06-06T15:30:00',
                    end: '2014-06-06T15:45:00',
                    color: '#FF7F50'
                },
                {
                    title: 'Lunch',
                    start: '2014-06-06T15:30:00',
                    end: '2014-06-06T15:45:00',
                    color: '#FF7F50'
                }
            ]

            });

});

and live:http://jsbin.com/fezidowo/3/

1 个答案:

答案 0 :(得分:0)

select: function(start, end) {
    console.log( 'Events :' + getEventsByTime( start, end ).length );
    var ev = getEventsByTime( start, end );
    console.log( ev );
    var itms = {};            

    ev.forEach(function(entry){

      var begin = moment(entry.start);
      var final = moment(entry.end);


    while( begin.diff(final) < 0 ) {
        itms[begin] =  ( itms[begin] || 0) + 1;
        if( itms[begin] >= maxEventsInInterval ) {
            console.log(' __ WARNING __ , max events exceeded! ');
        }

        begin = moment(begin).add('seconds', 900);
    }

});
    console.log( itms );
}

function getEventsByTime( start, stop ) {
    var todaysEvents = $('div[name=calendar]').fullCalendar('clientEvents', function(event) {

       return ( 
           ( event.start >= start && event.end <= stop ) || 
           ( start >= event.start && stop <= event.end)  || 
           (start <= event.start && stop >= event.start) ||
           (start >= event.start && start <= event.end)
       );
    });
    return todaysEvents;
}