mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-10 10:02:33 +03:00
Replace the toast function with a bootstrap equivalent
This commit is contained in:
parent
229a2aec90
commit
280c9d0ebb
1 changed files with 26 additions and 30 deletions
|
@ -47,42 +47,38 @@ window.App.Layouts.Backend = (function () {
|
||||||
* @param {Array} [actions] An array with custom actions that will be available to the user. Every array item is an
|
* @param {Array} [actions] An array with custom actions that will be available to the user. Every array item is an
|
||||||
* object that contains the 'label' and 'function' key values.
|
* object that contains the 'label' and 'function' key values.
|
||||||
*/
|
*/
|
||||||
function displayNotification(message = '- No message provided for this notification -', actions = null) {
|
function displayNotification(message, actions = []) {
|
||||||
if (!actions) {
|
if (!message) {
|
||||||
actions = [];
|
return;
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
$notification.fadeOut();
|
|
||||||
}, 5000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$notification.empty();
|
const $toast = $(`
|
||||||
|
<div class="toast bg-dark d-flex align-items-center mb-2 fade show position-fixed p-1 m-4 bottom-0 end-0 backend-notification" role="alert" aria-live="assertive" aria-atomic="true">
|
||||||
|
<div class="toast-body w-100 text-white">
|
||||||
|
${message}
|
||||||
|
</div>
|
||||||
|
<button type="button" class="btn-close btn-close-white me-2" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
`).appendTo('body');
|
||||||
|
|
||||||
const $instance = $('<div/>', {
|
actions.forEach(function (action) {
|
||||||
'class': 'notification alert alert-dismissible fade show',
|
|
||||||
'html': [
|
|
||||||
$('<strong/>', {
|
|
||||||
'html': message
|
|
||||||
}),
|
|
||||||
$('<button/>', {
|
$('<button/>', {
|
||||||
'type': 'button',
|
class: 'btn btn-light btn-xs ms-2',
|
||||||
'class': 'btn-close',
|
text: action.label,
|
||||||
'data-bs-dismiss': 'alert'
|
on: {
|
||||||
})
|
click: action.function,
|
||||||
]
|
},
|
||||||
}).appendTo($notification);
|
}).prependTo($toast);
|
||||||
|
|
||||||
actions.forEach((action) => {
|
|
||||||
$('<button/>', {
|
|
||||||
'class': 'btn btn-outline-secondary btn-xs',
|
|
||||||
'text': action.label,
|
|
||||||
'on': {
|
|
||||||
'click': action.function
|
|
||||||
}
|
|
||||||
}).prependTo($instance);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$notification.show('fade');
|
const toast = new bootstrap.Toast($toast[0]);
|
||||||
|
|
||||||
|
toast.show();
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
toast.dispose();
|
||||||
|
$toast.remove();
|
||||||
|
}, 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue