iflrandevu/assets/js/pages/calendar.js

126 lines
4.6 KiB
JavaScript
Raw Normal View History

2015-07-20 22:41:24 +03:00
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web 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
2015-07-20 22:41:24 +03:00
* @since v1.0.0
* ---------------------------------------------------------------------------- */
/**
* Calendar page.
*
* This module implements the functionality of the backend calendar page.
*/
App.Pages.Calendar = (function () {
/**
* Add the page event listeners.
*/
function addEventListeners() {
const $calendarPage = $('#calendar-page');
$calendarPage.on('click', '#toggle-fullscreen', (event) => {
const $toggleFullscreen = $(event.target);
const element = document.documentElement;
const isFullScreen = document.fullScreenElement || document.mozFullScreen || document.webkitIsFullScreen;
2018-01-23 12:08:37 +03:00
if (isFullScreen) {
// Exit fullscreen mode.
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
2016-10-10 19:29:48 +03:00
document.webkitExitFullscreen();
}
$toggleFullscreen.removeClass('btn-success').addClass('btn-light');
} else {
// Switch to fullscreen mode.
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
}
$toggleFullscreen.removeClass('btn-light').addClass('btn-success');
}
});
$('#insert-working-plan-exception').on('click', () => {
const providerId = $('#select-filter-item').val();
const provider = App.Vars.available_providers.find((availableProvider) => {
return Number(availableProvider.id) === Number(providerId);
});
if (!provider) {
throw new Error('Provider could not be found: ' + providerId);
}
App.Components.WorkingPlanExceptionsModal.add().done((date, workingPlanException) => {
const successCallback = () => {
Backend.displayNotification(App.Lang.working_plan_exception_saved);
const workingPlanExceptions = JSON.parse(provider.settings.working_plan_exceptions) || {};
workingPlanExceptions[date] = workingPlanException;
for (let index in App.Vars.available_providers) {
const availableProvider = App.Vars.available_providers[index];
if (Number(availableProvider.id) === Number(providerId)) {
App.Vars.available_providers[index].settings.working_plan_exceptions =
JSON.stringify(workingPlanExceptions);
break;
}
}
$('#select-filter-item').trigger('change'); // Update the calendar.
};
App.Http.Calendar.saveWorkingPlanException(
date,
workingPlanException,
providerId,
successCallback,
null
);
});
});
}
/**
* Initialize the module.
*
* 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.
*
* @param {String} view Optional (default), the calendar view to be loaded.
*/
function initialize(view) {
// Load and initialize the calendar view.
if (view === 'table') {
App.Utils.CalendarTableView.initialize();
} else {
App.Utils.CalendarDefaultView.initialize();
}
addEventListeners();
}
document.addEventListener('DOMContentLoaded', initialize);
return {
initialize
};
})();