* Notifies the user of something by a popup which can be stacked, auto-dismissed, etc... based on options
(
body: string,
{
group = '',
collapseSimilar = true,
alertClass = '',
autoDismiss = true,
dismissTime = 5000,
onBeforeShow = () => {},
}: AlertNotifyOptions,
)
| 96 | * Notifies the user of something by a popup which can be stacked, auto-dismissed, etc... based on options |
| 97 | */ |
| 98 | notify( |
| 99 | body: string, |
| 100 | { |
| 101 | group = '', |
| 102 | collapseSimilar = true, |
| 103 | alertClass = '', |
| 104 | autoDismiss = true, |
| 105 | dismissTime = 5000, |
| 106 | onBeforeShow = () => {}, |
| 107 | }: AlertNotifyOptions, |
| 108 | ) { |
| 109 | const container = $('#notifications'); |
| 110 | const newElement = $(` |
| 111 | <div class="toast" tabindex="-1" role="alert" aria-live="assertive" aria-atomic="true"> |
| 112 | <div class="toast-header ${alertClass}"> |
| 113 | <strong class="me-auto">${this.prefixMessage}</strong> |
| 114 | <button type="button" class="ms-2 mb-1 btn-close" data-bs-dismiss="toast" aria-label="Close"></button> |
| 115 | </div> |
| 116 | <div class="toast-body ${alertClass}"> |
| 117 | <span id="msg">${body}</span> |
| 118 | </div> |
| 119 | </div> |
| 120 | `); |
| 121 | container.append(newElement); |
| 122 | const toastOptions = { |
| 123 | autohide: autoDismiss, |
| 124 | delay: dismissTime, |
| 125 | }; |
| 126 | |
| 127 | new Toast(newElement[0], toastOptions); |
| 128 | |
| 129 | if (group !== '') { |
| 130 | if (collapseSimilar) { |
| 131 | // Only collapsing if a group has been specified |
| 132 | const old = container.find(`[data-group="${group}"]`); |
| 133 | old.each((_, element) => { |
| 134 | BootstrapUtils.hideToast(element); |
| 135 | $(element).remove(); |
| 136 | }); |
| 137 | } |
| 138 | newElement.attr('data-group', group); |
| 139 | } |
| 140 | onBeforeShow(newElement); |
| 141 | BootstrapUtils.showToast(newElement); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Asks the user a two choice question, where the title, content and buttons are customizable |
no test coverage detected