2016-07-17 14:46:38 +03:00
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
|
*
|
|
|
|
|
* @package EasyAppointments
|
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2020-05-04 12:32:00 +03:00
|
|
|
|
* @copyright Copyright (c) 2013 - 2016, Alex Tselegidis
|
2016-07-17 14:46:38 +03:00
|
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
|
* @since v1.2.0
|
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
window.BackendCalendarTableView = window.BackendCalendarTableView || {};
|
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
|
/**
|
|
|
|
|
* Backend Calendar
|
|
|
|
|
*
|
|
|
|
|
* This module implements the table calendar view of backend.
|
|
|
|
|
*
|
|
|
|
|
* @module BackendCalendarTableView
|
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
|
(function (exports) {
|
2016-07-17 14:46:38 +03:00
|
|
|
|
'use strict';
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var $filterProvider;
|
|
|
|
|
var $filterService;
|
|
|
|
|
var lastFocusedEventData;
|
2016-08-15 22:59:43 +03:00
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Bind page event handlers.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function bindEventHandlers() {
|
2016-07-24 14:25:54 +03:00
|
|
|
|
var $calendarToolbar = $('#calendar-toolbar');
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var $calendar = $('#calendar');
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$calendar.on('click', '.calendar-header .btn.previous', function () {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var dayInterval = $('#select-filter-item').val();
|
|
|
|
|
var currentDate = $('.select-date').datepicker('getDate');
|
|
|
|
|
var startDate = moment(currentDate).subtract(1, 'days');
|
|
|
|
|
var endDate = startDate.clone().add(dayInterval - 1, 'days');
|
|
|
|
|
$('.select-date').datepicker('setDate', startDate.toDate());
|
|
|
|
|
createView(startDate.toDate(), endDate.toDate());
|
2016-07-17 19:51:46 +03:00
|
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$calendar.on('click', '.calendar-header .btn.next', function () {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var dayInterval = $('#select-filter-item').val();
|
|
|
|
|
var currentDate = $('.select-date').datepicker('getDate');
|
|
|
|
|
var startDate = moment(currentDate).add(1, 'days');
|
|
|
|
|
var endDate = startDate.clone().add(dayInterval - 1, 'days');
|
|
|
|
|
$('.select-date').datepicker('setDate', startDate.toDate());
|
|
|
|
|
createView(startDate.toDate(), endDate.toDate());
|
2016-07-17 19:51:46 +03:00
|
|
|
|
});
|
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$calendarToolbar.on('change', '#select-filter-item', function () {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var dayInterval = $('#select-filter-item').val();
|
|
|
|
|
var currentDate = $('.select-date').datepicker('getDate');
|
|
|
|
|
var startDate = moment(currentDate);
|
|
|
|
|
var endDate = startDate.clone().add(dayInterval - 1, 'days');
|
|
|
|
|
createView(startDate.toDate(), endDate.toDate());
|
2016-07-18 21:18:55 +03:00
|
|
|
|
});
|
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$calendarToolbar.on('click', '#reload-appointments', function () {
|
2020-04-27 21:14:20 +03:00
|
|
|
|
// Remove all the events from the tables.
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$('.calendar-view .event').remove();
|
2016-08-15 22:32:31 +03:00
|
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
|
// Fetch the events and place them in the existing HTML format.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var dayInterval = $('#select-filter-item').val();
|
|
|
|
|
var currentDate = $('.select-date').datepicker('getDate');
|
|
|
|
|
var startDateMoment = moment(currentDate);
|
|
|
|
|
var startDate = startDateMoment.toDate();
|
|
|
|
|
var endDateMoment = startDateMoment.clone().add(dayInterval - 1, 'days');
|
|
|
|
|
var endDate = endDateMoment.toDate();
|
|
|
|
|
|
|
|
|
|
getCalendarEvents(startDate, endDate)
|
2018-01-23 12:08:37 +03:00
|
|
|
|
.done(function (response) {
|
|
|
|
|
var currentDate = startDate;
|
2016-08-15 22:32:31 +03:00
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
while (currentDate <= endDate) {
|
|
|
|
|
$('.calendar-view .date-column').each(function (index, dateColumn) {
|
|
|
|
|
var $dateColumn = $(dateColumn);
|
2016-08-15 22:32:31 +03:00
|
|
|
|
var date = new Date($dateColumn.data('date'));
|
|
|
|
|
|
2016-11-06 14:24:21 +03:00
|
|
|
|
if (currentDate.getTime() !== date.getTime()) {
|
2016-11-06 14:18:02 +03:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$dateColumn.find('.date-column-title').text(GeneralFunctions.formatDate(date, GlobalVariables.dateFormat));
|
|
|
|
|
|
|
|
|
|
$dateColumn.find('.provider-column').each(function (index, providerColumn) {
|
2016-08-15 22:32:31 +03:00
|
|
|
|
var $providerColumn = $(providerColumn);
|
|
|
|
|
var provider = $providerColumn.data('provider');
|
|
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
|
// $providerColumn.find('.calendar-wrapper').fullCalendar('removeEvents');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2020-05-12 21:52:32 +03:00
|
|
|
|
// createNonWorkingHours($providerColumn.find('.calendar-wrapper'), JSON.parse($providerColumn.data('provider').settings.working_plan));
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
|
// Add the appointments to the column.
|
2020-05-12 21:52:32 +03:00
|
|
|
|
// createAppointments($providerColumn, response.appointments);
|
2018-01-23 12:08:37 +03:00
|
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
|
// Add the unavailabilities to the column.
|
2020-05-12 21:52:32 +03:00
|
|
|
|
// createUnavailabilities($providerColumn, response.unavailabilities);
|
2016-08-15 22:32:31 +03:00
|
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
|
// Add the provider breaks to the column.
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var workingPlan = JSON.parse(provider.settings.working_plan);
|
2016-08-15 22:32:31 +03:00
|
|
|
|
var day = date.toString('dddd').toLowerCase();
|
|
|
|
|
if (workingPlan[day]) {
|
|
|
|
|
var breaks = workingPlan[day].breaks;
|
2020-05-12 21:52:32 +03:00
|
|
|
|
// createBreaks($providerColumn, breaks);
|
2016-08-15 22:32:31 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
currentDate.add({days: 1});
|
2016-08-15 22:32:31 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// setCalendarViewSize();
|
2016-08-15 22:32:31 +03:00
|
|
|
|
Backend.placeFooterToBottom();
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2016-08-15 22:32:31 +03:00
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2018-01-23 12:08:37 +03:00
|
|
|
|
});
|
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
/**
|
|
|
|
|
* Event: On Window Resize
|
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$(window).on('resize', function () {
|
|
|
|
|
setCalendarViewSize();
|
|
|
|
|
});
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event: Popover Close Button "Click"
|
|
|
|
|
*
|
|
|
|
|
* Hides the open popover element.
|
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$calendar.on('click', '.close-popover', function () {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$(this).parents('.popover').popover('destroy');
|
2016-07-18 23:22:28 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event: Popover Edit Button "Click"
|
|
|
|
|
*
|
2016-07-22 23:06:36 +03:00
|
|
|
|
* Enables the edit dialog of the selected table event.
|
2016-07-18 23:22:28 +03:00
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$calendar.on('click', '.edit-popover', function () {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$(this).parents('.popover').popover('destroy');
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
|
|
|
|
var $dialog;
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (lastFocusedEventData.data.is_unavailable === '0') {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var appointment = lastFocusedEventData.data;
|
2016-07-18 23:22:28 +03:00
|
|
|
|
$dialog = $('#manage-appointment');
|
|
|
|
|
|
|
|
|
|
BackendCalendarAppointmentsModal.resetAppointmentDialog();
|
|
|
|
|
|
|
|
|
|
// Apply appointment data and show modal dialog.
|
2017-09-11 17:09:15 +03:00
|
|
|
|
$dialog.find('.modal-header h3').text(EALang.edit_appointment_title);
|
2017-11-02 16:19:54 +03:00
|
|
|
|
$dialog.find('#appointment-id').val(appointment.id);
|
|
|
|
|
$dialog.find('#select-service').val(appointment.id_services).trigger('change');
|
|
|
|
|
$dialog.find('#select-provider').val(appointment.id_users_provider);
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
|
|
|
|
// Set the start and end datetime of the appointment.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var startDatetime = Date.parseExact(appointment.start_datetime, 'yyyy-MM-dd HH:mm:ss');
|
2016-07-18 23:22:28 +03:00
|
|
|
|
$dialog.find('#start-datetime').datetimepicker('setDate', startDatetime);
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var endDatetime = Date.parseExact(appointment.end_datetime, 'yyyy-MM-dd HH:mm:ss');
|
2016-07-18 23:22:28 +03:00
|
|
|
|
$dialog.find('#end-datetime').datetimepicker('setDate', endDatetime);
|
|
|
|
|
|
2017-11-02 16:19:54 +03:00
|
|
|
|
var customer = appointment.customer;
|
|
|
|
|
$dialog.find('#customer-id').val(appointment.id_users_customer);
|
|
|
|
|
$dialog.find('#first-name').val(customer.first_name);
|
|
|
|
|
$dialog.find('#last-name').val(customer.last_name);
|
|
|
|
|
$dialog.find('#email').val(customer.email);
|
|
|
|
|
$dialog.find('#phone-number').val(customer.phone_number);
|
|
|
|
|
$dialog.find('#address').val(customer.address);
|
|
|
|
|
$dialog.find('#city').val(customer.city);
|
|
|
|
|
$dialog.find('#zip-code').val(customer.zip_code);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$dialog.find('#appointment-location').val(appointment.location);
|
2017-11-02 16:19:54 +03:00
|
|
|
|
$dialog.find('#appointment-notes').val(appointment.notes);
|
|
|
|
|
$dialog.find('#customer-notes').val(customer.notes);
|
2016-07-18 23:22:28 +03:00
|
|
|
|
} else {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var unavailable = lastFocusedEventData.data;
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
|
|
|
|
// Replace string date values with actual date objects.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
unavailable.start_datetime = lastFocusedEventData.start.format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
var startDatetime = Date.parseExact(unavailable.start_datetime, 'yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
unavailable.end_datetime = lastFocusedEventData.end.format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
|
var endDatetime = Date.parseExact(unavailable.end_datetime, 'yyyy-MM-dd HH:mm:ss');
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
|
|
|
|
$dialog = $('#manage-unavailable');
|
2016-07-18 23:55:05 +03:00
|
|
|
|
BackendCalendarUnavailabilitiesModal.resetUnavailableDialog();
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Apply unavailable data to dialog.
|
2016-07-18 23:22:28 +03:00
|
|
|
|
$dialog.find('.modal-header h3').text('Edit Unavailable Period');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$dialog.find('#unavailable-start').datetimepicker('setDate', startDatetime);
|
2016-07-18 23:22:28 +03:00
|
|
|
|
$dialog.find('#unavailable-id').val(unavailable.id);
|
2016-07-18 23:55:05 +03:00
|
|
|
|
$dialog.find('#unavailable-provider').val(unavailable.id_users_provider);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$dialog.find('#unavailable-end').datetimepicker('setDate', endDatetime);
|
2016-07-18 23:22:28 +03:00
|
|
|
|
$dialog.find('#unavailable-notes').val(unavailable.notes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// :: DISPLAY EDIT DIALOG
|
|
|
|
|
$dialog.modal('show');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Event: Popover Delete Button "Click"
|
|
|
|
|
*
|
2017-11-02 16:19:54 +03:00
|
|
|
|
* Displays a prompt on whether the user wants the appointment to be deleted. If he confirms the
|
2016-07-18 23:22:28 +03:00
|
|
|
|
* deletion then an ajax call is made to the server and deletes the appointment from the database.
|
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$calendar.on('click', '.delete-popover', function () {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$(this).parents('.popover').popover('destroy'); // Hide the popover.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var url;
|
|
|
|
|
var data;
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// If id_role parameter exists the popover is an extra working day.
|
|
|
|
|
if (lastFocusedEventData.data.hasOwnProperty('id_roles')) {
|
|
|
|
|
// Do not display confirmation prompt.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_extra_period';
|
|
|
|
|
|
|
|
|
|
data = {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
extra_period: lastFocusedEventData.start.format('YYYY-MM-DD'),
|
|
|
|
|
provider_id: lastFocusedEventData.data.id
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function (response) {
|
|
|
|
|
$('#message_box').dialog('close');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var extraWorkingPlan = jQuery.parseJSON(lastFocusedEventData.data.settings.extra_working_plan);
|
|
|
|
|
delete extraWorkingPlan[lastFocusedEventData.start.format('YYYY-MM-DD')];
|
|
|
|
|
lastFocusedEventData.data.settings.extra_working_plan = JSON.stringify(extraWorkingPlan);
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
// Refresh calendar event items.
|
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
|
|
|
|
} else if (lastFocusedEventData.data.is_unavailable === '0') {
|
2017-09-23 04:49:46 +03:00
|
|
|
|
var buttons = [
|
|
|
|
|
{
|
|
|
|
|
text: 'OK',
|
2018-01-23 12:08:37 +03:00
|
|
|
|
click: function () {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_appointment';
|
|
|
|
|
|
|
|
|
|
data = {
|
2017-09-23 04:49:46 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
2020-05-04 12:32:00 +03:00
|
|
|
|
appointment_id: lastFocusedEventData.data.id,
|
2017-09-23 04:49:46 +03:00
|
|
|
|
delete_reason: $('#delete-reason').val()
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#message_box').dialog('close');
|
2017-09-23 04:49:46 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
// Refresh calendar event items.
|
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2017-09-23 04:49:46 +03:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: EALang.cancel,
|
2018-01-23 12:08:37 +03:00
|
|
|
|
click: function () {
|
2017-09-23 04:49:46 +03:00
|
|
|
|
$('#message_box').dialog('close');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
];
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2017-09-11 17:09:15 +03:00
|
|
|
|
GeneralFunctions.displayMessageBox(EALang.delete_appointment_title,
|
2018-01-23 12:08:37 +03:00
|
|
|
|
EALang.write_appointment_removal_reason, buttons);
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$('#message_box').append('<textarea id="delete-reason" rows="3"></textarea>');
|
|
|
|
|
$('#delete-reason').css('width', '100%');
|
2016-07-18 23:22:28 +03:00
|
|
|
|
} else {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Do not display confirmation prompt.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_delete_unavailable';
|
|
|
|
|
|
|
|
|
|
data = {
|
2016-07-18 23:22:28 +03:00
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
2020-05-04 12:32:00 +03:00
|
|
|
|
unavailable_id: lastFocusedEventData.data.id
|
2016-07-18 23:22:28 +03:00
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#message_box').dialog('close');
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
// Refresh calendar event items.
|
|
|
|
|
$('#select-filter-item').trigger('change');
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2016-07-18 23:22:28 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Create table view header container.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*
|
|
|
|
|
* The header contains the date navigation elements (buttons and datepicker).
|
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function createHeader() {
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var $calendarFilter = $('#calendar-filter');
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
|
|
|
|
$calendarFilter
|
|
|
|
|
.find('select')
|
|
|
|
|
.empty()
|
2018-01-23 12:08:37 +03:00
|
|
|
|
.append(new Option('1 ' + EALang.day, 1))
|
2017-09-11 17:09:15 +03:00
|
|
|
|
.append(new Option('3 ' + EALang.days, 3));
|
2018-01-23 12:08:37 +03:00
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
var $calendarHeader = $('<div/>', {
|
|
|
|
|
'class': 'calendar-header'
|
|
|
|
|
})
|
|
|
|
|
.appendTo('#calendar');
|
|
|
|
|
|
|
|
|
|
$('<button/>', {
|
2020-06-19 14:09:22 +03:00
|
|
|
|
'class': 'btn btn-xs btn-light previous',
|
2020-05-07 19:47:14 +03:00
|
|
|
|
'html': [
|
|
|
|
|
$('<span/>', {
|
2020-06-29 16:23:51 +03:00
|
|
|
|
'class': 'fas fa-chevron-left'
|
2020-05-07 19:47:14 +03:00
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
.appendTo($calendarHeader);
|
|
|
|
|
|
|
|
|
|
$('<input/>', {
|
|
|
|
|
'type': 'text',
|
|
|
|
|
'class': 'select-date',
|
|
|
|
|
'value': GeneralFunctions.formatDate(new Date(), GlobalVariables.dateFormat)
|
|
|
|
|
})
|
|
|
|
|
.appendTo($calendarHeader);
|
|
|
|
|
|
|
|
|
|
$('<button/>', {
|
2020-06-19 14:09:22 +03:00
|
|
|
|
'class': 'btn btn-xs btn-light next',
|
2020-05-07 19:47:14 +03:00
|
|
|
|
'html': [
|
|
|
|
|
$('<span/>', {
|
2020-06-29 16:23:51 +03:00
|
|
|
|
'class': 'fas fa-chevron-right'
|
2020-05-07 19:47:14 +03:00
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
.appendTo($calendarHeader);
|
2016-07-20 21:34:13 +03:00
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var dateFormat;
|
2016-07-20 21:34:13 +03:00
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
switch (GlobalVariables.dateFormat) {
|
2016-07-22 23:06:36 +03:00
|
|
|
|
case 'DMY':
|
|
|
|
|
dateFormat = 'dd/mm/yy';
|
|
|
|
|
break;
|
2016-07-20 21:34:13 +03:00
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
case 'MDY':
|
|
|
|
|
dateFormat = 'mm/dd/yy';
|
|
|
|
|
break;
|
2016-07-20 21:34:13 +03:00
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
case 'YMD':
|
|
|
|
|
dateFormat = 'yy/mm/dd';
|
|
|
|
|
break;
|
2016-07-20 21:34:13 +03:00
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
default:
|
|
|
|
|
throw new Error('Invalid date format setting provided!', GlobalVariables.dateFormat);
|
2018-01-23 12:08:37 +03:00
|
|
|
|
}
|
2016-07-20 21:34:13 +03:00
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
$calendarHeader.find('.select-date').datepicker({
|
|
|
|
|
defaultDate: new Date(),
|
|
|
|
|
dateFormat: dateFormat,
|
2018-01-23 12:08:37 +03:00
|
|
|
|
onSelect: function (dateText, instance) {
|
2016-07-22 23:06:36 +03:00
|
|
|
|
var startDate = new Date(instance.currentYear, instance.currentMonth, instance.currentDay);
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var endDate = new Date(startDate.getTime()).add({days: parseInt($('#select-filter-item').val()) - 1});
|
2020-05-04 12:32:00 +03:00
|
|
|
|
createView(startDate, endDate);
|
2018-01-23 12:08:37 +03:00
|
|
|
|
}
|
2016-07-22 23:06:36 +03:00
|
|
|
|
});
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
|
|
var providers = GlobalVariables.availableProviders.filter(function (provider) {
|
|
|
|
|
return GlobalVariables.user.role_slug === Backend.DB_SLUG_ADMIN
|
|
|
|
|
|| (GlobalVariables.user.role_slug === Backend.DB_SLUG_SECRETARY
|
|
|
|
|
&& GlobalVariables.secretaryProviders.indexOf(provider.id) !== -1)
|
|
|
|
|
|| (GlobalVariables.user.role_slug === Backend.DB_SLUG_PROVIDER
|
|
|
|
|
&& Number(provider.id) === Number(GlobalVariables.user.id));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Create providers and service filters.
|
|
|
|
|
if (GlobalVariables.user.role_slug !== Backend.DB_SLUG_PROVIDER) {
|
|
|
|
|
$('<label/>', {
|
|
|
|
|
'text': EALang.provider
|
|
|
|
|
})
|
|
|
|
|
.appendTo($calendarHeader);
|
|
|
|
|
|
|
|
|
|
$filterProvider = $('<select/>', {
|
|
|
|
|
'id': 'filter-provider',
|
2020-05-04 14:13:22 +03:00
|
|
|
|
'multiple': 'multiple',
|
2020-05-04 12:32:00 +03:00
|
|
|
|
'on': {
|
|
|
|
|
'change': function () {
|
|
|
|
|
var startDate = new Date($('.calendar-view .date-column:first').data('date'));
|
|
|
|
|
var endDate = new Date(startDate.getTime()).add({days: parseInt($('#select-date').val()) - 1});
|
|
|
|
|
createView(startDate, endDate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.appendTo($calendarHeader);
|
|
|
|
|
|
|
|
|
|
providers.forEach(function (provider) {
|
|
|
|
|
$filterProvider.append(new Option(provider.first_name + ' ' + provider.last_name, provider.id));
|
|
|
|
|
});
|
2020-05-04 14:13:22 +03:00
|
|
|
|
|
|
|
|
|
$filterProvider.select2();
|
2020-05-04 12:32:00 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var services = GlobalVariables.availableServices.filter(function (service) {
|
|
|
|
|
var provider = providers.find(function (provider) {
|
|
|
|
|
return provider.services.indexOf(service.id) !== -1;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return GlobalVariables.user.role_slug === Backend.DB_SLUG_ADMIN || provider;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('<label/>', {
|
|
|
|
|
'text': EALang.service
|
|
|
|
|
})
|
|
|
|
|
.appendTo($calendarHeader);
|
|
|
|
|
|
|
|
|
|
$filterService = $('<select/>', {
|
|
|
|
|
'id': 'filter-service',
|
2020-05-04 14:13:22 +03:00
|
|
|
|
'multiple': 'multiple',
|
2020-05-04 12:32:00 +03:00
|
|
|
|
'on': {
|
|
|
|
|
'change': function () {
|
|
|
|
|
var startDate = new Date($('.calendar-view .date-column:first').data('date'));
|
|
|
|
|
var endDate = new Date(startDate.getTime()).add({days: parseInt($('#select-date').val()) - 1});
|
|
|
|
|
createView(startDate, endDate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.appendTo($calendarHeader);
|
|
|
|
|
|
|
|
|
|
services.forEach(function (service) {
|
|
|
|
|
$filterService.append(new Option(service.name, service.id));
|
|
|
|
|
});
|
2020-05-04 14:13:22 +03:00
|
|
|
|
|
|
|
|
|
$filterService.select2();
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Create table schedule view.
|
|
|
|
|
*
|
|
|
|
|
* This method will destroy any previous instances and create a new view for displaying the appointments in
|
|
|
|
|
* a table format.
|
2016-07-17 19:51:46 +03:00
|
|
|
|
*
|
|
|
|
|
* @param {Date} startDate Start date to be displayed.
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* @param {Date} endDate End date to be displayed.
|
2016-07-17 19:51:46 +03:00
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function createView(startDate, endDate) {
|
2016-11-06 13:44:32 +03:00
|
|
|
|
// Disable date navigation.
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$('#calendar .calendar-header .btn')
|
|
|
|
|
.addClass('disabled')
|
|
|
|
|
.prop('disabled', true);
|
2016-11-06 13:44:32 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Remember provider calendar view mode.
|
|
|
|
|
var providerView = {};
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$('.provider-column').each(function (index, providerColumn) {
|
|
|
|
|
var $providerColumn = $(providerColumn);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var providerId = $providerColumn.data('provider').id;
|
|
|
|
|
providerView[providerId] = $providerColumn.find('.calendar-wrapper').fullCalendar('getView').name;
|
|
|
|
|
});
|
|
|
|
|
|
2016-07-18 22:20:43 +03:00
|
|
|
|
$('#calendar .calendar-view').remove();
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
Backend.placeFooterToBottom();
|
|
|
|
|
|
|
|
|
|
var $calendarView = $('<div/>', {
|
|
|
|
|
'class': 'calendar-view'
|
|
|
|
|
})
|
|
|
|
|
.appendTo('#calendar');
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
|
|
|
|
$calendarView.data({
|
|
|
|
|
startDate: startDate.toString('yyyy-MM-dd'),
|
|
|
|
|
endDate: endDate.toString('yyyy-MM-dd')
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var $wrapper = $('<div/>').appendTo($calendarView);
|
2016-07-18 22:20:43 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
getCalendarEvents(startDate, endDate)
|
2018-01-23 12:08:37 +03:00
|
|
|
|
.done(function (response) {
|
|
|
|
|
var currentDate = startDate;
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
while (currentDate <= endDate) {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
createDateColumn($wrapper, currentDate, response);
|
2018-01-23 12:08:37 +03:00
|
|
|
|
currentDate.add({days: 1});
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
2016-07-18 22:20:43 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
setCalendarViewSize();
|
|
|
|
|
|
2016-08-11 23:08:55 +03:00
|
|
|
|
Backend.placeFooterToBottom();
|
2016-11-06 13:44:32 +03:00
|
|
|
|
|
|
|
|
|
// Activate calendar navigation.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$('#calendar .calendar-header .btn').removeClass('disabled').prop('disabled', false);
|
|
|
|
|
|
|
|
|
|
// Apply provider calendar view mode.
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$('.provider-column').each(function (index, providerColumn) {
|
|
|
|
|
var $providerColumn = $(providerColumn);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var providerId = $providerColumn.data('provider').id;
|
|
|
|
|
$providerColumn.find('.calendar-wrapper')
|
|
|
|
|
.fullCalendar('changeView', providerView[providerId] || 'agendaDay');
|
|
|
|
|
});
|
|
|
|
|
|
2016-07-17 19:51:46 +03:00
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Create Date Column Container
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* This element will contain the provider columns.
|
|
|
|
|
*
|
|
|
|
|
* @param {jQuery} $wrapper The wrapper div element of the table view.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
* @param {Date} date Selected date for the column.
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* @param {Object[]} events Events to be displayed on this date.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function createDateColumn($wrapper, date, events) {
|
|
|
|
|
var $dateColumn = $('<div/>', {
|
|
|
|
|
'class': 'date-column'
|
|
|
|
|
})
|
|
|
|
|
.appendTo($wrapper);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2016-07-24 12:05:25 +03:00
|
|
|
|
$dateColumn.data('date', date.getTime());
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$('<h5/>', {
|
|
|
|
|
'class': 'date-column-title',
|
|
|
|
|
'text': GeneralFunctions.formatDate(date, GlobalVariables.dateFormat)
|
|
|
|
|
})
|
|
|
|
|
.appendTo($dateColumn);
|
|
|
|
|
|
2020-05-04 14:13:22 +03:00
|
|
|
|
var filterProviderIds = $filterProvider.val();
|
|
|
|
|
var filterServiceIds = $filterService.val();
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var providers = GlobalVariables.availableProviders.filter(function (provider) {
|
2020-05-04 21:41:46 +03:00
|
|
|
|
var servedServiceIds = provider.services.filter(function (serviceId) {
|
|
|
|
|
var matches = filterServiceIds.filter(function (filterServiceId) {
|
2020-05-04 14:13:22 +03:00
|
|
|
|
return Number(serviceId) === Number(filterServiceId);
|
|
|
|
|
});
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-05-04 14:13:22 +03:00
|
|
|
|
return matches.length;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (!filterProviderIds.length && !filterServiceIds.length) || servedServiceIds.length
|
|
|
|
|
|| filterProviderIds.indexOf(provider.id) !== -1;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
});
|
2016-07-22 23:06:36 +03:00
|
|
|
|
|
|
|
|
|
if (GlobalVariables.user.role_slug === 'provider') {
|
|
|
|
|
GlobalVariables.availableProviders.forEach(function (provider) {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
if (Number(provider.id) === Number(GlobalVariables.user.id)) {
|
2018-01-23 12:08:37 +03:00
|
|
|
|
providers = [provider];
|
2016-07-22 23:06:36 +03:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (GlobalVariables.user.role_slug === 'secretary') {
|
|
|
|
|
providers = [];
|
|
|
|
|
GlobalVariables.availableProviders.forEach(function (provider) {
|
|
|
|
|
if (GlobalVariables.secretaryProviders.indexOf(provider.id) > -1) {
|
|
|
|
|
providers.push(provider)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
providers.forEach(function (provider) {
|
|
|
|
|
createProviderColumn($dateColumn, date, provider, events);
|
|
|
|
|
});
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Create Provider Column Container
|
|
|
|
|
*
|
2016-07-22 23:06:36 +03:00
|
|
|
|
* @param {jQuery} $dateColumn Element to container the provider's column.
|
|
|
|
|
* @param {Date} date Selected date for the column.
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* @param {Object} provider Contains the provider data.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
* @param {Object[]} events Events to be displayed on this date.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function createProviderColumn($dateColumn, date, provider, events) {
|
2016-07-20 23:37:56 +03:00
|
|
|
|
if (provider.services.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var $providerColumn = $('<div/>', {
|
|
|
|
|
'class': 'provider-column'
|
|
|
|
|
})
|
|
|
|
|
.appendTo($dateColumn);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$providerColumn.data('provider', provider);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Create calendar.
|
|
|
|
|
createCalendar($providerColumn, date, provider);
|
|
|
|
|
|
|
|
|
|
// Create non working hours.
|
|
|
|
|
createNonWorkingHours($providerColumn.find('.calendar-wrapper'), JSON.parse(provider.settings.working_plan))
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
|
// Add the appointments to the column.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
createAppointments($providerColumn, events.appointments);
|
2018-01-23 12:08:37 +03:00
|
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
|
// Add the unavailabilities to the column.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
createUnavailabilities($providerColumn, events.unavailabilities);
|
|
|
|
|
|
|
|
|
|
Backend.placeFooterToBottom();
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
/**
|
2020-05-04 12:32:00 +03:00
|
|
|
|
* Get Calendar Component Height
|
2018-01-23 12:08:37 +03:00
|
|
|
|
*
|
2020-05-04 12:32:00 +03:00
|
|
|
|
* This method calculates the proper calendar height, in order to be displayed correctly, even when the
|
|
|
|
|
* browser window is resizing.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*
|
2020-05-04 12:32:00 +03:00
|
|
|
|
* @return {Number} Returns the calendar element height in pixels.
|
|
|
|
|
*/
|
|
|
|
|
function getCalendarHeight() {
|
|
|
|
|
var result = window.innerHeight - $('#footer').outerHeight() - $('#header').outerHeight()
|
|
|
|
|
- 60; // 60 for fine tuning
|
|
|
|
|
return result > 500 ? result : 500; // Minimum height is 500px
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createCalendar($providerColumn, goToDate, provider) {
|
|
|
|
|
var $wrapper = $('<div/>', {
|
|
|
|
|
'class': 'calendar-wrapper'
|
|
|
|
|
})
|
|
|
|
|
.appendTo($providerColumn);
|
|
|
|
|
|
|
|
|
|
var columnFormat = '';
|
|
|
|
|
|
|
|
|
|
switch (GlobalVariables.dateFormat) {
|
|
|
|
|
case 'DMY':
|
|
|
|
|
columnFormat = 'ddd D/M';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'MDY':
|
|
|
|
|
case 'YMD':
|
|
|
|
|
columnFormat = 'ddd M/D';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Invalid date format setting provided!', GlobalVariables.dateFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Time formats
|
|
|
|
|
var timeFormat = '';
|
|
|
|
|
var slotTimeFormat = '';
|
|
|
|
|
|
|
|
|
|
switch (GlobalVariables.timeFormat) {
|
|
|
|
|
case 'military':
|
|
|
|
|
timeFormat = 'H:mm';
|
|
|
|
|
slotTimeFormat = 'H(:mm)';
|
|
|
|
|
break;
|
|
|
|
|
case 'regular':
|
|
|
|
|
timeFormat = 'h:mm a';
|
|
|
|
|
slotTimeFormat = 'h(:mm) a';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new Error('Invalid time format setting provided!' + GlobalVariables.timeFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var firstWeekday = GlobalVariables.firstWeekday;
|
|
|
|
|
var firstWeekdayNumber = GeneralFunctions.getWeekDayId(firstWeekday);
|
|
|
|
|
|
|
|
|
|
$wrapper.fullCalendar({
|
|
|
|
|
defaultView: 'agendaDay',
|
|
|
|
|
height: getCalendarHeight(),
|
|
|
|
|
editable: true,
|
|
|
|
|
firstDay: firstWeekdayNumber,
|
|
|
|
|
timeFormat: timeFormat,
|
|
|
|
|
slotLabelFormat: slotTimeFormat,
|
|
|
|
|
allDaySlot: true,
|
|
|
|
|
columnFormat: columnFormat,
|
|
|
|
|
titleFormat: 'MMMM YYYY',
|
|
|
|
|
header: {
|
|
|
|
|
left: 'listDay,agendaDay',
|
|
|
|
|
center: '',
|
|
|
|
|
right: ''
|
|
|
|
|
},
|
|
|
|
|
// Selectable
|
|
|
|
|
selectable: true,
|
|
|
|
|
selectHelper: true,
|
|
|
|
|
select: function (start, end, jsEvent, view) {
|
|
|
|
|
if (!start.hasTime() || !end.hasTime()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#insert-appointment').trigger('click');
|
|
|
|
|
|
|
|
|
|
// Preselect service & provider.
|
|
|
|
|
var $providerColumn = $(jsEvent.target).parents('.provider-column');
|
|
|
|
|
var providerId = $providerColumn.data('provider').id;
|
|
|
|
|
|
|
|
|
|
var provider = GlobalVariables.availableProviders.find(function (provider) {
|
|
|
|
|
return Number(provider.id) === Number(providerId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var service = GlobalVariables.availableServices.find(function (service) {
|
|
|
|
|
return provider.services.indexOf(service.id) !== -1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#select-service').val(service.id).trigger('change');
|
|
|
|
|
$('#select-provider').val(provider.id).trigger('change');
|
|
|
|
|
|
|
|
|
|
// Preselect time
|
2020-07-06 19:07:43 +03:00
|
|
|
|
$('#start-datetime').datepicker('setDate', new Date(start.format('YYY/MM/DD HH:mm:ss')));
|
|
|
|
|
$('#end-datetime').datepicker('setDate', new Date(end.format('YYYY/MM/DD HH:mm:ss')));
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Translations
|
|
|
|
|
monthNames: [EALang.january, EALang.february, EALang.march, EALang.april,
|
|
|
|
|
EALang.may, EALang.june, EALang.july, EALang.august,
|
|
|
|
|
EALang.september, EALang.october, EALang.november,
|
|
|
|
|
EALang.december],
|
|
|
|
|
monthNamesShort: [EALang.january.substr(0, 3), EALang.february.substr(0, 3),
|
|
|
|
|
EALang.march.substr(0, 3), EALang.april.substr(0, 3),
|
|
|
|
|
EALang.may.substr(0, 3), EALang.june.substr(0, 3),
|
|
|
|
|
EALang.july.substr(0, 3), EALang.august.substr(0, 3),
|
|
|
|
|
EALang.september.substr(0, 3), EALang.october.substr(0, 3),
|
|
|
|
|
EALang.november.substr(0, 3), EALang.december.substr(0, 3)],
|
|
|
|
|
dayNames: [EALang.sunday, EALang.monday, EALang.tuesday, EALang.wednesday,
|
|
|
|
|
EALang.thursday, EALang.friday, EALang.saturday],
|
|
|
|
|
dayNamesShort: [EALang.sunday.substr(0, 3), EALang.monday.substr(0, 3),
|
|
|
|
|
EALang.tuesday.substr(0, 3), EALang.wednesday.substr(0, 3),
|
|
|
|
|
EALang.thursday.substr(0, 3), EALang.friday.substr(0, 3),
|
|
|
|
|
EALang.saturday.substr(0, 3)],
|
|
|
|
|
dayNamesMin: [EALang.sunday.substr(0, 2), EALang.monday.substr(0, 2),
|
|
|
|
|
EALang.tuesday.substr(0, 2), EALang.wednesday.substr(0, 2),
|
|
|
|
|
EALang.thursday.substr(0, 2), EALang.friday.substr(0, 2),
|
|
|
|
|
EALang.saturday.substr(0, 2)],
|
|
|
|
|
buttonText: {
|
|
|
|
|
today: EALang.today,
|
|
|
|
|
day: EALang.day,
|
|
|
|
|
week: EALang.week,
|
|
|
|
|
month: EALang.month,
|
|
|
|
|
agendaDay: EALang.calendar,
|
|
|
|
|
listDay: EALang.list,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Calendar events need to be declared on initialization.
|
|
|
|
|
eventClick: onEventClick,
|
|
|
|
|
eventResize: onEventResize,
|
|
|
|
|
eventDrop: onEventDrop,
|
|
|
|
|
dayClick: onDayClick,
|
|
|
|
|
viewRender: onViewRender
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$wrapper.fullCalendar('gotoDate', moment(goToDate));
|
|
|
|
|
|
|
|
|
|
$('<h6/>', {
|
|
|
|
|
'text': provider.first_name + ' ' + provider.last_name
|
|
|
|
|
})
|
|
|
|
|
.prependTo($providerColumn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calendar Day "Click" Callback
|
|
|
|
|
*
|
|
|
|
|
* When the user clicks on a day square on the calendar, then he will automatically be transferred to that
|
|
|
|
|
* day view calendar.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function onDayClick(date) {
|
|
|
|
|
$('#insert-appointment').trigger('click');
|
|
|
|
|
|
|
|
|
|
var $dialog = $('#manage-appointment');
|
|
|
|
|
|
|
|
|
|
var providerId = $(this).closest('.provider-column').data('provider').id;
|
|
|
|
|
|
|
|
|
|
var provider = GlobalVariables.availableProviders.find(function (provider) {
|
|
|
|
|
return Number(provider.id) === Number(providerId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!provider) {
|
2016-07-17 19:51:46 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var service = GlobalVariables.availableServices.find(function (service) {
|
|
|
|
|
return provider.services.indexOf(service.id) !== -1;
|
|
|
|
|
});
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
if (provider.services.length) {
|
|
|
|
|
$dialog.find('#select-service').val([provider.services[0]]).trigger('change');
|
|
|
|
|
$dialog.find('#select-provider').val(provider.id);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$dialog.find('#start-datetime').val(GeneralFunctions.formatDate(date, GlobalVariables.dateFormat, true));
|
|
|
|
|
$dialog.find('#start-datetime').datepicker('setDate', date);
|
|
|
|
|
$dialog.find('#end-datetime').val(GeneralFunctions.formatDate(date.addMinutes(service.duration),
|
|
|
|
|
GlobalVariables.dateFormat, true));
|
|
|
|
|
$dialog.find('#end-datetime').datepicker('setDate', date);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
2020-05-04 12:32:00 +03:00
|
|
|
|
}
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function onViewRender(view, element) {
|
|
|
|
|
$(element).fullCalendar('option', 'height', getCalendarHeight());
|
|
|
|
|
}
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function createNonWorkingHours($calendar, workingPlan) {
|
|
|
|
|
var view = $calendar.fullCalendar('getView');
|
2020-05-04 14:20:16 +03:00
|
|
|
|
var start = view.start.clone();
|
|
|
|
|
var end = view.end.clone();
|
|
|
|
|
var selDayName = start.toDate().toString('dddd').toLowerCase();
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (workingPlan[selDayName] === null) {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var nonWorkingDay = {
|
|
|
|
|
title: EALang.not_working,
|
2020-05-04 14:20:16 +03:00
|
|
|
|
start: start,
|
|
|
|
|
end: end,
|
2020-05-04 12:32:00 +03:00
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$calendar.fullCalendar('renderEvent', nonWorkingDay, true);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-05-04 14:20:16 +03:00
|
|
|
|
var workDateStart = moment(start.toDate().toString('yyyy-MM-dd') + ' ' + workingPlan[selDayName].start);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
|
|
if (start < workDateStart) {
|
|
|
|
|
unavailablePeriod = {
|
|
|
|
|
title: EALang.not_working,
|
|
|
|
|
start: start,
|
|
|
|
|
end: workDateStart,
|
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable'
|
|
|
|
|
};
|
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
|
|
|
|
}
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Add unavailable period after work ends.
|
2020-05-04 14:20:16 +03:00
|
|
|
|
var workDateEnd = moment(start.toDate().toString('yyyy-MM-dd') + ' ' + workingPlan[selDayName].end);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
|
|
if (end > workDateEnd) {
|
|
|
|
|
var unavailablePeriod = {
|
|
|
|
|
title: EALang.not_working,
|
|
|
|
|
start: workDateEnd,
|
|
|
|
|
end: end,
|
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable'
|
|
|
|
|
};
|
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
2016-08-11 23:08:55 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Add unavailable periods for breaks.
|
|
|
|
|
var breakStart;
|
|
|
|
|
var breakEnd;
|
|
|
|
|
|
|
|
|
|
workingPlan[selDayName].breaks.forEach(function (currentBreak, index) {
|
2020-05-04 14:20:16 +03:00
|
|
|
|
breakStart = moment(start.toDate().toString('yyyy-MM-dd') + ' ' + currentBreak.start);
|
|
|
|
|
breakEnd = moment(start.toDate().toString('yyyy-MM-dd') + ' ' + currentBreak.end);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
|
|
var unavailablePeriod = {
|
|
|
|
|
title: EALang.break,
|
|
|
|
|
start: breakStart,
|
|
|
|
|
end: breakEnd,
|
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#BEBEBE',
|
|
|
|
|
editable: false,
|
|
|
|
|
className: 'fc-unavailable fc-break'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$calendar.fullCalendar('renderEvent', unavailablePeriod, false);
|
|
|
|
|
});
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Create Appointment Events
|
|
|
|
|
*
|
|
|
|
|
* This method will add the appointment events on the table view.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*
|
|
|
|
|
* @param {jQuery} $providerColumn The provider column container.
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* @param {Object[]} appointments Contains the appointment events data.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function createAppointments($providerColumn, appointments) {
|
2016-07-17 19:51:46 +03:00
|
|
|
|
if (appointments.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 14:13:22 +03:00
|
|
|
|
var filterServiceIds = $filterService.val();
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
appointments = appointments.filter(function (appointment) {
|
2020-05-04 14:13:22 +03:00
|
|
|
|
return !filterServiceIds.length || filterServiceIds.indexOf(appointment.id_services) !== -1;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var calendarEvents = [];
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
|
|
|
|
for (var index in appointments) {
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var appointment = appointments[index];
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
|
|
|
|
if (appointment.id_users_provider !== $providerColumn.data('provider').id) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
calendarEvents.push({
|
|
|
|
|
id: appointment.id,
|
|
|
|
|
title: appointment.service.name + ' - '
|
|
|
|
|
+ appointment.customer.first_name + ' '
|
|
|
|
|
+ appointment.customer.last_name,
|
|
|
|
|
start: moment(appointment.start_datetime),
|
|
|
|
|
end: moment(appointment.end_datetime),
|
|
|
|
|
allDay: false,
|
|
|
|
|
data: appointment // Store appointment data for later use.
|
2018-01-23 12:08:37 +03:00
|
|
|
|
});
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
|
|
$providerColumn.find('.calendar-wrapper').fullCalendar('addEventSource', calendarEvents);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Create Unavailabilities Events
|
|
|
|
|
*
|
|
|
|
|
* This method will add the unavailability events on the table view.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*
|
|
|
|
|
* @param {jQuery} $providerColumn The provider column container.
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* @param {Object[]} unavailabilities Contains the unavailability events data.
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function createUnavailabilities($providerColumn, unavailabilities) {
|
2016-07-17 19:51:46 +03:00
|
|
|
|
if (unavailabilities.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-07-18 22:26:31 +03:00
|
|
|
|
|
|
|
|
|
for (var index in unavailabilities) {
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var unavailability = unavailabilities[index];
|
2016-07-18 22:26:31 +03:00
|
|
|
|
|
|
|
|
|
if (unavailability.id_users_provider !== $providerColumn.data('provider').id) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var event = {
|
|
|
|
|
title: EALang.unavailable,
|
|
|
|
|
start: moment(unavailability.start_datetime),
|
|
|
|
|
end: moment(unavailability.end_datetime),
|
|
|
|
|
allDay: false,
|
|
|
|
|
color: '#879DB4',
|
|
|
|
|
editable: true,
|
|
|
|
|
className: 'fc-unavailable fc-custom',
|
|
|
|
|
data: unavailability
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$providerColumn.find('.calendar-wrapper').fullCalendar('renderEvent', event, false);
|
2016-07-23 17:07:20 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Create break events in the table view.
|
|
|
|
|
*
|
2016-07-23 17:07:20 +03:00
|
|
|
|
* @param {jQuery} $providerColumn The provider column container.
|
|
|
|
|
* @param {Object[]} breaks Contains the break events data.
|
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function createBreaks($providerColumn, breaks) {
|
2016-07-23 17:07:20 +03:00
|
|
|
|
if (breaks.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var currentDate = new Date($providerColumn.parents('.date-column').data('date'));
|
2016-07-23 17:07:20 +03:00
|
|
|
|
var $tbody = $providerColumn.find('table tbody');
|
|
|
|
|
|
|
|
|
|
for (var index in breaks) {
|
|
|
|
|
var entry = breaks[index];
|
|
|
|
|
var startHour = entry.start.split(':');
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var eventDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), startHour[0], startHour[1]);
|
2016-07-23 17:07:20 +03:00
|
|
|
|
var endHour = entry.end.split(':');
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var endDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), endHour[0], endHour[1]);
|
2016-07-23 17:07:20 +03:00
|
|
|
|
var eventDuration = Math.round((endDate - eventDate) / 60000);
|
2020-05-07 19:47:14 +03:00
|
|
|
|
var $event = $('<div/>', {
|
|
|
|
|
'class': 'event unavailability break'
|
|
|
|
|
});
|
2016-07-23 17:07:20 +03:00
|
|
|
|
|
2016-07-24 12:23:56 +03:00
|
|
|
|
$event.html(
|
2017-09-11 17:09:15 +03:00
|
|
|
|
EALang.break +
|
2020-05-04 12:32:00 +03:00
|
|
|
|
' <span class="hour">' + eventDate.toString('HH:mm') + '</span> (' + eventDuration + '\')');
|
2016-07-23 17:07:20 +03:00
|
|
|
|
|
|
|
|
|
$event.data(entry);
|
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$tbody.find('tr').each(function (index, tr) {
|
|
|
|
|
var $td = $(tr).find('td:first');
|
2016-07-23 17:07:20 +03:00
|
|
|
|
|
|
|
|
|
var cellDate = new Date(currentDate.getTime()).set({
|
|
|
|
|
hour: parseInt($td.text().split(':')[0]),
|
|
|
|
|
minute: parseInt($td.text().split(':')[1])
|
2018-01-23 12:08:37 +03:00
|
|
|
|
});
|
2016-07-23 17:07:20 +03:00
|
|
|
|
|
|
|
|
|
if (eventDate < cellDate) {
|
2020-04-27 21:14:20 +03:00
|
|
|
|
// Remove the hour from the event if it is the same as the row.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
if (eventDate.toString('HH:mm') === $(tr).prev().find('td').eq(0).text()) {
|
2016-07-24 12:23:56 +03:00
|
|
|
|
$event.find('.hour').remove();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
$(tr).prev().find('td:gt(0)').each(function (index, td) {
|
2016-07-23 17:07:20 +03:00
|
|
|
|
$event.clone().appendTo($(td));
|
|
|
|
|
});
|
|
|
|
|
return false;
|
2016-07-18 22:26:31 +03:00
|
|
|
|
}
|
2018-01-23 12:08:37 +03:00
|
|
|
|
});
|
2016-07-18 22:26:31 +03:00
|
|
|
|
}
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 10:13:22 +03:00
|
|
|
|
/**
|
|
|
|
|
* Get the event notes for the popup widget.
|
|
|
|
|
*
|
|
|
|
|
* @param {Event} event
|
|
|
|
|
*/
|
|
|
|
|
function getEventNotes(event) {
|
|
|
|
|
if (!event.data || !event.data.notes) {
|
|
|
|
|
return '-';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var notes = event.data.notes;
|
|
|
|
|
|
|
|
|
|
return notes.length > 100 ? notes.substring(0, 100) + '...' : notes;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
/**
|
|
|
|
|
* Calendar Event "Click" Callback
|
|
|
|
|
*
|
|
|
|
|
* When the user clicks on an appointment object on the calendar, then a data preview popover is display
|
|
|
|
|
* above the calendar item.
|
|
|
|
|
*/
|
|
|
|
|
function onEventClick(event, jsEvent) {
|
2020-05-12 21:52:32 +03:00
|
|
|
|
$('.popover').popover('destroy'); // Close all open popovers.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
var $html;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var displayEdit;
|
|
|
|
|
var displayDelete;
|
|
|
|
|
|
|
|
|
|
// Depending where the user clicked the event (title or empty space) we
|
|
|
|
|
// need to use different selectors to reach the parent element.
|
|
|
|
|
var $parent = $(jsEvent.target.offsetParent);
|
|
|
|
|
var $altParent = $(jsEvent.target).parents().eq(1);
|
|
|
|
|
|
|
|
|
|
if ($(this).hasClass('fc-unavailable') || $parent.hasClass('fc-unavailable') || $altParent.hasClass('fc-unavailable')) {
|
|
|
|
|
displayEdit = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
2020-05-06 20:15:11 +03:00
|
|
|
|
&& GlobalVariables.user.privileges.appointments.edit === true)
|
2020-06-22 16:55:46 +03:00
|
|
|
|
? 'mr-2' : 'd-none';
|
2020-05-04 12:32:00 +03:00
|
|
|
|
displayDelete = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
2020-05-06 20:15:11 +03:00
|
|
|
|
&& GlobalVariables.user.privileges.appointments.delete === true)
|
2020-06-22 16:55:46 +03:00
|
|
|
|
? 'mr-2' : 'd-none'; // Same value at the time.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$html = $('<div/>', {
|
|
|
|
|
'html': [
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.start
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.start.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.end
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.end.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
2020-07-01 10:13:22 +03:00
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.notes
|
|
|
|
|
}),
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$('<span/>', {
|
2020-07-01 10:13:22 +03:00
|
|
|
|
'text': getEventNotes(event)
|
2020-05-07 19:47:14 +03:00
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<hr/>'),
|
|
|
|
|
|
|
|
|
|
$('<div/>', {
|
2020-06-18 21:41:36 +03:00
|
|
|
|
'class': 'd-flex justify-content-between',
|
2020-05-07 19:47:14 +03:00
|
|
|
|
'html': [
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'edit-popover btn btn-primary ' + displayEdit,
|
|
|
|
|
'text': EALang.edit
|
|
|
|
|
}),
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'delete-popover btn btn-danger ' + displayDelete,
|
|
|
|
|
'text': EALang.delete
|
|
|
|
|
}),
|
|
|
|
|
$('<button/>', {
|
2020-06-19 14:09:22 +03:00
|
|
|
|
'class': 'close-popover btn btn-light',
|
2020-05-07 19:47:14 +03:00
|
|
|
|
'text': EALang.close
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
});
|
2020-05-04 12:32:00 +03:00
|
|
|
|
} else if ($(this).hasClass('fc-extra') || $parent.hasClass('fc-extra') || $altParent.hasClass('fc-extra')) {
|
|
|
|
|
displayDelete = (($parent.hasClass('fc-custom') || $altParent.hasClass('fc-custom'))
|
2020-05-06 20:15:11 +03:00
|
|
|
|
&& GlobalVariables.user.privileges.appointments.delete === true)
|
2020-06-22 16:55:46 +03:00
|
|
|
|
? 'mr-2' : 'd-none'; // Same value at the time.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
|
|
var provider = '';
|
2020-05-07 19:47:14 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
if (event.data) { // Only custom unavailable periods have notes.
|
|
|
|
|
provider = '<strong>' + EALang.provider + '</strong> ' + event.data.first_name + ' ' + event.data.last_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var extraPeriod = jQuery.parseJSON(event.data.settings.extra_working_plan)[event.start.format()];
|
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$html = $('<div/>', {
|
|
|
|
|
'html': [
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.provider
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data ? event.data.first_name + ' ' + event.data.last_name : '-'
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.start
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.start.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.end
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.end.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.timezone
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GlobalVariables.timezones[event.data.provider.timezone]
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<hr/>'),
|
|
|
|
|
|
|
|
|
|
$('<div/>', {
|
2020-06-22 16:55:46 +03:00
|
|
|
|
'class': 'd-flex justify-content-center',
|
2020-05-07 19:47:14 +03:00
|
|
|
|
'html': [
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'delete-popover btn btn-danger ' + displayDelete,
|
|
|
|
|
'text': EALang.delete
|
|
|
|
|
}),
|
|
|
|
|
$('<button/>', {
|
2020-06-19 14:09:22 +03:00
|
|
|
|
'class': 'close-popover btn btn-light',
|
2020-05-07 19:47:14 +03:00
|
|
|
|
'text': EALang.close
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
});
|
2020-05-04 12:32:00 +03:00
|
|
|
|
} else {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
displayEdit = (GlobalVariables.user.privileges.appointments.edit === true)
|
2020-06-22 16:55:46 +03:00
|
|
|
|
? 'mr-2' : 'd-none';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
displayDelete = (GlobalVariables.user.privileges.appointments.delete === true)
|
2020-06-22 16:55:46 +03:00
|
|
|
|
? 'mr-2' : 'd-none';
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$html = $('<div/>', {
|
|
|
|
|
'html': [
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.start
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.start.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.end
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GeneralFunctions.formatDate(event.end.format('YYYY-MM-DD HH:mm:ss'), GlobalVariables.dateFormat, true)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.timezone
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': GlobalVariables.timezones[event.data.provider.timezone]
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.service
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data.service.name
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.provider
|
|
|
|
|
}),
|
|
|
|
|
GeneralFunctions.renderMapIcon(event.data.provider),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data.provider.first_name + ' ' + event.data.provider.last_name
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.customer
|
|
|
|
|
}),
|
|
|
|
|
GeneralFunctions.renderMapIcon(event.data.customer),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data.customer.first_name + ' ' + event.data.customer.last_name
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.email
|
|
|
|
|
}),
|
|
|
|
|
GeneralFunctions.renderMailIcon(event.data.customer.email),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data.customer.email
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.phone_number
|
|
|
|
|
}),
|
|
|
|
|
GeneralFunctions.renderPhoneIcon(event.data.customer.phone_number),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': event.data.customer.phone_number
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
2020-07-01 10:13:22 +03:00
|
|
|
|
$('<strong/>', {
|
|
|
|
|
'text': EALang.notes
|
|
|
|
|
}),
|
|
|
|
|
$('<span/>', {
|
|
|
|
|
'text': getEventNotes(event)
|
|
|
|
|
}),
|
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
|
$('<hr/>'),
|
|
|
|
|
|
|
|
|
|
$('<div/>', {
|
2020-06-22 16:55:46 +03:00
|
|
|
|
'class': 'd-flex justify-content-center',
|
2020-05-07 19:47:14 +03:00
|
|
|
|
'html': [
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'edit-popover btn btn-primary ' + displayEdit,
|
|
|
|
|
'text': EALang.edit
|
|
|
|
|
}),
|
|
|
|
|
$('<button/>', {
|
|
|
|
|
'class': 'delete-popover btn btn-danger ' + displayDelete,
|
|
|
|
|
'text': EALang.delete
|
|
|
|
|
}),
|
|
|
|
|
$('<button/>', {
|
2020-06-19 14:09:22 +03:00
|
|
|
|
'class': 'close-popover btn btn-light',
|
2020-05-07 19:47:14 +03:00
|
|
|
|
'text': EALang.close
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
]
|
|
|
|
|
});
|
2020-05-04 12:32:00 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(jsEvent.target).popover({
|
|
|
|
|
placement: 'top',
|
|
|
|
|
title: event.title,
|
2020-05-07 19:47:14 +03:00
|
|
|
|
content: $html,
|
2020-05-04 12:32:00 +03:00
|
|
|
|
html: true,
|
|
|
|
|
container: '#calendar',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
lastFocusedEventData = event;
|
|
|
|
|
|
|
|
|
|
$(jsEvent.target).popover('toggle');
|
|
|
|
|
|
|
|
|
|
// Fix popover position.
|
|
|
|
|
if ($('.popover').length > 0 && $('.popover').position().top < 200) {
|
|
|
|
|
$('.popover').css('top', '200px');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calendar Event "Resize" Callback
|
|
|
|
|
*
|
|
|
|
|
* The user can change the duration of an event by resizing an appointment object on the calendar. This
|
|
|
|
|
* change needs to be stored to the database too and this is done via an ajax call.
|
|
|
|
|
*
|
|
|
|
|
* @see updateAppointmentData()
|
|
|
|
|
*/
|
2020-05-04 21:41:46 +03:00
|
|
|
|
function onEventResize(event, delta, revertFunc, jsEvent, ui, view) {
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (GlobalVariables.user.privileges.appointments.edit === false) {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
revertFunc();
|
|
|
|
|
Backend.displayNotification(EALang.no_privileges_edit_appointments);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 21:41:46 +03:00
|
|
|
|
var $calendar = $('#calendar');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
2020-05-04 21:41:46 +03:00
|
|
|
|
if ($('#notification').is(':visible')) {
|
|
|
|
|
$('#notification').hide('bind');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
var successCallback;
|
|
|
|
|
|
|
|
|
|
if (event.data.is_unavailable === '0') {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Prepare appointment data.
|
2020-05-04 21:41:46 +03:00
|
|
|
|
event.data.end_datetime = Date.parseExact(
|
|
|
|
|
event.data.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
|
|
|
|
.add({days: delta.days(), hours: delta.hours(), minutes: delta.minutes()})
|
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var appointment = GeneralFunctions.clone(event.data);
|
|
|
|
|
|
2020-05-04 21:41:46 +03:00
|
|
|
|
// Must delete the following because only appointment data should be provided to the AJAX call.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
delete appointment.customer;
|
|
|
|
|
delete appointment.provider;
|
|
|
|
|
delete appointment.service;
|
|
|
|
|
|
|
|
|
|
// Success callback
|
2020-05-06 20:15:11 +03:00
|
|
|
|
successCallback = function () {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Display success notification to user.
|
|
|
|
|
var undoFunction = function () {
|
2020-05-04 21:41:46 +03:00
|
|
|
|
appointment.end_datetime = event.data.end_datetime = Date.parseExact(
|
2020-05-04 12:32:00 +03:00
|
|
|
|
appointment.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2020-05-04 21:41:46 +03:00
|
|
|
|
.add({days: -delta.days(), hours: -delta.hours(), minutes: -delta.minutes()})
|
2020-05-04 12:32:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
2020-05-04 21:41:46 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var data = {
|
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
appointment_data: JSON.stringify(appointment)
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
|
revertFunc();
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Backend.displayNotification(EALang.appointment_updated, [
|
|
|
|
|
{
|
2020-05-04 21:41:46 +03:00
|
|
|
|
'label': EALang.undo,
|
|
|
|
|
'function': undoFunction
|
2020-05-04 12:32:00 +03:00
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
2020-05-04 21:41:46 +03:00
|
|
|
|
|
|
|
|
|
// Update the event data for later use.
|
|
|
|
|
$calendar.fullCalendar('updateEvent', event);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Update appointment data.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
BackendCalendarApi.saveAppointment(appointment, null, successCallback);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
} else {
|
|
|
|
|
// Update unavailable time period.
|
|
|
|
|
var unavailable = {
|
|
|
|
|
id: event.data.id,
|
2020-05-04 21:41:46 +03:00
|
|
|
|
start_datetime: event.start.format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
|
end_datetime: event.end.format('YYYY-MM-DD HH:mm:ss'),
|
2020-05-04 12:32:00 +03:00
|
|
|
|
id_users_provider: event.data.id_users_provider
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-04 21:41:46 +03:00
|
|
|
|
event.data.end_datetime = unavailable.end_datetime;
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Define success callback function.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
successCallback = function () {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Display success notification to user.
|
|
|
|
|
var undoFunction = function () {
|
2020-05-04 21:41:46 +03:00
|
|
|
|
unavailable.end_datetime = event.data.end_datetime = Date.parseExact(
|
2020-05-04 12:32:00 +03:00
|
|
|
|
unavailable.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2020-05-04 21:41:46 +03:00
|
|
|
|
.add({minutes: -delta.minutes()})
|
2020-05-04 12:32:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var data = {
|
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
unavailable: JSON.stringify(unavailable)
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
|
revertFunc();
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Backend.displayNotification(EALang.unavailable_updated, [
|
|
|
|
|
{
|
2020-05-04 21:41:46 +03:00
|
|
|
|
'label': EALang.undo,
|
|
|
|
|
'function': undoFunction
|
2020-05-04 12:32:00 +03:00
|
|
|
|
}
|
|
|
|
|
]);
|
2020-05-04 21:41:46 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
2020-05-04 21:41:46 +03:00
|
|
|
|
|
|
|
|
|
// Update the event data for later use.
|
|
|
|
|
$calendar.fullCalendar('updateEvent', event);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
};
|
|
|
|
|
|
2020-05-04 21:41:46 +03:00
|
|
|
|
BackendCalendarApi.saveUnavailable(unavailable, successCallback);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calendar Event "Drop" Callback
|
|
|
|
|
*
|
|
|
|
|
* This event handler is triggered whenever the user drags and drops an event into a different position
|
|
|
|
|
* on the calendar. We need to update the database with this change. This is done via an ajax call.
|
|
|
|
|
*/
|
2020-05-06 20:15:11 +03:00
|
|
|
|
function onEventDrop(event, delta, revertFunc) {
|
|
|
|
|
if (GlobalVariables.user.privileges.appointments.edit === false) {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
revertFunc();
|
|
|
|
|
Backend.displayNotification(EALang.no_privileges_edit_appointments);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 21:41:46 +03:00
|
|
|
|
if ($('#notification').is(':visible')) {
|
|
|
|
|
$('#notification').hide('bind');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var successCallback;
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
if (event.data.is_unavailable === '0') {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// Prepare appointment data.
|
|
|
|
|
var appointment = GeneralFunctions.clone(event.data);
|
|
|
|
|
|
|
|
|
|
// Must delete the following because only appointment data should be provided to the ajax call.
|
|
|
|
|
delete appointment.customer;
|
|
|
|
|
delete appointment.provider;
|
|
|
|
|
delete appointment.service;
|
|
|
|
|
|
|
|
|
|
appointment.start_datetime = Date.parseExact(
|
|
|
|
|
appointment.start_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2020-05-04 21:41:46 +03:00
|
|
|
|
.add({days: delta.days(), hours: delta.hours(), minutes: delta.minutes()})
|
2020-05-04 12:32:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
appointment.end_datetime = Date.parseExact(
|
|
|
|
|
appointment.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2020-05-04 21:41:46 +03:00
|
|
|
|
.add({days: delta.days(), hours: delta.hours(), minutes: delta.minutes()})
|
2020-05-04 12:32:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
event.data.start_datetime = appointment.start_datetime;
|
|
|
|
|
event.data.end_datetime = appointment.end_datetime;
|
|
|
|
|
|
|
|
|
|
// Define success callback function.
|
|
|
|
|
successCallback = function () {
|
|
|
|
|
// Define the undo function, if the user needs to reset the last change.
|
|
|
|
|
var undoFunction = function () {
|
|
|
|
|
appointment.start_datetime = Date.parseExact(
|
|
|
|
|
appointment.start_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2020-05-04 21:41:46 +03:00
|
|
|
|
.add({days: -delta.days(), hours: -delta.hours(), minutes: -delta.minutes()})
|
2020-05-04 12:32:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
appointment.end_datetime = Date.parseExact(
|
|
|
|
|
appointment.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2020-05-04 21:41:46 +03:00
|
|
|
|
.add({days: -delta.days(), hours: -delta.hours(), minutes: -delta.minutes()})
|
2020-05-04 12:32:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
event.data.start_datetime = appointment.start_datetime;
|
|
|
|
|
event.data.end_datetime = appointment.end_datetime;
|
|
|
|
|
|
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_appointment';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var data = {
|
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
appointment_data: JSON.stringify(appointment)
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
|
revertFunc();
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Backend.displayNotification(EALang.appointment_updated, [
|
|
|
|
|
{
|
2020-05-04 21:41:46 +03:00
|
|
|
|
'label': EALang.undo,
|
|
|
|
|
'function': undoFunction
|
2020-05-04 12:32:00 +03:00
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Update appointment data.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
BackendCalendarApi.saveAppointment(appointment, null, successCallback);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
} else {
|
|
|
|
|
// Update unavailable time period.
|
|
|
|
|
var unavailable = {
|
|
|
|
|
id: event.data.id,
|
2020-05-04 21:41:46 +03:00
|
|
|
|
start_datetime: event.start.format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
|
end_datetime: event.end.format('YYYY-MM-DD HH:mm:ss'),
|
2020-05-04 12:32:00 +03:00
|
|
|
|
id_users_provider: event.data.id_users_provider
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
successCallback = function () {
|
|
|
|
|
var undoFunction = function () {
|
|
|
|
|
unavailable.start_datetime = Date.parseExact(
|
|
|
|
|
unavailable.start_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2020-05-04 21:41:46 +03:00
|
|
|
|
.add({days: -delta.days(), minutes: -delta.minutes()})
|
2020-05-04 12:32:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
unavailable.end_datetime = Date.parseExact(
|
|
|
|
|
unavailable.end_datetime, 'yyyy-MM-dd HH:mm:ss')
|
2020-05-04 21:41:46 +03:00
|
|
|
|
.add({days: -delta.days(), minutes: -delta.minutes()})
|
2020-05-04 12:32:00 +03:00
|
|
|
|
.toString('yyyy-MM-dd HH:mm:ss');
|
|
|
|
|
|
|
|
|
|
event.data.start_datetime = unavailable.start_datetime;
|
|
|
|
|
event.data.end_datetime = unavailable.end_datetime;
|
|
|
|
|
|
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_save_unavailable';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var data = {
|
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
unavailable: JSON.stringify(unavailable)
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
|
$.post(url, data)
|
|
|
|
|
.done(function () {
|
|
|
|
|
$('#notification').hide('blind');
|
|
|
|
|
revertFunc();
|
|
|
|
|
})
|
|
|
|
|
.fail(GeneralFunctions.ajaxFailureHandler);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Backend.displayNotification(EALang.unavailable_updated, [
|
|
|
|
|
{
|
|
|
|
|
label: EALang.undo,
|
|
|
|
|
function: undoFunction
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$('#footer').css('position', 'static'); // Footer position fix.
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-04 21:41:46 +03:00
|
|
|
|
BackendCalendarApi.saveUnavailable(unavailable, successCallback);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Set Table Calendar View
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*
|
|
|
|
|
* This method will set the optimal size in the calendar view elements in order to fit in the page without
|
|
|
|
|
* using scrollbars.
|
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function setCalendarViewSize() {
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var height = window.innerHeight - $('#header').outerHeight() - $('#footer').outerHeight()
|
|
|
|
|
- $('#calendar-toolbar').outerHeight() - $('.calendar-header').outerHeight() - 50;
|
2016-07-18 23:55:05 +03:00
|
|
|
|
|
|
|
|
|
if (height < 500) {
|
|
|
|
|
height = 500;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var $dateColumn = $('.date-column');
|
|
|
|
|
var $calendarViewDiv = $('.calendar-view > div');
|
2016-07-18 22:20:43 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$calendarViewDiv.css('min-width', '1000%');
|
2016-07-22 23:06:36 +03:00
|
|
|
|
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var width = 0;
|
2016-07-18 22:20:43 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$dateColumn.each(function (index, dateColumn) {
|
2016-07-18 22:20:43 +03:00
|
|
|
|
width += $(dateColumn).outerWidth();
|
|
|
|
|
});
|
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
$calendarViewDiv.css('min-width', width + 200);
|
2016-07-18 22:20:43 +03:00
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
|
var dateColumnHeight = $dateColumn.outerHeight();
|
2018-01-23 12:08:37 +03:00
|
|
|
|
|
|
|
|
|
$('.calendar-view .not-working').outerHeight((dateColumnHeight > height ? dateColumnHeight : height) - 70);
|
2016-07-18 22:20:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-17 19:51:46 +03:00
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Get the calendar events.
|
|
|
|
|
*
|
2016-08-11 23:08:55 +03:00
|
|
|
|
* @param {Date} startDate The start date of the selected period.
|
|
|
|
|
* @param {Date} endDate The end date of the selected period.
|
2018-01-23 12:08:37 +03:00
|
|
|
|
*
|
2016-07-17 19:51:46 +03:00
|
|
|
|
* @return {jQuery.jqXHR}
|
|
|
|
|
*/
|
2020-05-04 12:32:00 +03:00
|
|
|
|
function getCalendarEvents(startDate, endDate) {
|
2018-01-23 12:08:37 +03:00
|
|
|
|
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_get_calendar_events';
|
2020-05-06 20:15:11 +03:00
|
|
|
|
|
2016-07-17 19:51:46 +03:00
|
|
|
|
var data = {
|
|
|
|
|
csrfToken: GlobalVariables.csrfToken,
|
|
|
|
|
startDate: startDate.toString('yyyy-MM-dd'),
|
|
|
|
|
endDate: endDate.toString('yyyy-MM-dd')
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-11 22:24:37 +03:00
|
|
|
|
return $.ajax({
|
2018-01-23 12:08:37 +03:00
|
|
|
|
url: url,
|
|
|
|
|
data: data,
|
2016-08-11 22:24:37 +03:00
|
|
|
|
method: 'POST',
|
2018-01-23 12:08:37 +03:00
|
|
|
|
beforeSend: function () {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// $('#loading').css('visibility', 'hidden');
|
2018-01-23 12:08:37 +03:00
|
|
|
|
},
|
|
|
|
|
complete: function () {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
// $('#loading').css('visibility', '');
|
2016-08-11 22:24:37 +03:00
|
|
|
|
}
|
2018-01-23 12:08:37 +03:00
|
|
|
|
});
|
2016-07-17 19:51:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
|
* Initialize Page
|
2016-07-22 23:06:36 +03:00
|
|
|
|
*/
|
2018-01-23 12:08:37 +03:00
|
|
|
|
exports.initialize = function () {
|
2020-05-04 12:32:00 +03:00
|
|
|
|
createHeader();
|
|
|
|
|
|
|
|
|
|
var startDate = moment().toDate();
|
|
|
|
|
var endDate = moment().add(Number($('#select-filter-item').val()) - 1, 'days').toDate();
|
|
|
|
|
|
|
|
|
|
createView(startDate, endDate);
|
|
|
|
|
|
|
|
|
|
bindEventHandlers();
|
2018-01-23 12:08:37 +03:00
|
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
|
// Hide Google Calendar Sync buttons cause they can not be used within this view.
|
2016-07-22 23:10:33 +03:00
|
|
|
|
$('#enable-sync, #google-sync').hide();
|
2016-07-17 14:46:38 +03:00
|
|
|
|
};
|
|
|
|
|
})(window.BackendCalendarTableView);
|