2016-07-17 14:46:38 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2016-07-17 14:46:38 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2022-01-18 15:01:22 +03:00
|
|
|
* @since v1.5.0
|
2016-07-17 14:46:38 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2022-01-17 07:10:26 +03:00
|
|
|
* Default calendar view utility.
|
2016-07-17 14:46:38 +03:00
|
|
|
*
|
2022-01-14 11:26:44 +03:00
|
|
|
* This module implements the functionality of the default calendar view.
|
2016-07-17 14:46:38 +03:00
|
|
|
*
|
2022-01-12 13:22:54 +03:00
|
|
|
* Old Name: BackendCalendarDefaultView
|
2016-07-17 14:46:38 +03:00
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Utils.CalendarDefaultView = (function () {
|
2022-01-17 07:10:26 +03:00
|
|
|
const $calendarPage = $('#calendar-page');
|
|
|
|
const $reloadAppointments = $('#reload-appointments');
|
|
|
|
const $calendar = $('#calendar');
|
|
|
|
const $selectFilterItem = $('#select-filter-item');
|
|
|
|
const $appointmentsModal = $('#appointments-modal');
|
|
|
|
const $unavailabilitiesModal = $('#unavailabilities-modal');
|
|
|
|
const $header = $('#header');
|
|
|
|
const $footer = $('#footer');
|
|
|
|
const $notification = $('#notification');
|
|
|
|
const $calendarToolbar = $('#calendar-toolbar');
|
2022-01-12 13:22:54 +03:00
|
|
|
const FILTER_TYPE_PROVIDER = 'provider';
|
|
|
|
const FILTER_TYPE_SERVICE = 'service';
|
2022-01-18 17:55:21 +03:00
|
|
|
let fullCalendar = null;
|
2022-01-12 13:22:54 +03:00
|
|
|
let lastFocusedEventData; // Contains event data for later use.
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
/**
|
2022-01-17 07:10:26 +03:00
|
|
|
* Add the utility event listeners.
|
2016-07-17 14:46:38 +03:00
|
|
|
*/
|
2022-01-17 07:10:26 +03:00
|
|
|
function addEventListeners() {
|
2016-07-17 15:43:50 +03:00
|
|
|
/**
|
|
|
|
* Event: Reload Button "Click"
|
|
|
|
*
|
2022-01-12 13:22:54 +03:00
|
|
|
* When the user clicks the reload button, the calendar items need to be refreshed.
|
2016-07-17 15:43:50 +03:00
|
|
|
*/
|
2022-01-17 07:10:26 +03:00
|
|
|
$reloadAppointments.on('click', () => {
|
2022-01-18 17:55:21 +03:00
|
|
|
const calendarView = fullCalendar.view;
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-03-02 15:28:20 +03:00
|
|
|
const $popovers = $('.popover');
|
|
|
|
|
|
|
|
if ($popovers.length) {
|
|
|
|
$popovers.popover('dispose');
|
|
|
|
}
|
|
|
|
|
2020-05-06 20:23:49 +03:00
|
|
|
refreshCalendarAppointments(
|
2022-01-17 07:10:26 +03:00
|
|
|
$calendar,
|
|
|
|
$selectFilterItem.val(),
|
|
|
|
$selectFilterItem.find('option:selected').attr('type'),
|
2022-01-18 17:55:21 +03:00
|
|
|
calendarView.currentStart,
|
|
|
|
calendarView.currentEnd
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Popover Close Button "Click"
|
|
|
|
*
|
|
|
|
* Hides the open popover element.
|
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
$calendarPage.on('click', '.close-popover', (event) => {
|
|
|
|
$(event.target).parents('.popover').popover('dispose');
|
2016-07-17 15:43:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Popover Edit Button "Click"
|
|
|
|
*
|
|
|
|
* Enables the edit dialog of the selected calendar event.
|
2022-01-17 07:10:26 +03:00
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
2016-07-17 15:43:50 +03:00
|
|
|
*/
|
2022-01-17 07:10:26 +03:00
|
|
|
$calendarPage.on('click', '.edit-popover', (event) => {
|
|
|
|
const $target = $(event.target);
|
|
|
|
|
|
|
|
$target.closest('.popover').popover('dispose');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let startMoment;
|
|
|
|
let endMoment;
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
if (lastFocusedEventData.extendedProps.data.workingPlanException) {
|
|
|
|
const date = lastFocusedEventData.extendedProps.data.date;
|
|
|
|
const workingPlanException = lastFocusedEventData.extendedProps.data.workingPlanException;
|
|
|
|
const provider = lastFocusedEventData.extendedProps.data.provider;
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-17 17:21:59 +03:00
|
|
|
App.Components.WorkingPlanExceptionsModal.edit(date, workingPlanException).done(
|
|
|
|
(date, workingPlanException) => {
|
|
|
|
const successCallback = () => {
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('working_plan_exception_saved'));
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-17 17:21:59 +03:00
|
|
|
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-17 17:21:59 +03:00
|
|
|
workingPlanExceptions[date] = workingPlanException;
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
for (const index in vars('available_providers')) {
|
|
|
|
const availableProvider = vars('available_providers')[index];
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-17 17:21:59 +03:00
|
|
|
if (Number(availableProvider.id) === Number(provider.id)) {
|
|
|
|
availableProvider.settings.working_plan_exceptions =
|
|
|
|
JSON.stringify(workingPlanExceptions);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
$reloadAppointments.trigger('click'); // Update the calendar.
|
2022-01-17 17:21:59 +03:00
|
|
|
};
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-17 17:21:59 +03:00
|
|
|
App.Http.Calendar.saveWorkingPlanException(
|
|
|
|
date,
|
|
|
|
workingPlanException,
|
|
|
|
provider.id,
|
|
|
|
successCallback,
|
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2022-01-18 17:55:21 +03:00
|
|
|
} else if (!lastFocusedEventData.extendedProps.data.is_unavailability) {
|
|
|
|
const appointment = lastFocusedEventData.extendedProps.data;
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-17 06:33:01 +03:00
|
|
|
App.Components.AppointmentsModal.resetModal();
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Apply appointment data and show modal dialog.
|
2022-01-18 10:22:25 +03:00
|
|
|
$appointmentsModal.find('.modal-header h3').text(lang('edit_appointment_title'));
|
2022-01-17 07:10:26 +03:00
|
|
|
$appointmentsModal.find('#appointment-id').val(appointment.id);
|
|
|
|
$appointmentsModal.find('#select-service').val(appointment.id_services).trigger('change');
|
|
|
|
$appointmentsModal.find('#select-provider').val(appointment.id_users_provider);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Set the start and end datetime of the appointment.
|
2021-11-24 10:34:26 +03:00
|
|
|
startMoment = moment(appointment.start_datetime);
|
2022-01-17 07:10:26 +03:00
|
|
|
$appointmentsModal.find('#start-datetime').datetimepicker('setDate', startMoment.toDate());
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2021-11-24 10:34:26 +03:00
|
|
|
endMoment = moment(appointment.end_datetime);
|
2022-01-17 07:10:26 +03:00
|
|
|
$appointmentsModal.find('#end-datetime').datetimepicker('setDate', endMoment.toDate());
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const customer = appointment.customer;
|
2022-01-17 07:10:26 +03:00
|
|
|
$appointmentsModal.find('#customer-id').val(appointment.id_users_customer);
|
|
|
|
$appointmentsModal.find('#first-name').val(customer.first_name);
|
|
|
|
$appointmentsModal.find('#last-name').val(customer.last_name);
|
|
|
|
$appointmentsModal.find('#email').val(customer.email);
|
|
|
|
$appointmentsModal.find('#phone-number').val(customer.phone_number);
|
|
|
|
$appointmentsModal.find('#address').val(customer.address);
|
|
|
|
$appointmentsModal.find('#city').val(customer.city);
|
|
|
|
$appointmentsModal.find('#zip-code').val(customer.zip_code);
|
2022-03-29 11:15:24 +03:00
|
|
|
$appointmentsModal.find('#language').val(customer.language);
|
|
|
|
$appointmentsModal.find('#timezone').val(customer.timezone);
|
2022-01-17 07:10:26 +03:00
|
|
|
$appointmentsModal.find('#appointment-location').val(appointment.location);
|
|
|
|
$appointmentsModal.find('#appointment-notes').val(appointment.notes);
|
|
|
|
$appointmentsModal.find('#customer-notes').val(customer.notes);
|
2022-01-18 21:01:26 +03:00
|
|
|
|
|
|
|
App.Components.ColorSelection.setColor(
|
|
|
|
$appointmentsModal.find('#appointment-color'),
|
|
|
|
appointment.color
|
|
|
|
);
|
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
$appointmentsModal.modal('show');
|
2016-07-17 15:43:50 +03:00
|
|
|
} else {
|
2022-01-18 17:55:21 +03:00
|
|
|
const unavailability = lastFocusedEventData.extendedProps.data;
|
2016-07-17 15:43:50 +03:00
|
|
|
|
|
|
|
// Replace string date values with actual date objects.
|
2022-01-18 17:55:21 +03:00
|
|
|
unavailability.start_datetime = moment(lastFocusedEventData.start).format('YYYY-MM-DD HH:mm:ss');
|
2022-01-18 14:54:41 +03:00
|
|
|
startMoment = moment(unavailability.start_datetime);
|
2022-01-18 17:55:21 +03:00
|
|
|
unavailability.end_datetime = moment(lastFocusedEventData.end).format('YYYY-MM-DD HH:mm:ss');
|
2022-01-18 14:54:41 +03:00
|
|
|
endMoment = moment(unavailability.end_datetime);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-17 06:46:18 +03:00
|
|
|
App.Components.UnavailabilitiesModal.resetModal();
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Apply unavailability data to dialog.
|
2022-01-24 16:23:29 +03:00
|
|
|
$unavailabilitiesModal.find('.modal-header h3').text(lang('edit_unavailability_title'));
|
2022-01-18 14:54:41 +03:00
|
|
|
$unavailabilitiesModal.find('#unavailability-start').datetimepicker('setDate', startMoment.toDate());
|
|
|
|
$unavailabilitiesModal.find('#unavailability-id').val(unavailability.id);
|
|
|
|
$unavailabilitiesModal.find('#unavailability-provider').val(unavailability.id_users_provider);
|
|
|
|
$unavailabilitiesModal.find('#unavailability-end').datetimepicker('setDate', endMoment.toDate());
|
|
|
|
$unavailabilitiesModal.find('#unavailability-notes').val(unavailability.notes);
|
2022-01-17 07:10:26 +03:00
|
|
|
$unavailabilitiesModal.modal('show');
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Popover Delete Button "Click"
|
|
|
|
*
|
2016-10-10 19:29:48 +03:00
|
|
|
* Displays a prompt on whether the user wants the appointment to be deleted. If he confirms the
|
2017-10-31 12:37:00 +03:00
|
|
|
* deletion then an AJAX call is made to the server and deletes the appointment from the database.
|
2022-01-17 07:10:26 +03:00
|
|
|
*
|
|
|
|
* @param {jQuery.Event} event
|
2016-07-17 15:43:50 +03:00
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
$calendarPage.on('click', '.delete-popover', (event) => {
|
2022-01-17 07:10:26 +03:00
|
|
|
const $target = $(event.target);
|
|
|
|
|
|
|
|
$target.parents('.popover').popover('dispose');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
if (lastFocusedEventData.extendedProps.data.workingPlanException) {
|
2022-01-17 07:10:26 +03:00
|
|
|
const providerId = $selectFilterItem.val();
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const provider = vars('available_providers').find(
|
2022-01-12 13:22:54 +03:00
|
|
|
(availableProvider) => Number(availableProvider.id) === Number(providerId)
|
|
|
|
);
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2020-10-20 16:03:48 +03:00
|
|
|
if (!provider) {
|
|
|
|
throw new Error('Provider could not be found: ' + providerId);
|
|
|
|
}
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const successCallback = () => {
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('working_plan_exception_deleted'));
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
|
2020-10-20 16:03:48 +03:00
|
|
|
delete workingPlanExceptions[date];
|
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
for (const index in vars('available_providers')) {
|
|
|
|
const availableProvider = vars('available_providers')[index];
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
if (Number(availableProvider.id) === Number(providerId)) {
|
|
|
|
availableProvider.settings.working_plan_exceptions = JSON.stringify(workingPlanExceptions);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
$reloadAppointments.trigger('click'); // Update the calendar.
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
const date = moment(lastFocusedEventData.start).format('YYYY-MM-DD');
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Http.Calendar.deleteWorkingPlanException(date, providerId, successCallback);
|
2022-01-18 17:55:21 +03:00
|
|
|
} else if (!lastFocusedEventData.extendedProps.data.is_unavailability) {
|
2022-01-12 13:22:54 +03:00
|
|
|
const buttons = [
|
2020-09-07 11:15:01 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
text: lang('cancel'),
|
2022-01-12 13:22:54 +03:00
|
|
|
click: () => {
|
2020-09-07 11:15:01 +03:00
|
|
|
$('#message-box').dialog('close');
|
|
|
|
}
|
|
|
|
},
|
2017-10-31 12:37:00 +03:00
|
|
|
{
|
2022-01-24 16:11:15 +03:00
|
|
|
text: lang('delete'),
|
2022-01-17 17:21:59 +03:00
|
|
|
click: () => {
|
2022-01-18 17:55:21 +03:00
|
|
|
const appointmentId = lastFocusedEventData.extendedProps.data.id;
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
const deleteReason = $('#delete-reason').val();
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
App.Http.Calendar.deleteAppointment(appointmentId, deleteReason).done(() => {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#message-box').dialog('close');
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Refresh calendar event items.
|
2022-01-18 17:55:21 +03:00
|
|
|
$reloadAppointments.trigger('click');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
2017-10-31 12:37:00 +03:00
|
|
|
}
|
|
|
|
];
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Utils.Message.show(
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('delete_appointment_title'),
|
|
|
|
lang('write_appointment_removal_reason'),
|
2021-11-06 19:38:37 +03:00
|
|
|
buttons
|
|
|
|
);
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2020-09-07 11:07:24 +03:00
|
|
|
$('<textarea/>', {
|
|
|
|
'class': 'form-control w-100',
|
|
|
|
'id': 'delete-reason',
|
2020-09-07 11:15:01 +03:00
|
|
|
'rows': '3'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#message-box');
|
2016-07-17 15:43:50 +03:00
|
|
|
} else {
|
2016-10-10 19:29:48 +03:00
|
|
|
// Do not display confirmation prompt.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
const unavailabilityId = lastFocusedEventData.extendedProps.data.id;
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Calendar.deleteUnavailability(unavailabilityId).done(() => {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#message-box').dialog('close');
|
2016-07-17 15:43:50 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Refresh calendar event items.
|
2022-01-18 17:55:21 +03:00
|
|
|
$reloadAppointments.trigger('click');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2016-07-17 15:43:50 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
/**
|
|
|
|
* Event: Calendar Filter Item "Change"
|
|
|
|
*
|
|
|
|
* Load the appointments that correspond to the select filter item and display them on the calendar.
|
|
|
|
*/
|
2022-01-17 07:10:26 +03:00
|
|
|
$selectFilterItem.on('change', () => {
|
2016-07-17 14:46:38 +03:00
|
|
|
// If current value is service, then the sync buttons must be disabled.
|
2022-01-17 07:10:26 +03:00
|
|
|
if ($selectFilterItem.find('option:selected').attr('type') === FILTER_TYPE_SERVICE) {
|
2020-05-10 00:29:16 +03:00
|
|
|
$('#google-sync, #enable-sync, #insert-appointment, #insert-dropdown').prop('disabled', true);
|
2022-01-18 17:55:21 +03:00
|
|
|
fullCalendar.setOption('selectable', false);
|
|
|
|
fullCalendar.setOption('editable', false);
|
2016-07-17 14:46:38 +03:00
|
|
|
} else {
|
2020-05-10 00:29:16 +03:00
|
|
|
$('#google-sync, #enable-sync, #insert-appointment, #insert-dropdown').prop('disabled', false);
|
2022-01-18 17:55:21 +03:00
|
|
|
fullCalendar.setOption('selectable', true);
|
|
|
|
fullCalendar.setOption('editable', true);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
const providerId = $selectFilterItem.val();
|
2020-03-29 16:08:07 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const provider = vars('available_providers').find(
|
2022-01-17 17:21:59 +03:00
|
|
|
(availableProvider) => Number(availableProvider.id) === Number(providerId)
|
|
|
|
);
|
2020-03-29 16:08:07 +03:00
|
|
|
|
|
|
|
if (provider && provider.timezone) {
|
2022-01-18 10:18:22 +03:00
|
|
|
$('.provider-timezone').text(vars('timezones')[provider.timezone]);
|
2020-03-29 16:08:07 +03:00
|
|
|
}
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
// If the user has already the sync enabled then apply the proper style changes.
|
2022-01-17 23:33:04 +03:00
|
|
|
if ($selectFilterItem.find('option:selected').attr('google-sync') === 'true') {
|
2020-12-09 15:06:47 +03:00
|
|
|
$('#enable-sync').removeClass('btn-light').addClass('btn-secondary enabled');
|
2022-01-18 10:22:25 +03:00
|
|
|
$('#enable-sync span').text(lang('disable_sync'));
|
2016-07-17 14:46:38 +03:00
|
|
|
$('#google-sync').prop('disabled', false);
|
|
|
|
} else {
|
2020-12-09 15:06:47 +03:00
|
|
|
$('#enable-sync').removeClass('btn-secondary enabled').addClass('btn-light');
|
2022-01-18 10:22:25 +03:00
|
|
|
$('#enable-sync span').text(lang('enable_sync'));
|
2016-07-17 14:46:38 +03:00
|
|
|
$('#google-sync').prop('disabled', true);
|
|
|
|
}
|
|
|
|
}
|
2022-01-18 17:55:21 +03:00
|
|
|
|
2022-01-25 00:00:47 +03:00
|
|
|
$reloadAppointments.trigger('click');
|
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Calendar Component Height
|
|
|
|
*
|
|
|
|
* This method calculates the proper calendar height, in order to be displayed correctly, even when the
|
|
|
|
* browser window is resizing.
|
|
|
|
*
|
|
|
|
* @return {Number} Returns the calendar element height in pixels.
|
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
function getCalendarHeight() {
|
2022-01-12 13:22:54 +03:00
|
|
|
const result =
|
2022-01-17 07:10:26 +03:00
|
|
|
window.innerHeight - $footer.outerHeight() - $header.outerHeight() - $calendarToolbar.outerHeight() - 60; // 60 for fine tuning
|
2021-11-06 19:38:37 +03:00
|
|
|
return result > 500 ? result : 500; // Minimum height is 500px
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2020-07-01 10:13:22 +03:00
|
|
|
/**
|
|
|
|
* Get the event notes for the popup widget.
|
|
|
|
*
|
|
|
|
* @param {Event} event
|
|
|
|
*/
|
|
|
|
function getEventNotes(event) {
|
2022-01-18 17:55:21 +03:00
|
|
|
if (!event.extendedProps || !event.extendedProps.data || !event.extendedProps.data.notes) {
|
2020-07-01 10:13:22 +03:00
|
|
|
return '-';
|
|
|
|
}
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
const notes = event.extendedProps.data.notes;
|
2020-07-01 10:13:22 +03:00
|
|
|
|
|
|
|
return notes.length > 100 ? notes.substring(0, 100) + '...' : notes;
|
|
|
|
}
|
|
|
|
|
2016-07-17 14:46:38 +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.
|
2022-01-18 17:55:21 +03:00
|
|
|
*
|
|
|
|
* @param {Object} info
|
2016-07-17 14:46:38 +03:00
|
|
|
*/
|
2022-01-18 19:40:43 +03:00
|
|
|
function onEventClick(info) {
|
2022-01-18 17:55:21 +03:00
|
|
|
const $target = $(info.el);
|
2022-01-17 07:10:26 +03:00
|
|
|
|
|
|
|
$calendarPage.find('.popover').popover('dispose'); // Close all open popovers.
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let $html;
|
|
|
|
let displayEdit;
|
|
|
|
let displayDelete;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
// Depending on where the user clicked the event (title or empty space) we
|
2016-07-17 14:46:38 +03:00
|
|
|
// need to use different selectors to reach the parent element.
|
2022-01-18 17:55:21 +03:00
|
|
|
|
|
|
|
if ($target.hasClass('fc-unavailability')) {
|
2021-11-06 19:38:37 +03:00
|
|
|
displayEdit =
|
2022-01-24 16:11:15 +03:00
|
|
|
$target.hasClass('fc-custom') && vars('privileges').appointments.edit === true ? '' : 'd-none';
|
2021-11-06 19:38:37 +03:00
|
|
|
displayDelete =
|
2022-01-18 17:55:21 +03:00
|
|
|
$target.hasClass('fc-custom') && vars('privileges').appointments.delete === true ? 'me-2' : 'd-none'; // Same value at the time.
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$html = $('<div/>', {
|
|
|
|
'html': [
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('start')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-12 13:22:54 +03:00
|
|
|
'text': App.Utils.Date.format(
|
2022-01-18 17:55:21 +03:00
|
|
|
moment(info.event.start).format('YYYY-MM-DD HH:mm:ss'),
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('date_format'),
|
|
|
|
vars('time_format'),
|
2021-11-06 19:38:37 +03:00
|
|
|
true
|
|
|
|
)
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('end')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-12 13:22:54 +03:00
|
|
|
'text': App.Utils.Date.format(
|
2022-01-18 17:55:21 +03:00
|
|
|
moment(info.event.end).format('YYYY-MM-DD HH:mm:ss'),
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('date_format'),
|
|
|
|
vars('time_format'),
|
2021-11-06 19:38:37 +03:00
|
|
|
true
|
|
|
|
)
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
2020-07-01 10:13:22 +03:00
|
|
|
$('<strong/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('notes')
|
2020-07-01 10:13:22 +03:00
|
|
|
}),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2022-01-18 17:55:21 +03:00
|
|
|
'text': getEventNotes(info.event)
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<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/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'close-popover btn btn-outline-secondary me-2',
|
2020-09-07 12:21:16 +03:00
|
|
|
'html': [
|
|
|
|
$('<i/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'fas fa-ban me-2'
|
2020-09-07 12:21:16 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('close')
|
2020-09-07 12:21:16 +03:00
|
|
|
})
|
|
|
|
]
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<button/>', {
|
2020-10-20 16:03:48 +03:00
|
|
|
'class': 'delete-popover btn btn-outline-secondary ' + displayDelete,
|
2020-09-07 12:21:16 +03:00
|
|
|
'html': [
|
|
|
|
$('<i/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'fas fa-trash-alt me-2'
|
2020-09-07 12:21:16 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('delete')
|
2020-09-07 12:21:16 +03:00
|
|
|
})
|
|
|
|
]
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<button/>', {
|
2020-09-28 15:17:47 +03:00
|
|
|
'class': 'edit-popover btn btn-primary ' + displayEdit,
|
2020-09-07 12:21:16 +03:00
|
|
|
'html': [
|
|
|
|
$('<i/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'fas fa-edit me-2'
|
2020-09-07 12:21:16 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('edit')
|
2020-09-07 12:21:16 +03:00
|
|
|
})
|
|
|
|
]
|
2020-05-07 19:47:14 +03:00
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
2022-01-18 17:55:21 +03:00
|
|
|
} else if ($target.hasClass('fc-working-plan-exception')) {
|
2021-11-06 19:38:37 +03:00
|
|
|
displayDelete =
|
2022-01-18 17:55:21 +03:00
|
|
|
$target.hasClass('fc-custom') && vars('privileges').appointments.delete === true ? 'me-2' : 'd-none';
|
2018-04-12 16:03:46 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$html = $('<div/>', {
|
|
|
|
'html': [
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('provider')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 17:55:21 +03:00
|
|
|
'text': info.event.extendedProps.data
|
|
|
|
? info.event.extendedProps.data.provider.first_name +
|
|
|
|
' ' +
|
|
|
|
info.event.extendedProps.data.provider.last_name
|
|
|
|
: '-'
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('start')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-12 13:22:54 +03:00
|
|
|
'text': App.Utils.Date.format(
|
2022-01-18 17:55:21 +03:00
|
|
|
info.event.extendedProps.data.date +
|
|
|
|
' ' +
|
|
|
|
info.event.extendedProps.data.workingPlanException.start,
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('date_format'),
|
|
|
|
vars('time_format'),
|
2021-11-06 19:38:37 +03:00
|
|
|
true
|
|
|
|
)
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('end')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-12 13:22:54 +03:00
|
|
|
'text': App.Utils.Date.format(
|
2022-01-18 17:55:21 +03:00
|
|
|
info.event.extendedProps.data.date +
|
|
|
|
' ' +
|
|
|
|
info.event.extendedProps.data.workingPlanException.end,
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('date_format'),
|
|
|
|
vars('time_format'),
|
2021-11-06 19:38:37 +03:00
|
|
|
true
|
|
|
|
)
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('timezone')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 17:55:21 +03:00
|
|
|
'text': vars('timezones')[info.event.extendedProps.data.provider.timezone]
|
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/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'close-popover btn btn-outline-secondary me-2',
|
2020-09-07 12:21:16 +03:00
|
|
|
'html': [
|
|
|
|
$('<i/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'fas fa-ban me-2'
|
2020-09-07 12:21:16 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('close')
|
2020-09-07 12:21:16 +03:00
|
|
|
})
|
|
|
|
]
|
2020-10-20 16:03:48 +03:00
|
|
|
}),
|
|
|
|
$('<button/>', {
|
|
|
|
'class': 'delete-popover btn btn-outline-secondary ' + displayDelete,
|
|
|
|
'html': [
|
|
|
|
$('<i/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'fas fa-trash-alt me-2'
|
2020-10-20 16:03:48 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('delete')
|
2020-10-20 16:03:48 +03:00
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
$('<button/>', {
|
2022-01-17 07:10:26 +03:00
|
|
|
'class': 'edit-popover btn btn-primary',
|
2020-10-20 16:03:48 +03:00
|
|
|
'html': [
|
|
|
|
$('<i/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'fas fa-edit me-2'
|
2020-10-20 16:03:48 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('edit')
|
2020-10-20 16:03:48 +03:00
|
|
|
})
|
|
|
|
]
|
2021-11-06 19:38:37 +03:00
|
|
|
})
|
2020-05-07 19:47:14 +03:00
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
} else {
|
2022-01-24 16:11:15 +03:00
|
|
|
displayEdit = vars('privileges').appointments.edit === true ? '' : 'd-none';
|
2022-01-18 10:18:22 +03:00
|
|
|
displayDelete = vars('privileges').appointments.delete === true ? 'me-2' : 'd-none';
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$html = $('<div/>', {
|
|
|
|
'html': [
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('start')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-12 13:22:54 +03:00
|
|
|
'text': App.Utils.Date.format(
|
2022-01-18 17:55:21 +03:00
|
|
|
moment(info.event.start).format('YYYY-MM-DD HH:mm:ss'),
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('date_format'),
|
|
|
|
vars('time_format'),
|
2021-11-06 19:38:37 +03:00
|
|
|
true
|
|
|
|
)
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('end')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-12 13:22:54 +03:00
|
|
|
'text': App.Utils.Date.format(
|
2022-01-18 17:55:21 +03:00
|
|
|
moment(info.event.end).format('YYYY-MM-DD HH:mm:ss'),
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('date_format'),
|
|
|
|
vars('time_format'),
|
2021-11-06 19:38:37 +03:00
|
|
|
true
|
|
|
|
)
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('timezone')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 17:55:21 +03:00
|
|
|
'text': vars('timezones')[info.event.extendedProps.data.provider.timezone]
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('service')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 17:55:21 +03:00
|
|
|
'text': info.event.extendedProps.data.service.name
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('provider')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
2022-01-18 17:55:21 +03:00
|
|
|
App.Utils.CalendarEventPopover.renderMapIcon(info.event.extendedProps.data.provider),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2022-01-18 17:55:21 +03:00
|
|
|
'text':
|
|
|
|
info.event.extendedProps.data.provider.first_name +
|
|
|
|
' ' +
|
|
|
|
info.event.extendedProps.data.provider.last_name
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('customer')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
2022-01-18 17:55:21 +03:00
|
|
|
App.Utils.CalendarEventPopover.renderMapIcon(info.event.extendedProps.data.customer),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block ms-1',
|
2022-01-18 17:55:21 +03:00
|
|
|
'text':
|
|
|
|
info.event.extendedProps.data.customer.first_name +
|
|
|
|
' ' +
|
|
|
|
info.event.extendedProps.data.customer.last_name
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('email')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
2022-01-18 17:55:21 +03:00
|
|
|
App.Utils.CalendarEventPopover.renderMailIcon(info.event.extendedProps.data.customer.email),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block ms-1',
|
2022-01-18 17:55:21 +03:00
|
|
|
'text': info.event.extendedProps.data.customer.email
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block me-2',
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('phone')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
2022-01-18 17:55:21 +03:00
|
|
|
App.Utils.CalendarEventPopover.renderPhoneIcon(info.event.extendedProps.data.customer.phone_number),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'd-inline-block ms-1',
|
2022-01-18 17:55:21 +03:00
|
|
|
'text': info.event.extendedProps.data.customer.phone_number
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
2020-07-01 10:13:22 +03:00
|
|
|
$('<strong/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('notes')
|
2020-07-01 10:13:22 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 17:55:21 +03:00
|
|
|
'text': getEventNotes(info.event)
|
2020-07-01 10:13:22 +03:00
|
|
|
}),
|
|
|
|
$('<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/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'close-popover btn btn-outline-secondary me-2',
|
2020-09-07 12:21:16 +03:00
|
|
|
'html': [
|
|
|
|
$('<i/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'fas fa-ban me-2'
|
2020-09-07 12:21:16 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('close')
|
2020-09-07 12:21:16 +03:00
|
|
|
})
|
|
|
|
]
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<button/>', {
|
2020-10-20 16:03:48 +03:00
|
|
|
'class': 'delete-popover btn btn-outline-secondary ' + displayDelete,
|
2020-09-07 12:21:16 +03:00
|
|
|
'html': [
|
|
|
|
$('<i/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'fas fa-trash-alt me-2'
|
2020-09-07 12:21:16 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('delete')
|
2020-09-07 12:21:16 +03:00
|
|
|
})
|
|
|
|
]
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<button/>', {
|
2020-09-28 15:17:47 +03:00
|
|
|
'class': 'edit-popover btn btn-primary ' + displayEdit,
|
2020-09-07 12:21:16 +03:00
|
|
|
'html': [
|
|
|
|
$('<i/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'fas fa-edit me-2'
|
2020-09-07 12:21:16 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('edit')
|
2020-09-07 12:21:16 +03:00
|
|
|
})
|
|
|
|
]
|
2020-05-07 19:47:14 +03:00
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
$target.popover({
|
2016-07-17 14:46:38 +03:00
|
|
|
placement: 'top',
|
2022-01-18 17:55:21 +03:00
|
|
|
title: info.event.title,
|
2020-05-07 19:47:14 +03:00
|
|
|
content: $html,
|
2016-07-17 14:46:38 +03:00
|
|
|
html: true,
|
2016-07-18 23:55:05 +03:00
|
|
|
container: '#calendar',
|
2016-07-17 14:46:38 +03:00
|
|
|
trigger: 'manual'
|
|
|
|
});
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
lastFocusedEventData = info.event;
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
$target.popover('toggle');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
// Fix popover position.
|
2022-01-17 07:10:26 +03:00
|
|
|
const $popover = $calendarPage.find('.popover');
|
|
|
|
|
|
|
|
if ($popover.length > 0 && $popover.position().top < 200) {
|
|
|
|
$popover.css('top', '200px');
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()
|
2022-01-18 17:55:21 +03:00
|
|
|
*
|
|
|
|
* @param {Object} info
|
2016-07-17 14:46:38 +03:00
|
|
|
*/
|
2022-01-18 19:40:43 +03:00
|
|
|
function onEventResize(info) {
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('privileges').appointments.edit === false) {
|
2022-01-18 17:55:21 +03:00
|
|
|
info.revert();
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('no_privileges_edit_appointments'));
|
2016-07-17 14:46:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let successCallback;
|
2018-01-18 00:06:42 +03:00
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
if ($notification.is(':visible')) {
|
|
|
|
$notification.hide('bind');
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
if (!info.event.extendedProps.data.is_unavailability) {
|
2016-07-17 14:46:38 +03:00
|
|
|
// Prepare appointment data.
|
2022-01-18 17:55:21 +03:00
|
|
|
info.event.extendedProps.data.end_datetime = moment(info.event.extendedProps.data.end_datetime)
|
2022-01-18 19:40:43 +03:00
|
|
|
.add({days: info.endDelta.days, milliseconds: info.endDelta.milliseconds})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2018-01-18 00:06:42 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
const appointment = {...info.event.extendedProps.data};
|
2022-01-12 13:22:54 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
appointment.is_unavailability = Number(appointment.is_unavailability);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
// Must delete the following because only appointment data should be provided to the AJAX call.
|
|
|
|
delete appointment.customer;
|
|
|
|
delete appointment.provider;
|
|
|
|
delete appointment.service;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
// Success callback
|
2022-01-12 13:22:54 +03:00
|
|
|
successCallback = () => {
|
2016-07-17 14:46:38 +03:00
|
|
|
// Display success notification to user.
|
2022-01-12 13:22:54 +03:00
|
|
|
const undoFunction = () => {
|
2022-01-18 17:55:21 +03:00
|
|
|
appointment.end_datetime = info.event.extendedProps.data.end_datetime = moment(
|
|
|
|
appointment.end_datetime
|
|
|
|
)
|
2022-01-18 19:40:43 +03:00
|
|
|
.add({days: -info.endDelta.days, milliseconds: -info.endDelta.milliseconds})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
App.Http.Calendar.saveAppointment(appointment).done(() => {
|
2022-01-17 07:10:26 +03:00
|
|
|
$notification.hide('blind');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2020-12-08 10:42:28 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
info.revert();
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('appointment_updated'), [
|
2016-07-17 14:46:38 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
'label': lang('undo'),
|
2016-07-17 14:46:38 +03:00
|
|
|
'function': undoFunction
|
|
|
|
}
|
|
|
|
]);
|
2022-01-17 07:10:26 +03:00
|
|
|
$footer.css('position', 'static'); // Footer position fix.
|
2018-01-18 00:06:42 +03:00
|
|
|
|
|
|
|
// Update the event data for later use.
|
2022-01-18 17:55:21 +03:00
|
|
|
info.event.setProp('data', info.event.extendedProps.data);
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Update appointment data.
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Http.Calendar.saveAppointment(appointment, null, successCallback);
|
2016-07-17 14:46:38 +03:00
|
|
|
} else {
|
2022-01-18 14:54:41 +03:00
|
|
|
// Update unavailability time period.
|
|
|
|
const unavailability = {
|
2022-01-18 17:55:21 +03:00
|
|
|
id: info.event.extendedProps.data.id,
|
|
|
|
start_datetime: moment(info.event.start).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
end_datetime: moment(info.event.end).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
id_users_provider: info.event.extendedProps.data.id_users_provider
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
info.event.extendedProps.data.end_datetime = unavailability.end_datetime;
|
2018-01-18 00:06:42 +03:00
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
// Define success callback function.
|
2022-01-12 13:22:54 +03:00
|
|
|
successCallback = () => {
|
2016-07-17 14:46:38 +03:00
|
|
|
// Display success notification to user.
|
2022-01-12 13:22:54 +03:00
|
|
|
const undoFunction = () => {
|
2022-01-18 17:55:21 +03:00
|
|
|
unavailability.end_datetime = info.event.extendedProps.data.end_datetime = moment(
|
|
|
|
unavailability.end_datetime
|
|
|
|
)
|
|
|
|
.add({days: -info.delta.days, milliseconds: -info.delta.milliseconds})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
unavailability.is_unavailability = Number(unavailability.is_unavailability);
|
2022-01-12 13:22:54 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Calendar.saveAppointment(unavailability).done(() => {
|
2022-01-17 07:10:26 +03:00
|
|
|
$notification.hide('blind');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2020-12-08 10:42:28 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
info.revert();
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('unavailability_updated'), [
|
2016-07-17 14:46:38 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
'label': lang('undo'),
|
2016-07-17 14:46:38 +03:00
|
|
|
'function': undoFunction
|
|
|
|
}
|
|
|
|
]);
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
$footer.css('position', 'static'); // Footer position fix.
|
2018-01-18 00:06:42 +03:00
|
|
|
|
|
|
|
// Update the event data for later use.
|
2022-01-18 17:55:21 +03:00
|
|
|
info.event.setProp('data', info.event.extendedProps.data);
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Calendar.saveUnavailability(unavailability, successCallback, null);
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calendar Window "Resize" Callback
|
|
|
|
*
|
2016-10-10 19:29:48 +03:00
|
|
|
* The calendar element needs to be re-sized too in order to fit into the window. Nevertheless, if the window
|
2022-01-18 17:55:21 +03:00
|
|
|
* becomes very small the calendar won't shrink anymore.
|
2016-07-17 14:46:38 +03:00
|
|
|
*
|
2020-05-06 20:23:49 +03:00
|
|
|
* @see getCalendarHeight()
|
2016-07-17 14:46:38 +03:00
|
|
|
*/
|
2022-01-18 19:40:43 +03:00
|
|
|
function onWindowResize() {
|
2022-01-18 17:55:21 +03:00
|
|
|
fullCalendar.setOption('height', getCalendarHeight());
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calendar Day "Click" Callback
|
|
|
|
*
|
2016-10-10 19:29:48 +03:00
|
|
|
* When the user clicks on a day square on the calendar, then he will automatically be transferred to that
|
2016-07-17 14:46:38 +03:00
|
|
|
* day view calendar.
|
2020-09-23 12:24:42 +03:00
|
|
|
*
|
2022-01-18 17:55:21 +03:00
|
|
|
* @param {Object} info
|
2016-07-17 14:46:38 +03:00
|
|
|
*/
|
2022-01-18 19:40:43 +03:00
|
|
|
function onDateClick(info) {
|
2022-01-18 17:55:21 +03:00
|
|
|
if (info.allDay) {
|
|
|
|
fullCalendar.changeView('timeGridDay');
|
|
|
|
fullCalendar.gotoDate(info.date);
|
2016-07-17 14:46:38 +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-09-23 12:24:42 +03:00
|
|
|
*
|
2022-01-18 17:55:21 +03:00
|
|
|
* @param {Object} info
|
2016-07-17 14:46:38 +03:00
|
|
|
*/
|
2022-01-18 19:40:43 +03:00
|
|
|
function onEventDrop(info) {
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('privileges').appointments.edit === false) {
|
2022-01-18 17:55:21 +03:00
|
|
|
info.revert();
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('no_privileges_edit_appointments'));
|
2016-07-17 14:46:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
if ($notification.is(':visible')) {
|
|
|
|
$notification.hide('bind');
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let successCallback;
|
2020-09-23 12:24:42 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
if (!info.event.extendedProps.data.is_unavailability) {
|
2016-07-17 14:46:38 +03:00
|
|
|
// Prepare appointment data.
|
2022-01-18 17:55:21 +03:00
|
|
|
const appointment = {...info.event.extendedProps.data};
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
// Must delete the following because only appointment data should be provided to the ajax call.
|
2017-10-31 12:37:00 +03:00
|
|
|
delete appointment.customer;
|
|
|
|
delete appointment.provider;
|
|
|
|
delete appointment.service;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2021-11-24 10:34:26 +03:00
|
|
|
appointment.start_datetime = moment(appointment.start_datetime)
|
2022-01-18 17:55:21 +03:00
|
|
|
.add({days: info.delta.days, millisecond: info.delta.milliseconds})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2021-11-24 10:34:26 +03:00
|
|
|
appointment.end_datetime = moment(appointment.end_datetime)
|
2022-01-18 17:55:21 +03:00
|
|
|
.add({days: info.delta.days, millisecond: info.delta.milliseconds})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
appointment.is_unavailability = Number(appointment.is_unavailability);
|
2022-01-12 13:22:54 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
info.event.extendedProps.data.start_datetime = appointment.start_datetime;
|
|
|
|
info.event.extendedProps.data.end_datetime = appointment.end_datetime;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
// Define success callback function.
|
2022-01-12 13:22:54 +03:00
|
|
|
successCallback = () => {
|
2016-07-17 14:46:38 +03:00
|
|
|
// Define the undo function, if the user needs to reset the last change.
|
2022-01-12 13:22:54 +03:00
|
|
|
const undoFunction = () => {
|
2021-11-24 10:34:26 +03:00
|
|
|
appointment.start_datetime = moment(appointment.start_datetime)
|
2022-01-18 17:55:21 +03:00
|
|
|
.add({
|
|
|
|
days: -info.delta.days,
|
|
|
|
milliseconds: -info.delta.milliseconds
|
|
|
|
})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2021-11-24 10:34:26 +03:00
|
|
|
appointment.end_datetime = moment(appointment.end_datetime)
|
2022-01-18 17:55:21 +03:00
|
|
|
.add({days: -info.delta.days, milliseconds: -info.delta.milliseconds})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
info.event.extendedProps.data.start_datetime = appointment.start_datetime;
|
|
|
|
info.event.extendedProps.data.end_datetime = appointment.end_datetime;
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
App.Http.Calendar.saveAppointment(appointment).done(() => {
|
2022-01-17 07:10:26 +03:00
|
|
|
$notification.hide('blind');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2020-12-08 10:42:28 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
info.revert();
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('appointment_updated'), [
|
2016-07-17 14:46:38 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
'label': lang('undo'),
|
2016-07-17 14:46:38 +03:00
|
|
|
'function': undoFunction
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
$footer.css('position', 'static'); // Footer position fix.
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Update appointment data.
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Http.Calendar.saveAppointment(appointment, null, successCallback);
|
2016-07-17 14:46:38 +03:00
|
|
|
} else {
|
2022-01-18 14:54:41 +03:00
|
|
|
// Update unavailability time period.
|
|
|
|
const unavailability = {
|
2022-01-18 17:55:21 +03:00
|
|
|
id: info.event.extendedProps.data.id,
|
|
|
|
start_datetime: moment(info.event.start).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
end_datetime: moment(info.event.end).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
id_users_provider: info.event.extendedProps.data.id_users_provider
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
successCallback = () => {
|
|
|
|
const undoFunction = () => {
|
2022-01-18 14:54:41 +03:00
|
|
|
unavailability.start_datetime = moment(unavailability.start_datetime)
|
2022-01-18 17:55:21 +03:00
|
|
|
.add({days: -info.delta.days, milliseconds: -info.delta.milliseconds})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
unavailability.end_datetime = moment(unavailability.end_datetime)
|
2022-01-18 17:55:21 +03:00
|
|
|
.add({days: -info.delta.days, milliseconds: -info.delta.milliseconds})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
unavailability.is_unavailability = Number(unavailability.is_unavailability);
|
2022-01-12 13:22:54 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
info.event.extendedProps.data.start_datetime = unavailability.start_datetime;
|
|
|
|
info.event.extendedProps.data.end_datetime = unavailability.end_datetime;
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Calendar.saveUnavailability(unavailability).done(() => {
|
2022-01-17 07:10:26 +03:00
|
|
|
$notification.hide('blind');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2020-12-08 10:42:28 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
info.revert();
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('unavailability_updated'), [
|
2016-07-17 14:46:38 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
label: lang('undo'),
|
2016-07-17 14:46:38 +03:00
|
|
|
function: undoFunction
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
$footer.css('position', 'static'); // Footer position fix.
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Calendar.saveUnavailability(unavailability, successCallback);
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-31 12:37:00 +03:00
|
|
|
* Calendar "View Render" Callback
|
2016-07-17 14:46:38 +03:00
|
|
|
*
|
|
|
|
* Whenever the calendar changes or refreshes its view certain actions need to be made, in order to
|
|
|
|
* display proper information to the user.
|
|
|
|
*/
|
2022-01-18 19:40:43 +03:00
|
|
|
function onDatesSet() {
|
2022-01-17 07:10:26 +03:00
|
|
|
if ($selectFilterItem.val() === null) {
|
2017-10-31 12:37:00 +03:00
|
|
|
return;
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2020-05-06 20:23:49 +03:00
|
|
|
refreshCalendarAppointments(
|
2022-01-17 07:10:26 +03:00
|
|
|
$calendar,
|
|
|
|
$selectFilterItem.val(),
|
2017-10-31 12:37:00 +03:00
|
|
|
$('#select-filter-item option:selected').attr('type'),
|
2022-01-18 17:55:21 +03:00
|
|
|
fullCalendar.view.currentStart,
|
|
|
|
fullCalendar.view.currentEnd
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
$(window).trigger('resize'); // Places the footer on the bottom.
|
|
|
|
|
|
|
|
// Remove all open popovers.
|
2022-01-12 13:22:54 +03:00
|
|
|
$('.close-popover').each((index, closePopoverButton) => {
|
2020-06-18 21:23:16 +03:00
|
|
|
$(closePopoverButton).parents('.popover').popover('dispose');
|
2016-07-17 14:46:38 +03:00
|
|
|
});
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
// Add new popovers.
|
2022-01-18 17:55:21 +03:00
|
|
|
$('.fv-events').each((index, eventEl) => {
|
|
|
|
$(eventEl).popover();
|
2016-07-17 14:46:38 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
// /**
|
|
|
|
// * Convert titles to HTML
|
|
|
|
// *
|
|
|
|
// * On some calendar events the titles contain html markup that is not displayed properly due to the
|
|
|
|
// * FullCalendar plugin. This plugin sets the .fc-event-title value by using the $.text() method and
|
|
|
|
// * not the $.html() method. So in order for the title to display the html properly we convert all the
|
|
|
|
// * .fc-event-titles where needed into html.
|
|
|
|
// */
|
|
|
|
// function convertTitlesToHtml() {
|
|
|
|
// // Convert the titles to html code.
|
|
|
|
// $('.fc-custom').each((index, customEventElement) => {
|
|
|
|
// const title = $(customEventElement).find('.fc-event-title').text();
|
|
|
|
// $(customEventElement).find('.fc-event-title').html(title);
|
|
|
|
// const time = $(customEventElement).find('.fc-event-time').text();
|
|
|
|
// $(customEventElement).find('.fc-event-time').html(time);
|
|
|
|
// });
|
|
|
|
// }
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh Calendar Appointments
|
|
|
|
*
|
|
|
|
* This method reloads the registered appointments for the selected date period and filter type.
|
|
|
|
*
|
|
|
|
* @param {Object} $calendar The calendar jQuery object.
|
|
|
|
* @param {Number} recordId The selected record id.
|
|
|
|
* @param {String} filterType The filter type, could be either FILTER_TYPE_PROVIDER or FILTER_TYPE_SERVICE.
|
2022-01-17 21:44:44 +03:00
|
|
|
* @param {String} startDate Visible start date of the calendar.
|
|
|
|
* @param {String} endDate Visible end date of the calendar.
|
2016-07-17 14:46:38 +03:00
|
|
|
*/
|
2020-05-06 20:23:49 +03:00
|
|
|
function refreshCalendarAppointments($calendar, recordId, filterType, startDate, endDate) {
|
2020-04-06 21:48:11 +03:00
|
|
|
$('#loading').css('visibility', 'hidden');
|
2020-04-06 21:34:32 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const calendarEventSource = [];
|
2021-03-25 13:12:10 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
startDate = moment(startDate).format('YYYY-MM-DD');
|
|
|
|
|
|
|
|
endDate = moment(endDate).format('YYYY-MM-DD');
|
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
App.Http.Calendar.getCalendarAppointments(recordId, startDate, endDate, filterType)
|
2022-01-12 13:22:54 +03:00
|
|
|
.done((response) => {
|
2022-01-18 17:55:21 +03:00
|
|
|
const calendarEventSources = fullCalendar.getEventSources();
|
|
|
|
|
|
|
|
calendarEventSources.forEach((calendarEventSource) => calendarEventSource.remove());
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
// Add appointments to calendar.
|
2022-01-12 13:22:54 +03:00
|
|
|
response.appointments.forEach((appointment) => {
|
|
|
|
const appointmentEvent = {
|
2020-05-06 20:15:11 +03:00
|
|
|
id: appointment.id,
|
2021-11-06 19:38:37 +03:00
|
|
|
title:
|
|
|
|
appointment.service.name +
|
|
|
|
' - ' +
|
|
|
|
appointment.customer.first_name +
|
|
|
|
' ' +
|
|
|
|
appointment.customer.last_name,
|
2022-01-18 17:55:21 +03:00
|
|
|
start: moment(appointment.start_datetime).toDate(),
|
|
|
|
end: moment(appointment.end_datetime).toDate(),
|
2020-05-06 20:15:11 +03:00
|
|
|
allDay: false,
|
2022-01-18 21:03:06 +03:00
|
|
|
color: appointment.color,
|
2020-05-06 20:15:11 +03:00
|
|
|
data: appointment // Store appointment data for later use.
|
|
|
|
};
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(appointmentEvent);
|
2020-05-06 20:15:11 +03:00
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
// Add custom unavailability periods (they are always displayed on the calendar, even if the provider
|
|
|
|
// won't work on that day).
|
2022-01-18 14:54:41 +03:00
|
|
|
response.unavailabilities.forEach((unavailability) => {
|
|
|
|
let notes = unavailability.notes ? ' - ' + unavailability.notes : '';
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
if (unavailability.notes && unavailability.notes.length > 30) {
|
|
|
|
notes = unavailability.notes.substring(0, 30) + '...';
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const unavailabilityEvent = {
|
2022-01-18 14:54:41 +03:00
|
|
|
title: lang('unavailability') + notes,
|
2022-01-18 17:55:21 +03:00
|
|
|
start: moment(unavailability.start_datetime).toDate(),
|
|
|
|
end: moment(unavailability.end_datetime).toDate(),
|
2020-10-20 16:03:48 +03:00
|
|
|
allDay: false,
|
|
|
|
color: '#879DB4',
|
|
|
|
editable: true,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability fc-custom',
|
|
|
|
data: unavailability
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(unavailabilityEvent);
|
2020-10-20 16:03:48 +03:00
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
const calendarView = fullCalendar.view;
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
if (filterType === FILTER_TYPE_PROVIDER && calendarView.type !== 'dayGridMonth') {
|
2022-01-18 10:18:22 +03:00
|
|
|
const provider = vars('available_providers').find(
|
2022-01-12 13:22:54 +03:00
|
|
|
(availableProvider) => Number(availableProvider.id) === Number(recordId)
|
|
|
|
);
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2020-10-20 16:03:48 +03:00
|
|
|
if (!provider) {
|
|
|
|
throw new Error('Provider was not found.');
|
|
|
|
}
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const workingPlan = JSON.parse(provider.settings.working_plan);
|
|
|
|
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions);
|
|
|
|
let unavailabilityEvent;
|
|
|
|
let viewStart;
|
|
|
|
let viewEnd;
|
|
|
|
let breakStart;
|
|
|
|
let breakEnd;
|
|
|
|
let workingPlanExceptionStart;
|
|
|
|
let workingPlanExceptionEnd;
|
|
|
|
let weekdayNumber;
|
|
|
|
let weekdayName;
|
|
|
|
let weekdayDate;
|
|
|
|
let workingPlanExceptionEvent;
|
|
|
|
let startHour;
|
|
|
|
let endHour;
|
|
|
|
let workDateStart;
|
|
|
|
let workDateEnd;
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
// Sort the working plan starting with the first day as set in General settings to correctly align
|
|
|
|
// breaks in the calendar display.
|
2022-01-18 10:18:22 +03:00
|
|
|
const firstWeekdayNumber = App.Utils.Date.getWeekdayId(vars('first_weekday'));
|
2022-01-12 13:22:54 +03:00
|
|
|
const sortedWorkingPlan = App.Utils.Date.sortWeekDictionary(workingPlan, firstWeekdayNumber);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
switch (calendarView.type) {
|
|
|
|
case 'timeGridDay':
|
|
|
|
weekdayNumber = parseInt(moment(calendarView.currentStart).format('d'));
|
2022-01-12 13:22:54 +03:00
|
|
|
weekdayName = App.Utils.Date.getWeekdayName(weekdayNumber);
|
2022-01-18 17:55:21 +03:00
|
|
|
weekdayDate = moment(calendarView.currentStart).clone().format('YYYY-MM-DD');
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
// Add working plan exception.
|
|
|
|
if (workingPlanExceptions && workingPlanExceptions[weekdayDate]) {
|
|
|
|
sortedWorkingPlan[weekdayName] = workingPlanExceptions[weekdayDate];
|
|
|
|
workingPlanExceptionStart = weekdayDate + ' ' + sortedWorkingPlan[weekdayName].start;
|
|
|
|
workingPlanExceptionEnd = weekdayDate + ' ' + sortedWorkingPlan[weekdayName].end;
|
|
|
|
|
|
|
|
workingPlanExceptionEvent = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('working_plan_exception'),
|
2022-01-18 17:55:21 +03:00
|
|
|
start: moment(workingPlanExceptionStart, 'YYYY-MM-DD HH:mm', true).toDate(),
|
|
|
|
end: moment(workingPlanExceptionEnd, 'YYYY-MM-DD HH:mm', true)
|
|
|
|
.add(1, 'day')
|
|
|
|
.toDate(),
|
2020-10-20 16:03:48 +03:00
|
|
|
allDay: true,
|
|
|
|
color: '#879DB4',
|
|
|
|
editable: false,
|
|
|
|
className: 'fc-working-plan-exception fc-custom',
|
|
|
|
data: {
|
|
|
|
date: weekdayDate,
|
|
|
|
workingPlanException: workingPlanExceptions[weekdayDate],
|
|
|
|
provider: provider
|
|
|
|
}
|
|
|
|
};
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(workingPlanExceptionEvent);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2020-10-20 16:03:48 +03:00
|
|
|
// Non-working day.
|
|
|
|
if (sortedWorkingPlan[weekdayName] === null) {
|
|
|
|
// Working plan exception.
|
2020-10-21 21:36:37 +03:00
|
|
|
unavailabilityEvent = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('not_working'),
|
2022-01-18 17:55:21 +03:00
|
|
|
start: calendarView.currentStart.clone().toDate(),
|
|
|
|
end: calendarView.currentEnd.clone().toDate(),
|
2020-10-20 16:03:48 +03:00
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability'
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(unavailabilityEvent);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
return; // Go to next loop.
|
|
|
|
}
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Add unavailability period before work starts.
|
2022-01-18 17:55:21 +03:00
|
|
|
viewStart = moment(calendarView.currentStart.format('YYYY-MM-DD') + ' 00:00:00');
|
2020-10-20 16:03:48 +03:00
|
|
|
startHour = sortedWorkingPlan[weekdayName].start.split(':');
|
|
|
|
workDateStart = viewStart.clone();
|
|
|
|
workDateStart.hour(parseInt(startHour[0]));
|
|
|
|
workDateStart.minute(parseInt(startHour[1]));
|
|
|
|
|
|
|
|
if (viewStart < workDateStart) {
|
2022-01-18 14:54:41 +03:00
|
|
|
const unavailabilityPeriodBeforeWorkStarts = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('not_working'),
|
2020-10-20 16:03:48 +03:00
|
|
|
start: viewStart,
|
|
|
|
end: workDateStart,
|
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability'
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
calendarEventSource.push(unavailabilityPeriodBeforeWorkStarts);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Add unavailability period after work ends.
|
2022-01-18 17:55:21 +03:00
|
|
|
viewEnd = moment(calendarView.currentEnd.format('YYYY-MM-DD') + ' 00:00:00');
|
2020-10-20 16:03:48 +03:00
|
|
|
endHour = sortedWorkingPlan[weekdayName].end.split(':');
|
|
|
|
workDateEnd = viewStart.clone();
|
|
|
|
workDateEnd.hour(parseInt(endHour[0]));
|
|
|
|
workDateEnd.minute(parseInt(endHour[1]));
|
|
|
|
|
|
|
|
if (viewEnd > workDateEnd) {
|
2022-01-18 14:54:41 +03:00
|
|
|
const unavailabilityPeriodAfterWorkEnds = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('not_working'),
|
2020-10-20 16:03:48 +03:00
|
|
|
start: workDateEnd,
|
|
|
|
end: viewEnd,
|
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability'
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
calendarEventSource.push(unavailabilityPeriodAfterWorkEnds);
|
2020-05-06 20:15:11 +03:00
|
|
|
}
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Add unavailability periods for breaks.
|
2022-01-12 13:22:54 +03:00
|
|
|
sortedWorkingPlan[weekdayName].breaks.forEach((breakPeriod) => {
|
|
|
|
const breakStartString = breakPeriod.start.split(':');
|
2020-10-20 16:03:48 +03:00
|
|
|
breakStart = viewStart.clone();
|
|
|
|
breakStart.hour(parseInt(breakStartString[0]));
|
|
|
|
breakStart.minute(parseInt(breakStartString[1]));
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const breakEndString = breakPeriod.end.split(':');
|
2020-10-20 16:03:48 +03:00
|
|
|
breakEnd = viewStart.clone();
|
|
|
|
breakEnd.hour(parseInt(breakEndString[0]));
|
|
|
|
breakEnd.minute(parseInt(breakEndString[1]));
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
const unavailabilityPeriod = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('break'),
|
2020-10-20 16:03:48 +03:00
|
|
|
start: breakStart,
|
|
|
|
end: breakEnd,
|
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability fc-break'
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
calendarEventSource.push(unavailabilityPeriod);
|
2020-10-20 16:03:48 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
case 'timeGridWeek':
|
|
|
|
const calendarDate = moment(calendarView.currentStart).clone();
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
while (calendarDate.toDate() < calendarView.currentEnd) {
|
2021-11-06 19:38:37 +03:00
|
|
|
weekdayNumber = parseInt(calendarDate.format('d'));
|
2022-01-12 13:22:54 +03:00
|
|
|
weekdayName = App.Utils.Date.getWeekdayName(weekdayNumber);
|
2020-10-20 16:03:48 +03:00
|
|
|
weekdayDate = calendarDate.format('YYYY-MM-DD');
|
|
|
|
|
|
|
|
// Add working plan exception event.
|
|
|
|
if (workingPlanExceptions && workingPlanExceptions[weekdayDate]) {
|
|
|
|
sortedWorkingPlan[weekdayName] = workingPlanExceptions[weekdayDate];
|
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
workingPlanExceptionStart =
|
|
|
|
weekdayDate + ' ' + sortedWorkingPlan[weekdayName].start;
|
2020-10-20 16:03:48 +03:00
|
|
|
workingPlanExceptionEnd = weekdayDate + ' ' + sortedWorkingPlan[weekdayName].end;
|
|
|
|
|
|
|
|
workingPlanExceptionEvent = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('working_plan_exception'),
|
2022-01-18 17:55:21 +03:00
|
|
|
start: moment(workingPlanExceptionStart, 'YYYY-MM-DD HH:mm', true).toDate(),
|
|
|
|
end: moment(workingPlanExceptionEnd, 'YYYY-MM-DD HH:mm', true)
|
|
|
|
.add(1, 'day')
|
|
|
|
.toDate(),
|
2020-10-20 16:03:48 +03:00
|
|
|
allDay: true,
|
|
|
|
color: '#879DB4',
|
|
|
|
editable: false,
|
|
|
|
className: 'fc-working-plan-exception fc-custom',
|
|
|
|
data: {
|
|
|
|
date: weekdayDate,
|
|
|
|
workingPlanException: workingPlanExceptions[weekdayDate],
|
|
|
|
provider: provider
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(workingPlanExceptionEvent);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Non-working day.
|
|
|
|
if (sortedWorkingPlan[weekdayName] === null) {
|
2022-01-18 14:54:41 +03:00
|
|
|
// Add a full day unavailability event.
|
2020-10-21 21:36:37 +03:00
|
|
|
unavailabilityEvent = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('not_working'),
|
2022-01-18 17:55:21 +03:00
|
|
|
start: calendarDate.clone().toDate(),
|
|
|
|
end: calendarDate.clone().add(1, 'day').toDate(),
|
2020-10-20 16:03:48 +03:00
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability'
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(unavailabilityEvent);
|
2020-10-20 16:03:48 +03:00
|
|
|
|
|
|
|
calendarDate.add(1, 'day');
|
|
|
|
|
|
|
|
continue; // Go to the next loop.
|
|
|
|
}
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Add unavailability period before work starts.
|
2020-10-20 16:03:48 +03:00
|
|
|
startHour = sortedWorkingPlan[weekdayName].start.split(':');
|
|
|
|
workDateStart = calendarDate.clone();
|
|
|
|
workDateStart.hour(parseInt(startHour[0]));
|
|
|
|
workDateStart.minute(parseInt(startHour[1]));
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
if (calendarDate.toDate() < workDateStart.toDate()) {
|
2020-10-21 21:36:37 +03:00
|
|
|
unavailabilityEvent = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('not_working'),
|
2022-01-18 17:55:21 +03:00
|
|
|
start: calendarDate.clone().toDate(),
|
2021-11-06 19:38:37 +03:00
|
|
|
end: moment(
|
|
|
|
calendarDate.format('YYYY-MM-DD') +
|
|
|
|
' ' +
|
|
|
|
sortedWorkingPlan[weekdayName].start +
|
|
|
|
':00'
|
2022-01-18 17:55:21 +03:00
|
|
|
).toDate(),
|
2020-10-20 16:03:48 +03:00
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability'
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(unavailabilityEvent);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Add unavailability period after work ends.
|
2020-10-20 16:03:48 +03:00
|
|
|
endHour = sortedWorkingPlan[weekdayName].end.split(':');
|
|
|
|
workDateEnd = calendarDate.clone();
|
|
|
|
workDateEnd.hour(parseInt(endHour[0]));
|
|
|
|
workDateEnd.minute(parseInt(endHour[1]));
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
if (calendarView.currentEnd > workDateEnd.toDate()) {
|
2020-10-21 21:36:37 +03:00
|
|
|
unavailabilityEvent = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('not_working'),
|
2021-11-06 19:38:37 +03:00
|
|
|
start: moment(
|
|
|
|
calendarDate.format('YYYY-MM-DD') +
|
|
|
|
' ' +
|
|
|
|
sortedWorkingPlan[weekdayName].end +
|
|
|
|
':00'
|
2022-01-18 17:55:21 +03:00
|
|
|
).toDate(),
|
|
|
|
end: calendarDate.clone().add(1, 'day').toDate(),
|
2020-10-20 16:03:48 +03:00
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability'
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(unavailabilityEvent);
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Add unavailability periods during day breaks.
|
2022-01-12 13:22:54 +03:00
|
|
|
sortedWorkingPlan[weekdayName].breaks.forEach((breakPeriod) => {
|
|
|
|
const breakStartString = breakPeriod.start.split(':');
|
2020-10-20 16:03:48 +03:00
|
|
|
breakStart = calendarDate.clone();
|
|
|
|
breakStart.hour(parseInt(breakStartString[0]));
|
|
|
|
breakStart.minute(parseInt(breakStartString[1]));
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const breakEndString = breakPeriod.end.split(':');
|
2020-10-20 16:03:48 +03:00
|
|
|
breakEnd = calendarDate.clone();
|
|
|
|
breakEnd.hour(parseInt(breakEndString[0]));
|
|
|
|
breakEnd.minute(parseInt(breakEndString[1]));
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const unavailabilityEvent = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('break'),
|
2022-01-18 17:55:21 +03:00
|
|
|
start: moment(
|
|
|
|
calendarDate.format('YYYY-MM-DD') + ' ' + breakPeriod.start
|
|
|
|
).toDate(),
|
|
|
|
end: moment(calendarDate.format('YYYY-MM-DD') + ' ' + breakPeriod.end).toDate(),
|
2020-10-20 16:03:48 +03:00
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability fc-break'
|
2020-10-20 16:03:48 +03:00
|
|
|
};
|
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(unavailabilityEvent);
|
2020-10-20 16:03:48 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
calendarDate.add(1, 'day');
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-05-06 20:15:11 +03:00
|
|
|
}
|
|
|
|
})
|
2022-01-12 13:22:54 +03:00
|
|
|
.always(() => {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#loading').css('visibility', '');
|
2022-01-18 17:55:21 +03:00
|
|
|
fullCalendar.addEventSource(calendarEventSource);
|
2020-04-06 21:34:32 +03:00
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
function initialize() {
|
2017-10-31 12:37:00 +03:00
|
|
|
// Dynamic date formats.
|
2022-01-12 13:22:54 +03:00
|
|
|
let columnFormat = {};
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
switch (vars('date_format')) {
|
2016-07-17 14:46:38 +03:00
|
|
|
case 'DMY':
|
2017-10-31 12:37:00 +03:00
|
|
|
columnFormat = 'ddd D/M';
|
2016-07-17 14:46:38 +03:00
|
|
|
break;
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
case 'MDY':
|
|
|
|
case 'YMD':
|
2017-10-31 12:37:00 +03:00
|
|
|
columnFormat = 'ddd M/D';
|
2016-07-17 14:46:38 +03:00
|
|
|
break;
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
default:
|
2022-01-18 10:18:22 +03:00
|
|
|
throw new Error('Invalid date format setting provided!', vars('date_format'));
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2018-03-06 14:20:47 +03:00
|
|
|
// Time formats
|
2022-01-12 13:22:54 +03:00
|
|
|
let timeFormat = '';
|
|
|
|
let slotTimeFormat = '';
|
2018-03-06 14:20:47 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
switch (vars('time_format')) {
|
2018-03-08 16:55:51 +03:00
|
|
|
case 'military':
|
2018-03-06 14:20:47 +03:00
|
|
|
timeFormat = 'H:mm';
|
2022-01-25 00:43:18 +03:00
|
|
|
slotTimeFormat = 'H';
|
2018-03-06 14:20:47 +03:00
|
|
|
break;
|
2018-03-08 16:55:51 +03:00
|
|
|
case 'regular':
|
2018-03-17 20:00:55 +03:00
|
|
|
timeFormat = 'h:mm a';
|
2022-01-25 00:43:18 +03:00
|
|
|
slotTimeFormat = 'h a';
|
2018-03-06 14:20:47 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-01-18 10:18:22 +03:00
|
|
|
throw new Error('Invalid time format setting provided!', vars('time_format'));
|
2018-03-06 14:20:47 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
const initialView = window.innerWidth < 468 ? 'timeGridDay' : 'timeGridWeek';
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const firstWeekday = vars('first_weekday');
|
2022-01-12 13:22:54 +03:00
|
|
|
const firstWeekdayNumber = App.Utils.Date.getWeekdayId(firstWeekday);
|
2018-06-29 01:41:17 +03:00
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
// Initialize page calendar
|
2022-01-18 17:55:21 +03:00
|
|
|
fullCalendar = new FullCalendar.Calendar($calendar[0], {
|
|
|
|
initialView,
|
2020-05-06 20:23:49 +03:00
|
|
|
height: getCalendarHeight(),
|
2016-07-17 14:46:38 +03:00
|
|
|
editable: true,
|
2020-04-27 21:14:20 +03:00
|
|
|
firstDay: firstWeekdayNumber,
|
2021-10-28 14:30:39 +03:00
|
|
|
slotDuration: '00:15:00',
|
2020-12-08 10:36:46 +03:00
|
|
|
snapDuration: '00:15:00',
|
2021-07-19 16:59:21 +03:00
|
|
|
slotLabelInterval: '01:00',
|
2022-01-18 17:55:21 +03:00
|
|
|
eventTimeFormat: timeFormat,
|
|
|
|
eventTextColor: '#333',
|
2018-03-06 14:20:47 +03:00
|
|
|
slotLabelFormat: slotTimeFormat,
|
2022-01-18 17:55:21 +03:00
|
|
|
allDayContent: lang('all_day'),
|
|
|
|
dayHeaderFormat: columnFormat,
|
|
|
|
headerToolbar: {
|
2016-07-17 14:46:38 +03:00
|
|
|
left: 'prev,next today',
|
|
|
|
center: 'title',
|
2022-01-18 17:55:21 +03:00
|
|
|
right: 'timeGridDay,timeGridWeek,dayGridMonth'
|
2016-07-17 14:46:38 +03:00
|
|
|
},
|
|
|
|
|
2017-11-08 17:17:29 +03:00
|
|
|
// Selectable
|
|
|
|
selectable: true,
|
2022-01-18 17:55:21 +03:00
|
|
|
selectMirror: true,
|
|
|
|
select: (info) => {
|
|
|
|
if (info.allDay) {
|
2017-11-08 17:17:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
const isProviderDisplayed =
|
|
|
|
$selectFilterItem.find('option:selected').attr('type') === FILTER_TYPE_PROVIDER;
|
2017-11-08 17:17:29 +03:00
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
const buttons = [
|
|
|
|
{
|
|
|
|
text: lang('close'),
|
|
|
|
click: () => {
|
|
|
|
$('#message-box').dialog('close');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: lang('unavailability'),
|
|
|
|
click: () => {
|
|
|
|
$('#insert-unavailability').trigger('click');
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
if (isProviderDisplayed) {
|
|
|
|
$('#unavailability-provider').val($selectFilterItem.val());
|
|
|
|
} else {
|
|
|
|
$('#unavailability-provider option:first').prop('selected', true);
|
|
|
|
}
|
2017-11-08 17:17:29 +03:00
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
$('#unavailability-start').datepicker('setDate', info.start);
|
|
|
|
|
|
|
|
$('#unavailability-end').datepicker('setDate', info.end);
|
2017-11-08 17:17:29 +03:00
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
$('#message-box').dialog('close');
|
2022-01-25 00:40:35 +03:00
|
|
|
}
|
2022-01-25 00:55:35 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: lang('appointment'),
|
|
|
|
click: () => {
|
|
|
|
$('#insert-appointment').trigger('click');
|
2020-12-08 15:16:58 +03:00
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
// Preselect service & provider.
|
|
|
|
let service;
|
2020-12-08 15:16:58 +03:00
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
if (isProviderDisplayed) {
|
|
|
|
const provider = vars('available_providers').find(
|
|
|
|
(availableProvider) =>
|
|
|
|
Number(availableProvider.id) === Number($selectFilterItem.val())
|
|
|
|
);
|
2020-12-08 15:16:58 +03:00
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
if (provider) {
|
|
|
|
service = vars('available_services').find(
|
|
|
|
(availableService) => provider.services.indexOf(availableService.id) !== -1
|
|
|
|
);
|
2020-12-09 15:06:47 +03:00
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
if (service) {
|
|
|
|
$appointmentsModal.find('#select-service').val(service.id);
|
|
|
|
}
|
|
|
|
}
|
2020-12-08 15:16:58 +03:00
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
if (!$appointmentsModal.find('#select-service').val()) {
|
|
|
|
$('#select-service option:first').prop('selected', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$appointmentsModal.find('#select-service').trigger('change');
|
|
|
|
|
|
|
|
if (provider) {
|
|
|
|
$appointmentsModal.find('#select-provider').val(provider.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$appointmentsModal.find('#select-provider').val()) {
|
|
|
|
$appointmentsModal.find('#select-provider option:first').prop('selected', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$appointmentsModal.find('#select-provider').trigger('change');
|
|
|
|
} else {
|
|
|
|
service = vars('available_services').find(
|
|
|
|
(availableService) =>
|
|
|
|
Number(availableService.id) === Number($selectFilterItem.val())
|
|
|
|
);
|
2022-02-10 22:34:59 +03:00
|
|
|
|
|
|
|
if (service) {
|
|
|
|
$appointmentsModal.find('#select-service').val(service.id).trigger('change');
|
|
|
|
}
|
2022-01-25 00:55:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Preselect time
|
|
|
|
$('#start-datetime').datepicker('setDate', info.start);
|
|
|
|
$('#end-datetime').datepicker('setDate', info.end);
|
|
|
|
$('#message-box').dialog('close');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2017-11-08 17:17:29 +03:00
|
|
|
|
2022-01-25 00:55:35 +03:00
|
|
|
App.Utils.Message.show(lang('add_new_event'), lang('what_kind_of_event'), buttons);
|
2017-11-08 17:17:29 +03:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
buttonText: {
|
2022-01-18 10:22:25 +03:00
|
|
|
today: lang('today'),
|
|
|
|
day: lang('day'),
|
|
|
|
week: lang('week'),
|
|
|
|
month: lang('month')
|
2016-07-17 14:46:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// Calendar events need to be declared on initialization.
|
2022-01-18 19:40:43 +03:00
|
|
|
windowResize: onWindowResize,
|
|
|
|
datesSet: onDatesSet,
|
|
|
|
dateClick: onDateClick,
|
|
|
|
eventClick: onEventClick,
|
|
|
|
eventResize: onEventResize,
|
|
|
|
eventDrop: onEventDrop
|
2016-07-17 14:46:38 +03:00
|
|
|
});
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
fullCalendar.render();
|
|
|
|
|
2016-07-17 14:46:38 +03:00
|
|
|
// Trigger once to set the proper footer position after calendar initialization.
|
2022-01-18 19:40:43 +03:00
|
|
|
onWindowResize();
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-25 00:07:24 +03:00
|
|
|
$selectFilterItem.append(new Option(lang('all'), 'all', true, true));
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
// Fill the select list boxes of the page.
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('available_providers').length > 0) {
|
2022-01-17 23:33:04 +03:00
|
|
|
$('<optgroup/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'label': lang('providers'),
|
2020-05-07 19:47:14 +03:00
|
|
|
'type': 'providers-group',
|
2022-01-18 10:18:22 +03:00
|
|
|
'html': vars('available_providers').map((availableProvider) => {
|
2022-01-12 13:22:54 +03:00
|
|
|
const hasGoogleSync = availableProvider.settings.google_sync === '1' ? 'true' : 'false';
|
2020-05-07 19:47:14 +03:00
|
|
|
|
|
|
|
return $('<option/>', {
|
|
|
|
'value': availableProvider.id,
|
|
|
|
'type': FILTER_TYPE_PROVIDER,
|
|
|
|
'google-sync': hasGoogleSync,
|
|
|
|
'text': availableProvider.first_name + ' ' + availableProvider.last_name
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2020-05-07 19:47:14 +03:00
|
|
|
})
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#select-filter-item');
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('available_services').length > 0) {
|
2022-01-17 23:33:04 +03:00
|
|
|
$('<optgroup/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'label': lang('services'),
|
2020-05-07 19:47:14 +03:00
|
|
|
'type': 'services-group',
|
2022-01-18 10:18:22 +03:00
|
|
|
'html': vars('available_services').map((availableService) =>
|
2022-01-12 13:22:54 +03:00
|
|
|
$('<option/>', {
|
2020-05-07 19:47:14 +03:00
|
|
|
'value': availableService.id,
|
|
|
|
'type': FILTER_TYPE_SERVICE,
|
|
|
|
'text': availableService.name
|
2022-01-12 13:22:54 +03:00
|
|
|
})
|
|
|
|
)
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#select-filter-item');
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2017-10-31 12:37:00 +03:00
|
|
|
// Check permissions.
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('role_slug') === App.Layouts.Backend.DB_SLUG_PROVIDER) {
|
2022-01-17 07:10:26 +03:00
|
|
|
$selectFilterItem
|
|
|
|
.find('optgroup:eq(0)')
|
2022-01-18 10:18:22 +03:00
|
|
|
.find('option[value="' + vars('user_id') + '"]')
|
2017-10-31 12:37:00 +03:00
|
|
|
.prop('selected', true);
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
// Add the page event listeners.
|
2022-01-17 07:10:26 +03:00
|
|
|
addEventListeners();
|
2017-10-31 12:37:00 +03:00
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
$reloadAppointments.trigger('click');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
// Display the edit dialog if an appointment hash is provided.
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('edit_appointment')) {
|
|
|
|
const appointment = vars('edit_appointment');
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
App.Components.AppointmentsModal.resetModal();
|
|
|
|
|
2022-01-18 10:22:25 +03:00
|
|
|
$appointmentsModal.find('.modal-header h3').text(lang('edit_appointment_title'));
|
2022-01-17 07:10:26 +03:00
|
|
|
$appointmentsModal.find('#appointment-id').val(appointment.id);
|
|
|
|
$appointmentsModal.find('#select-service').val(appointment.id_services).trigger('change');
|
|
|
|
$appointmentsModal.find('#select-provider').val(appointment.id_users_provider);
|
2016-07-17 14:46:38 +03:00
|
|
|
|
|
|
|
// Set the start and end datetime of the appointment.
|
2022-01-17 23:33:04 +03:00
|
|
|
const startDatetimeMoment = moment(appointment.start_datetime);
|
|
|
|
$appointmentsModal.find('#start-datetime').datetimepicker('setDate', startDatetimeMoment.toDate());
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
const endDatetimeMoment = moment(appointment.end_datetime);
|
|
|
|
$appointmentsModal.find('#end-datetime').datetimepicker('setDate', endDatetimeMoment.toDate());
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const customer = appointment.customer;
|
2022-01-17 07:10:26 +03:00
|
|
|
$appointmentsModal.find('#customer-id').val(appointment.id_users_customer);
|
|
|
|
$appointmentsModal.find('#first-name').val(customer.first_name);
|
|
|
|
$appointmentsModal.find('#last-name').val(customer.last_name);
|
|
|
|
$appointmentsModal.find('#email').val(customer.email);
|
|
|
|
$appointmentsModal.find('#phone-number').val(customer.phone_number);
|
|
|
|
$appointmentsModal.find('#address').val(customer.address);
|
|
|
|
$appointmentsModal.find('#city').val(customer.city);
|
|
|
|
$appointmentsModal.find('#zip-code').val(customer.zip_code);
|
2022-03-29 11:15:24 +03:00
|
|
|
$appointmentsModal.find('#language').val(customer.language);
|
|
|
|
$appointmentsModal.find('#timezone').val(customer.timezone);
|
2022-01-17 07:10:26 +03:00
|
|
|
$appointmentsModal.find('#appointment-location').val(appointment.location);
|
|
|
|
$appointmentsModal.find('#appointment-notes').val(appointment.notes);
|
|
|
|
$appointmentsModal.find('#customer-notes').val(customer.notes);
|
|
|
|
|
2022-01-18 21:01:26 +03:00
|
|
|
App.Components.ColorSelection.setColor($appointmentsModal.find('#appointment-color'), appointment.color);
|
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
$appointmentsModal.modal('show');
|
|
|
|
|
2022-01-18 17:55:21 +03:00
|
|
|
fullCalendar.gotoDate(moment(appointment.start_datetime).toDate());
|
2016-07-17 14:46:38 +03:00
|
|
|
}
|
|
|
|
|
2022-01-17 07:10:26 +03:00
|
|
|
if (!$selectFilterItem.find('option').length) {
|
2016-07-17 14:46:38 +03:00
|
|
|
$('#calendar-actions button').prop('disabled', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fine tune the footer's position only for this page.
|
|
|
|
if (window.innerHeight < 700) {
|
2022-01-17 07:10:26 +03:00
|
|
|
$footer.css('position', 'static');
|
2017-10-31 12:37:00 +03:00
|
|
|
}
|
2020-03-18 22:30:15 +03:00
|
|
|
|
|
|
|
// Automatically refresh the calendar page every 10 seconds (without loading animation).
|
2022-01-12 13:22:54 +03:00
|
|
|
setInterval(() => {
|
2022-03-02 15:28:20 +03:00
|
|
|
if ($('.popover').length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-06 20:23:49 +03:00
|
|
|
refreshCalendarAppointments(
|
2020-03-18 22:30:15 +03:00
|
|
|
$calendar,
|
|
|
|
$selectFilterItem.val(),
|
|
|
|
$selectFilterItem.find('option:selected').attr('type'),
|
2022-01-18 17:55:21 +03:00
|
|
|
fullCalendar.view.currentStart,
|
|
|
|
fullCalendar.view.currentEnd
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
2020-12-08 01:11:01 +03:00
|
|
|
}, 60000);
|
2022-01-18 17:55:21 +03:00
|
|
|
|
|
|
|
$reloadAppointments.trigger('click');
|
2022-01-12 13:22:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
initialize
|
2016-07-17 14:46:38 +03:00
|
|
|
};
|
2022-01-12 13:22:54 +03:00
|
|
|
})();
|