2022-01-06 11:54:30 +03:00
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2022-01-06 11:54:30 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
* @since v1.5.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2022-01-14 11:26:44 +03:00
|
|
|
/**
|
|
|
|
* Messages utility.
|
|
|
|
*
|
|
|
|
* This module implements the functionality of messages.
|
|
|
|
*/
|
2022-01-06 11:54:30 +03:00
|
|
|
window.App.Utils.Message = (function () {
|
2023-01-27 17:54:45 +03:00
|
|
|
let messageModal = null;
|
|
|
|
|
2022-01-06 11:54:30 +03:00
|
|
|
/**
|
|
|
|
* Show a message box to the user.
|
|
|
|
*
|
|
|
|
* This functions displays a message box in the admin array. It is useful when user
|
|
|
|
* decisions or verifications are needed.
|
|
|
|
*
|
|
|
|
* @param {String} title The title of the message box.
|
|
|
|
* @param {String} message The message of the dialog.
|
|
|
|
* @param {Array} [buttons] Contains the dialog buttons along with their functions.
|
2023-05-04 12:36:49 +03:00
|
|
|
* @param {Boolean} [isDismissible] If true, the button will show the close X in the header and close with the press of the Escape button.
|
2024-04-26 17:11:17 +03:00
|
|
|
*
|
|
|
|
* @return {jQuery|null} Return the #message-modal selector or null if the arguments are invalid.
|
2022-01-06 11:54:30 +03:00
|
|
|
*/
|
2023-05-04 12:36:49 +03:00
|
|
|
function show(title, message, buttons = null, isDismissible = true) {
|
2023-01-27 17:54:45 +03:00
|
|
|
if (!title || !message) {
|
2024-04-26 17:11:17 +03:00
|
|
|
return null;
|
2023-01-27 17:54:45 +03:00
|
|
|
}
|
|
|
|
|
2022-01-06 11:54:30 +03:00
|
|
|
if (!buttons) {
|
|
|
|
buttons = [
|
|
|
|
{
|
2022-01-18 10:22:25 +03:00
|
|
|
text: lang('close'),
|
2023-01-27 17:54:45 +03:00
|
|
|
className: 'btn btn-outline-primary',
|
|
|
|
click: function (event, messageModal) {
|
|
|
|
messageModal.dispose();
|
|
|
|
},
|
|
|
|
},
|
2022-01-06 11:54:30 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-05-12 15:24:58 +03:00
|
|
|
if (messageModal?.dispose && messageModal?.hide && messageModal?._element) {
|
|
|
|
messageModal.hide();
|
2023-01-27 17:54:45 +03:00
|
|
|
messageModal.dispose();
|
2024-05-12 15:24:58 +03:00
|
|
|
messageModal = undefined;
|
2023-01-27 17:54:45 +03:00
|
|
|
}
|
2022-01-06 11:54:30 +03:00
|
|
|
|
2023-01-27 17:54:45 +03:00
|
|
|
$('#message-modal').remove();
|
2022-01-06 11:54:30 +03:00
|
|
|
|
2023-01-27 17:54:45 +03:00
|
|
|
const $messageModal = $(`
|
2023-05-04 12:36:49 +03:00
|
|
|
<div class="modal" id="message-modal" tabindex="-1">
|
2023-02-02 10:48:13 +03:00
|
|
|
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
|
2023-01-27 17:54:45 +03:00
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title">
|
|
|
|
${title}
|
|
|
|
</h5>
|
2023-12-22 13:35:41 +03:00
|
|
|
${
|
|
|
|
isDismissible
|
|
|
|
? '<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>'
|
|
|
|
: ''
|
|
|
|
}
|
2023-01-27 17:54:45 +03:00
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<p>
|
|
|
|
${message}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
|
|
<!-- * -->
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`).appendTo('body');
|
2022-01-06 11:54:30 +03:00
|
|
|
|
2023-01-27 17:54:45 +03:00
|
|
|
buttons.forEach((button) => {
|
|
|
|
if (!button) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-06 11:54:30 +03:00
|
|
|
|
2023-01-27 17:54:45 +03:00
|
|
|
if (!button.className) {
|
|
|
|
button.className = 'btn btn-outline-primary';
|
|
|
|
}
|
|
|
|
|
|
|
|
const $button = $(`
|
2024-05-12 15:24:58 +03:00
|
|
|
<button type="button" class="${button.className}">
|
2023-01-27 17:54:45 +03:00
|
|
|
${button.text}
|
|
|
|
</button>
|
|
|
|
`).appendTo($messageModal.find('.modal-footer'));
|
|
|
|
|
|
|
|
if (button.click) {
|
|
|
|
$button.on('click', (event) => button.click(event, messageModal));
|
|
|
|
}
|
2022-01-06 11:54:30 +03:00
|
|
|
});
|
|
|
|
|
2023-01-27 17:54:45 +03:00
|
|
|
messageModal = new bootstrap.Modal('#message-modal', {
|
2023-05-04 12:36:49 +03:00
|
|
|
keyboard: isDismissible,
|
2023-01-27 17:54:45 +03:00
|
|
|
backdrop: 'static',
|
|
|
|
});
|
2022-01-06 11:54:30 +03:00
|
|
|
|
2023-01-27 17:54:45 +03:00
|
|
|
messageModal.show();
|
2022-01-06 11:54:30 +03:00
|
|
|
|
2024-04-26 17:11:17 +03:00
|
|
|
$messageModal.css('z-index', '99999').next().css('z-index', '9999');
|
|
|
|
|
|
|
|
return $messageModal;
|
2022-01-06 11:54:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2023-12-22 13:35:41 +03:00
|
|
|
show,
|
2022-01-06 11:54:30 +03:00
|
|
|
};
|
|
|
|
})();
|