diff --git a/static/js/ui-channels.js b/static/js/ui-channels.js index 6f2eb10..388c2f4 100644 --- a/static/js/ui-channels.js +++ b/static/js/ui-channels.js @@ -1,5 +1,25 @@ // static/js/ui-channels.js – Kanal-Rendering & Listener +// Gemeinsame Helper-Funktion zum Senden von Steuerbefehlen +async function sendControl(port, value) { + try { + const res = await fetch('/api/control', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ port, value }) + }); + + const data = await res.json(); + if (!data.success) { + throw new Error(data.message || 'Unbekannter Fehler'); + } + } catch (err) { + console.error(`sendControl(${port}, ${value}) fehlgeschlagen:`, err); + alert(`Steuerbefehl fehlgeschlagen: ${err.message}`); + updateStatus(false, 'Steuerfehler'); + } +} + function renderChannels() { console.log("renderChannels() START"); console.log("→ config.channels existiert?", !!config?.channels); @@ -87,4 +107,4 @@ function renderChannels() { } // Am Ende von ui-channels.js -window.initChannels = renderChannels; \ No newline at end of file +window.initChannels = renderChannels; diff --git a/templates/control.html b/templates/control.html index 44bc050..1810452 100644 --- a/templates/control.html +++ b/templates/control.html @@ -167,14 +167,14 @@ {% block scripts %} - {{ super() }} - + + {{ super() }} {% endblock %}