Merge "update the huawei's lab"
[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         event = {
18             id: bookings[i]['id'],
19             title: bookings[i]['purpose'],
20             start: start,
21             end: end,
22         };
23         events.push(event);
24     }
25     return events;
26 }
27
28 function loadEvents(url) {
29     $.ajax({
30         url: url,
31         type: 'get',
32         success: function (data) {
33             $('#calendar').fullCalendar('addEventSource', parseCalendarEvents(data['bookings']));
34         },
35         failure: function (data) {
36             alert('Error loading booking data');
37         }
38     });
39 }
40
41 $(document).ready(function () {
42     $('#calendar').fullCalendar(calendarOptions);
43     loadEvents(bookings_url);
44     $('#starttimepicker').datetimepicker(timepickerOptions);
45     $('#endtimepicker').datetimepicker(timepickerOptions);
46 });