feat: Verwende fetch statt window.location.href für Digitalausgang-Schalteraktionen

This commit is contained in:
ISA
2025-07-08 10:09:46 +02:00
parent 2af99f2740
commit 976f3126f2
8 changed files with 41 additions and 20 deletions

View File

@@ -49,22 +49,22 @@ export default function DigitalOutputsModal({
try {
if (isCPL) {
// ✅ Name speichern (DANx=...)
const nameEncoded = encodeURIComponent(label.trim());
const nameUrl = `/CPL?digitalOutputs.html&DAN0${selectedOutput.id}=${nameEncoded}`;
// ✅ Status speichern (DASx=...)
const statusUrl = `/CPL?digitalOutputs.html&DAS0${selectedOutput.id}=${
status ? 1 : 0
}`;
// 🟢 Beide nacheinander senden (wichtig bei älteren CPL-Versionen)
window.location.href = nameUrl; // Name zuerst (ggf. durch Refresh überschrieben)
setTimeout(() => {
window.location.href = statusUrl;
}, 300); // kleine Verzögerung (optional)
try {
await fetch(nameUrl, { method: "GET" });
await new Promise((res) => setTimeout(res, 300));
await fetch(statusUrl, { method: "GET" });
// 💡 Modal wird nicht automatisch geschlossen — da Seite neu lädt.
closeOutputModal(); // Seite bleibt erhalten
} catch (err) {
console.error("❌ Fehler bei fetch:", err);
setErrorMsg("❌ Fehler beim Speichern.");
}
} else {
// 🧪 Lokaler Entwicklungsmodus
const res = await fetch("/api/cpl/updateDigitalOutputsHandler", {

View File

@@ -32,9 +32,25 @@ export default function DigitalOutputsWidget({
try {
if (isCPL) {
window.location.href = `/CPL?digitalOutputs.html&DAS0${id}=${
updatedOutputs[id - 1].status ? 1 : 0
}`;
// Statt redirect:
// window.location.href = `/CPL?...`;
// Verwende fetch:
fetch(
`/CPL?digitalOutputs.html&DAS0${id}=${
updatedOutputs[id - 1].status ? 1 : 0
}`,
{
method: "GET",
}
)
.then((res) => {
if (!res.ok) throw new Error("Fehler beim Schalten");
// Optional: Feedback anzeigen
})
.catch((err) => {
console.error("CPL Fehler:", err);
});
} else {
await fetch("/api/cpl/updateDigitalOutputsHandler", {
method: "POST",