2015-07-20 22:41:24 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2015-10-06 00:30:56 +03:00
|
|
|
*
|
2015-07-20 22:41:24 +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
|
2015-07-20 22:41:24 +03:00
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2013-06-12 18:31:16 +03:00
|
|
|
/**
|
2022-01-14 11:26:44 +03:00
|
|
|
* Calendar page.
|
2016-04-02 13:25:29 +03:00
|
|
|
*
|
2022-01-14 11:26:44 +03:00
|
|
|
* This module implements the functionality of the backend calendar page.
|
2013-06-12 18:31:16 +03:00
|
|
|
*/
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Pages.Calendar = (function () {
|
2022-01-17 08:31:27 +03:00
|
|
|
const $insertWorkingPlanException = $('#insert-working-plan-exception');
|
|
|
|
|
2024-05-11 18:04:04 +03:00
|
|
|
const moment = window.moment;
|
|
|
|
|
2016-07-24 14:26:20 +03:00
|
|
|
/**
|
2022-01-17 07:10:14 +03:00
|
|
|
* Add the page event listeners.
|
2016-07-24 14:26:20 +03:00
|
|
|
*/
|
2022-01-17 07:10:14 +03:00
|
|
|
function addEventListeners() {
|
2022-01-12 13:22:54 +03:00
|
|
|
const $calendarPage = $('#calendar-page');
|
2016-07-24 14:26:20 +03:00
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
$calendarPage.on('click', '#toggle-fullscreen', (event) => {
|
|
|
|
const $toggleFullscreen = $(event.target);
|
|
|
|
const element = document.documentElement;
|
2023-12-22 13:35:41 +03:00
|
|
|
const isFullScreen =
|
|
|
|
document.fullScreenElement || document.mozFullScreen || document.webkitIsFullScreen || false;
|
2018-01-23 12:08:37 +03:00
|
|
|
|
|
|
|
if (isFullScreen) {
|
2020-03-11 12:10:59 +03:00
|
|
|
// Exit fullscreen mode.
|
2020-05-06 20:15:11 +03:00
|
|
|
if (document.exitFullscreen) {
|
2016-07-24 14:26:20 +03:00
|
|
|
document.exitFullscreen();
|
2020-05-06 20:15:11 +03:00
|
|
|
} else if (document.msExitFullscreen) {
|
2016-07-24 14:26:20 +03:00
|
|
|
document.msExitFullscreen();
|
2020-05-06 20:15:11 +03:00
|
|
|
} else if (document.mozCancelFullScreen) {
|
2016-07-24 14:26:20 +03:00
|
|
|
document.mozCancelFullScreen();
|
2020-05-06 20:15:11 +03:00
|
|
|
} else if (document.webkitExitFullscreen) {
|
2016-10-10 19:29:48 +03:00
|
|
|
document.webkitExitFullscreen();
|
2020-05-06 20:15:11 +03:00
|
|
|
}
|
2016-07-24 14:26:20 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
$toggleFullscreen.removeClass('btn-success').addClass('btn-light');
|
2016-07-24 14:26:20 +03:00
|
|
|
} else {
|
|
|
|
// Switch to fullscreen mode.
|
2020-05-06 20:15:11 +03:00
|
|
|
if (element.requestFullscreen) {
|
2016-07-24 14:26:20 +03:00
|
|
|
element.requestFullscreen();
|
2020-05-06 20:15:11 +03:00
|
|
|
} else if (element.msRequestFullscreen) {
|
2016-07-24 14:26:20 +03:00
|
|
|
element.msRequestFullscreen();
|
2020-05-06 20:15:11 +03:00
|
|
|
} else if (element.mozRequestFullScreen) {
|
2016-07-24 14:26:20 +03:00
|
|
|
element.mozRequestFullScreen();
|
2020-05-06 20:15:11 +03:00
|
|
|
} else if (element.webkitRequestFullscreen) {
|
2016-07-24 14:26:20 +03:00
|
|
|
element.webkitRequestFullscreen();
|
2020-05-06 20:15:11 +03:00
|
|
|
}
|
2021-11-06 19:38:37 +03:00
|
|
|
$toggleFullscreen.removeClass('btn-light').addClass('btn-success');
|
2016-07-24 14:26:20 +03:00
|
|
|
}
|
|
|
|
});
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-17 08:31:27 +03:00
|
|
|
$insertWorkingPlanException.on('click', () => {
|
2022-01-12 13:22:54 +03:00
|
|
|
const providerId = $('#select-filter-item').val();
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-05-20 19:03:03 +03:00
|
|
|
if (providerId === App.Utils.CalendarDefaultView.FILTER_TYPE_ALL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
const provider = vars('available_providers').find((availableProvider) => {
|
2020-10-20 16:03:48 +03:00
|
|
|
return Number(availableProvider.id) === Number(providerId);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!provider) {
|
|
|
|
throw new Error('Provider could not be found: ' + providerId);
|
|
|
|
}
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Components.WorkingPlanExceptionsModal.add().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-12 13:22:54 +03:00
|
|
|
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
workingPlanExceptions[date] = workingPlanException;
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2022-01-18 10:18:22 +03:00
|
|
|
for (let index in vars('available_providers')) {
|
|
|
|
const availableProvider = vars('available_providers')[index];
|
2020-10-20 16:03:48 +03:00
|
|
|
|
2021-11-06 19:38:37 +03:00
|
|
|
if (Number(availableProvider.id) === Number(providerId)) {
|
2022-01-18 10:18:22 +03:00
|
|
|
vars('available_providers')[index].settings.working_plan_exceptions =
|
2021-11-06 19:38:37 +03:00
|
|
|
JSON.stringify(workingPlanExceptions);
|
|
|
|
break;
|
2020-10-20 16:03:48 +03:00
|
|
|
}
|
2021-11-06 19:38:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$('#select-filter-item').trigger('change'); // Update the calendar.
|
|
|
|
};
|
|
|
|
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Http.Calendar.saveWorkingPlanException(
|
2021-11-06 19:38:37 +03:00
|
|
|
date,
|
|
|
|
workingPlanException,
|
|
|
|
providerId,
|
|
|
|
successCallback,
|
2023-12-22 13:35:41 +03:00
|
|
|
null,
|
2021-11-06 19:38:37 +03:00
|
|
|
);
|
|
|
|
});
|
2020-10-20 16:03:48 +03:00
|
|
|
});
|
2016-07-24 14:26:20 +03:00
|
|
|
}
|
|
|
|
|
2022-05-26 15:26:36 +03:00
|
|
|
/**
|
|
|
|
* Get calendar selection end date.
|
|
|
|
*
|
|
|
|
* On calendar slot selection, calculate the end date based on the provided start date.
|
|
|
|
*
|
|
|
|
* @param {Object} info Holding the "start" and "end" props, as provided by FullCalendar.
|
|
|
|
*
|
|
|
|
* @return {Date}
|
|
|
|
*/
|
|
|
|
function getSelectionEndDate(info) {
|
|
|
|
const startMoment = moment(info.start);
|
|
|
|
const endMoment = moment(info.end);
|
|
|
|
const startTillEndDiff = endMoment.diff(startMoment);
|
|
|
|
const startTillEndDuration = moment.duration(startTillEndDiff);
|
|
|
|
const durationInMinutes = startTillEndDuration.asMinutes();
|
|
|
|
const minDurationInMinutes = 15;
|
|
|
|
|
|
|
|
if (durationInMinutes <= minDurationInMinutes) {
|
|
|
|
const serviceId = $('#select-service').val();
|
2023-12-22 13:35:41 +03:00
|
|
|
const service = vars('available_services').find(
|
|
|
|
(availableService) => Number(availableService.id) === Number(serviceId),
|
|
|
|
);
|
2022-05-26 15:26:36 +03:00
|
|
|
|
|
|
|
if (service) {
|
|
|
|
endMoment.add(service.duration - durationInMinutes, 'minutes');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return endMoment.toDate();
|
|
|
|
}
|
|
|
|
|
2016-04-02 13:25:29 +03:00
|
|
|
/**
|
2022-01-14 11:26:44 +03:00
|
|
|
* Initialize the module.
|
2016-05-15 14:05:28 +03:00
|
|
|
*
|
2022-01-14 11:26:44 +03:00
|
|
|
* This function makes the necessary initialization for the default backend calendar page.
|
|
|
|
*
|
|
|
|
* If this module is used in another page then this function might not be needed.
|
2016-04-02 13:25:29 +03:00
|
|
|
*/
|
2022-01-17 23:33:04 +03:00
|
|
|
function initialize() {
|
2020-03-11 12:10:59 +03:00
|
|
|
// Load and initialize the calendar view.
|
2022-01-18 10:18:22 +03:00
|
|
|
if (vars('calendar_view') === 'table') {
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Utils.CalendarTableView.initialize();
|
2016-07-17 14:46:38 +03:00
|
|
|
} else {
|
2022-01-12 13:22:54 +03:00
|
|
|
App.Utils.CalendarDefaultView.initialize();
|
2016-04-02 13:25:29 +03:00
|
|
|
}
|
|
|
|
|
2024-05-11 18:04:04 +03:00
|
|
|
App.Pages.Calendar.addEventListeners();
|
2022-01-12 13:22:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', initialize);
|
|
|
|
|
|
|
|
return {
|
2024-05-11 18:04:04 +03:00
|
|
|
addEventListeners,
|
2023-12-22 13:35:41 +03:00
|
|
|
getSelectionEndDate,
|
2016-04-02 13:25:29 +03:00
|
|
|
};
|
2022-01-12 13:22:54 +03:00
|
|
|
})();
|