diff --git a/static/js/app.js b/static/js/app.js index 34242df..72dfca0 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -17,13 +17,13 @@ document.addEventListener('DOMContentLoaded', () => { if (!connectBtn) { console.warn('Nicht auf der Steuerseite – Connect-Button nicht gefunden'); - return; + // Dennoch Status und Soundboard-Logik initialisieren (falls vorhanden) } - // ── Config aus Template ──────────────────────────────────────────────────── + // ── Config & globale Sounds aus Template ────────────────────────────────── const config = {{ config | tojson | safe }}; const globalSounds = {{ global_sounds | tojson | safe }}; - window.mkConfig = config; // global für Konsistenz + window.mkConfig = config; // global verfügbar console.log("Config im JS:", config); console.log("Globale Sounds:", globalSounds); @@ -85,48 +85,50 @@ document.addEventListener('DOMContentLoaded', () => { }); // ── Connect-Button ──────────────────────────────────────────────────────── - connectBtn.addEventListener('click', async () => { - connectBtn.disabled = true; - connectBtn.innerHTML = ' Verbinde...'; + if (connectBtn) { + connectBtn.addEventListener('click', async () => { + connectBtn.disabled = true; + connectBtn.innerHTML = ' Verbinde...'; - try { - console.log("→ Sende /api/connect ..."); - const response = await fetch('/api/connect', { - method: 'POST', - headers: { 'Content-Type': 'application/json' } - }); + try { + console.log("→ Sende /api/connect ..."); + const response = await fetch('/api/connect', { + method: 'POST', + headers: { 'Content-Type': 'application/json' } + }); - console.log("→ Antwort erhalten:", response.status); - const result = await response.json(); - console.log("→ Resultat:", result); + console.log("→ Antwort erhalten:", response.status); + const result = await response.json(); + console.log("→ Resultat:", result); - if (result.success) { - console.log("→ Connect erfolgreich – blende Sections um"); - connectSection.style.display = 'none'; - controlSection.style.display = 'block'; - reconnectSection.style.display = 'none'; + if (result.success) { + console.log("→ Connect erfolgreich – blende Sections um"); + connectSection.style.display = 'none'; + controlSection.style.display = 'block'; + reconnectSection.style.display = 'none'; - updateStatus(true); - startConnectionCheck(); + updateStatus(true); + startConnectionCheck(); - console.log("→ Rufe renderChannels() auf"); - renderChannels(); + console.log("→ Rufe renderChannels() auf"); + renderChannels(); - console.log("→ renderChannels() abgeschlossen"); - } else { - console.warn("→ Connect fehlgeschlagen:", result.message); - alert('Verbindung fehlgeschlagen:\n' + (result.message || 'Unbekannter Fehler')); + console.log("→ renderChannels() abgeschlossen"); + } else { + console.warn("→ Connect fehlgeschlagen:", result.message); + alert('Verbindung fehlgeschlagen:\n' + (result.message || 'Unbekannter Fehler')); + updateStatus(false); + } + } catch (err) { + console.error("→ Connect-Fehler:", err); + alert('Netzwerk- oder Verbindungsfehler: ' + err.message); updateStatus(false); + } finally { + connectBtn.disabled = false; + connectBtn.innerHTML = ' Mit Hub verbinden'; } - } catch (err) { - console.error("→ Connect-Fehler:", err); - alert('Netzwerk- oder Verbindungsfehler: ' + err.message); - updateStatus(false); - } finally { - connectBtn.disabled = false; - connectBtn.innerHTML = ' Mit Hub verbinden'; - } - }); + }); + } // ── Alle stoppen ────────────────────────────────────────────────────────── if (stopAllBtn) { @@ -301,7 +303,7 @@ document.addEventListener('DOMContentLoaded', () => { }); }); - // ── Event-Listener Toggle-Buttons (Licht/Sound/Fogger) ────────────────── + // ── Event-Listener Toggle-Buttons ────────────────────────────────────── document.querySelectorAll('.toggle-btn').forEach(btn => { btn.addEventListener('click', async () => { const current = btn.dataset.state; @@ -335,7 +337,6 @@ document.addEventListener('DOMContentLoaded', () => { } } catch (err) { console.error('sendControl Fehler:', err); - // Bei Fehler: Verbindungsprüfung triggern updateStatus(false, 'Fehler beim Senden'); } } @@ -355,7 +356,6 @@ document.addEventListener('DOMContentLoaded', () => { btn.addEventListener('click', async () => { const soundId = btn.dataset.soundId; - // Alten Play-Button zurücksetzen if (currentSoundButton && currentSoundButton !== btn) { currentSoundButton.classList.remove('btn-success'); currentSoundButton.classList.add('btn-outline-primary', 'btn-outline-secondary'); @@ -395,7 +395,7 @@ document.addEventListener('DOMContentLoaded', () => { }); }); - // ── Stop-Button für aktuellen Sound + // ── Stop-Button für aktuellen Sound ──────────────────────────────────────── document.querySelectorAll('.stop-sound-btn').forEach(btn => { btn.addEventListener('click', async () => { try { @@ -420,7 +420,7 @@ document.addEventListener('DOMContentLoaded', () => { }); }); - // ── Volume-Regler + // ── Volume-Regler ────────────────────────────────────────────────────────── if (volumeSlider && volumeDisplay) { volumeSlider.addEventListener('input', () => { const vol = volumeSlider.value / 100;