dev #1

Merged
alientim merged 145 commits from dev into main 2025-10-12 13:44:14 +02:00
Showing only changes of commit 207eed1f00 - Show all commits

View File

@@ -239,12 +239,13 @@ document.addEventListener("input", function(e) {
if (e.target.name === "mac") validateMAC(e.target); if (e.target.name === "mac") validateMAC(e.target);
}); });
// Aktivieren/Deaktivieren
function toggleDevice(mac, btn) { function toggleDevice(mac, btn) {
fetch(`/devices/toggle/${mac}`, { method: 'POST' }) fetch(`/devices/toggle/${mac}`, { method: 'POST' })
.then(resp => resp.json()) .then(resp => resp.json())
.then(data => { .then(data => {
if (data.success) { if (data.success) {
// Button-Styling und Text aktualisieren // Button aktualisieren
if (data.new_status === 1) { if (data.new_status === 1) {
btn.classList.remove('btn-secondary'); btn.classList.remove('btn-secondary');
btn.classList.add('btn-success'); btn.classList.add('btn-success');
@@ -255,10 +256,35 @@ function toggleDevice(mac, btn) {
btn.innerText = 'Aktivieren'; btn.innerText = 'Aktivieren';
} }
// Optional: Flash-Nachricht anzeigen // Flash-Nachricht im Frontend aktualisieren
alert(data.msg); let flashContainer = document.getElementById('flash-messages');
if (!flashContainer) {
flashContainer = document.createElement('div');
flashContainer.id = 'flash-messages';
flashContainer.style.position = 'fixed';
flashContainer.style.top = '10px';
flashContainer.style.right = '10px';
flashContainer.style.zIndex = 1050;
document.body.appendChild(flashContainer);
}
const flash = document.createElement('div');
flash.className = 'alert alert-success alert-dismissible fade show';
flash.role = 'alert';
flash.innerHTML = `
${data.msg}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
`;
flashContainer.appendChild(flash);
// Automatisch nach 3 Sekunden ausblenden
setTimeout(() => {
flash.classList.remove('show');
flash.classList.add('hide');
flash.addEventListener('transitionend', () => flash.remove());
}, 3000);
} else { } else {
alert(data.msg); console.error(data.msg);
} }
}) })
.catch(err => console.error(err)); .catch(err => console.error(err));