Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

$(function () {
        $(document).on('click', '.notification-calendar', function () {
                loadNotificationCalendar('main-content');
        });
});

function loadNotificationCalendar(domId) {
        doGetAjaxRequestHandler(context + '/notificationCalendar', function (response) {
                $('#' + domId).html(response);
                initNotificationCalendar();
        });
}

function initNotificationCalendar() {
        $('#notification-calendar').fullCalendar({
                header: {
                        left: 'prev,next today',
                        center: 'title',
                        right: 'month,agendaWeek,agendaDay'
                },
                editable: false,
                timeFormat: 'H:mm',
                // FullCalendar v1.x: (start, end, callback). start/end are JS Date objects for the visible range.
                events: function (start, end, callback) {
                        var params = 'from=' + moment(start).format('YYYY-MM-DD') +
                                '&to=' + moment(end).format('YYYY-MM-DD');
                        $.getJSON(context + '/notificationCalendarData?' + params, function (data) {
                                callback(data);
                        });
                },
                eventClick: function (event) {
                        $('#ncDetailCampaign').text(event.title);
                        $('#ncDetailWhen').text(moment(event.start).format('DD/MM/YYYY HH:mm'));
                        $('#ncDetailStatus').text(event.status);
                        $('#ncDetailScheduleId').text(event.id);

                        var $btn = $('#ncCancelBtn').off('click');
                        if (event.status !== 'SCHEDULED') {
                                $btn.prop('disabled', true).text('Not cancellable');
                        } else {
                                $btn.prop('disabled', false).text('Cancel Schedule').on('click', function () {
                                        if (!confirm('Cancel this scheduled notification?')) {
                                                return;
                                        }
                                        doPostAjaxRequestWithJsonHandler(
                                                context + '/notificationSchedule/cancel?scheduleId=' + encodeURIComponent(event.id),
                                                '{}',
                                                function (response) {
                                                        $('#scheduleDetailModal').modal('hide');
                                                        if (response === 'true' || response === true) {
                                                                $('#notification-calendar').fullCalendar('refetchEvents');
                                                        } else {
                                                                alert('Could not cancel — the schedule may already be dispatched or cancelled.');
                                                        }
                                                });
                                });
                        }
                        $('#scheduleDetailModal').modal('show');
                }
        });
}