如何在点击按钮时在fullcalendar中添加任何事件?

时间:2015-04-05 08:17:32

标签: javascript jquery jsp fullcalendar

我在每天/单元格中添加了(' +')按钮。

var add_button = '<input type="button" value="+" />'; 
$(".fc-day-number").prepend(add_button);

calendar with each cells having button to add event

如何在点击此按钮后添加活动(&#39; +&#39;)按钮,只需点击任何一天即可执行相同操作:

dayClick: function(date) {
                addEvent(date);                 
            },

function addEvent(date) {
    var newEvent = {
    title: timeSlot,
    start: date.format()
    };
}

1 个答案:

答案 0 :(得分:0)

单击该按钮时,您可以打开一个对话框。 Dialog是一个接受值的表单。保存表单后,您可以执行jquery ajax调用以将其保存到存储中。

dayClick: function (date, allDay, jsEvent, view) {
            $('#eventTitle').val("");
            $('#eventDate').val($.fullCalendar.formatDate(date, 'dd/MM/yyyy'));
            $('#eventTime').val($.fullCalendar.formatDate(date, 'HH:mm'));
            ShowEventPopup(date);
        },

function ShowEventPopup(date) {

    $('#popupEventForm').modal('show');
    $('#eventTitle').focus();
}

$('#btnPopupSave').click(function () {

    $('#popupEventForm').hide();

    var dataRow = {
        'Title': $('#eventTitle').val(),
        'NewEventDate': $('#eventDate').val(),
        'NewEventTime': $('#eventTime').val(),
        'NewEventDuration': $('#eventDuration').val()
    }

    ClearPopupFormValues();

    $.ajax({
        type: 'POST',
        url: "/Diary/SaveEvent",
        data: dataRow,
        success: function (response) {
            if (response == 'True') {
                $('#calendar').fullCalendar('refetchEvents');
                alert('New event saved!');
            }
            else {
                alert('Error, could not save event!');
            }
        }
    });
});