drdr123456 2011-06-10 21:09
浏览 107
已采纳

jQuery FullCalendar没有清除事件

I am currently working away with FullCalendar, which is pretty cool and has done a lot of neat stuff for me. The only problem I'm having is that if I edit an event, and then try and create another event the javascript seems to hold onto the initial events data.

I am using calendar.fullCalendar('unselect') when I need the link to end, but it doesn't seem to make a difference no matter what I do. I'm hoping you guys might be able to see something I'm overlooking.

<script type='text/javascript'>

    $(document).ready(function() {

        var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();

         var calendar = $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            defaultView: 'agendaWeek',
            selectable: true,
            unselectAuto: true,
            selectHelper: true,
            editable: true,
            select: function(start, end, allDay) {
                //var title = prompt('Event Title:');
                //var desc = prompt('Event Description:');
                //calendar.fullCalendar('unselect');    

                $('#eventStart').val(start);
                $('#eventEnd').val(end);
                $('#eventAllDay').val(allDay);

                $('#formName').fadeIn();

                $('.closeSchedule a').click(function(){
                    $('#formName').fadeOut('slow');

                    $('#calendar').fullCalendar('unselect');    
                    //alert(jsEvent);
                });
            },
            events: [
                <?php

                 $first = true;

                 foreach ($events as $event)
                 {

                    if ($first == true)
                    {
                        $comma = '';
                        $first = false;
                    }
                    else
                    {
                        $comma = ',';
                    }

                     echo $comma."
                     {
                        id: '".$event->id."',
                        title: '".addSlashes($event->title)."',
                        start: '".$event->start."',
                        end: '".$event->end."',
                        allDay: ".$event->allDay."
                    }";
                    $first = false;
                 }

                ?>
                            ],

            eventClick: function(event) {
                //alert(event.id);


                $.ajax({
                  url: './schedule/getEdit/'+event.id,
                  success: function(data) {
                    var formEmpty = $('formName').html();
                    $('#formName').html(data);
                    $('#formName').fadeIn('fast');

                    $('.closeSchedule a').click(function(){
                        $('#formName').fadeOut('slow');
                        $('#calendar').fullCalendar('unselect');
                    });

                    $('#deleteEvent').live('click', function(){
                        var answer = confirm("Are you sure you wish to delete this event?")

                        if (answer){
                            $.ajax({
                               type: "POST",
                               url: "./schedule/deleteEvent/"+event.id,
                               success: function(msg){

                                  $('#formName').fadeOut('fast');            

                                  calendar.fullCalendar( 'removeEvents', [event.id ] )
                                  $('#calendar').fullCalendar('unselect');
                               }
                            });
                        }

                    }); 

                    $('#updateEvent').live('click', function(){

                        var title       = $('#eventName').val();
                        var trainerID   = $('#eventTrainer').val();
                        var trainer     = $('#eventTrainer option:selected').text();
                        var classID     = $('#eventType').val();
                        var eventType   = $('#eventType option:selected').text();
                        var eventStart  = $('#eventStart').val();
                        var eventEnd    = $('#eventEnd').val();
                        var eventAllDay = $('#eventAllDay').val();

                        if (eventAllDay == 'false')
                        {
                            allDay = false;
                        }
                        else
                        {
                            allDay = true;
                        }



                    // This runs the ajax to add the event to the database.
                    newData = 'title='+title+'&trainerID='+trainerID+'&classID='+classID+'&start='+eventStart+'&end='+eventEnd+'&allDay='+allDay

                    $.ajax({
                       type: "POST",
                       url: "./schedule/updateEvent/"+event.id,
                       data: newData,
                       success: function(msg){

                         event.title = title;

                         calendar.fullCalendar('rerenderEvents');

                         //calendar.fullCalendar('unselect');
                         $('#calendar').fullCalendar('unselect');
                       }
                     });



                    $('#formName').fadeOut('fast');
                    $('#eventName').val('');
                    $('#eventTrainer').val();
                    $('#eventType').val();  


                    });
                  }
                });

            },
            eventDrop: function(event,dayDelta,minuteDelta,allDay,revertFunc) {


                    newData = 'start='+event.start+'&end='+event.end+'&allDay='+allDay

                    $.ajax({
                       type: "POST",
                       url: "./schedule/updateEventTime/"+event.id,
                       data: newData,
                       success: function(msg){

                       }
                     }); 
            },
            eventResize: function(event,dayDelta,minuteDelta,revertFunc) {

                newData = 'start='+event.start+'&end='+event.end+'&allDay='+event.allDay

                $.ajax({
                   type: "POST",
                   url: "./schedule/updateEventTime/"+event.id,
                   data: newData,
                   success: function(msg){

                   }
                 }); 

            }
        }); 



        $('#submitEvent').click(function(){
                    $('#calendar').fullCalendar('unselect');
                    var title       = $('#eventName').val();
                    var trainerID   = $('#eventTrainer').val();
                    var trainer     = $('#eventTrainer option:selected').text();
                    var classID     = $('#eventType').val();
                    var eventType   = $('#eventType option:selected').text();
                    var eventStart  = $('#eventStart').val();
                    var eventEnd    = $('#eventEnd').val();
                    var eventAllDay = $('#eventAllDay').val();

                    if (eventAllDay == 'false')
                    {
                        allDay = false;
                    }
                    else
                    {
                        allDay = true;
                    }



                    // This runs the ajax to add the event to the database.
                    newData = 'title='+title+'&trainerID='+trainerID+'&classID='+classID+'&start='+eventStart+'&end='+eventEnd+'&allDay='+allDay

                    $.ajax({
                       type: "POST",
                       url: "./schedule/addEvent",
                       data: newData,
                       success: function(msg){

                         var description = '<ol><li>'+title+'</li><li>'+trainer+'</li><li><a href="#" target="_blank">'+eventType+'</a></li><li class="eventID hide">'+msg+'</li>';

                         calendar.fullCalendar('renderEvent',
                            {
                                id: msg,
                                title: title,
                                description: description,
                                start: eventStart,
                                end: eventEnd,
                                allDay: allDay

                            },
                            true // make the event "stick"
                         );


                         calendar.fullCalendar('unselect');
                         //calendar.fullCalendar( 'rerenderEvents' )
                       }
                     });



                    $('#formName').fadeOut('fast');
                    $('#eventName').val('');
                    $('#eventTrainer option:selected').removeAttr('selected');
                    $('#eventType option:selected').removeAttr('selected');


        });
    });

   </script>

At this point, I feel like I've tried it all, and I'm just hoping a fresh set of eyes will see what I missed.

  • 写回答

1条回答 默认 最新

  • duanqianpu6499 2011-06-10 21:30
    关注

    Ok took a quick look it looks like you aren't initializing the form with a blank form for the add action in the "select:" function of your full calendar:

    In your event click you are doing this:

    $('#formName').html(data);
    

    I don't see where you are clearing that with a blank form for a new event. (might have just missed it there is a lot of code there)

    Let me know.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!