From 7db07a9e6acbeac7b34f91589680a8443afcc33c Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 18 Jul 2016 21:26:31 +0200 Subject: [PATCH] Added display for unavailabilities (#182). --- src/assets/js/backend_calendar_table_view.js | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/assets/js/backend_calendar_table_view.js b/src/assets/js/backend_calendar_table_view.js index 741b8820..2fceaa30 100644 --- a/src/assets/js/backend_calendar_table_view.js +++ b/src/assets/js/backend_calendar_table_view.js @@ -266,6 +266,36 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {}; if (unavailabilities.length === 0) { return; } + + var currentDate = new Date($providerColumn.parents('.date-column').data('date')); + var $tbody = $providerColumn.find('table tbody'); + + for (var index in unavailabilities) { + var unavailability = unavailabilities[index]; + + if (unavailability.id_users_provider !== $providerColumn.data('provider').id) { + continue; + } + + var eventDate = Date.parse(unavailability.start_datetime); + var $event = $('
'); + + $event.html(unavailability.notes || 'Unavailability'); + + $tbody.find('tr').each(function(index, tr) { + var $td = $(tr).find('td:first'); + + var cellDate = new Date(currentDate.getTime()).set({ + hour: parseInt($td.text().split(':')[0]), + minute: parseInt($td.text().split(':')[1]) + }); + + if (eventDate < cellDate) { + $event.appendTo($(tr).prev().find('td').eq(1)); + return false; + } + }); + } } function _setCalendarSize() {