Skip to content

Commit 1464c37

Browse files
author
Marcel Diegelmann
committed
statistics_assembly_controller bzgl. Alert-Ausgabe aktualisieren
1 parent 2e29297 commit 1464c37

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

assets/controllers/pages/statistics_assembly_controller.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,32 @@ export default class extends Controller {
126126
}
127127

128128
showToast(type, message) {
129-
// Create a simple alert that doesn't disrupt layout
130-
const alertId = 'alert-' + Date.now();
131129
const iconClass = type === 'success' ? 'fa-check-circle' : 'fa-exclamation-triangle';
132-
const alertClass = type === 'success' ? 'alert-success' : 'alert-danger';
133-
134-
const alertHTML = `
135-
<div class="alert ${alertClass} alert-dismissible fade show position-fixed"
136-
style="top: 20px; right: 20px; z-index: 9999; max-width: 400px;"
137-
id="${alertId}" role="alert">
138-
<i class="fas ${iconClass} me-2"></i>
139-
${message}
140-
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
130+
const bgClass = type === 'success' ? 'bg-success' : 'bg-danger';
131+
const title = type === 'success' ? 'Success' : 'Error';
132+
const timeString = new Date().toLocaleString(undefined, {
133+
year: '2-digit',
134+
month: 'numeric',
135+
day: 'numeric',
136+
hour: 'numeric',
137+
minute: '2-digit'
138+
});
139+
140+
const toastHTML = `
141+
<div role="alert" aria-live="assertive" aria-atomic="true" data-delay="5000" data-controller="common--toast" class="toast shadow fade show">
142+
<div class="toast-header ${bgClass} text-white">
143+
<i class="fas fa-fw ${iconClass} me-2"></i>
144+
<strong class="me-auto">${title}</strong>
145+
<small class="text-white">${timeString}</small>
146+
<button type="button" class="ms-2 mb-1 btn-close btn-close-white" data-bs-dismiss="toast" aria-label="Close"></button>
147+
</div>
148+
<div class="toast-body ${bgClass} text-white">
149+
${message}
150+
</div>
141151
</div>
142152
`;
143153

144-
// Add alert to body
145-
document.body.insertAdjacentHTML('beforeend', alertHTML);
146-
147-
// Auto-remove after 5 seconds if not closed manually
148-
setTimeout(() => {
149-
const elementToRemove = document.getElementById(alertId);
150-
if (elementToRemove) {
151-
elementToRemove.remove();
152-
}
153-
}, 5000);
154+
// Add toast to body. The common--toast controller will move it to the container.
155+
document.body.insertAdjacentHTML('beforeend', toastHTML);
154156
}
155157
}

0 commit comments

Comments
 (0)