Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
37513 ranu 1
$(function () {
2
	$(document).on('click', '.notification-calendar', function () {
3
		loadNotificationCalendar('main-content');
4
	});
5
});
6
 
7
function loadNotificationCalendar(domId) {
8
	doGetAjaxRequestHandler(context + '/notificationCalendar', function (response) {
9
		$('#' + domId).html(response);
10
		initNotificationCalendar();
11
	});
12
}
13
 
14
function initNotificationCalendar() {
15
	$('#notification-calendar').fullCalendar({
16
		header: {
17
			left: 'prev,next today',
18
			center: 'title',
19
			right: 'month,agendaWeek,agendaDay'
20
		},
21
		editable: false,
22
		timeFormat: 'H:mm',
23
		// FullCalendar v1.x: (start, end, callback). start/end are JS Date objects for the visible range.
24
		events: function (start, end, callback) {
25
			var params = 'from=' + moment(start).format('YYYY-MM-DD') +
26
				'&to=' + moment(end).format('YYYY-MM-DD');
27
			$.getJSON(context + '/notificationCalendarData?' + params, function (data) {
28
				callback(data);
29
			});
30
		},
31
		eventClick: function (event) {
32
			$('#ncDetailCampaign').text(event.title);
33
			$('#ncDetailWhen').text(moment(event.start).format('DD/MM/YYYY HH:mm'));
34
			$('#ncDetailStatus').text(event.status);
35
			$('#ncDetailScheduleId').text(event.id);
36
 
37
			var $btn = $('#ncCancelBtn').off('click');
38
			if (event.status !== 'SCHEDULED') {
39
				$btn.prop('disabled', true).text('Not cancellable');
40
			} else {
41
				$btn.prop('disabled', false).text('Cancel Schedule').on('click', function () {
42
					if (!confirm('Cancel this scheduled notification?')) {
43
						return;
44
					}
45
					doPostAjaxRequestWithJsonHandler(
46
						context + '/notificationSchedule/cancel?scheduleId=' + encodeURIComponent(event.id),
47
						'{}',
48
						function (response) {
49
							$('#scheduleDetailModal').modal('hide');
50
							if (response === 'true' || response === true) {
51
								$('#notification-calendar').fullCalendar('refetchEvents');
52
							} else {
53
								alert('Could not cancel — the schedule may already be dispatched or cancelled.');
54
							}
55
						});
56
				});
57
			}
58
			$('#scheduleDetailModal').modal('show');
59
		}
60
	});
61
}