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.
|
|
|
|
*/
|
|
|
|
function show(title, message, buttons = null) {
|
2023-01-27 17:54:45 +03:00
|
|
|
if (!title || !message) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2023-01-27 17:54:45 +03:00
|
|
|
if (messageModal?.dispose && messageModal?._element) {
|
|
|
|
messageModal.dispose();
|
|
|
|
}
|
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 = $(`
|
|
|
|
<div class="modal" id="message-modal">
|
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>
|
|
|
|
</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 = $(`
|
|
|
|
<button type="button" class="${button.className}" data-bs-dismiss="modal">
|
|
|
|
${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', {
|
|
|
|
keyboard: false,
|
|
|
|
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
|
|
|
|
2023-01-27 17:54:45 +03:00
|
|
|
$('#message-modal').css('z-index', '99999').next().css('z-index', '9999');
|
2022-01-06 11:54:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
show
|
|
|
|
};
|
|
|
|
})();
|