(c)
document.addEventListener("DOMContentLoaded", function () {
console.log("Kindergeburtstag: Script gestartet");
// API-Endpunkt – wie du ihn im Browser aufrufst
const apiUrl = "https://www.blau-weiss-hand.de/wp-json/bwh/v1/slots";
// alternativ ginge auch: const apiUrl = "/wp-json/bwh/v1/slots";
// Alle Raven-Feldgruppen holen
const groups = document.querySelectorAll(".raven-field-group");
console.log("Kindergeburtstag: gefundene Gruppen =", groups);
let wishSelect = null;
let altSelect = null;
groups.forEach(function (group) {
const labelEl = group.querySelector(".raven-field-label");
if (!labelEl) return;
const labelText = (labelEl.textContent || "").trim().toLowerCase();
// Konsole zur Kontrolle
console.log("Kindergeburtstag: Gruppe mit Label =", labelText);
if (labelText === "wunschtermin") {
wishSelect = group.querySelector("select");
} else if (labelText === "alternativ-termin") {
altSelect = group.querySelector("select");
}
});
console.log("Kindergeburtstag: wishSelect =", wishSelect);
console.log("Kindergeburtstag: altSelect =", altSelect);
if (!wishSelect || !altSelect) {
console.warn("Kindergeburtstag: Konnte Wunschtermin/Alternativ-Termin über Label nicht finden.");
return;
}
function resetSelect(select, placeholder) {
while (select.firstChild) {
select.removeChild(select.firstChild);
}
const opt = new Option(placeholder, "");
opt.disabled = true;
opt.selected = true;
select.appendChild(opt);
}
resetSelect(wishSelect, "Wunschtermin wählen");
resetSelect(altSelect, "Alternativtermin wählen (optional)");
fetch(apiUrl)
.then(function (res) {
console.log("Kindergeburtstag: Response Status", res.status);
return res.json();
})
.then(function (slots) {
console.log("Kindergeburtstag: Slots JSON", slots);
if (!Array.isArray(slots)) {
console.error("Kindergeburtstag: Unerwartetes Format", slots);
return;
}
slots.forEach(function (s) {
if (!s.buchungs_id) return;
wishSelect.appendChild(new Option(s.label, s.buchungs_id));
altSelect.appendChild(new Option(s.label, s.buchungs_id));
});
})
.catch(function (err) {
console.error("Kindergeburtstag: Fehler beim Laden der Slots", err);
});
});
