1. 程式人生 > >CAS演算法解決fullcalendar的prev-button的click事件失靈

CAS演算法解決fullcalendar的prev-button的click事件失靈

註冊fullcalendar日曆左右箭頭的點選事件有時會失靈,並且eventAfterAllRender事件可能也會多次觸發,所以放棄註冊事件。但發現title是正確的,從title中提取year and month,與old year,old month進行對比,值不同時重新重新整理頁面


$('#calendar').fullCalendar({
    height:640,
    width: 1200,
    themeSystem: 'jquery-ui',
    header: {
        left: '',
        center: 'title',
        right: 'prev, next'
    },
    monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
    monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
    dayNames: ["週日", "週一", "週二", "週三", "週四", "週五", "週六"],
    dayNamesShort: ["週日", "週一", "週二", "週三", "週四", "週五", "週六"],
    today: ["今天"],
    firstDay: 1,
    buttonText: {
        today: '今天',
        month: '月',
        week: '周',
        day: '日'
    },
    // events:eventss,
    dayClick: function (date, allDay, jsEvent, view) {
        if (date <= new Date()) {
            return;
        }
        var id = null;
        window.openDlg({
            url: "~detail-dialog.html?id=" + id,
            width: 700,
            height: 600,
            title: "新增值班人員",
            callback: function (details) {
                if (details != null && details.length > 0) {
                    var arrangement = {};
                    arrangement.details = details;
                    arrangement.arrangeDate = date._d.getFullYear() + '-' + (date._d.getMonth() + 1) + '-' + date._d.getDate() + " " + details[0].arrangeDate;
                    arrangement.endDate = date._d.getFullYear() + '-' + (date._d.getMonth() + 1) + '-' + date._d.getDate()  + " " +  details[0].endDate;
                    service.add(arrangement, function (result) {
                        if (result.header.success) {
                            if (id) {
                                service.delete(id, function (result) {
                                });
                            }
                            id = result.body.id;
                            $("#calendar").fullCalendar('renderEvent', {allDay:false,start:date,end:date,id:id,                                      fullname:details[0].user.name,
                                    title:details[0].arrangeDate +"-" + details[0].endDate},
                                true);
                        }
                    })
                }
            }
        });
    },
    loading: function (bool) {
        if (bool) $('#loading').show();
        else $('#loading').hide();
    },
    eventAfterAllRender: function (event, element, view) {
        var title = event.title;
        title = title.split(" ");
        var monthList = ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"];
        for (var i = 0; i < monthList.length; i++) {
            if (title[0] == monthList[i]) {
                month2 = i;
            }
        }
       year2 = title[1] - 1900;
        if (year1 != year2 || month1 != month2) {
            year1 = year2;
            month1 = month2;
            load(year1,month1);
        }
    },
    eventMouseover: function (calEvent, jsEvent, view) {
        $(this).attr('title', calEvent.fullname);
        $(this).css('font-weight', 'normal');
    },
    eventClick: function (event) {
        window.openDlg({
            url: "~detail-dialog.html?id=" + event.id,
            width: 700,
            height: 500,
            title: "新增值班人員",
            callback: function (details) {
                if (details != null && details.length > 0) {
                    var arrangement = {};
                    arrangement.id = event._id;
                    arrangement.details = details;
                    arrangement.arrangeDate = event.start._d.getFullYear() + '-' + (event.start._d.getMonth() + 1) + '-' + event.start._d.getDate() + " " + details[0].arrangeDate;
                    arrangement.endDate = event.start._d.getFullYear() + '-' + (event.start._d.getMonth() + 1) + '-' + event.start._d.getDate()  + " " +  details[0].endDate;
                    service.update(arrangement, function (result) {
                        if (result.header.success) {
                            var fullname = "";
                            for (var i = 0; i < details.length; i++) {
                                fullname = fullname + details[i].user.name + ",";
                            }
                            $("#calendar").fullCalendar('removeEvents',event._id);
                            $("#calendar").fullCalendar('renderEvent', {allDay:false,start:event.start._d,end:event.start._d,id:result.body.id,                                      fullname:fullname,
                                    title:details[0].arrangeDate +"-" + details[0].endDate},
                                true);
                        }
                    })
                }
            }
        });
    },
    editable: true,
    droppable: true,
    eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {
        service.dragUpdate(event.start._d,event._id,function (result) {

        })
    }
});
if (eventss) {
    $('#calendar').fullCalendar('removeEvents');
}
$('#calendar').fullCalendar('addEventSource', eventss );