ThinkPhp+Mysql+FullCalendar日曆拖動與資料儲存

來源:互聯網
上載者:User

FullCalendar提供了可拖動議程事件的方法,但必須依賴jquery ui的draggable外掛程式。當拖動完畢後,eventDrop回呼函數中,我們使用post方式向後台php發送ajax請求,請求的參數包括id: 當前拖動事件的id唯一標識,daydiff:拖動前後的天數變更(天數位移量),minudiff:拖動前後分鐘變更(分鐘位移量),allday:是 否為全天事件。然後接收後台php處理的結果,如果返回的不是1(拖動處理失敗),就彈出提示資訊,並且將議程事件恢複到拖動前的狀態。
html代碼:
<div class="container">
            <div class="demo">
                <div id='calendar'></div>
            </div>
        </div>
        <script type="text/javascript" src="/Public/js/jquery.js"></script>
        <script src='/Public/js/jquery-ui.js'></script>
        <script src='/Public/js/fullcalendar.min.js'></script>
        <script src='/Public/js/jquery.fancybox-1.3.1.pack.js'></script>
        <script type="text/javascript">
            $(function() {
                $('#calendar').fullCalendar({
                    header: {
                        left: 'prev,next today',
                        center: 'title',
                        right: 'month,agendaWeek,agendaDay'
                    },
                    editable: true,
                    dragOpacity: {
                        agenda: .5,
                        '': .6
                    },
                    eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) {
                        $.post("{:U('Ajax/index')}?action=drag", {id: event.id, daydiff: dayDelta, minudiff: minuteDelta, allday: allDay}, function(msg) {
                            if (msg != 1) {
                                alert(msg);
                                revertFunc();
                            }
                        });
                    },
                    eventResize: function(event, dayDelta, minuteDelta, revertFunc) {
                        $.post("{:U('Ajax/index')}?action=resize", {id: event.id, daydiff: dayDelta, minudiff: minuteDelta}, function(msg) {
                            if (msg != 1) {
                                alert(msg);
                                revertFunc();
                            }
                        });
                    },
                    selectable: true,
                    select: function(startDate, endDate, allDay, jsEvent, view) {
                        var start = $.fullCalendar.formatDate(startDate, 'yyyy-MM-dd');
                        var end = $.fullCalendar.formatDate(endDate, 'yyyy-MM-dd');
                        $.fancybox({
                            'type': 'ajax',
                            'href': '{:U("Even/index")}?action=add&date=' + start + '&end=' + end
                        });
                    },
                    events: '{:U("Json/index")}',
                    dayClick: function(date, allDay, jsEvent, view) {
                        var selDate = $.fullCalendar.formatDate(date, 'yyyy-MM-dd');
                        $.fancybox({
                            'type': 'ajax',
                            'href': '{:U("Even/index")}?action=add&date=2015-05-07'
                        });
                    },
                    eventClick: function(calEvent, jsEvent, view) {
                        $.fancybox({
                            'type': 'ajax',
                            'href': '{:U("Even/index")}?action=edit&id=' + calEvent.id
                        });
                    }
                });
            });
        </script>
由於代碼過於太多就不一一貼出點擊下面連結下載代碼及資料庫。
http://pan.baidu.com/s/1kUgki8J
官方文檔地址:http://arshaw.com/fullcalendar/docs/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.