Add Installer and Scenario fields to bookings
[pharos.git] / tools / pharos-dashboard / src / static / js / booking-calendar.js
1 /*****************************************************************************
2  * Copyright (c) 2016 Max Breitenfeldt and others.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Apache License, Version 2.0
6  * which accompanies this distribution, and is available at
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *****************************************************************************/
9
10
11 function parseCalendarEvents(bookings) {
12     var events = [];
13     for (var i = 0; i < bookings.length; i++) {
14         // convert ISO 8601 timestring to moment, needed for timezone handling
15         start = moment(bookings[i]['start']);
16         end = moment(bookings[i]['end']);
17
18         installer = bookings[i]['installer__name'];
19         if (installer === null) {
20             installer = '';
21         }
22
23         scenario = bookings[i]['scenario__name'];
24         if (scenario === null) {
25             scenario = '';
26         }
27         title = bookings[i]['purpose'] + ' ' + installer + ' ' + scenario;
28
29         event = {
30             id: bookings[i]['id'],
31             title: title,
32             start: start,
33             end: end,
34         };
35         events.push(event);
36     }
37     return events;
38 }
39
40 function loadEvents(url) {
41     $.ajax({
42         url: url,
43         type: 'get',
44         success: function (data) {
45             $('#calendar').fullCalendar('addEventSource', parseCalendarEvents(data['bookings']));
46         },
47         failure: function (data) {
48             alert('Error loading booking data');
49         }
50     });
51 }
52
53 $(document).ready(function () {
54     $('#calendar').fullCalendar(calendarOptions);
55     loadEvents(bookings_url);
56     $('#starttimepicker').datetimepicker(timepickerOptions);
57     $('#endtimepicker').datetimepicker(timepickerOptions);
58 });