diff --git a/srv/poe_manager/templates/devices.html b/srv/poe_manager/templates/devices.html index f1db549..9476f01 100644 --- a/srv/poe_manager/templates/devices.html +++ b/srv/poe_manager/templates/devices.html @@ -29,11 +29,10 @@ {{ d['port'] }} {{ d['switch_hostname'] or '-' }} -
- -
+ {% if current_user.is_admin %} @@ -239,6 +238,31 @@ document.addEventListener("input", function(e) { if (e.target.name === "rpi_ip") validateIP(e.target); if (e.target.name === "mac") validateMAC(e.target); }); + +function toggleDevice(mac, btn) { + fetch(`/devices/toggle/${mac}`, { method: 'POST' }) + .then(resp => resp.json()) + .then(data => { + if (data.success) { + // Button-Styling und Text aktualisieren + if (data.new_status === 1) { + btn.classList.remove('btn-secondary'); + btn.classList.add('btn-success'); + btn.innerText = 'Deaktivieren'; + } else { + btn.classList.remove('btn-success'); + btn.classList.add('btn-secondary'); + btn.innerText = 'Aktivieren'; + } + + // Optional: Flash-Nachricht anzeigen + alert(data.msg); + } else { + alert(data.msg); + } + }) + .catch(err => console.error(err)); +} {% endblock %}