blob: edc20551e1cf3aa6038acfd2c9ff783725a9a1d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
function parseDisabledTimeIntervals(bookings) {
var timeIntervals = [];
for (var i = 0; i < bookings.length; i++) {
var interval = [
moment(bookings[i]['start_date_time']),
moment(bookings[i]['end_date_time'])
];
timeIntervals.push(interval);
}
return timeIntervals;
}
function parseCalendarEvents(bookings) {
var events = [];
for (var i = 0; i < bookings.length; i++) {
event = {
id: bookings[i]['booking_id'],
title: bookings[i]['purpose'],
start: bookings[i]['start_date_time'],
end: bookings[i]['end_date_time'],
editable: true
};
events.push(event);
}
return events;
}
function loadEvents(bookings_url) {
$.ajax({
url: bookings_url,
type: 'get',
success: function (data) {
$('#calendar').fullCalendar('addEventSource', parseCalendarEvents(data['bookings']));
var intervals = parseDisabledTimeIntervals(data['bookings']);
$('#starttimepicker').data("DateTimePicker").disabledTimeIntervals(intervals);
$('#endtimepicker').data("DateTimePicker").disabledTimeIntervals(intervals);
},
failure: function (data) {
alert('Error loading booking data');
}
});
}
$(document).ready(function () {
$('#calendar').fullCalendar(calendarOptions);
$('#starttimepicker').datetimepicker(timepickerOptions);
$('#endtimepicker').datetimepicker(timepickerOptions);
loadEvents(bookings_url);
// send Post request to delete url if button is clicked
$("#deletebutton").click(function () {
var booking_id = $('#id_booking_id').val();
$.ajax({
type: 'post',
url: '/booking/' + booking_id + '/delete',
success: function () {
$('#calendar').fullCalendar('removeEvents');
loadEvents(bookings_url);
$('#calendar').fullCalendar('rerenderEvents');
},
failure: function () {
alert('Deleting failed')
}
})
})
});
|