summaryrefslogtreecommitdiffstats
path: root/pharos-dashboard/static/js/booking-calendar.js
blob: f8a9a0ff6de4ca1274407e6b06283cfbfb01ac86 (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
function parseCalendarEvents(bookings) {
    var events = [];
    for (var i = 0; i < bookings.length; i++) {
        // convert ISO 8601 timestring to moment, needed for timezone handling
        start = moment(bookings[i]['start']);
        end = moment(bookings[i]['end']);
        event = {
            id: bookings[i]['id'],
            title: bookings[i]['purpose'],
            start: start,
            end: end,
        };
        events.push(event);
    }
    return events;
}

function loadEvents(url) {
    $.ajax({
        url: url,
        type: 'get',
        success: function (data) {
            $('#calendar').fullCalendar('addEventSource', parseCalendarEvents(data['bookings']));
        },
        failure: function (data) {
            alert('Error loading booking data');
        }
    });
}

$(document).ready(function () {
    $('#calendar').fullCalendar(calendarOptions);
    loadEvents(bookings_url);
    $('#starttimepicker').datetimepicker(timepickerOptions);
    $('#endtimepicker').datetimepicker(timepickerOptions);
});