如何在fullcalendar瞬间发生事件?

时间:2016-02-29 08:13:16

标签: javascript jquery html ajax fullcalendar

我有这个功能:

CODE JS:

function addEditEvent(state, event, start, end) {
    if (state == "select") {
        $('#myModal').modal('show');
        calculate_hours(start, end);
        changeDataFormat(start, "#date");
        var url = "<?php echo $this->serverUrl() . str_replace('public', '', $this->basePath()) . '/user/ajaxcreateeventagenda'; ?>";
        $("#save-Appointment").off('click').on('click', function (e) {
            var title = $("#eventName").val();

            if (title && BeforeSubmit(".app-event")) {
                appointmentType = 'appointment';                                  
                ajaxData = {
                    'title': title,
                    'app_type': appointmentType,
                    'patientId': $('#pacient_id').val(),
                    'date': $('#date').val() + ' ' + $('#time').val(),
                    'duration': $('#duration').val(),
                };
                $.ajax({
                    type: 'POST',
                    data: ajaxData,
                    url: url,
                    success: function (result) {
                        if (result.success) {
                            calendar.fullCalendar('renderEvent',
                                {
                                    title: title,
                                    start: start,
                                    end: end,
                                    time: $('#time').val(),
                                    date: $('#date').val(),
                                    duration: $('#duration').val(),
                                },
                                true
                            );
                        }
                    }
                })
                e.preventDefault();
                $('#myModal').modal('hide');
                calendar.fullCalendar('unselect');

            } else {
                e.preventDefault();
                CheckBefore();
            }
        });

        $("#save-Event").off('click').on('click', function (e) {

        });

        calendar.fullCalendar('unselect');
    } else if (state == "eventClick") {
        $('#myModal').modal('show');
        $("#save-Appointment").off('click').on('click', function (e) {
            e.preventDefault();
            event.title = $("#eventName").val();
            if (event.title && BeforeSubmit(".app-event")) {
                $('#calendar-app').fullCalendar('updateEvent', event);
                $('#myModal').modal('hide');
            } else {
                e.preventDefault();
                CheckBefore();
            }

        });
    }
    }

这是一个名为

的函数
    var state = "";
    var calendar = $('#calendar-app').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        defaultDate: '<?php echo $date; ?>',
        editable: true,
        eventLimit: true, // allow "more" link when too many events
        defaultView: 'agendaDay',
        selectable: true,   
        selectHelper: true,  


        eventClick: function (event, jsEvent, view) {

            addEditEvent("eventClick", event);
        },
        select: function (start, end, allDay) {
            addEditEvent("select", event, start, end);
        },

        events: [
            <?php
            foreach($app AS $a)
            {

            $name = '';
            if ($a['patient_id'] == 0) {
                $name = 'Leed: ' . $a['leed_name'];
            } else {
                $patient = $this->patient->getPacient($a['patient_id']);
                $name = $patient->firstname . ' ' . $patient->lastname;
            }
            ?>
            {
                title: '<?php echo $name . ' ->' . $a['reason'] ?>',
                patientname: '<?php echo $name; ?>',
                start: '<?php echo trim($a['date']) . 'T' . $a['hour'] ?>',
                end: '<?php echo trim($a['date']) . 'T' . $a['end_hour'] ?>',
            },
            <?php

            }
            ?>

        ]

    });

代码HTML:

<div id='calendar-app'></div>


<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <ul class="nav nav-tabs" id="tabContent">
                <li class="active"><a href="#details" data-toggle="tab">Appointments</a></li>
                <li><a href="#access-security" data-toggle="tab">Events</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active" id="details">
                    <div class="col-md-12" style="background:white;">
                        <form class="app-event">
                            <div class="row">
                                <label class="control-label">Appointment Name</label>
                                <input type="text" name="eventName" id="eventName" class="required-input">
                                <input type="hidden" name="pacient_id" id="pacient_id" value="92">
                                <div class="row">
                                    <label class="control-label">Start</label>
                                    <input type="text" name="time" id="time" value="17:30">
                                </div>
                                <div class="row">
                                    <label class="control-label">Duration</label>
                                    <input type="text" name="duration" id="duration" value="60">
                                </div>

                                <input type="text" name="date" id="date">
                            </div>

                            <input type="submit" value="Submit" id="save-Appointment">

                        </form>
                    </div>
                </div>
                <div class="tab-pane" id="access-security">
                    <div class="row">
                        <label class="control-label">Event Name</label>
                        <input type="text" name="eventName" id="eventName" class="required-input">
                    </div>
                    <input type="submit" value="Submit" id="save-Event">
                </div>
            </div>
        </div>

    </div>
</div>

我将尝试描述这段代码:

1.我使用完整日历库在日历中添加事件

2.当您点击日历时,会打开一个弹出式输入来添加事件

3.当事件保存在数据库中时“保存”

存在哪些问题

1.Events日历应该立即出现(没有页面收费)。此时只有我刷新发生的事件

2.如何改进addEditEvent函数?此时代码非常复杂,我希望你简化。有些东西可以单独移动Ajax代码吗?

我希望我能设法描述一下.Daca担心他们有问题请问我

提前致谢!

0 个答案:

没有答案