diff options
author | 2016-07-29 12:43:43 +0200 | |
---|---|---|
committer | 2016-07-29 11:25:20 +0000 | |
commit | 639cd5db77064c275253828780c17ae59551d95c (patch) | |
tree | fca05cf81b3f068ff25c5db46ddd7c27fd1986af /pharos-dashboard/dashboard/static/js/booking-calendar.js | |
parent | 0f7eae0c112b39c071d41a09ad1caf509b70ac32 (diff) |
import pharos dashboard code
JIRA: RELENG-12
The last commit was missing some JS/CSS dependencies of the site. This
happened because they are in folders that are named 'build' or 'dist'.
This commit adds a bower.json file, that specifies dependencies.
Dependencies can now be installed by running 'bower install' in the
dashboard/static folder.
Change-Id: I054f319c66771f767e97711cb678d79d3bd6bee4
Signed-off-by: maxbr <maxbr@mi.fu-berlin.de>
Diffstat (limited to 'pharos-dashboard/dashboard/static/js/booking-calendar.js')
-rw-r--r-- | pharos-dashboard/dashboard/static/js/booking-calendar.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/pharos-dashboard/dashboard/static/js/booking-calendar.js b/pharos-dashboard/dashboard/static/js/booking-calendar.js new file mode 100644 index 0000000..edc2055 --- /dev/null +++ b/pharos-dashboard/dashboard/static/js/booking-calendar.js @@ -0,0 +1,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') + } + }) + }) +});
\ No newline at end of file |