From 5bb56b8653c15fe92a4e772dd3c1e46f2e335169 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 15 Aug 2016 21:32:31 +0200 Subject: [PATCH] Reload only the events markup on table calendar view. --- src/assets/js/backend_calendar_table_view.js | 45 +++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/assets/js/backend_calendar_table_view.js b/src/assets/js/backend_calendar_table_view.js index bd00511f..b41f4844 100644 --- a/src/assets/js/backend_calendar_table_view.js +++ b/src/assets/js/backend_calendar_table_view.js @@ -50,9 +50,52 @@ window.BackendCalendarTableView = window.BackendCalendarTableView || {}; }); $calendarToolbar.on('click', '#reload-appointments', function() { + // Remove all the events from the tables. + $('.calendar-view .event').remove(); + + // Fetch the events and place them in the existing HTML format. var startDate = new Date($('.calendar-view .date-column:first').data('date')); var endDate = new Date($('.calendar-view .date-column:last').data('date')); - _createView(startDate, endDate); + _getCalendarEvents(startDate, endDate) + .done(function(response) { + if (!GeneralFunctions.handleAjaxExceptions(response)) { + return; + } + + var currentDate = startDate; + + while(currentDate <= endDate) { + $('.calendar-view .date-column').each(function(index, dateColumn) { + var $dateColumn = $(dateColumn); + var date = new Date($dateColumn.data('date')); + + $(dateColumn).find('.provider-column').each(function(index, providerColumn) { + var $providerColumn = $(providerColumn); + var provider = $providerColumn.data('provider'); + + // Add the appointments to the column. + _createAppointments($providerColumn, response.appointments); + + // Add the unavailabilities to the column. + _createUnavailabilities($providerColumn, response.unavailabilities); + + // Add the provider breaks to the column. + var workingPlan = JSON.parse(provider.settings.working_plan); + var day = date.toString('dddd').toLowerCase(); + if (workingPlan[day]) { + var breaks = workingPlan[day].breaks; + _createBreaks($providerColumn, breaks); + } + }); + }); + + currentDate.add({days: 1}); + } + + _setCalendarSize(); + Backend.placeFooterToBottom(); + }) + .fail(GeneralFunctions.ajaxFailureHandler); }); $calendar.on('click', '.calendar-view table td', function() {