FullCalendar重复活动(客户端)

时间:2014-10-28 14:18:29

标签: javascript jquery fullcalendar momentjs

我很难尝试为FullCalendar事件实现重复计划。我设法做了每日重复活动。但这是我正在努力的每周事件。我想让它模仿MS Outlook中的那个。我必须为SO上的帖子中提到的定期事件生成ID。以下是我正在处理的示例代码:

            //freqValue is the number of occurrences 
            if (freqValue != null) {
                eventData.id = randomString();//Assigns a "uniqueID" as generated by randomString function
                $("#calendar").fullCalendar('renderEvent', eventData, true);//render for a non-repeat event
                switch (freqValue) {
                    //======================================================================================
                    //Daily events code works!
                    case 'Daily':
                        if (freqValueDaily != null) {
                            switch (freqValueDaily) {
                                case 'everyNumDays':
                                    //loop through the Event frequency
                                    for (var i = 0; i < eventFrequency; i++) {
                                        //Manufacture events
                                        var dayInterval = $('#dayInterval').val();
                                        eventData.start = moment(eventData.start).add(dayInterval, 'days').format();
                                        eventData.end = moment(eventData.end).add(dayInterval, 'days').format();

                                        $("#calendar").fullCalendar('renderEvent', eventData, true);
                                    }
                                    break;
                                case 'everyWeekDay':
                                    for (var l = 0; l < eventFrequency; l++) {
                                        for (var m = 0; m < 7; m++) {
                                            eventData.start = moment(eventData.start).add(1, 'days').format();
                                            eventData.end = moment(eventData.end).add(1, 'days').format();

                                            $("#calendar").fullCalendar('renderEvent', eventData, true);
                                        }
                                    }
                                    break;
                                default:
                            }
                        }

                        break;
                        //=====================================================================================
                    //Code for WEEKLY events that does not work!!!!!Help needed here.
                    case 'Weekly':
                        if (weekDays.length > 0) {//weekdays is an array that contains the user selected week days i.e Sunday, Tuesday, Monday e.t.c
                            var weekInterval = $("#weekInterval").val();//takes value for repeat interval e.g Repeat every 2 weeks on Sunday and Friday etc. 2 being the weekInterval

                            for (var n = 0; n < eventFrequency; n++) {//eventFrequency =no of occurances
                                for (var p = 0; p < weekDays.length; p++) {
                                    if (weekInterval != 0) {
                                        for (var o = 0; o < weekInterval; o++) {

                                            eventData.start = moment(eventData.start).weekday(weekDays[p]).add(o * 7, 'days').format();//assign a value to weekday
                                            eventData.end = moment(eventData.end).weekday(weekDays[p]).add(o * 7, 'days').format();

                                            $("#calendar").fullCalendar('renderEvent', eventData, true);
                                        }

                                    } else {
                                        eventData.start = moment(eventData.start).weekday(weekDays[p]).format();//assign a value to weekday
                                        eventData.end = moment(eventData.end).weekday(weekDays[p]).format();

                                        $("#calendar").fullCalendar('renderEvent', eventData, true);
                                    }
                                }
                            }
                        } else {
                            for (var j = 0; j < eventFrequency-1; j++) {
                                eventData.start = moment(eventData.start).add(7, 'days').format();//assign a value to weekday
                                eventData.end = moment(eventData.end).add(7, 'days').format();


                                $("#calendar").fullCalendar('renderEvent', eventData, true);
                            }
                        }

                        $('#calendar').fullCalendar('changeView', 'month');
                        break;
                        //==========================================================================================

0 个答案:

没有答案