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>
|
2020-05-04 12:32:00 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2016, Alex Tselegidis
|
2021-12-18 19:43:45 +03:00
|
|
|
* @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-14 11:26:44 +03:00
|
|
|
* Working plan utility.
|
2016-07-17 14:46:38 +03:00
|
|
|
*
|
2022-01-14 11:26:44 +03:00
|
|
|
* This module implements the functionality of table calendar view.
|
2016-07-17 14:46:38 +03:00
|
|
|
*
|
2022-01-12 13:22:54 +03:00
|
|
|
* Old Name: BackendCalendarTableView
|
2016-07-17 14:46:38 +03:00
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Utils.CalendarTableView = (function () {
|
2022-01-18 19:38:57 +03:00
|
|
|
const $calendar = $('#calendar');
|
|
|
|
const $calendarToolbar = $('#calendar-toolbar');
|
|
|
|
const $calendarFilter = $('#calendar-filter');
|
|
|
|
const $notification = $('#notification');
|
|
|
|
const $reloadAppointments = $('#reload-appointments');
|
2022-01-17 23:33:04 +03:00
|
|
|
const $selectFilterItem = $('#select-filter-item');
|
|
|
|
const $selectService = $('#select-service');
|
|
|
|
const $selectProvider = $('#select-provider');
|
|
|
|
const $appointmentsModal = $('#appointments-modal');
|
|
|
|
const $unavailabilitiesModal = $('#unavailabilities-modal');
|
2022-01-18 19:38:57 +03:00
|
|
|
const $header = $('#header');
|
|
|
|
const $footer = $('#footer');
|
2022-01-12 13:22:54 +03:00
|
|
|
let $filterProvider;
|
|
|
|
let $filterService;
|
2022-01-17 23:33:04 +03:00
|
|
|
let $selectDate;
|
2022-06-02 10:37:43 +03:00
|
|
|
|
|
|
|
const moment = window.moment;
|
2022-01-12 13:22:54 +03:00
|
|
|
let lastFocusedEventData;
|
2016-08-15 22:59:43 +03:00
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
/**
|
2022-01-17 17:21:59 +03:00
|
|
|
* Add the utility event listeners.
|
2016-07-22 23:06:36 +03:00
|
|
|
*/
|
2022-01-17 17:21:59 +03:00
|
|
|
function addEventListeners() {
|
2022-01-12 13:22:54 +03:00
|
|
|
$calendar.on('click', '.calendar-header .btn.previous', () => {
|
2022-01-17 23:33:04 +03:00
|
|
|
const dayInterval = $selectFilterItem.val();
|
|
|
|
const currentDate = $selectDate.datepicker('getDate');
|
2022-01-12 13:22:54 +03:00
|
|
|
const startDate = moment(currentDate).subtract(1, 'days');
|
|
|
|
const endDate = startDate.clone().add(dayInterval - 1, 'days');
|
2022-01-17 23:33:04 +03:00
|
|
|
$selectDate.datepicker('setDate', startDate.toDate());
|
2020-05-04 12:32:00 +03:00
|
|
|
createView(startDate.toDate(), endDate.toDate());
|
2016-07-17 19:51:46 +03:00
|
|
|
});
|
2016-07-17 14:46:38 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
$calendar.on('click', '.calendar-header .btn.next', () => {
|
2022-01-17 23:33:04 +03:00
|
|
|
const dayInterval = $selectFilterItem.val();
|
|
|
|
const currentDate = $selectDate.datepicker('getDate');
|
2022-01-12 13:22:54 +03:00
|
|
|
const startDate = moment(currentDate).add(1, 'days');
|
|
|
|
const endDate = startDate.clone().add(dayInterval - 1, 'days');
|
2022-01-17 23:33:04 +03:00
|
|
|
$selectDate.datepicker('setDate', startDate.toDate());
|
2020-05-04 12:32:00 +03:00
|
|
|
createView(startDate.toDate(), endDate.toDate());
|
2016-07-17 19:51:46 +03:00
|
|
|
});
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
$calendarToolbar.on('change', '#select-filter-item', () => {
|
2022-01-17 23:33:04 +03:00
|
|
|
const dayInterval = $selectFilterItem.val();
|
|
|
|
const currentDate = $selectDate.datepicker('getDate');
|
2022-01-12 13:22:54 +03:00
|
|
|
const startDate = moment(currentDate);
|
|
|
|
const endDate = startDate.clone().add(dayInterval - 1, 'days');
|
2020-05-04 12:32:00 +03:00
|
|
|
createView(startDate.toDate(), endDate.toDate());
|
2016-07-18 21:18:55 +03:00
|
|
|
});
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
$calendarToolbar.on('click', '#reload-appointments', () => {
|
2020-04-27 21:14:20 +03:00
|
|
|
// Fetch the events and place them in the existing HTML format.
|
2022-01-17 23:33:04 +03:00
|
|
|
const dayInterval = $selectFilterItem.val();
|
|
|
|
const currentDate = $selectDate.datepicker('getDate');
|
2022-01-12 13:22:54 +03:00
|
|
|
const startDateMoment = moment(currentDate);
|
|
|
|
const startDate = startDateMoment.toDate();
|
|
|
|
const endDateMoment = startDateMoment.clone().add(dayInterval - 1, 'days');
|
|
|
|
const endDate = endDateMoment.toDate();
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
App.Http.Calendar.getCalendarAppointmentsForTableView(startDate, endDate).done((response) => {
|
2022-01-17 23:33:04 +03:00
|
|
|
let currentDate = startDate;
|
2016-08-15 22:32:31 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
while (currentDate <= endDate) {
|
2022-01-12 13:22:54 +03:00
|
|
|
$('.calendar-view .date-column').each((index, dateColumn) => {
|
|
|
|
const $dateColumn = $(dateColumn);
|
|
|
|
const date = new Date($dateColumn.data('date'));
|
2016-08-15 22:32:31 +03:00
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
if (moment(currentDate).format('YYYY-MM-DD') !== moment(date).format('YYYY-MM-DD')) {
|
2021-11-06 19:38:37 +03:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-06 14:18:02 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$dateColumn
|
|
|
|
.find('.date-column-title')
|
2022-01-18 10:18:22 +03:00
|
|
|
.text(App.Utils.Date.format(date, vars('date_format'), vars('time_format')));
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-17 17:21:59 +03:00
|
|
|
$dateColumn.find('.provider-column').each((index, providerColumn) => {
|
2022-01-12 13:22:54 +03:00
|
|
|
const $providerColumn = $(providerColumn);
|
|
|
|
const provider = $providerColumn.data('provider');
|
2016-08-15 22:32:31 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$providerColumn
|
|
|
|
.find('.calendar-wrapper')
|
|
|
|
.data('fullCalendar')
|
|
|
|
.getEventSources()
|
|
|
|
.forEach((eventSource) => eventSource.remove());
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
createNonWorkingHours(
|
|
|
|
$providerColumn.find('.calendar-wrapper'),
|
|
|
|
$providerColumn.data('provider')
|
|
|
|
);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Add the appointments to the column.
|
2022-06-02 10:37:43 +03:00
|
|
|
/** @var {Array} response.appointments */
|
2021-11-06 19:38:37 +03:00
|
|
|
createAppointments($providerColumn, response.appointments);
|
2018-01-23 12:08:37 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
// Add the unavailabilities to the column.
|
2022-06-02 10:37:43 +03:00
|
|
|
/** @var {Array} response.unavailabilities */
|
2022-01-18 19:38:57 +03:00
|
|
|
createUnavailabilities($providerColumn, response.unavailabilities);
|
2016-08-15 22:32:31 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Add the provider breaks to the column.
|
2022-01-12 13:22:54 +03:00
|
|
|
const workingPlan = JSON.parse(provider.settings.working_plan);
|
|
|
|
const day = moment(date).format('dddd').toLowerCase();
|
2021-11-06 19:38:37 +03:00
|
|
|
if (workingPlan[day]) {
|
2022-01-12 13:22:54 +03:00
|
|
|
const breaks = workingPlan[day].breaks;
|
2021-11-06 19:38:37 +03:00
|
|
|
createBreaks($providerColumn, breaks);
|
|
|
|
}
|
2016-08-15 22:32:31 +03:00
|
|
|
});
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2016-08-15 22:32:31 +03:00
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
currentDate = moment(currentDate).add({days: 1}).toDate();
|
2021-11-06 19:38:37 +03:00
|
|
|
}
|
2016-08-15 22:32:31 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// setCalendarViewSize();
|
2022-01-17 07:26:57 +03:00
|
|
|
App.Layouts.Backend.placeFooterToBottom();
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2018-01-23 12:08:37 +03:00
|
|
|
});
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
/**
|
|
|
|
* Event: On Window Resize
|
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
$(window).on('resize', () => {
|
2020-05-04 12:32:00 +03:00
|
|
|
setCalendarViewSize();
|
|
|
|
});
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event: Popover Close Button "Click"
|
|
|
|
*
|
|
|
|
* Hides the open popover element.
|
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
$calendar.on('click', '.close-popover', (event) => {
|
|
|
|
$(event.target).parents('.popover').popover('dispose');
|
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
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
$calendar.on('click', '.edit-popover', (event) => {
|
|
|
|
$(event.target).parents('.popover').popover('dispose');
|
2016-07-18 23:22:28 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let startMoment;
|
|
|
|
let endMoment;
|
2016-07-18 23:22:28 +03:00
|
|
|
|
2022-01-18 19:38:57 +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-22 12:01:33 +03:00
|
|
|
|
2022-01-12 13:22:54 +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-22 12:01:33 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
|
2020-10-22 12:01:33 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
workingPlanExceptions[date] = workingPlanException;
|
2020-10-22 12:01:33 +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-22 12:01:33 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
if (Number(availableProvider.id) === Number(provider.id)) {
|
|
|
|
availableProvider.settings.working_plan_exceptions =
|
|
|
|
JSON.stringify(workingPlanExceptions);
|
|
|
|
break;
|
|
|
|
}
|
2020-10-22 12:01:33 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$reloadAppointments.trigger('click'); // Update the calendar.
|
2022-01-12 13:22:54 +03:00
|
|
|
};
|
2020-10-22 12:01:33 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Http.Calendar.saveWorkingPlanException(
|
|
|
|
date,
|
|
|
|
workingPlanException,
|
|
|
|
provider.id,
|
|
|
|
successCallback,
|
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
2022-01-18 19:38:57 +03:00
|
|
|
} else if (lastFocusedEventData.extendedProps.data.is_unavailability === false) {
|
|
|
|
const appointment = lastFocusedEventData.extendedProps.data;
|
|
|
|
App.Components.AppointmentsModal.resetModal();
|
2016-07-18 23:22:28 +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 23:33:04 +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-18 23:22:28 +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-18 19:38:57 +03:00
|
|
|
$appointmentsModal.find('#start-datetime').datetimepicker('setDate', startMoment.toDate());
|
2016-07-18 23:22:28 +03:00
|
|
|
|
2021-11-24 10:34:26 +03:00
|
|
|
endMoment = moment(appointment.end_datetime);
|
2022-01-18 19:38:57 +03:00
|
|
|
$appointmentsModal.find('#end-datetime').datetimepicker('setDate', endMoment.toDate());
|
2016-07-18 23:22:28 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const customer = appointment.customer;
|
2022-01-17 23:33:04 +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 23:33:04 +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 23:33:04 +03:00
|
|
|
$appointmentsModal.modal('show');
|
2016-07-18 23:22:28 +03:00
|
|
|
} else {
|
2022-01-18 19:38:57 +03:00
|
|
|
const unavailability = lastFocusedEventData.extendedProps.data;
|
2016-07-18 23:22:28 +03:00
|
|
|
|
|
|
|
// Replace string date values with actual date objects.
|
2022-01-18 19:38:57 +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 19:38:57 +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-18 23:22:28 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
App.Components.UnavailabilitiesModal.resetModal();
|
2016-07-18 23:22:28 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Apply unavailability data to dialog.
|
2022-01-18 19:38:57 +03:00
|
|
|
$unavailabilitiesModal.find('.modal-header h3').text(lang('edit_unavailability_title'));
|
|
|
|
$unavailabilitiesModal.find('#unavailability-start').datetimepicker('setDate', startMoment.toDate());
|
2022-01-18 14:54:41 +03:00
|
|
|
$unavailabilitiesModal.find('#unavailability-id').val(unavailability.id);
|
|
|
|
$unavailabilitiesModal.find('#unavailability-provider').val(unavailability.id_users_provider);
|
2022-01-18 19:38:57 +03:00
|
|
|
$unavailabilitiesModal.find('#unavailability-end').datetimepicker('setDate', endMoment.toDate());
|
2022-01-18 14:54:41 +03:00
|
|
|
$unavailabilitiesModal.find('#unavailability-notes').val(unavailability.notes);
|
2022-01-17 23:33:04 +03:00
|
|
|
|
|
|
|
$unavailabilitiesModal.modal('show');
|
2020-12-08 15:16:58 +03:00
|
|
|
}
|
2016-07-18 23:22:28 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
$calendar.on('click', '.delete-popover', (event) => {
|
|
|
|
$(event.target).parents('.popover').popover('dispose'); // Hide the popover.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2020-10-20 16:03:48 +03:00
|
|
|
// If id_role parameter exists the popover is an working plan exception.
|
2022-01-18 19:38:57 +03:00
|
|
|
if (lastFocusedEventData.extendedProps.data.hasOwnProperty('id_roles')) {
|
2020-05-04 12:32:00 +03:00
|
|
|
// Do not display confirmation prompt.
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
const date = moment(lastFocusedEventData.start).format('YYYY-MM-DD');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
const providerId = lastFocusedEventData.extendedProps.data.id;
|
2022-01-17 21:44:44 +03:00
|
|
|
|
|
|
|
App.Http.Calendar.deleteWorkingPlanException(date, providerId).done(() => {
|
2021-11-06 19:38:37 +03:00
|
|
|
$('#message-box').dialog('close');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const workingPlanExceptions = JSON.parse(
|
2022-01-18 19:38:57 +03:00
|
|
|
lastFocusedEventData.extendedProps.data.settings.working_plan_exceptions
|
2022-01-12 13:22:54 +03:00
|
|
|
);
|
2022-01-17 21:44:44 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
delete workingPlanExceptions[moment(lastFocusedEventData.start).format('YYYY-MM-DD')];
|
2022-01-17 21:44:44 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
lastFocusedEventData.extendedProps.data.settings.working_plan_exceptions =
|
|
|
|
JSON.stringify(workingPlanExceptions);
|
2016-07-18 23:22:28 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Refresh calendar event items.
|
2022-01-18 19:38:57 +03:00
|
|
|
$reloadAppointments.trigger('click');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2022-01-18 19:38:57 +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-17 17:21:59 +03:00
|
|
|
click: () => {
|
2020-09-07 11:15:01 +03:00
|
|
|
$('#message-box').dialog('close');
|
|
|
|
}
|
|
|
|
},
|
2017-09-23 04:49:46 +03:00
|
|
|
{
|
2022-01-24 16:11:15 +03:00
|
|
|
text: lang('delete'),
|
2022-01-12 13:22:54 +03:00
|
|
|
click: () => {
|
2022-01-18 19:38:57 +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-09-23 04:49:46 +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-09-23 04:49:46 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Refresh calendar event items.
|
2022-01-18 19:38:57 +03:00
|
|
|
$reloadAppointments.trigger('click');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2017-09-23 04:49:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2016-07-18 23:22:28 +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-18 23:22:28 +03:00
|
|
|
|
2020-09-07 13:04:07 +03:00
|
|
|
$('<textarea/>', {
|
|
|
|
'class': 'form-control w-100',
|
|
|
|
'id': 'delete-reason',
|
|
|
|
'rows': '3'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#message-box');
|
2016-07-18 23:22:28 +03:00
|
|
|
} else {
|
2020-05-04 12:32:00 +03:00
|
|
|
// Do not display confirmation prompt.
|
2022-01-18 19:38:57 +03:00
|
|
|
const unavailabilityId = lastFocusedEventData.extendedProps.data.id;
|
2016-07-18 23:22:28 +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-18 23:22:28 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Refresh calendar event items.
|
2022-01-18 19:38:57 +03:00
|
|
|
$reloadAppointments.trigger('click');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
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() {
|
2016-07-17 19:51:46 +03:00
|
|
|
$calendarFilter
|
|
|
|
.find('select')
|
|
|
|
.empty()
|
2022-06-02 10:37:43 +03:00
|
|
|
.append(new Option(`1 ${lang('day')}`, '1'))
|
|
|
|
.append(new Option(`3 ${lang('days')}`, '3'));
|
2018-01-23 12:08:37 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const $calendarHeader = $('<div/>', {
|
2020-05-07 19:47:14 +03:00
|
|
|
'class': 'calendar-header'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#calendar');
|
2020-05-07 19:47:14 +03:00
|
|
|
|
|
|
|
$('<button/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'btn btn-xs btn-outline-secondary previous me-2',
|
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
|
|
|
})
|
|
|
|
]
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($calendarHeader);
|
2020-05-07 19:47:14 +03:00
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
$selectDate = $('<input/>', {
|
2020-05-07 19:47:14 +03:00
|
|
|
'type': 'text',
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'form-control d-inline-block select-date me-2',
|
2022-01-18 10:18:22 +03:00
|
|
|
'value': App.Utils.Date.format(new Date(), vars('date_format'), vars('time_format'), false)
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($calendarHeader);
|
2020-05-07 19:47:14 +03:00
|
|
|
|
|
|
|
$('<button/>', {
|
2020-09-28 15:24:29 +03:00
|
|
|
'class': 'btn btn-xs btn-outline-secondary 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
|
|
|
})
|
|
|
|
]
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($calendarHeader);
|
2016-07-20 21:34:13 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let dateFormat;
|
2016-07-20 21:34:13 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
switch (vars('date_format')) {
|
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:
|
2022-01-18 10:18:22 +03:00
|
|
|
throw new Error('Invalid date format setting provided: ' + vars('date_format'));
|
2018-01-23 12:08:37 +03:00
|
|
|
}
|
2016-07-20 21:34:13 +03:00
|
|
|
|
2022-02-22 14:04:20 +03:00
|
|
|
const firstWeekday = vars('first_weekday');
|
|
|
|
const firstWeekdayNumber = App.Utils.Date.getWeekdayId(firstWeekday);
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
$calendarHeader.find('.select-date').datepicker({
|
|
|
|
defaultDate: new Date(),
|
|
|
|
dateFormat: dateFormat,
|
2022-02-22 14:04:20 +03:00
|
|
|
|
|
|
|
// Translation
|
|
|
|
dayNames: [lang('sunday'), lang('monday'), lang('tuesday'), lang('wednesday'),
|
|
|
|
lang('thursday'), lang('friday'), lang('saturday')],
|
2022-06-02 10:37:43 +03:00
|
|
|
dayNamesShort: [lang('sunday').substring(0, 3), lang('monday').substring(0, 3),
|
|
|
|
lang('tuesday').substring(0, 3), lang('wednesday').substring(0, 3),
|
|
|
|
lang('thursday').substring(0, 3), lang('friday').substring(0, 3),
|
|
|
|
lang('saturday').substring(0, 3)],
|
|
|
|
dayNamesMin: [lang('sunday').substring(0, 2), lang('monday').substring(0, 2),
|
|
|
|
lang('tuesday').substring(0, 2), lang('wednesday').substring(0, 2),
|
|
|
|
lang('thursday').substring(0, 2), lang('friday').substring(0, 2),
|
|
|
|
lang('saturday').substring(0, 2)],
|
2022-02-22 14:04:20 +03:00
|
|
|
monthNames: [lang('january'), lang('february'), lang('march'), lang('april'),
|
|
|
|
lang('may'), lang('june'), lang('july'), lang('august'), lang('september'),
|
|
|
|
lang('october'), lang('november'), lang('december')],
|
|
|
|
prevText: lang('previous'),
|
|
|
|
nextText: lang('next'),
|
|
|
|
currentText: lang('now'),
|
|
|
|
closeText: lang('close'),
|
|
|
|
timeOnlyTitle: lang('select_time'),
|
|
|
|
timeText: lang('time'),
|
|
|
|
hourText: lang('hour'),
|
|
|
|
minuteText: lang('minutes'),
|
|
|
|
firstDay: firstWeekdayNumber,
|
2022-01-12 13:22:54 +03:00
|
|
|
onSelect: (dateText, instance) => {
|
|
|
|
const startDate = new Date(instance.currentYear, instance.currentMonth, instance.currentDay);
|
2022-06-02 10:37:43 +03:00
|
|
|
const endDate = moment(startDate).add(parseInt($selectFilterItem.val()) - 1, 'days').toDate();
|
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
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const providers = vars('available_providers').filter(
|
2022-01-12 13:22:54 +03:00
|
|
|
(provider) =>
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('role_slug') === App.Layouts.Backend.DB_SLUG_ADMIN ||
|
|
|
|
(vars('role_slug') === App.Layouts.Backend.DB_SLUG_SECRETARY &&
|
|
|
|
vars('secretary_providers').indexOf(provider.id) !== -1) ||
|
|
|
|
(vars('role_slug') === App.Layouts.Backend.DB_SLUG_PROVIDER &&
|
|
|
|
Number(provider.id) === Number(vars('user_id')))
|
2022-01-12 13:22:54 +03:00
|
|
|
);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
// Create providers and service filters.
|
2020-11-16 11:15:52 +03:00
|
|
|
$('<label/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('provider')
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($calendarHeader);
|
2020-11-16 11:15:52 +03:00
|
|
|
|
|
|
|
$filterProvider = $('<select/>', {
|
|
|
|
'id': 'filter-provider',
|
|
|
|
'multiple': 'multiple',
|
|
|
|
'on': {
|
2022-01-12 13:22:54 +03:00
|
|
|
'change': () => {
|
2022-01-17 23:33:04 +03:00
|
|
|
const firstColumnDate = $('.calendar-view .date-column:first').data('date');
|
|
|
|
const startDateMoment = moment(firstColumnDate);
|
2022-06-02 10:37:43 +03:00
|
|
|
const endDateMoment = moment(firstColumnDate).add(parseInt($selectFilterItem.val()) - 1, 'day');
|
2022-01-17 23:33:04 +03:00
|
|
|
createView(startDateMoment.toDate(), endDateMoment.toDate());
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
2020-11-16 11:15:52 +03:00
|
|
|
}
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($calendarHeader);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('role_slug') !== App.Layouts.Backend.DB_SLUG_PROVIDER) {
|
2022-01-12 13:22:54 +03:00
|
|
|
providers.forEach((provider) => {
|
2020-05-04 12:32:00 +03:00
|
|
|
$filterProvider.append(new Option(provider.first_name + ' ' + provider.last_name, provider.id));
|
|
|
|
});
|
2020-11-16 11:15:52 +03:00
|
|
|
} else {
|
2022-01-12 13:22:54 +03:00
|
|
|
providers.forEach((provider) => {
|
2022-01-18 10:18:22 +03:00
|
|
|
if (Number(provider.id) === Number(vars('user_id'))) {
|
2020-11-16 11:15:52 +03:00
|
|
|
$filterProvider.append(new Option(provider.first_name + ' ' + provider.last_name, provider.id));
|
|
|
|
}
|
|
|
|
});
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
|
2022-05-26 16:17:33 +03:00
|
|
|
App.Utils.UI.initializeDropdown($filterProvider);
|
2020-11-16 11:15:52 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const services = vars('available_services').filter((service) => {
|
2022-01-17 17:21:59 +03:00
|
|
|
const provider = providers.find((provider) => provider.services.indexOf(service.id) !== -1);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
return vars('role_slug') === App.Layouts.Backend.DB_SLUG_ADMIN || provider;
|
2020-05-04 12:32:00 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$('<label/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('service')
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($calendarHeader);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
$filterService = $('<select/>', {
|
|
|
|
'id': 'filter-service',
|
2020-05-04 14:13:22 +03:00
|
|
|
'multiple': 'multiple',
|
2020-05-04 12:32:00 +03:00
|
|
|
'on': {
|
2022-01-12 13:22:54 +03:00
|
|
|
'change': () => {
|
2022-01-17 23:33:04 +03:00
|
|
|
const firstColumnDate = $('.calendar-view .date-column:first').data('date');
|
|
|
|
const startDateMoment = moment(firstColumnDate);
|
2022-06-02 10:37:43 +03:00
|
|
|
const endDateMoment = moment(firstColumnDate).add({days: parseInt($selectFilterItem.val()) - 1});
|
2022-01-17 23:33:04 +03:00
|
|
|
createView(startDateMoment.toDate(), endDateMoment.toDate());
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
}
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($calendarHeader);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
services.forEach((service) => {
|
2020-05-04 12:32:00 +03:00
|
|
|
$filterService.append(new Option(service.name, service.id));
|
|
|
|
});
|
2020-05-04 14:13:22 +03:00
|
|
|
|
2022-05-26 16:17:33 +03:00
|
|
|
App.Utils.UI.initializeDropdown($filterService);
|
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.
|
2021-11-06 19:38:37 +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.
|
2022-01-12 13:22:54 +03:00
|
|
|
const providerView = {};
|
|
|
|
$('.provider-column').each((index, providerColumn) => {
|
|
|
|
const $providerColumn = $(providerColumn);
|
|
|
|
const providerId = $providerColumn.data('provider').id;
|
2022-01-18 19:38:57 +03:00
|
|
|
providerView[providerId] = $providerColumn.find('.calendar-wrapper').data('fullCalendar').view.type;
|
2020-05-04 12:32:00 +03:00
|
|
|
});
|
|
|
|
|
2016-07-18 22:20:43 +03:00
|
|
|
$('#calendar .calendar-view').remove();
|
2016-07-17 19:51:46 +03:00
|
|
|
|
2022-01-17 07:26:57 +03:00
|
|
|
App.Layouts.Backend.placeFooterToBottom();
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const $calendarView = $('<div/>', {
|
2020-05-04 12:32:00 +03:00
|
|
|
'class': 'calendar-view'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo('#calendar');
|
2016-07-17 19:51:46 +03:00
|
|
|
|
|
|
|
$calendarView.data({
|
2021-11-25 10:40:48 +03:00
|
|
|
startDate: moment(startDate).format('YYYY-MM-DD'),
|
|
|
|
endDate: moment(endDate).format('YYYY-MM-DD')
|
2016-07-17 19:51:46 +03:00
|
|
|
});
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const $wrapper = $('<div/>').appendTo($calendarView);
|
2016-07-18 22:20:43 +03:00
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
App.Http.Calendar.getCalendarAppointmentsForTableView(startDate, endDate).done((response) => {
|
|
|
|
let currentDate = startDate;
|
2016-07-17 19:51:46 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
while (currentDate <= endDate) {
|
|
|
|
createDateColumn($wrapper, currentDate, response);
|
2022-01-17 23:33:04 +03:00
|
|
|
currentDate = moment(currentDate).add({days: 1}).toDate();
|
2021-11-06 19:38:37 +03:00
|
|
|
}
|
2016-07-18 22:20:43 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
setCalendarViewSize();
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-17 07:26:57 +03:00
|
|
|
App.Layouts.Backend.placeFooterToBottom();
|
2016-11-06 13:44:32 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Activate calendar navigation.
|
|
|
|
$('#calendar .calendar-header .btn').removeClass('disabled').prop('disabled', false);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
// Apply provider calendar view mode.
|
2022-01-12 13:22:54 +03:00
|
|
|
$('.provider-column').each((index, providerColumn) => {
|
|
|
|
const $providerColumn = $(providerColumn);
|
|
|
|
const providerId = $providerColumn.data('provider').id;
|
2021-11-06 19:38:37 +03:00
|
|
|
$providerColumn
|
|
|
|
.find('.calendar-wrapper')
|
2022-01-18 19:38:57 +03:00
|
|
|
.data('fullCalendar')
|
|
|
|
.changeView(providerView[providerId] || 'timeGridDay');
|
2020-12-02 20:57:49 +03:00
|
|
|
});
|
2021-11-06 19:38: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
|
|
|
* 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) {
|
2022-01-12 13:22:54 +03:00
|
|
|
const $dateColumn = $('<div/>', {
|
2020-05-04 12:32:00 +03:00
|
|
|
'class': 'date-column'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).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',
|
2022-01-18 10:18:22 +03:00
|
|
|
'text': App.Utils.Date.format(date, vars('date_format'), vars('time_format'))
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($dateColumn);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const filterProviderIds = $filterProvider.val();
|
|
|
|
const filterServiceIds = $filterService.val();
|
2020-05-04 14:13:22 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
let providers = vars('available_providers').filter((provider) => {
|
2022-01-12 13:22:54 +03:00
|
|
|
const servedServiceIds = provider.services.filter((serviceId) => {
|
|
|
|
const matches = filterServiceIds.filter(
|
|
|
|
(filterServiceId) => Number(serviceId) === Number(filterServiceId)
|
|
|
|
);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
2020-05-04 14:13:22 +03:00
|
|
|
return matches.length;
|
|
|
|
});
|
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
return (
|
|
|
|
(!filterProviderIds.length && !filterServiceIds.length) ||
|
|
|
|
(filterProviderIds.length &&
|
|
|
|
!filterServiceIds.length &&
|
|
|
|
filterProviderIds.indexOf(provider.id) !== -1) ||
|
|
|
|
(!filterProviderIds.length && filterServiceIds.length && servedServiceIds.length) ||
|
|
|
|
(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
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('role_slug') === 'provider') {
|
|
|
|
vars('available_providers').forEach((provider) => {
|
|
|
|
if (Number(provider.id) === Number(vars('user_id'))) {
|
2018-01-23 12:08:37 +03:00
|
|
|
providers = [provider];
|
2016-07-22 23:06:36 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('role_slug') === 'secretary') {
|
2016-07-22 23:06:36 +03:00
|
|
|
providers = [];
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('available_providers').forEach((provider) => {
|
|
|
|
if (vars('secretary_providers').indexOf(provider.id) > -1) {
|
2021-11-06 19:38:37 +03:00
|
|
|
providers.push(provider);
|
2016-07-22 23:06:36 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
providers.forEach((provider) => {
|
2020-05-04 12:32:00 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const $providerColumn = $('<div/>', {
|
2020-05-04 12:32:00 +03:00
|
|
|
'class': 'provider-column'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).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);
|
|
|
|
|
2022-06-02 10:37:43 +03:00
|
|
|
// Create non-working hours.
|
2021-11-06 19:38:37 +03:00
|
|
|
createNonWorkingHours($providerColumn.find('.calendar-wrapper'), provider);
|
2016-07-17 19:51:46 +03:00
|
|
|
|
2020-04-27 21:14:20 +03:00
|
|
|
// Add the appointments to the column.
|
2022-06-02 10:37:43 +03:00
|
|
|
/** @var {Array} events.appointments */
|
2020-05-04 12:32:00 +03:00
|
|
|
createAppointments($providerColumn, events.appointments);
|
2018-01-23 12:08:37 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
// Add the unavailabilities to the column.
|
2022-06-02 10:37:43 +03:00
|
|
|
/** @var {Array} events.unavailabilities */
|
2022-01-18 19:38:57 +03:00
|
|
|
createUnavailabilities($providerColumn, events.unavailabilities);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-17 07:26:57 +03:00
|
|
|
App.Layouts.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-10-21 21:44:35 +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() {
|
2022-01-18 19:38:57 +03:00
|
|
|
const result = window.innerHeight - $footer.outerHeight() - $header.outerHeight() - 60; // 60 for fine tuning
|
2020-05-04 12:32:00 +03:00
|
|
|
return result > 500 ? result : 500; // Minimum height is 500px
|
|
|
|
}
|
|
|
|
|
|
|
|
function createCalendar($providerColumn, goToDate, provider) {
|
2022-01-12 13:22:54 +03:00
|
|
|
const $wrapper = $('<div/>', {
|
2020-05-04 12:32:00 +03:00
|
|
|
'class': 'calendar-wrapper'
|
2021-11-06 19:38:37 +03:00
|
|
|
}).appendTo($providerColumn);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let columnFormat = '';
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
switch (vars('date_format')) {
|
2020-05-04 12:32:00 +03:00
|
|
|
case 'DMY':
|
|
|
|
columnFormat = 'ddd D/M';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'MDY':
|
|
|
|
case 'YMD':
|
|
|
|
columnFormat = 'ddd M/D';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-01-18 10:18:22 +03:00
|
|
|
throw new Error('Invalid date format setting provided!', vars('date_format'));
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Time formats
|
2022-01-12 13:22:54 +03:00
|
|
|
let timeFormat = '';
|
|
|
|
let slotTimeFormat = '';
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
switch (vars('time_format')) {
|
2020-05-04 12:32:00 +03:00
|
|
|
case 'military':
|
|
|
|
timeFormat = 'H:mm';
|
2022-05-26 15:29:29 +03:00
|
|
|
slotTimeFormat = 'H';
|
2020-05-04 12:32:00 +03:00
|
|
|
break;
|
|
|
|
case 'regular':
|
|
|
|
timeFormat = 'h:mm a';
|
2022-05-26 15:29:29 +03:00
|
|
|
slotTimeFormat = 'h a';
|
2020-05-04 12:32:00 +03:00
|
|
|
break;
|
|
|
|
default:
|
2022-01-18 10:18:22 +03:00
|
|
|
throw new Error('Invalid time format setting provided!' + vars('time_format'));
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const firstWeekday = vars('first_weekday');
|
2022-01-17 17:21:59 +03:00
|
|
|
const firstWeekdayNumber = App.Utils.Date.getWeekdayId(firstWeekday);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
const fullCalendar = new FullCalendar.Calendar($wrapper[0], {
|
|
|
|
initialView: 'timeGridDay',
|
2020-05-04 12:32:00 +03:00
|
|
|
height: getCalendarHeight(),
|
|
|
|
editable: true,
|
2020-12-08 10:36:46 +03:00
|
|
|
firstDay: firstWeekdayNumber,
|
2022-01-18 19:38:57 +03:00
|
|
|
slotDuration: '00:15:00',
|
2020-12-08 10:36:46 +03:00
|
|
|
snapDuration: '00:15:00',
|
2022-01-18 19:38:57 +03:00
|
|
|
slotLabelInterval: '01:00',
|
|
|
|
eventTimeFormat: timeFormat,
|
|
|
|
eventTextColor: '#333',
|
|
|
|
slotLabelFormat: slotTimeFormat,
|
|
|
|
allDayContent: lang('all_day'),
|
|
|
|
dayHeaderFormat: columnFormat,
|
|
|
|
headerToolbar: {
|
|
|
|
left: 'listDay,timeGridDay',
|
2020-05-04 12:32:00 +03:00
|
|
|
center: '',
|
|
|
|
right: ''
|
|
|
|
},
|
|
|
|
// Selectable
|
|
|
|
selectable: true,
|
|
|
|
selectHelper: true,
|
2022-01-18 19:38:57 +03:00
|
|
|
select: (info) => {
|
|
|
|
if (info.allDay) {
|
2020-05-04 12:32:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#insert-appointment').trigger('click');
|
|
|
|
|
|
|
|
// Preselect service & provider.
|
2022-01-18 19:38:57 +03:00
|
|
|
const $providerColumn = $(info.jsEvent.target).parents('.provider-column');
|
2022-01-12 13:22:54 +03:00
|
|
|
const providerId = $providerColumn.data('provider').id;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const provider = vars('available_providers').find(
|
2022-01-12 13:22:54 +03:00
|
|
|
(provider) => Number(provider.id) === Number(providerId)
|
|
|
|
);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const service = vars('available_services').find(
|
2022-01-12 13:22:54 +03:00
|
|
|
(service) => provider.services.indexOf(service.id) !== -1
|
|
|
|
);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2020-12-08 15:16:58 +03:00
|
|
|
if (service) {
|
2022-01-17 23:33:04 +03:00
|
|
|
$selectService.val(service.id);
|
2020-12-08 15:16:58 +03:00
|
|
|
}
|
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
if (!$selectService.val()) {
|
|
|
|
$selectService.find('option:first').prop('selected', true);
|
2020-12-08 15:16:58 +03:00
|
|
|
}
|
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
$selectService.trigger('change');
|
2020-12-08 15:16:58 +03:00
|
|
|
|
|
|
|
if (provider) {
|
2022-01-17 23:33:04 +03:00
|
|
|
$selectProvider.val(provider.id);
|
2020-12-08 15:16:58 +03:00
|
|
|
}
|
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
if (!$selectProvider.val()) {
|
2020-12-08 15:16:58 +03:00
|
|
|
$('#select-provider option:first').prop('selected', true);
|
|
|
|
}
|
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
$selectProvider.trigger('change');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
// Preselect time
|
2022-05-26 15:26:36 +03:00
|
|
|
$('#start-datetime').datepicker('setDate', info.start);
|
|
|
|
$('#end-datetime').datepicker('setDate', App.Pages.Calendar.getSelectionEndDate(info));
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
buttonText: {
|
2022-01-18 10:22:25 +03:00
|
|
|
today: lang('today'),
|
|
|
|
day: lang('day'),
|
|
|
|
week: lang('week'),
|
|
|
|
month: lang('month'),
|
2022-01-18 19:38:57 +03:00
|
|
|
timeGridDay: lang('calendar'),
|
2022-01-18 10:22:25 +03:00
|
|
|
listDay: lang('list')
|
2020-05-04 12:32:00 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// Calendar events need to be declared on initialization.
|
|
|
|
eventClick: onEventClick,
|
|
|
|
eventResize: onEventResize,
|
2022-01-18 19:38:57 +03:00
|
|
|
eventDrop: onEventDrop
|
|
|
|
// datesSet: onDatesSet
|
2020-05-04 12:32:00 +03:00
|
|
|
});
|
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
fullCalendar.render();
|
|
|
|
|
|
|
|
$wrapper.data('fullCalendar', fullCalendar);
|
|
|
|
|
|
|
|
fullCalendar.gotoDate(goToDate);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
$('<h6/>', {
|
|
|
|
'text': provider.first_name + ' ' + provider.last_name
|
2021-11-06 19:38:37 +03:00
|
|
|
}).prependTo($providerColumn);
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
// function onDatesSet() {
|
|
|
|
// $(element).fullCalendar('option', 'height', getCalendarHeight());
|
|
|
|
// }
|
2016-07-17 19:51:46 +03:00
|
|
|
|
2020-10-22 12:01:33 +03:00
|
|
|
function createNonWorkingHours($calendar, provider) {
|
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) || {};
|
2022-01-18 19:38:57 +03:00
|
|
|
const view = $calendar.data('fullCalendar').view;
|
|
|
|
const start = moment(view.currentStart).clone();
|
|
|
|
const end = moment(view.currentEnd).clone();
|
2022-01-12 13:22:54 +03:00
|
|
|
const selDayName = start.format('dddd').toLowerCase();
|
|
|
|
const selDayDate = start.format('YYYY-MM-DD');
|
|
|
|
const calendarEventSource = [];
|
2020-10-22 12:01:33 +03:00
|
|
|
|
|
|
|
if (workingPlanExceptions[selDayDate]) {
|
|
|
|
workingPlan[selDayName] = workingPlanExceptions[selDayDate];
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const workingPlanExceptionStart = selDayDate + ' ' + workingPlan[selDayName].start;
|
|
|
|
const workingPlanExceptionEnd = selDayDate + ' ' + workingPlan[selDayName].end;
|
2020-10-22 12:01:33 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const workingPlanExceptionEvent = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('working_plan_exception'),
|
2020-10-22 12:01:33 +03:00
|
|
|
start: moment(workingPlanExceptionStart, 'YYYY-MM-DD HH:mm', true),
|
|
|
|
end: moment(workingPlanExceptionEnd, 'YYYY-MM-DD HH:mm', true).add(1, 'day'),
|
|
|
|
allDay: true,
|
|
|
|
color: '#879DB4',
|
|
|
|
editable: false,
|
|
|
|
className: 'fc-working-plan-exception fc-custom',
|
|
|
|
data: {
|
|
|
|
date: selDayDate,
|
|
|
|
workingPlanException: workingPlanExceptions[selDayDate],
|
|
|
|
provider: provider
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(workingPlanExceptionEvent);
|
2020-10-22 12:01:33 +03:00
|
|
|
}
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2020-05-06 20:15:11 +03:00
|
|
|
if (workingPlan[selDayName] === null) {
|
2022-01-12 13:22:54 +03:00
|
|
|
const nonWorkingDay = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('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,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability'
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(nonWorkingDay);
|
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$calendar.data('fullCalendar').addEventSource(calendarEventSource);
|
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
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const workDateStart = moment(start.format('YYYY-MM-DD') + ' ' + workingPlan[selDayName].start);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
if (start < workDateStart) {
|
2022-01-18 14:54:41 +03:00
|
|
|
unavailabilityPeriod = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('not_working'),
|
2022-01-18 19:38:57 +03:00
|
|
|
start: start.toDate(),
|
|
|
|
end: workDateStart.toDate(),
|
2020-05-04 12:32:00 +03:00
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability'
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
2021-03-25 13:12:10 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
calendarEventSource.push(unavailabilityPeriod);
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
2016-07-17 19:51:46 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Add unavailability period after work ends.
|
2022-01-12 13:22:54 +03:00
|
|
|
const workDateEnd = moment(start.format('YYYY-MM-DD') + ' ' + workingPlan[selDayName].end);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
if (end > workDateEnd) {
|
2022-01-18 14:54:41 +03:00
|
|
|
const unavailabilityPeriod = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('not_working'),
|
2022-01-18 19:38:57 +03:00
|
|
|
start: workDateEnd.toDate(),
|
|
|
|
end: end.toDate(),
|
2020-05-04 12:32:00 +03:00
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability'
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
2021-03-25 13:12:10 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
calendarEventSource.push(unavailabilityPeriod);
|
2016-07-17 19:51:46 +03:00
|
|
|
}
|
2016-08-11 23:08:55 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
// Add unavailability periods for breaks.
|
2022-01-12 13:22:54 +03:00
|
|
|
let breakStart;
|
|
|
|
let breakEnd;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
workingPlan[selDayName].breaks.forEach((currentBreak) => {
|
2021-11-25 10:40:48 +03:00
|
|
|
breakStart = moment(start.format('YYYY-MM-DD') + ' ' + currentBreak.start);
|
|
|
|
breakEnd = moment(start.format('YYYY-MM-DD') + ' ' + currentBreak.end);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
const unavailabilityPeriod = {
|
2022-01-18 10:22:25 +03:00
|
|
|
title: lang('break'),
|
2022-01-18 19:38:57 +03:00
|
|
|
start: breakStart.toDate(),
|
|
|
|
end: breakEnd.toDate(),
|
2020-05-04 12:32:00 +03:00
|
|
|
allDay: false,
|
|
|
|
color: '#BEBEBE',
|
|
|
|
editable: false,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability fc-break'
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
calendarEventSource.push(unavailabilityPeriod);
|
2020-05-04 12:32:00 +03:00
|
|
|
});
|
2021-03-25 13:12:10 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$calendar.data('fullCalendar').addEventSource(calendarEventSource);
|
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;
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const filterServiceIds = $filterService.val();
|
2020-05-04 14:13:22 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
appointments = appointments.filter(
|
|
|
|
(appointment) => !filterServiceIds.length || filterServiceIds.indexOf(appointment.id_services) !== -1
|
|
|
|
);
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const calendarEvents = [];
|
2016-07-17 19:51:46 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
for (const index in appointments) {
|
|
|
|
const appointment = appointments[index];
|
2016-07-17 19:51:46 +03:00
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
if (Number(appointment.id_users_provider) !== Number($providerColumn.data('provider').id)) {
|
2016-07-17 19:51:46 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
calendarEvents.push({
|
|
|
|
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 19:38:57 +03:00
|
|
|
start: moment(appointment.start_datetime).toDate(),
|
|
|
|
end: moment(appointment.end_datetime).toDate(),
|
2020-05-04 12:32:00 +03:00
|
|
|
allDay: false,
|
2022-01-18 21:03:06 +03:00
|
|
|
color: appointment.color,
|
2020-05-04 12:32:00 +03:00
|
|
|
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
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$providerColumn.find('.calendar-wrapper').data('fullCalendar').addEventSource(calendarEvents);
|
2016-07-17 19:51:46 +03:00
|
|
|
}
|
|
|
|
|
2016-07-22 23:06:36 +03:00
|
|
|
/**
|
2020-10-21 21:44:35 +03:00
|
|
|
* Create Unavailability Events
|
2018-01-23 12:08:37 +03:00
|
|
|
*
|
2022-01-18 19:38:57 +03:00
|
|
|
* This method will add the unavailabilities on the table view.
|
2016-07-22 23:06:36 +03:00
|
|
|
*
|
|
|
|
* @param {jQuery} $providerColumn The provider column container.
|
2022-01-18 19:38:57 +03:00
|
|
|
* @param {Object[]} unavailabilities Contains the unavailabilities data.
|
2016-07-22 23:06:36 +03:00
|
|
|
*/
|
2022-01-18 19:38:57 +03:00
|
|
|
function createUnavailabilities($providerColumn, unavailabilities) {
|
|
|
|
if (unavailabilities.length === 0) {
|
2016-07-17 19:51:46 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-07-18 22:26:31 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const calendarEventSource = [];
|
2021-03-25 13:12:10 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
for (const index in unavailabilities) {
|
|
|
|
const unavailability = unavailabilities[index];
|
2016-07-18 22:26:31 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
if (Number(unavailability.id_users_provider) !== Number($providerColumn.data('provider').id)) {
|
2016-07-18 22:26:31 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const event = {
|
2022-01-18 14:54:41 +03:00
|
|
|
title: lang('unavailability'),
|
2022-01-18 19:38:57 +03:00
|
|
|
start: moment(unavailability.start_datetime).toDate(),
|
|
|
|
end: moment(unavailability.end_datetime).toDate(),
|
2020-05-04 12:32:00 +03:00
|
|
|
allDay: false,
|
|
|
|
color: '#879DB4',
|
|
|
|
editable: true,
|
2022-01-18 14:54:41 +03:00
|
|
|
className: 'fc-unavailability fc-custom',
|
2020-05-04 12:32:00 +03:00
|
|
|
data: unavailability
|
|
|
|
};
|
|
|
|
|
2021-03-25 13:12:10 +03:00
|
|
|
calendarEventSource.push(event);
|
2016-07-23 17:07:20 +03:00
|
|
|
}
|
2021-03-25 13:12:10 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$providerColumn.find('.calendar-wrapper').data('fullCalendar').addEventSource(calendarEventSource);
|
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;
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const currentDate = new Date($providerColumn.parents('.date-column').data('date'));
|
|
|
|
const $tbody = $providerColumn.find('table tbody');
|
2016-07-23 17:07:20 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
for (const index in breaks) {
|
|
|
|
const entry = breaks[index];
|
|
|
|
const startHour = entry.start.split(':');
|
|
|
|
const eventDate = new Date(
|
2021-11-06 19:38:37 +03:00
|
|
|
currentDate.getFullYear(),
|
|
|
|
currentDate.getMonth(),
|
|
|
|
currentDate.getDate(),
|
|
|
|
startHour[0],
|
|
|
|
startHour[1]
|
|
|
|
);
|
2022-01-12 13:22:54 +03:00
|
|
|
const endHour = entry.end.split(':');
|
|
|
|
const endDate = new Date(
|
2021-11-06 19:38:37 +03:00
|
|
|
currentDate.getFullYear(),
|
|
|
|
currentDate.getMonth(),
|
|
|
|
currentDate.getDate(),
|
|
|
|
endHour[0],
|
|
|
|
endHour[1]
|
|
|
|
);
|
2022-01-12 13:22:54 +03:00
|
|
|
const eventDuration = Math.round((endDate - eventDate) / 60000);
|
|
|
|
const $event = $('<div/>', {
|
2020-05-07 19:47:14 +03:00
|
|
|
'class': 'event unavailability break'
|
|
|
|
});
|
2016-07-23 17:07:20 +03:00
|
|
|
|
2016-07-24 12:23:56 +03:00
|
|
|
$event.html(
|
2022-01-18 10:22:25 +03:00
|
|
|
lang('break') +
|
2022-05-26 16:17:33 +03:00
|
|
|
' <span class="hour">' +
|
|
|
|
moment(eventDate).format('HH:mm') +
|
|
|
|
'</span> (' +
|
|
|
|
eventDuration +
|
|
|
|
"')"
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
2016-07-23 17:07:20 +03:00
|
|
|
|
|
|
|
$event.data(entry);
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
$tbody.find('tr').each((index, tr) => {
|
|
|
|
const $td = $(tr).find('td:first');
|
2016-07-23 17:07:20 +03:00
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
const cellDate = moment(currentDate)
|
|
|
|
.set({
|
|
|
|
hour: parseInt($td.text().split(':')[0]),
|
|
|
|
minute: parseInt($td.text().split(':')[1])
|
|
|
|
})
|
|
|
|
.toDate();
|
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.
|
2021-11-25 10:40:48 +03:00
|
|
|
if (moment(eventDate).format('HH:mm') === $(tr).prev().find('td').eq(0).text()) {
|
2016-07-24 12:23:56 +03:00
|
|
|
$event.find('.hour').remove();
|
|
|
|
}
|
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$(tr)
|
|
|
|
.prev()
|
|
|
|
.find('td:gt(0)')
|
2022-01-12 13:22:54 +03:00
|
|
|
.each((index, td) => {
|
2021-11-06 19:38:37 +03:00
|
|
|
$event.clone().appendTo($(td));
|
|
|
|
});
|
2016-07-23 17:07:20 +03:00
|
|
|
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.
|
|
|
|
*
|
2022-01-18 19:38:57 +03:00
|
|
|
* @param {*|Event} event
|
2020-07-01 10:13:22 +03:00
|
|
|
*/
|
|
|
|
function getEventNotes(event) {
|
2022-01-18 19:38:57 +03:00
|
|
|
if (!event.extendedProps || !event.extendedProps.data || !event.extendedProps.data.notes) {
|
2020-07-01 10:13:22 +03:00
|
|
|
return '-';
|
|
|
|
}
|
|
|
|
|
2022-01-18 19:38:57 +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;
|
|
|
|
}
|
|
|
|
|
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.
|
2022-01-18 19:38:57 +03:00
|
|
|
*
|
|
|
|
* @param {Object} info
|
2020-05-04 12:32:00 +03:00
|
|
|
*/
|
2022-01-18 19:38:57 +03:00
|
|
|
function onEventClick(info) {
|
2022-01-17 23:33:04 +03:00
|
|
|
const $popover = $('.popover');
|
|
|
|
|
|
|
|
$popover.popover('dispose'); // Close all open popovers.
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let $html;
|
|
|
|
let displayEdit;
|
|
|
|
let displayDelete;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
// Depending on where the user clicked the event (title or empty space) we need to use different selectors to
|
|
|
|
// reach the parent element.
|
2022-01-18 19:38:57 +03:00
|
|
|
const $target = $(info.el);
|
|
|
|
|
|
|
|
if ($target.hasClass('fc-unavailability')) {
|
2021-11-06 19:38:37 +03:00
|
|
|
displayEdit =
|
2022-01-18 19:38:57 +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 19:38:57 +03:00
|
|
|
$target.hasClass('fc-custom') && vars('privileges').appointments.delete === true ? '' : '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/>', {
|
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 19:38:57 +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/>', {
|
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 19:38:57 +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 19:38:57 +03:00
|
|
|
'text': getEventNotes(info.event)
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<hr/>'),
|
|
|
|
|
|
|
|
$('<div/>', {
|
2020-10-22 12:01:33 +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/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'delete-popover btn btn-outline-secondary me-2 ' + 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-10-22 12:01:33 +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
|
|
|
})
|
|
|
|
]
|
2021-11-06 19:38:37 +03:00
|
|
|
})
|
2020-05-07 19:47:14 +03:00
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
2022-01-18 19:38:57 +03:00
|
|
|
} else if ($target.hasClass('fc-working-plan-exception')) {
|
2021-11-06 19:38:37 +03:00
|
|
|
displayEdit =
|
2022-01-18 19:38:57 +03:00
|
|
|
$target.hasClass('fc-custom') && vars('privileges').appointments.edit === true ? '' : 'd-none'; // Same value at the time.
|
2021-11-06 19:38:37 +03:00
|
|
|
|
|
|
|
displayDelete =
|
2022-01-18 19:38:57 +03:00
|
|
|
$target.hasClass('fc-custom') && vars('privileges').appointments.delete === true ? '' : '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/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('provider')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 19:38:57 +03:00
|
|
|
'text': info.event.extendedProps.data
|
|
|
|
? info.event.extendedProps.data.provider.first_name +
|
2022-05-26 16:17:33 +03:00
|
|
|
' ' +
|
|
|
|
info.event.extendedProps.data.provider.last_name
|
2022-01-18 19:38:57 +03:00
|
|
|
: '-'
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
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 19:38:57 +03:00
|
|
|
info.event.extendedProps.data.date +
|
2022-05-26 16:17:33 +03:00
|
|
|
' ' +
|
|
|
|
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/>', {
|
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 19:38:57 +03:00
|
|
|
info.event.extendedProps.data.date +
|
2022-05-26 16:17:33 +03:00
|
|
|
' ' +
|
|
|
|
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/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('timezone')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 19:38:57 +03:00
|
|
|
'text': vars('timezones')[info.event.extendedProps.data.provider.timezone]
|
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': [
|
2020-09-07 12:21:16 +03:00
|
|
|
$('<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/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'delete-popover btn btn-outline-secondary me-2 ' + 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-10-22 12:01:33 +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
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
2020-05-04 12:32:00 +03:00
|
|
|
} else {
|
2022-01-18 10:18:22 +03:00
|
|
|
displayEdit = vars('privileges').appointments.edit === true ? '' : 'd-none';
|
|
|
|
displayDelete = vars('privileges').appointments.delete === true ? '' : 'd-none';
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2020-05-07 19:47:14 +03:00
|
|
|
$html = $('<div/>', {
|
|
|
|
'html': [
|
|
|
|
$('<strong/>', {
|
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 19:38:57 +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/>', {
|
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 19:38:57 +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/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('timezone')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 19:38:57 +03:00
|
|
|
'text': vars('timezones')[info.event.extendedProps.data.provider.timezone]
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('service')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<span/>', {
|
2022-01-18 19:38:57 +03:00
|
|
|
'text': info.event.extendedProps.data.service.name
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('provider')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
2022-01-18 19:38:57 +03:00
|
|
|
App.Utils.CalendarEventPopover.renderMapIcon(info.event.extendedProps.data.provider),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2022-01-18 19:38:57 +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/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('customer')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
2022-01-18 19:38:57 +03:00
|
|
|
App.Utils.CalendarEventPopover.renderMapIcon(info.event.extendedProps.data.customer),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2022-01-18 19:38:57 +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/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('email')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
2022-01-18 19:38:57 +03:00
|
|
|
App.Utils.CalendarEventPopover.renderMailIcon(info.event.extendedProps.data.customer.email),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2022-01-18 19:38:57 +03:00
|
|
|
'text': info.event.extendedProps.data.customer.email
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
|
|
|
$('<br/>'),
|
|
|
|
|
|
|
|
$('<strong/>', {
|
2022-01-18 10:22:25 +03:00
|
|
|
'text': lang('phone')
|
2020-05-07 19:47:14 +03:00
|
|
|
}),
|
2022-01-18 19:38:57 +03:00
|
|
|
App.Utils.CalendarEventPopover.renderPhoneIcon(info.event.extendedProps.data.customer.phone_number),
|
2020-05-07 19:47:14 +03:00
|
|
|
$('<span/>', {
|
2022-01-18 19:38:57 +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 19:38:57 +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/>', {
|
2021-11-23 10:43:40 +03:00
|
|
|
'class': 'delete-popover btn btn-outline-secondary me-2 ' + 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-10-22 12:01:33 +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
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
});
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$target.popover({
|
2020-05-04 12:32:00 +03:00
|
|
|
placement: 'top',
|
2022-01-18 19:38:57 +03:00
|
|
|
title: info.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'
|
|
|
|
});
|
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
lastFocusedEventData = info.event;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$target.popover('toggle');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
// Fix popover position.
|
2022-01-18 19:38:57 +03:00
|
|
|
const $newPopover = $calendar.find('.popover');
|
|
|
|
|
|
|
|
if ($newPopover.length > 0 && $newPopover.position().top < 200) {
|
|
|
|
$newPopover.css('top', '200px');
|
2020-05-04 12:32:00 +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 19:38:57 +03:00
|
|
|
*
|
|
|
|
* @param {Object} info
|
2020-05-04 12:32:00 +03:00
|
|
|
*/
|
2022-01-18 19:38:57 +03:00
|
|
|
function onEventResize(info) {
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('privileges').appointments.edit === false) {
|
2022-01-18 19:38:57 +03:00
|
|
|
info.revert();
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('no_privileges_edit_appointments'));
|
2020-05-04 12:32:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
if ($notification.is(':visible')) {
|
|
|
|
$notification.hide('bind');
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let successCallback;
|
2020-05-06 20:15:11 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
if (info.event.extendedProps.data.is_unavailability === false) {
|
2020-05-04 12:32:00 +03:00
|
|
|
// Prepare appointment data.
|
2022-01-18 19:38:57 +03:00
|
|
|
info.event.extendedProps.data.end_datetime = moment(info.event.extendedProps.data.end_datetime)
|
2022-06-02 10:37: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');
|
2020-05-04 21:41:46 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
const appointment = {...info.event.extendedProps.data};
|
2020-05-04 12:32:00 +03:00
|
|
|
|
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
|
2022-01-12 13:22:54 +03:00
|
|
|
successCallback = () => {
|
2020-05-04 12:32:00 +03:00
|
|
|
// Display success notification to user.
|
2022-01-12 13:22:54 +03:00
|
|
|
const undoFunction = () => {
|
2022-01-18 19:38:57 +03:00
|
|
|
appointment.end_datetime = info.event.extendedProps.data.end_datetime = moment(
|
|
|
|
appointment.end_datetime
|
|
|
|
)
|
2022-06-02 10:37: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');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
App.Http.Calendar.saveAppointment(appointment).done(() => {
|
2022-01-18 19:38:57 +03:00
|
|
|
$notification.hide('blind');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2020-12-08 10:42:28 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
info.revert();
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('appointment_updated'), [
|
2020-05-04 12:32:00 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
'label': lang('undo'),
|
2020-05-04 21:41:46 +03:00
|
|
|
'function': undoFunction
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
]);
|
2022-01-18 19:38:57 +03:00
|
|
|
|
|
|
|
$footer.css('position', 'static'); // Footer position fix.
|
2020-05-04 21:41:46 +03:00
|
|
|
|
|
|
|
// Update the event data for later use.
|
2022-01-18 19:38:57 +03:00
|
|
|
info.event.setProp('data', event.extendedProps.data);
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Update appointment data.
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Http.Calendar.saveAppointment(appointment, null, successCallback);
|
2020-05-04 12:32:00 +03:00
|
|
|
} else {
|
2022-01-18 14:54:41 +03:00
|
|
|
// Update unavailability time period.
|
|
|
|
const unavailability = {
|
2022-01-18 19:38:57 +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
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
info.event.extendedProps.data.end_datetime = unavailability.end_datetime;
|
2020-05-04 21:41:46 +03:00
|
|
|
|
2020-05-04 12:32:00 +03:00
|
|
|
// Define success callback function.
|
2022-01-12 13:22:54 +03:00
|
|
|
successCallback = () => {
|
2020-05-04 12:32:00 +03:00
|
|
|
// Display success notification to user.
|
2022-01-12 13:22:54 +03:00
|
|
|
const undoFunction = () => {
|
2022-01-18 19:38:57 +03:00
|
|
|
unavailability.end_datetime = info.event.extendedProps.data.end_datetime = moment(
|
|
|
|
unavailability.end_datetime
|
|
|
|
)
|
|
|
|
.add({days: -info.endDelta.days, milliseconds: -info.endDelta.milliseconds})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Calendar.saveUnavailability(unavailability).done(() => {
|
2022-01-18 19:38:57 +03:00
|
|
|
$notification.hide('blind');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2020-12-08 10:42:28 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
info.revert();
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('unavailability_updated'), [
|
2020-05-04 12:32:00 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
'label': lang('undo'),
|
2020-05-04 21:41:46 +03:00
|
|
|
'function': undoFunction
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
]);
|
2020-05-04 21:41:46 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$footer.css('position', 'static'); // Footer position fix.
|
2020-05-04 21:41:46 +03:00
|
|
|
|
|
|
|
// Update the event data for later use.
|
2022-01-18 19:38:57 +03:00
|
|
|
info.event.setProp('data', info.event.extendedProps.data);
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Calendar.saveUnavailability(unavailability, 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.
|
2022-01-18 19:38:57 +03:00
|
|
|
*
|
|
|
|
* @param {Object} info
|
2020-05-04 12:32:00 +03:00
|
|
|
*/
|
2022-01-18 19:38:57 +03:00
|
|
|
function onEventDrop(info) {
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('privileges').appointments.edit === false) {
|
2022-01-18 19:38:57 +03:00
|
|
|
info.revert();
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('no_privileges_edit_appointments'));
|
2020-05-04 12:32:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-17 23:33:04 +03:00
|
|
|
if ($notification.is(':visible')) {
|
|
|
|
$notification.hide('bind');
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let successCallback;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
if (info.event.extendedProps.data.is_unavailability === false) {
|
2020-05-04 12:32:00 +03:00
|
|
|
// Prepare appointment data.
|
2022-01-18 19:38:57 +03:00
|
|
|
const appointment = {...info.event.extendedProps.data};
|
2020-05-04 12:32: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;
|
|
|
|
|
2021-11-24 10:34:26 +03:00
|
|
|
appointment.start_datetime = moment(appointment.start_datetime)
|
2022-06-02 10:37:43 +03:00
|
|
|
.add({days: info.endDelta.days(), hours: info.endDelta.hours(), minutes: info.endDelta.minutes()})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2021-11-24 10:34:26 +03:00
|
|
|
appointment.end_datetime = moment(appointment.end_datetime)
|
2022-06-02 10:37:43 +03:00
|
|
|
.add({days: info.endDelta.days(), hours: info.endDelta.hours(), minutes: info.endDelta.minutes()})
|
2021-11-24 10:34:26 +03:00
|
|
|
.format('YYYY-MM-DD HH:mm:ss');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
info.event.extendedProps.data.start_datetime = appointment.start_datetime;
|
|
|
|
info.event.extendedProps.data.end_datetime = appointment.end_datetime;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
// Define success callback function.
|
2022-01-12 13:22:54 +03:00
|
|
|
successCallback = () => {
|
2020-05-04 12:32:00 +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-06-02 10:37: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');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2021-11-24 10:34:26 +03:00
|
|
|
appointment.end_datetime = moment(appointment.end_datetime)
|
2022-06-02 10:37: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');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
info.event.extendedProps.data.start_datetime = appointment.start_datetime;
|
|
|
|
info.event.extendedProps.data.end_datetime = appointment.end_datetime;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-17 21:44:44 +03:00
|
|
|
App.Http.Calendar.saveAppointment(appointment).done(() => {
|
2022-01-18 19:38:57 +03:00
|
|
|
$notification.hide('blind');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2020-12-08 10:42:28 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
info.revert();
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 10:22:25 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('appointment_updated'), [
|
2020-05-04 12:32:00 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
'label': lang('undo'),
|
2020-05-04 21:41:46 +03:00
|
|
|
'function': undoFunction
|
2020-05-04 12:32:00 +03:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$footer.css('position', 'static'); // Footer position fix.
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Update appointment data.
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Http.Calendar.saveAppointment(appointment, null, successCallback);
|
2020-05-04 12:32:00 +03:00
|
|
|
} else {
|
2022-01-18 14:54:41 +03:00
|
|
|
// Update unavailability time period.
|
|
|
|
const unavailability = {
|
2022-01-18 19:38:57 +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
|
2020-05-04 12:32:00 +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-06-02 10:37: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');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
unavailability.end_datetime = moment(unavailability.end_datetime)
|
2022-06-02 10:37: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');
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
info.event.extendedProps.data.start_datetime = unavailability.start_datetime;
|
|
|
|
info.event.extendedProps.data.end_datetime = unavailability.end_datetime;
|
2020-05-04 12:32:00 +03:00
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Calendar.saveUnavailability(unavailability).done(() => {
|
2022-01-18 19:38:57 +03:00
|
|
|
$notification.hide('blind');
|
2021-11-06 19:38:37 +03:00
|
|
|
});
|
2020-12-08 10:42:28 +03:00
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
info.revert();
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Layouts.Backend.displayNotification(lang('unavailability_updated'), [
|
2020-05-04 12:32:00 +03:00
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
label: lang('undo'),
|
2020-05-04 12:32:00 +03:00
|
|
|
function: undoFunction
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2022-01-18 19:38:57 +03:00
|
|
|
$footer.css('position', 'static'); // Footer position fix.
|
2020-05-04 12:32:00 +03:00
|
|
|
};
|
|
|
|
|
2022-01-18 14:54:41 +03:00
|
|
|
App.Http.Calendar.saveUnavailability(unavailability, 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() {
|
2022-01-12 13:22:54 +03:00
|
|
|
let height =
|
2021-11-06 19:38:37 +03:00
|
|
|
window.innerHeight -
|
2022-01-18 19:38:57 +03:00
|
|
|
$header.outerHeight() -
|
|
|
|
$footer.outerHeight() -
|
|
|
|
$calendarToolbar.outerHeight() -
|
2021-11-06 19:38:37 +03:00
|
|
|
$('.calendar-header').outerHeight() -
|
|
|
|
50;
|
2016-07-18 23:55:05 +03:00
|
|
|
|
|
|
|
if (height < 500) {
|
|
|
|
height = 500;
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const $dateColumn = $('.date-column');
|
|
|
|
const $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
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
let width = 0;
|
2016-07-18 22:20:43 +03:00
|
|
|
|
2022-01-17 17:21:59 +03:00
|
|
|
$dateColumn.each((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
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const 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-22 23:06:36 +03:00
|
|
|
/**
|
2018-01-23 12:08:37 +03:00
|
|
|
* Initialize Page
|
2016-07-22 23:06:36 +03:00
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
function initialize() {
|
2020-05-04 12:32:00 +03:00
|
|
|
createHeader();
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
const startDate = moment().toDate();
|
|
|
|
|
|
|
|
const endDate = moment()
|
2022-01-17 23:33:04 +03:00
|
|
|
.add(Number($selectFilterItem.val()) - 1, 'days')
|
2021-11-06 19:38:37 +03:00
|
|
|
.toDate();
|
2020-05-04 12:32:00 +03:00
|
|
|
|
|
|
|
createView(startDate, endDate);
|
|
|
|
|
2020-10-22 12:12:19 +03:00
|
|
|
$('#insert-working-plan-exception').hide();
|
|
|
|
|
2022-01-17 17:21:59 +03:00
|
|
|
addEventListeners();
|
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();
|
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
|
|
|
})();
|