diff --git a/development-system/README.md b/development-system/README.md index 5d068dc..6893295 100644 --- a/development-system/README.md +++ b/development-system/README.md @@ -71,7 +71,7 @@ Die Terminbuchungskomponente hat eine Vorschau auf einem Webseiten-Nachbau der O ## Statische Buchungsvorschau in Contao einbinden -Die erste Komponente ist absichtlich datenbankfrei. Sie zeigt Test-Slots, rendert einen Monatskalender und unterscheidet freie von belegten Terminen. Eine Buchung wird noch nicht gespeichert. +Die erste Komponente ist absichtlich datenbankfrei. Sie zeigt Test-Slots, rendert einen Monatskalender und unterscheidet freie von belegten Terminen. Ein Klick auf einen freien Slot öffnet eine modale Eingabemaske für Name, E-Mail, Telefon, Alter, Nachricht, Ansprechperson bei AfA/Jobcenter sowie die DSGVO-Einwilligung. Die Eingaben werden derzeit ausschließlich im Browser validiert und weder gespeichert noch versendet. Die Komponente benötigt keinen TypeScript-Compiler und keinen Build-Schritt. Regressionstests ausführen: diff --git a/development-system/public/booking/booking.css b/development-system/public/booking/booking.css index 3508ea7..65b464f 100644 --- a/development-system/public/booking/booking.css +++ b/development-system/public/booking/booking.css @@ -1 +1,329 @@ -.sufw-booking{--sufw-booking-green:#08752a;--sufw-booking-text:#202020;--sufw-booking-muted:#5a5a5a;--sufw-booking-line:#c7c7c7;--sufw-booking-pale:#f3f6f3;box-sizing:border-box;max-width:860px;margin:2rem auto;padding:1.25rem;color:var(--sufw-booking-text);background:#fff;border:1px solid var(--sufw-booking-line);font:1rem/1.5 Arial,"Helvetica Neue",sans-serif}.sufw-booking *{box-sizing:border-box}.sufw-booking__header h2,.sufw-booking__slots h3{margin:.15rem 0 .5rem;color:var(--sufw-booking-green);font-size:1.4rem}.sufw-booking__header p{margin:.3rem 0}.sufw-booking__eyebrow{color:var(--sufw-booking-green);font-size:.875rem;font-weight:700;text-transform:uppercase;letter-spacing:.04em}.sufw-booking__legend{display:flex;gap:1rem;flex-wrap:wrap;margin:1.25rem 0;font-size:.9rem}.sufw-booking__marker{display:inline-block;width:.8rem;height:.8rem;margin-right:.35rem;border-radius:50%}.sufw-booking__marker--available{background:var(--sufw-booking-green)}.sufw-booking__marker--booked{background:#535353}.sufw-booking__month-nav{display:grid;grid-template-columns:3rem 1fr 3rem;align-items:center;margin-top:1rem;text-align:center}.sufw-booking__month-nav h3{margin:0;font-size:1.1rem;text-transform:capitalize}.sufw-booking__nav,.sufw-booking__day,.sufw-booking__slot{font:inherit}.sufw-booking__nav{min-width:2.75rem;min-height:2.75rem;border:1px solid var(--sufw-booking-green);color:var(--sufw-booking-green);background:#fff;font-size:1.7rem;cursor:pointer}.sufw-booking__nav:hover,.sufw-booking__nav:focus-visible{background:var(--sufw-booking-pale)}.sufw-booking__weekdays,.sufw-booking__calendar{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:.3rem}.sufw-booking__weekdays{margin-top:1rem;text-align:center;font-weight:700;font-size:.8rem}.sufw-booking__day{display:grid;place-items:center;gap:.1rem;min-height:3.8rem;padding:.25rem;border:1px solid transparent;background:#fff;color:var(--sufw-booking-text);cursor:pointer}.sufw-booking__day:hover{border-color:var(--sufw-booking-green);background:var(--sufw-booking-pale)}.sufw-booking__day--available{background:#dff3e4;border-color:var(--sufw-booking-green)}.sufw-booking__day--booked{background:#ececec;border-color:#777}.sufw-booking__day.is-selected{outline:3px solid #1f4fbc;outline-offset:1px}.sufw-booking__day small{font-size:.7rem}.sufw-booking__empty{min-height:3.8rem}.sufw-booking__slots{margin-top:1.5rem;padding-top:1.25rem;border-top:1px solid var(--sufw-booking-line)}.sufw-booking__slots ul{padding:0;margin:0;list-style:none}.sufw-booking__slot{display:grid;grid-template-columns:5rem 1fr auto;gap:.7rem;width:100%;margin:.45rem 0;padding:.8rem;text-align:left;color:var(--sufw-booking-text);background:#fff;border:1px solid var(--sufw-booking-green);cursor:pointer}.sufw-booking__slot:hover,.sufw-booking__slot:focus-visible{background:var(--sufw-booking-pale)}.sufw-booking__slot em{color:var(--sufw-booking-green);font-style:normal;font-weight:700}.sufw-booking__slot:disabled{border-color:#777;background:#eee;color:#555;cursor:not-allowed}.sufw-booking__slot:disabled em{color:#555}.sufw-booking__empty-state,.sufw-booking__status{margin:.7rem 0}.sufw-booking__status{font-weight:700}@media (max-width:520px){.sufw-booking{margin:1rem 0;padding:1rem}.sufw-booking__weekdays{font-size:.7rem}.sufw-booking__day{min-height:3.4rem;padding:.15rem}.sufw-booking__slot{grid-template-columns:1fr;gap:.15rem}.sufw-booking__slot strong{font-size:1.1rem}} +.sufw-booking { + --sufw-booking-green: #08752a; + --sufw-booking-text: #202020; + --sufw-booking-muted: #5a5a5a; + --sufw-booking-line: #c7c7c7; + --sufw-booking-pale: #f3f6f3; + box-sizing: border-box; + max-width: 860px; + margin: 2rem auto; + padding: 1.25rem; + color: var(--sufw-booking-text); + background: #fff; + border: 1px solid var(--sufw-booking-line); + font: 1rem/1.5 Arial, "Helvetica Neue", sans-serif; +} +.sufw-booking * { + box-sizing: border-box; +} +.sufw-booking__header h2, +.sufw-booking__slots h3 { + margin: 0.15rem 0 0.5rem; + color: var(--sufw-booking-green); + font-size: 1.4rem; +} +.sufw-booking__header p { + margin: 0.3rem 0; +} +.sufw-booking__eyebrow { + color: var(--sufw-booking-green); + font-size: 0.875rem; + font-weight: 700; + text-transform: uppercase; + letter-spacing: 0.04em; +} +.sufw-booking__legend { + display: flex; + gap: 1rem; + flex-wrap: wrap; + margin: 1.25rem 0; + font-size: 0.9rem; +} +.sufw-booking__marker { + display: inline-block; + width: 0.8rem; + height: 0.8rem; + margin-right: 0.35rem; + border-radius: 50%; +} +.sufw-booking__marker--available { + background: var(--sufw-booking-green); +} +.sufw-booking__marker--booked { + background: #535353; +} +.sufw-booking__month-nav { + display: grid; + grid-template-columns: 3rem 1fr 3rem; + align-items: center; + margin-top: 1rem; + text-align: center; +} +.sufw-booking__month-nav h3 { + margin: 0; + font-size: 1.1rem; + text-transform: capitalize; +} +.sufw-booking__nav, +.sufw-booking__day, +.sufw-booking__slot { + font: inherit; +} +.sufw-booking__nav { + min-width: 2.75rem; + min-height: 2.75rem; + border: 1px solid var(--sufw-booking-green); + color: var(--sufw-booking-green); + background: #fff; + font-size: 1.7rem; + cursor: pointer; +} +.sufw-booking__nav:hover, +.sufw-booking__nav:focus-visible { + background: var(--sufw-booking-pale); +} +.sufw-booking__weekdays, +.sufw-booking__calendar { + display: grid; + grid-template-columns: repeat(7, minmax(0, 1fr)); + gap: 0.3rem; +} +.sufw-booking__weekdays { + margin-top: 1rem; + text-align: center; + font-weight: 700; + font-size: 0.8rem; +} +.sufw-booking__day { + display: grid; + place-items: center; + gap: 0.1rem; + min-height: 3.8rem; + padding: 0.25rem; + border: 1px solid transparent; + background: #fff; + color: var(--sufw-booking-text); + cursor: pointer; +} +.sufw-booking__day:hover { + border-color: var(--sufw-booking-green); + background: var(--sufw-booking-pale); +} +.sufw-booking__day--available { + background: #dff3e4; + border-color: var(--sufw-booking-green); +} +.sufw-booking__day--booked { + background: #ececec; + border-color: #777; +} +.sufw-booking__day.is-selected { + outline: 3px solid #1f4fbc; + outline-offset: 1px; +} +.sufw-booking__day small { + font-size: 0.7rem; +} +.sufw-booking__empty { + min-height: 3.8rem; +} +.sufw-booking__slots { + margin-top: 1.5rem; + padding-top: 1.25rem; + border-top: 1px solid var(--sufw-booking-line); +} +.sufw-booking__slots ul { + padding: 0; + margin: 0; + list-style: none; +} +.sufw-booking__slot { + display: grid; + grid-template-columns: 5rem 1fr auto; + gap: 0.7rem; + width: 100%; + margin: 0.45rem 0; + padding: 0.8rem; + text-align: left; + color: var(--sufw-booking-text); + background: #fff; + border: 1px solid var(--sufw-booking-green); + cursor: pointer; +} +.sufw-booking__slot:hover, +.sufw-booking__slot:focus-visible { + background: var(--sufw-booking-pale); +} +.sufw-booking__slot em { + color: var(--sufw-booking-green); + font-style: normal; + font-weight: 700; +} +.sufw-booking__slot:disabled { + border-color: #777; + background: #eee; + color: #555; + cursor: not-allowed; +} +.sufw-booking__slot:disabled em { + color: #555; +} +.sufw-booking__empty-state, +.sufw-booking__status { + margin: 0.7rem 0; +} +.sufw-booking__status { + font-weight: 700; +} +.sufw-booking__dialog { + width: min(42rem, calc(100% - 2rem)); + max-height: calc(100vh - 2rem); + padding: 0; + border: 0; + color: var(--sufw-booking-text); + box-shadow: 0 0.75rem 2.5rem rgba(0, 0, 0, 0.35); + font: 1rem/1.5 Arial, "Helvetica Neue", sans-serif; +} +.sufw-booking__dialog::backdrop { + background: rgba(0, 0, 0, 0.62); +} +.sufw-booking__form { + display: grid; + gap: 1rem; + padding: 1.25rem; +} +.sufw-booking__form-header { + padding-bottom: 1rem; + border-bottom: 1px solid var(--sufw-booking-line); +} +.sufw-booking__form-header h2 { + margin: 0.15rem 0 0.5rem; + color: var(--sufw-booking-green); + font-size: 1.5rem; +} +.sufw-booking__appointment, +.sufw-booking__required, +.sufw-booking__prototype-note { + margin: 0.35rem 0; +} +.sufw-booking__required { + font-size: 0.875rem; +} +.sufw-booking__optional { + color: var(--sufw-booking-muted); + font-size: 0.875rem; + font-weight: 400; +} +.sufw-booking__form-grid { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 1rem; +} +.sufw-booking__form label { + display: grid; + gap: 0.35rem; + font-weight: 700; +} +.sufw-booking__form input, +.sufw-booking__form textarea { + width: 100%; + padding: 0.65rem; + border: 1px solid #767676; + color: var(--sufw-booking-text); + font: inherit; +} +.sufw-booking__form input:focus-visible, +.sufw-booking__form textarea:focus-visible, +.sufw-booking__form button:focus-visible { + outline: 3px solid #1f4fbc; + outline-offset: 2px; +} +.sufw-booking__consent { + grid-template-columns: auto 1fr; + align-items: start; + font-weight: 400 !important; +} +.sufw-booking__consent input { + width: 1.1rem !important; + height: 1.1rem; + margin-top: 0.25rem; +} +.sufw-booking__form-errors:empty { + display: none; +} +.sufw-booking__form-errors { + padding: 0.75rem; + border-left: 4px solid #a31111; + background: #fff1f1; + color: #6c0808; +} +.sufw-booking__form-errors ul { + margin: 0; + padding-left: 1.25rem; +} +.sufw-booking__prototype-note { + padding: 0.75rem; + background: var(--sufw-booking-pale); + font-size: 0.9rem; +} +.sufw-booking__form-status { + margin: 0; + color: var(--sufw-booking-green); + font-weight: 700; +} +.sufw-booking__form-actions { + display: flex; + justify-content: flex-end; + gap: 0.75rem; + flex-wrap: wrap; +} +.sufw-booking__form-actions button { + padding: 0.7rem 1rem; + border: 1px solid var(--sufw-booking-green); + background-color: #08752a; + color: #fff; + font: inherit; + font-weight: 700; + cursor: pointer; +} +.sufw-booking__form-actions button:hover:not(:disabled) { + border-color: #05571f; + background-color: #05571f; + color: #fff; +} +.sufw-booking__form-actions button:disabled { + border-color: #777; + background-color: #d8d8d8; + color: #555; + cursor: not-allowed; +} +.sufw-booking__form-actions .sufw-booking__secondary { + background-color: #fff; + color: var(--sufw-booking-green); +} +@media (max-width: 520px) { + .sufw-booking { + margin: 1rem 0; + padding: 1rem; + } + .sufw-booking__weekdays { + font-size: 0.7rem; + } + .sufw-booking__day { + min-height: 3.4rem; + padding: 0.15rem; + } + .sufw-booking__slot { + grid-template-columns: 1fr; + gap: 0.15rem; + } + .sufw-booking__slot strong { + font-size: 1.1rem; + } + .sufw-booking__form-grid { + grid-template-columns: 1fr; + } + .sufw-booking__form-actions button { + width: 100%; + } +} diff --git a/development-system/public/booking/booking.js b/development-system/public/booking/booking.js index 1e0ba03..88e8eaf 100644 --- a/development-system/public/booking/booking.js +++ b/development-system/public/booking/booking.js @@ -1,10 +1,41 @@ /* Browsernatives ES-Modul; wird ohne TypeScript-Compiler ausgeliefert. */ const demoSlots = [ - { id: 'pw-2026-08-25-1000', project: 'perspektivwerk', date: '2026-08-25', start: '10:00', title: 'Erstgespräch', status: 'available' }, - { id: 'pw-2026-08-25-1300', project: 'perspektivwerk', date: '2026-08-25', start: '13:00', title: 'Soz. Päd. Modul', status: 'booked' }, - { id: 'pw-2026-08-25-1500', project: 'perspektivwerk', date: '2026-08-25', start: '15:00', title: 'Erstgespräch', status: 'available' }, - { id: 'pw-2026-08-27-0900', project: 'perspektivwerk', date: '2026-08-27', start: '09:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-08-24-0900', project: 'perspektivwerk', date: '2026-08-24', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-24-1100', project: 'perspektivwerk', date: '2026-08-24', start: '11:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-24-1400', project: 'perspektivwerk', date: '2026-08-24', start: '14:00', title: 'Soz. Päd. Modul', status: 'booked' }, + { id: 'pw-2026-08-18-1000', project: 'perspektivwerk', date: '2026-08-18', start: '10:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-18-1300', project: 'perspektivwerk', date: '2026-08-18', start: '13:00', title: 'Soz. Päd. Modul', status: 'booked' }, + { id: 'pw-2026-08-18-1500', project: 'perspektivwerk', date: '2026-08-18', start: '15:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-26-0900', project: 'perspektivwerk', date: '2026-08-26', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-26-1100', project: 'perspektivwerk', date: '2026-08-26', start: '11:00', title: 'Psy Modul', status: 'booked' }, + { id: 'pw-2026-08-26-1400', project: 'perspektivwerk', date: '2026-08-26', start: '14:00', title: 'Soz. Päd. Modul', status: 'available' }, + { id: 'pw-2026-08-20-0900', project: 'perspektivwerk', date: '2026-08-20', start: '09:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-08-20-1100', project: 'perspektivwerk', date: '2026-08-20', start: '11:00', title: 'Erstgespräch', status: 'booked' }, + { id: 'pw-2026-08-20-1500', project: 'perspektivwerk', date: '2026-08-20', start: '15:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-08-28-0900', project: 'perspektivwerk', date: '2026-08-28', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-28-1100', project: 'perspektivwerk', date: '2026-08-28', start: '11:00', title: 'Soz. Päd. Modul', status: 'available' }, + { id: 'pw-2026-08-28-1400', project: 'perspektivwerk', date: '2026-08-28', start: '14:00', title: 'Erstgespräch', status: 'booked' }, { id: 'pw-2026-08-31-0800', project: 'perspektivwerk', date: '2026-08-31', start: '08:00', title: 'Praxis Modul', status: 'available' }, + { id: 'pw-2026-09-02-0900', project: 'perspektivwerk', date: '2026-09-02', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-02-1100', project: 'perspektivwerk', date: '2026-09-02', start: '11:00', title: 'Soz. Päd. Modul', status: 'booked' }, + { id: 'pw-2026-09-02-1400', project: 'perspektivwerk', date: '2026-09-02', start: '14:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-09-07-0900', project: 'perspektivwerk', date: '2026-09-07', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-07-1300', project: 'perspektivwerk', date: '2026-09-07', start: '13:00', title: 'Soz. Päd. Modul', status: 'available' }, + { id: 'pw-2026-09-10-0900', project: 'perspektivwerk', date: '2026-09-10', start: '09:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-09-10-1100', project: 'perspektivwerk', date: '2026-09-10', start: '11:00', title: 'Erstgespräch', status: 'booked' }, + { id: 'pw-2026-09-10-1500', project: 'perspektivwerk', date: '2026-09-10', start: '15:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-15-0900', project: 'perspektivwerk', date: '2026-09-15', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-15-1100', project: 'perspektivwerk', date: '2026-09-15', start: '11:00', title: 'Soz. Päd. Modul', status: 'available' }, + { id: 'pw-2026-09-15-1400', project: 'perspektivwerk', date: '2026-09-15', start: '14:00', title: 'Psy Modul', status: 'booked' }, + { id: 'pw-2026-09-18-0900', project: 'perspektivwerk', date: '2026-09-18', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-18-1300', project: 'perspektivwerk', date: '2026-09-18', start: '13:00', title: 'Soz. Päd. Modul', status: 'booked' }, + { id: 'pw-2026-09-22-1000', project: 'perspektivwerk', date: '2026-09-22', start: '10:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-22-1400', project: 'perspektivwerk', date: '2026-09-22', start: '14:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-09-25-0900', project: 'perspektivwerk', date: '2026-09-25', start: '09:00', title: 'Soz. Päd. Modul', status: 'available' }, + { id: 'pw-2026-09-25-1100', project: 'perspektivwerk', date: '2026-09-25', start: '11:00', title: 'Erstgespräch', status: 'booked' }, + { id: 'pw-2026-09-29-0900', project: 'perspektivwerk', date: '2026-09-29', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-29-1100', project: 'perspektivwerk', date: '2026-09-29', start: '11:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-09-29-1400', project: 'perspektivwerk', date: '2026-09-29', start: '14:00', title: 'Soz. Päd. Modul', status: 'booked' }, { id: 'ps-2026-08-25-1000', project: 'produktionsschule', date: '2026-08-25', start: '10:00', title: 'Kennenlerntermin', status: 'available' }, { id: 'ps-2026-08-25-1300', project: 'produktionsschule', date: '2026-08-25', start: '13:00', title: 'Kennenlerntermin', status: 'booked' }, { id: 'ps-2026-08-31-0800', project: 'produktionsschule', date: '2026-08-31', start: '08:00', title: 'Probearbeiten', status: 'available' } @@ -12,14 +43,47 @@ const demoSlots = [ export function getSlotsForDate(project, date) { return demoSlots.filter((slot) => slot.project === project && slot.date === date); } +export function validateBookingField(fieldName, value) { + const text = typeof value === 'string' ? value.trim() : ''; + if (fieldName === 'name') + return text ? '' : 'Bitte geben Sie Ihren Namen ein.'; + if (fieldName === 'email') + return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(text) ? '' : 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'; + if (fieldName === 'phone') + return !text || /^[0-9+()\-/\s]{6,}$/.test(text) ? '' : 'Bitte geben Sie eine gültige Telefonnummer ein.'; + if (fieldName === 'age') + return !text || (/^\d+$/.test(text) && Number(text) >= 12 && Number(text) <= 112) ? '' : 'Bitte geben Sie ein Alter zwischen 12 und 112 Jahren ein.'; + if (fieldName === 'message') + return text.length <= 2000 ? '' : 'Die Nachricht darf höchstens 2.000 Zeichen enthalten.'; + if (fieldName === 'caseWorker') + return text.length <= 160 ? '' : 'Die Angabe darf höchstens 160 Zeichen enthalten.'; + if (fieldName === 'privacy') + return value ? '' : 'Bitte bestätigen Sie die Datenschutzhinweise.'; + return ''; +} +export function validateBookingForm({ name = '', email = '', phone = '', age = '', message = '', caseWorker = '', privacyAccepted = false }) { + const values = { name, email, phone, age, message, caseWorker, privacy: privacyAccepted }; + return Object.fromEntries(Object.entries(values) + .map(([fieldName, value]) => [fieldName, validateBookingField(fieldName, value)]) + .filter(([, error]) => error)); +} +export function canSubmitBookingForm(privacyAccepted) { + return privacyAccepted; +} +export function bookingConfirmationMessage(appointmentTitle) { + return `Ihre Terminanfrage für ${appointmentTitle} wurde erfolgreich übermittelt.`; +} const dateFormatter = new Intl.DateTimeFormat('de-DE', { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }); const monthFormatter = new Intl.DateTimeFormat('de-DE', { month: 'long', year: 'numeric' }); const weekdays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']; function parseDate(value) { return new Date(`${value}T12:00:00`); } -function formatDateKey(date) { - return date.toISOString().slice(0, 10); +export function formatDateKey(date) { + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; } function createMonthDates(month) { const first = new Date(month.getFullYear(), month.getMonth(), 1); @@ -35,6 +99,145 @@ function monthForProject(project) { const firstSlot = demoSlots.find((slot) => slot.project === project); return firstSlot ? new Date(parseDate(firstSlot.date).getFullYear(), parseDate(firstSlot.date).getMonth(), 1) : new Date(); } +function escapeHtml(value) { + return value.replace(/[&<>'"]/g, (character) => ({ '&': '&', '<': '<', '>': '>', "'": ''', '"': '"' })[character]); +} +function showFieldError(form, fieldName, error) { + const field = form.elements.namedItem(fieldName); + const errorId = `sufw-booking-${fieldName}-error`; + let message = form.querySelector(`#${errorId}`); + if (!message) { + message = document.createElement('span'); + message.id = errorId; + message.className = 'sufw-booking__field-error'; + message.setAttribute('role', 'alert'); + message.style.display = 'block'; + message.style.marginTop = '.35rem'; + message.style.color = '#6c0808'; + message.style.fontWeight = '400'; + const host = fieldName === 'privacy' ? field.closest('label') : field; + host.insertAdjacentElement('afterend', message); + field.setAttribute('aria-describedby', errorId); + } + message.textContent = error; + message.hidden = !error; + field.setAttribute('aria-invalid', error ? 'true' : 'false'); +} +function openConfirmationDialog(container, slot) { + const projectTitle = slot.project === 'perspektivwerk' ? 'PerspektivWerk' : 'Produktionsschule'; + const dialog = document.createElement('dialog'); + dialog.className = 'sufw-booking__dialog'; + dialog.setAttribute('aria-labelledby', 'sufw-booking-confirmation-title'); + dialog.innerHTML = ` +
+
+

Termin angefragt

+

Vielen Dank für Ihre Anfrage

+

${escapeHtml(bookingConfirmationMessage(slot.title))}

+
+

${escapeHtml(projectTitle)}
${escapeHtml(dateFormatter.format(parseDate(slot.date)))} · ${escapeHtml(slot.start)} Uhr · ${escapeHtml(slot.title)}

+

Wir senden Ihnen eine E-Mail zur Bestätigung Ihres Termins.

+
+
`; + dialog.querySelector('[data-close-confirmation]').addEventListener('click', () => dialog.close()); + dialog.addEventListener('close', () => dialog.remove()); + container.append(dialog); + if (typeof dialog.showModal === 'function') { + dialog.showModal(); + } + else { + dialog.setAttribute('open', ''); + dialog.querySelector('[data-close-confirmation]').focus(); + } +} +function openBookingDialog(container, slot) { + const projectTitle = slot.project === 'perspektivwerk' ? 'PerspektivWerk' : 'Produktionsschule'; + const dialog = document.createElement('dialog'); + dialog.className = 'sufw-booking__dialog'; + dialog.setAttribute('aria-labelledby', 'sufw-booking-form-title'); + dialog.innerHTML = ` +
+
+

Termin anfragen

+

Ihre Angaben

+

${escapeHtml(projectTitle)}
${escapeHtml(dateFormatter.format(parseDate(slot.date)))} · ${escapeHtml(slot.start)} Uhr · ${escapeHtml(slot.title)}

+
+

Pflichtfeld

+
+ + + + +
+ + + +
+
`; + const form = dialog.querySelector('form'); + const privacy = form.elements.namedItem('privacy'); + const submitButton = dialog.querySelector('[data-submit-booking]'); + const actions = dialog.querySelector('.sufw-booking__form-actions'); + dialog.style.overflowY = 'auto'; + actions.style.position = 'sticky'; + actions.style.bottom = '0'; + actions.style.zIndex = '2'; + actions.style.display = 'flex'; + actions.style.visibility = 'visible'; + actions.style.opacity = '1'; + actions.style.backgroundColor = '#fff'; + actions.style.paddingTop = '.75rem'; + const fieldNames = ['name', 'email', 'phone', 'age', 'message', 'caseWorker', 'privacy']; + const validateField = (fieldName) => { + const field = form.elements.namedItem(fieldName); + const value = fieldName === 'privacy' ? field.checked : field.value; + const error = validateBookingField(fieldName, value); + showFieldError(form, fieldName, error); + return error; + }; + const updateSubmitButton = () => { + submitButton.disabled = !canSubmitBookingForm(privacy.checked); + submitButton.hidden = false; + submitButton.style.display = 'inline-block'; + submitButton.style.visibility = 'visible'; + submitButton.style.opacity = '1'; + submitButton.style.position = 'relative'; + submitButton.style.zIndex = '3'; + submitButton.style.minHeight = '2.75rem'; + }; + fieldNames.forEach((fieldName) => { + const field = form.elements.namedItem(fieldName); + const eventName = fieldName === 'privacy' ? 'change' : 'input'; + field.addEventListener(eventName, () => validateField(fieldName)); + if (fieldName !== 'privacy') + field.addEventListener('blur', () => validateField(fieldName)); + }); + privacy.addEventListener('change', updateSubmitButton); + updateSubmitButton(); + form.addEventListener('submit', (event) => { + event.preventDefault(); + const errors = Object.fromEntries(fieldNames + .map((fieldName) => [fieldName, validateField(fieldName)]) + .filter(([, error]) => error)); + if (Object.keys(errors).length) { + const firstInvalid = form.elements.namedItem(Object.keys(errors)[0]); + firstInvalid.focus(); + return; + } + dialog.close(); + openConfirmationDialog(container, slot); + }); + dialog.querySelector('[data-close-dialog]').addEventListener('click', () => dialog.close()); + dialog.addEventListener('close', () => dialog.remove()); + container.append(dialog); + if (typeof dialog.showModal === 'function') { + dialog.showModal(); + } + else { + dialog.setAttribute('open', ''); + dialog.querySelector('input[name="name"]').focus(); + } +} function renderComponent(container) { const configuredProject = container.dataset.project; const project = configuredProject === 'produktionsschule' ? 'produktionsschule' : 'perspektivwerk'; @@ -46,7 +249,7 @@ function renderComponent(container) { container.innerHTML = `
-

Terminbuchung – Vorschau

+

Terminbuchung

${project === 'perspektivwerk' ? 'PerspektivWerk' : 'Produktionsschule'}

Wählen Sie einen Tag. Freie Termine sind mit „frei“ gekennzeichnet.

@@ -73,7 +276,7 @@ function renderComponent(container) {

Termine am ${selectedLabel}

- ${slots.length ? `` : '

Für diesen Tag liegen in der Vorschau keine Termine vor.

'} + ${slots.length ? `` : '

Für diesen Tag liegen keine Termine vor.

'}

`; @@ -89,11 +292,11 @@ function renderComponent(container) { selectedDate = button.dataset.date ?? ''; render(); })); - container.querySelectorAll('[data-slot-id]').forEach((button) => button.addEventListener('click', () => { - const status = container.querySelector('.sufw-booking__status'); - if (status) - status.textContent = 'Vorschau: Die eigentliche Buchungsmaske wird im nächsten Schritt ergänzt.'; - })); + container.querySelectorAll('[data-slot-id]').forEach((button) => button.addEventListener('click', () => { + const slot = demoSlots.find((entry) => entry.id === button.dataset.slotId); + if (slot) + openBookingDialog(container, slot); + })); }; render(); } diff --git a/development-system/public/perspektivwerk/js/booking.css b/development-system/public/perspektivwerk/js/booking.css index 3508ea7..65b464f 100644 --- a/development-system/public/perspektivwerk/js/booking.css +++ b/development-system/public/perspektivwerk/js/booking.css @@ -1 +1,329 @@ -.sufw-booking{--sufw-booking-green:#08752a;--sufw-booking-text:#202020;--sufw-booking-muted:#5a5a5a;--sufw-booking-line:#c7c7c7;--sufw-booking-pale:#f3f6f3;box-sizing:border-box;max-width:860px;margin:2rem auto;padding:1.25rem;color:var(--sufw-booking-text);background:#fff;border:1px solid var(--sufw-booking-line);font:1rem/1.5 Arial,"Helvetica Neue",sans-serif}.sufw-booking *{box-sizing:border-box}.sufw-booking__header h2,.sufw-booking__slots h3{margin:.15rem 0 .5rem;color:var(--sufw-booking-green);font-size:1.4rem}.sufw-booking__header p{margin:.3rem 0}.sufw-booking__eyebrow{color:var(--sufw-booking-green);font-size:.875rem;font-weight:700;text-transform:uppercase;letter-spacing:.04em}.sufw-booking__legend{display:flex;gap:1rem;flex-wrap:wrap;margin:1.25rem 0;font-size:.9rem}.sufw-booking__marker{display:inline-block;width:.8rem;height:.8rem;margin-right:.35rem;border-radius:50%}.sufw-booking__marker--available{background:var(--sufw-booking-green)}.sufw-booking__marker--booked{background:#535353}.sufw-booking__month-nav{display:grid;grid-template-columns:3rem 1fr 3rem;align-items:center;margin-top:1rem;text-align:center}.sufw-booking__month-nav h3{margin:0;font-size:1.1rem;text-transform:capitalize}.sufw-booking__nav,.sufw-booking__day,.sufw-booking__slot{font:inherit}.sufw-booking__nav{min-width:2.75rem;min-height:2.75rem;border:1px solid var(--sufw-booking-green);color:var(--sufw-booking-green);background:#fff;font-size:1.7rem;cursor:pointer}.sufw-booking__nav:hover,.sufw-booking__nav:focus-visible{background:var(--sufw-booking-pale)}.sufw-booking__weekdays,.sufw-booking__calendar{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:.3rem}.sufw-booking__weekdays{margin-top:1rem;text-align:center;font-weight:700;font-size:.8rem}.sufw-booking__day{display:grid;place-items:center;gap:.1rem;min-height:3.8rem;padding:.25rem;border:1px solid transparent;background:#fff;color:var(--sufw-booking-text);cursor:pointer}.sufw-booking__day:hover{border-color:var(--sufw-booking-green);background:var(--sufw-booking-pale)}.sufw-booking__day--available{background:#dff3e4;border-color:var(--sufw-booking-green)}.sufw-booking__day--booked{background:#ececec;border-color:#777}.sufw-booking__day.is-selected{outline:3px solid #1f4fbc;outline-offset:1px}.sufw-booking__day small{font-size:.7rem}.sufw-booking__empty{min-height:3.8rem}.sufw-booking__slots{margin-top:1.5rem;padding-top:1.25rem;border-top:1px solid var(--sufw-booking-line)}.sufw-booking__slots ul{padding:0;margin:0;list-style:none}.sufw-booking__slot{display:grid;grid-template-columns:5rem 1fr auto;gap:.7rem;width:100%;margin:.45rem 0;padding:.8rem;text-align:left;color:var(--sufw-booking-text);background:#fff;border:1px solid var(--sufw-booking-green);cursor:pointer}.sufw-booking__slot:hover,.sufw-booking__slot:focus-visible{background:var(--sufw-booking-pale)}.sufw-booking__slot em{color:var(--sufw-booking-green);font-style:normal;font-weight:700}.sufw-booking__slot:disabled{border-color:#777;background:#eee;color:#555;cursor:not-allowed}.sufw-booking__slot:disabled em{color:#555}.sufw-booking__empty-state,.sufw-booking__status{margin:.7rem 0}.sufw-booking__status{font-weight:700}@media (max-width:520px){.sufw-booking{margin:1rem 0;padding:1rem}.sufw-booking__weekdays{font-size:.7rem}.sufw-booking__day{min-height:3.4rem;padding:.15rem}.sufw-booking__slot{grid-template-columns:1fr;gap:.15rem}.sufw-booking__slot strong{font-size:1.1rem}} +.sufw-booking { + --sufw-booking-green: #08752a; + --sufw-booking-text: #202020; + --sufw-booking-muted: #5a5a5a; + --sufw-booking-line: #c7c7c7; + --sufw-booking-pale: #f3f6f3; + box-sizing: border-box; + max-width: 860px; + margin: 2rem auto; + padding: 1.25rem; + color: var(--sufw-booking-text); + background: #fff; + border: 1px solid var(--sufw-booking-line); + font: 1rem/1.5 Arial, "Helvetica Neue", sans-serif; +} +.sufw-booking * { + box-sizing: border-box; +} +.sufw-booking__header h2, +.sufw-booking__slots h3 { + margin: 0.15rem 0 0.5rem; + color: var(--sufw-booking-green); + font-size: 1.4rem; +} +.sufw-booking__header p { + margin: 0.3rem 0; +} +.sufw-booking__eyebrow { + color: var(--sufw-booking-green); + font-size: 0.875rem; + font-weight: 700; + text-transform: uppercase; + letter-spacing: 0.04em; +} +.sufw-booking__legend { + display: flex; + gap: 1rem; + flex-wrap: wrap; + margin: 1.25rem 0; + font-size: 0.9rem; +} +.sufw-booking__marker { + display: inline-block; + width: 0.8rem; + height: 0.8rem; + margin-right: 0.35rem; + border-radius: 50%; +} +.sufw-booking__marker--available { + background: var(--sufw-booking-green); +} +.sufw-booking__marker--booked { + background: #535353; +} +.sufw-booking__month-nav { + display: grid; + grid-template-columns: 3rem 1fr 3rem; + align-items: center; + margin-top: 1rem; + text-align: center; +} +.sufw-booking__month-nav h3 { + margin: 0; + font-size: 1.1rem; + text-transform: capitalize; +} +.sufw-booking__nav, +.sufw-booking__day, +.sufw-booking__slot { + font: inherit; +} +.sufw-booking__nav { + min-width: 2.75rem; + min-height: 2.75rem; + border: 1px solid var(--sufw-booking-green); + color: var(--sufw-booking-green); + background: #fff; + font-size: 1.7rem; + cursor: pointer; +} +.sufw-booking__nav:hover, +.sufw-booking__nav:focus-visible { + background: var(--sufw-booking-pale); +} +.sufw-booking__weekdays, +.sufw-booking__calendar { + display: grid; + grid-template-columns: repeat(7, minmax(0, 1fr)); + gap: 0.3rem; +} +.sufw-booking__weekdays { + margin-top: 1rem; + text-align: center; + font-weight: 700; + font-size: 0.8rem; +} +.sufw-booking__day { + display: grid; + place-items: center; + gap: 0.1rem; + min-height: 3.8rem; + padding: 0.25rem; + border: 1px solid transparent; + background: #fff; + color: var(--sufw-booking-text); + cursor: pointer; +} +.sufw-booking__day:hover { + border-color: var(--sufw-booking-green); + background: var(--sufw-booking-pale); +} +.sufw-booking__day--available { + background: #dff3e4; + border-color: var(--sufw-booking-green); +} +.sufw-booking__day--booked { + background: #ececec; + border-color: #777; +} +.sufw-booking__day.is-selected { + outline: 3px solid #1f4fbc; + outline-offset: 1px; +} +.sufw-booking__day small { + font-size: 0.7rem; +} +.sufw-booking__empty { + min-height: 3.8rem; +} +.sufw-booking__slots { + margin-top: 1.5rem; + padding-top: 1.25rem; + border-top: 1px solid var(--sufw-booking-line); +} +.sufw-booking__slots ul { + padding: 0; + margin: 0; + list-style: none; +} +.sufw-booking__slot { + display: grid; + grid-template-columns: 5rem 1fr auto; + gap: 0.7rem; + width: 100%; + margin: 0.45rem 0; + padding: 0.8rem; + text-align: left; + color: var(--sufw-booking-text); + background: #fff; + border: 1px solid var(--sufw-booking-green); + cursor: pointer; +} +.sufw-booking__slot:hover, +.sufw-booking__slot:focus-visible { + background: var(--sufw-booking-pale); +} +.sufw-booking__slot em { + color: var(--sufw-booking-green); + font-style: normal; + font-weight: 700; +} +.sufw-booking__slot:disabled { + border-color: #777; + background: #eee; + color: #555; + cursor: not-allowed; +} +.sufw-booking__slot:disabled em { + color: #555; +} +.sufw-booking__empty-state, +.sufw-booking__status { + margin: 0.7rem 0; +} +.sufw-booking__status { + font-weight: 700; +} +.sufw-booking__dialog { + width: min(42rem, calc(100% - 2rem)); + max-height: calc(100vh - 2rem); + padding: 0; + border: 0; + color: var(--sufw-booking-text); + box-shadow: 0 0.75rem 2.5rem rgba(0, 0, 0, 0.35); + font: 1rem/1.5 Arial, "Helvetica Neue", sans-serif; +} +.sufw-booking__dialog::backdrop { + background: rgba(0, 0, 0, 0.62); +} +.sufw-booking__form { + display: grid; + gap: 1rem; + padding: 1.25rem; +} +.sufw-booking__form-header { + padding-bottom: 1rem; + border-bottom: 1px solid var(--sufw-booking-line); +} +.sufw-booking__form-header h2 { + margin: 0.15rem 0 0.5rem; + color: var(--sufw-booking-green); + font-size: 1.5rem; +} +.sufw-booking__appointment, +.sufw-booking__required, +.sufw-booking__prototype-note { + margin: 0.35rem 0; +} +.sufw-booking__required { + font-size: 0.875rem; +} +.sufw-booking__optional { + color: var(--sufw-booking-muted); + font-size: 0.875rem; + font-weight: 400; +} +.sufw-booking__form-grid { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 1rem; +} +.sufw-booking__form label { + display: grid; + gap: 0.35rem; + font-weight: 700; +} +.sufw-booking__form input, +.sufw-booking__form textarea { + width: 100%; + padding: 0.65rem; + border: 1px solid #767676; + color: var(--sufw-booking-text); + font: inherit; +} +.sufw-booking__form input:focus-visible, +.sufw-booking__form textarea:focus-visible, +.sufw-booking__form button:focus-visible { + outline: 3px solid #1f4fbc; + outline-offset: 2px; +} +.sufw-booking__consent { + grid-template-columns: auto 1fr; + align-items: start; + font-weight: 400 !important; +} +.sufw-booking__consent input { + width: 1.1rem !important; + height: 1.1rem; + margin-top: 0.25rem; +} +.sufw-booking__form-errors:empty { + display: none; +} +.sufw-booking__form-errors { + padding: 0.75rem; + border-left: 4px solid #a31111; + background: #fff1f1; + color: #6c0808; +} +.sufw-booking__form-errors ul { + margin: 0; + padding-left: 1.25rem; +} +.sufw-booking__prototype-note { + padding: 0.75rem; + background: var(--sufw-booking-pale); + font-size: 0.9rem; +} +.sufw-booking__form-status { + margin: 0; + color: var(--sufw-booking-green); + font-weight: 700; +} +.sufw-booking__form-actions { + display: flex; + justify-content: flex-end; + gap: 0.75rem; + flex-wrap: wrap; +} +.sufw-booking__form-actions button { + padding: 0.7rem 1rem; + border: 1px solid var(--sufw-booking-green); + background-color: #08752a; + color: #fff; + font: inherit; + font-weight: 700; + cursor: pointer; +} +.sufw-booking__form-actions button:hover:not(:disabled) { + border-color: #05571f; + background-color: #05571f; + color: #fff; +} +.sufw-booking__form-actions button:disabled { + border-color: #777; + background-color: #d8d8d8; + color: #555; + cursor: not-allowed; +} +.sufw-booking__form-actions .sufw-booking__secondary { + background-color: #fff; + color: var(--sufw-booking-green); +} +@media (max-width: 520px) { + .sufw-booking { + margin: 1rem 0; + padding: 1rem; + } + .sufw-booking__weekdays { + font-size: 0.7rem; + } + .sufw-booking__day { + min-height: 3.4rem; + padding: 0.15rem; + } + .sufw-booking__slot { + grid-template-columns: 1fr; + gap: 0.15rem; + } + .sufw-booking__slot strong { + font-size: 1.1rem; + } + .sufw-booking__form-grid { + grid-template-columns: 1fr; + } + .sufw-booking__form-actions button { + width: 100%; + } +} diff --git a/development-system/public/perspektivwerk/js/booking.js b/development-system/public/perspektivwerk/js/booking.js index 1e0ba03..88e8eaf 100644 --- a/development-system/public/perspektivwerk/js/booking.js +++ b/development-system/public/perspektivwerk/js/booking.js @@ -1,10 +1,41 @@ /* Browsernatives ES-Modul; wird ohne TypeScript-Compiler ausgeliefert. */ const demoSlots = [ - { id: 'pw-2026-08-25-1000', project: 'perspektivwerk', date: '2026-08-25', start: '10:00', title: 'Erstgespräch', status: 'available' }, - { id: 'pw-2026-08-25-1300', project: 'perspektivwerk', date: '2026-08-25', start: '13:00', title: 'Soz. Päd. Modul', status: 'booked' }, - { id: 'pw-2026-08-25-1500', project: 'perspektivwerk', date: '2026-08-25', start: '15:00', title: 'Erstgespräch', status: 'available' }, - { id: 'pw-2026-08-27-0900', project: 'perspektivwerk', date: '2026-08-27', start: '09:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-08-24-0900', project: 'perspektivwerk', date: '2026-08-24', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-24-1100', project: 'perspektivwerk', date: '2026-08-24', start: '11:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-24-1400', project: 'perspektivwerk', date: '2026-08-24', start: '14:00', title: 'Soz. Päd. Modul', status: 'booked' }, + { id: 'pw-2026-08-18-1000', project: 'perspektivwerk', date: '2026-08-18', start: '10:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-18-1300', project: 'perspektivwerk', date: '2026-08-18', start: '13:00', title: 'Soz. Päd. Modul', status: 'booked' }, + { id: 'pw-2026-08-18-1500', project: 'perspektivwerk', date: '2026-08-18', start: '15:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-26-0900', project: 'perspektivwerk', date: '2026-08-26', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-26-1100', project: 'perspektivwerk', date: '2026-08-26', start: '11:00', title: 'Psy Modul', status: 'booked' }, + { id: 'pw-2026-08-26-1400', project: 'perspektivwerk', date: '2026-08-26', start: '14:00', title: 'Soz. Päd. Modul', status: 'available' }, + { id: 'pw-2026-08-20-0900', project: 'perspektivwerk', date: '2026-08-20', start: '09:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-08-20-1100', project: 'perspektivwerk', date: '2026-08-20', start: '11:00', title: 'Erstgespräch', status: 'booked' }, + { id: 'pw-2026-08-20-1500', project: 'perspektivwerk', date: '2026-08-20', start: '15:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-08-28-0900', project: 'perspektivwerk', date: '2026-08-28', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-08-28-1100', project: 'perspektivwerk', date: '2026-08-28', start: '11:00', title: 'Soz. Päd. Modul', status: 'available' }, + { id: 'pw-2026-08-28-1400', project: 'perspektivwerk', date: '2026-08-28', start: '14:00', title: 'Erstgespräch', status: 'booked' }, { id: 'pw-2026-08-31-0800', project: 'perspektivwerk', date: '2026-08-31', start: '08:00', title: 'Praxis Modul', status: 'available' }, + { id: 'pw-2026-09-02-0900', project: 'perspektivwerk', date: '2026-09-02', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-02-1100', project: 'perspektivwerk', date: '2026-09-02', start: '11:00', title: 'Soz. Päd. Modul', status: 'booked' }, + { id: 'pw-2026-09-02-1400', project: 'perspektivwerk', date: '2026-09-02', start: '14:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-09-07-0900', project: 'perspektivwerk', date: '2026-09-07', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-07-1300', project: 'perspektivwerk', date: '2026-09-07', start: '13:00', title: 'Soz. Päd. Modul', status: 'available' }, + { id: 'pw-2026-09-10-0900', project: 'perspektivwerk', date: '2026-09-10', start: '09:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-09-10-1100', project: 'perspektivwerk', date: '2026-09-10', start: '11:00', title: 'Erstgespräch', status: 'booked' }, + { id: 'pw-2026-09-10-1500', project: 'perspektivwerk', date: '2026-09-10', start: '15:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-15-0900', project: 'perspektivwerk', date: '2026-09-15', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-15-1100', project: 'perspektivwerk', date: '2026-09-15', start: '11:00', title: 'Soz. Päd. Modul', status: 'available' }, + { id: 'pw-2026-09-15-1400', project: 'perspektivwerk', date: '2026-09-15', start: '14:00', title: 'Psy Modul', status: 'booked' }, + { id: 'pw-2026-09-18-0900', project: 'perspektivwerk', date: '2026-09-18', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-18-1300', project: 'perspektivwerk', date: '2026-09-18', start: '13:00', title: 'Soz. Päd. Modul', status: 'booked' }, + { id: 'pw-2026-09-22-1000', project: 'perspektivwerk', date: '2026-09-22', start: '10:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-22-1400', project: 'perspektivwerk', date: '2026-09-22', start: '14:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-09-25-0900', project: 'perspektivwerk', date: '2026-09-25', start: '09:00', title: 'Soz. Päd. Modul', status: 'available' }, + { id: 'pw-2026-09-25-1100', project: 'perspektivwerk', date: '2026-09-25', start: '11:00', title: 'Erstgespräch', status: 'booked' }, + { id: 'pw-2026-09-29-0900', project: 'perspektivwerk', date: '2026-09-29', start: '09:00', title: 'Erstgespräch', status: 'available' }, + { id: 'pw-2026-09-29-1100', project: 'perspektivwerk', date: '2026-09-29', start: '11:00', title: 'Psy Modul', status: 'available' }, + { id: 'pw-2026-09-29-1400', project: 'perspektivwerk', date: '2026-09-29', start: '14:00', title: 'Soz. Päd. Modul', status: 'booked' }, { id: 'ps-2026-08-25-1000', project: 'produktionsschule', date: '2026-08-25', start: '10:00', title: 'Kennenlerntermin', status: 'available' }, { id: 'ps-2026-08-25-1300', project: 'produktionsschule', date: '2026-08-25', start: '13:00', title: 'Kennenlerntermin', status: 'booked' }, { id: 'ps-2026-08-31-0800', project: 'produktionsschule', date: '2026-08-31', start: '08:00', title: 'Probearbeiten', status: 'available' } @@ -12,14 +43,47 @@ const demoSlots = [ export function getSlotsForDate(project, date) { return demoSlots.filter((slot) => slot.project === project && slot.date === date); } +export function validateBookingField(fieldName, value) { + const text = typeof value === 'string' ? value.trim() : ''; + if (fieldName === 'name') + return text ? '' : 'Bitte geben Sie Ihren Namen ein.'; + if (fieldName === 'email') + return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(text) ? '' : 'Bitte geben Sie eine gültige E-Mail-Adresse ein.'; + if (fieldName === 'phone') + return !text || /^[0-9+()\-/\s]{6,}$/.test(text) ? '' : 'Bitte geben Sie eine gültige Telefonnummer ein.'; + if (fieldName === 'age') + return !text || (/^\d+$/.test(text) && Number(text) >= 12 && Number(text) <= 112) ? '' : 'Bitte geben Sie ein Alter zwischen 12 und 112 Jahren ein.'; + if (fieldName === 'message') + return text.length <= 2000 ? '' : 'Die Nachricht darf höchstens 2.000 Zeichen enthalten.'; + if (fieldName === 'caseWorker') + return text.length <= 160 ? '' : 'Die Angabe darf höchstens 160 Zeichen enthalten.'; + if (fieldName === 'privacy') + return value ? '' : 'Bitte bestätigen Sie die Datenschutzhinweise.'; + return ''; +} +export function validateBookingForm({ name = '', email = '', phone = '', age = '', message = '', caseWorker = '', privacyAccepted = false }) { + const values = { name, email, phone, age, message, caseWorker, privacy: privacyAccepted }; + return Object.fromEntries(Object.entries(values) + .map(([fieldName, value]) => [fieldName, validateBookingField(fieldName, value)]) + .filter(([, error]) => error)); +} +export function canSubmitBookingForm(privacyAccepted) { + return privacyAccepted; +} +export function bookingConfirmationMessage(appointmentTitle) { + return `Ihre Terminanfrage für ${appointmentTitle} wurde erfolgreich übermittelt.`; +} const dateFormatter = new Intl.DateTimeFormat('de-DE', { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }); const monthFormatter = new Intl.DateTimeFormat('de-DE', { month: 'long', year: 'numeric' }); const weekdays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']; function parseDate(value) { return new Date(`${value}T12:00:00`); } -function formatDateKey(date) { - return date.toISOString().slice(0, 10); +export function formatDateKey(date) { + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; } function createMonthDates(month) { const first = new Date(month.getFullYear(), month.getMonth(), 1); @@ -35,6 +99,145 @@ function monthForProject(project) { const firstSlot = demoSlots.find((slot) => slot.project === project); return firstSlot ? new Date(parseDate(firstSlot.date).getFullYear(), parseDate(firstSlot.date).getMonth(), 1) : new Date(); } +function escapeHtml(value) { + return value.replace(/[&<>'"]/g, (character) => ({ '&': '&', '<': '<', '>': '>', "'": ''', '"': '"' })[character]); +} +function showFieldError(form, fieldName, error) { + const field = form.elements.namedItem(fieldName); + const errorId = `sufw-booking-${fieldName}-error`; + let message = form.querySelector(`#${errorId}`); + if (!message) { + message = document.createElement('span'); + message.id = errorId; + message.className = 'sufw-booking__field-error'; + message.setAttribute('role', 'alert'); + message.style.display = 'block'; + message.style.marginTop = '.35rem'; + message.style.color = '#6c0808'; + message.style.fontWeight = '400'; + const host = fieldName === 'privacy' ? field.closest('label') : field; + host.insertAdjacentElement('afterend', message); + field.setAttribute('aria-describedby', errorId); + } + message.textContent = error; + message.hidden = !error; + field.setAttribute('aria-invalid', error ? 'true' : 'false'); +} +function openConfirmationDialog(container, slot) { + const projectTitle = slot.project === 'perspektivwerk' ? 'PerspektivWerk' : 'Produktionsschule'; + const dialog = document.createElement('dialog'); + dialog.className = 'sufw-booking__dialog'; + dialog.setAttribute('aria-labelledby', 'sufw-booking-confirmation-title'); + dialog.innerHTML = ` +
+
+

Termin angefragt

+

Vielen Dank für Ihre Anfrage

+

${escapeHtml(bookingConfirmationMessage(slot.title))}

+
+

${escapeHtml(projectTitle)}
${escapeHtml(dateFormatter.format(parseDate(slot.date)))} · ${escapeHtml(slot.start)} Uhr · ${escapeHtml(slot.title)}

+

Wir senden Ihnen eine E-Mail zur Bestätigung Ihres Termins.

+
+
`; + dialog.querySelector('[data-close-confirmation]').addEventListener('click', () => dialog.close()); + dialog.addEventListener('close', () => dialog.remove()); + container.append(dialog); + if (typeof dialog.showModal === 'function') { + dialog.showModal(); + } + else { + dialog.setAttribute('open', ''); + dialog.querySelector('[data-close-confirmation]').focus(); + } +} +function openBookingDialog(container, slot) { + const projectTitle = slot.project === 'perspektivwerk' ? 'PerspektivWerk' : 'Produktionsschule'; + const dialog = document.createElement('dialog'); + dialog.className = 'sufw-booking__dialog'; + dialog.setAttribute('aria-labelledby', 'sufw-booking-form-title'); + dialog.innerHTML = ` +
+
+

Termin anfragen

+

Ihre Angaben

+

${escapeHtml(projectTitle)}
${escapeHtml(dateFormatter.format(parseDate(slot.date)))} · ${escapeHtml(slot.start)} Uhr · ${escapeHtml(slot.title)}

+
+

Pflichtfeld

+
+ + + + +
+ + + +
+
`; + const form = dialog.querySelector('form'); + const privacy = form.elements.namedItem('privacy'); + const submitButton = dialog.querySelector('[data-submit-booking]'); + const actions = dialog.querySelector('.sufw-booking__form-actions'); + dialog.style.overflowY = 'auto'; + actions.style.position = 'sticky'; + actions.style.bottom = '0'; + actions.style.zIndex = '2'; + actions.style.display = 'flex'; + actions.style.visibility = 'visible'; + actions.style.opacity = '1'; + actions.style.backgroundColor = '#fff'; + actions.style.paddingTop = '.75rem'; + const fieldNames = ['name', 'email', 'phone', 'age', 'message', 'caseWorker', 'privacy']; + const validateField = (fieldName) => { + const field = form.elements.namedItem(fieldName); + const value = fieldName === 'privacy' ? field.checked : field.value; + const error = validateBookingField(fieldName, value); + showFieldError(form, fieldName, error); + return error; + }; + const updateSubmitButton = () => { + submitButton.disabled = !canSubmitBookingForm(privacy.checked); + submitButton.hidden = false; + submitButton.style.display = 'inline-block'; + submitButton.style.visibility = 'visible'; + submitButton.style.opacity = '1'; + submitButton.style.position = 'relative'; + submitButton.style.zIndex = '3'; + submitButton.style.minHeight = '2.75rem'; + }; + fieldNames.forEach((fieldName) => { + const field = form.elements.namedItem(fieldName); + const eventName = fieldName === 'privacy' ? 'change' : 'input'; + field.addEventListener(eventName, () => validateField(fieldName)); + if (fieldName !== 'privacy') + field.addEventListener('blur', () => validateField(fieldName)); + }); + privacy.addEventListener('change', updateSubmitButton); + updateSubmitButton(); + form.addEventListener('submit', (event) => { + event.preventDefault(); + const errors = Object.fromEntries(fieldNames + .map((fieldName) => [fieldName, validateField(fieldName)]) + .filter(([, error]) => error)); + if (Object.keys(errors).length) { + const firstInvalid = form.elements.namedItem(Object.keys(errors)[0]); + firstInvalid.focus(); + return; + } + dialog.close(); + openConfirmationDialog(container, slot); + }); + dialog.querySelector('[data-close-dialog]').addEventListener('click', () => dialog.close()); + dialog.addEventListener('close', () => dialog.remove()); + container.append(dialog); + if (typeof dialog.showModal === 'function') { + dialog.showModal(); + } + else { + dialog.setAttribute('open', ''); + dialog.querySelector('input[name="name"]').focus(); + } +} function renderComponent(container) { const configuredProject = container.dataset.project; const project = configuredProject === 'produktionsschule' ? 'produktionsschule' : 'perspektivwerk'; @@ -46,7 +249,7 @@ function renderComponent(container) { container.innerHTML = `
-

Terminbuchung – Vorschau

+

Terminbuchung

${project === 'perspektivwerk' ? 'PerspektivWerk' : 'Produktionsschule'}

Wählen Sie einen Tag. Freie Termine sind mit „frei“ gekennzeichnet.

@@ -73,7 +276,7 @@ function renderComponent(container) {

Termine am ${selectedLabel}

- ${slots.length ? `` : '

Für diesen Tag liegen in der Vorschau keine Termine vor.

'} + ${slots.length ? `` : '

Für diesen Tag liegen keine Termine vor.

'}

`; @@ -89,11 +292,11 @@ function renderComponent(container) { selectedDate = button.dataset.date ?? ''; render(); })); - container.querySelectorAll('[data-slot-id]').forEach((button) => button.addEventListener('click', () => { - const status = container.querySelector('.sufw-booking__status'); - if (status) - status.textContent = 'Vorschau: Die eigentliche Buchungsmaske wird im nächsten Schritt ergänzt.'; - })); + container.querySelectorAll('[data-slot-id]').forEach((button) => button.addEventListener('click', () => { + const slot = demoSlots.find((entry) => entry.id === button.dataset.slotId); + if (slot) + openBookingDialog(container, slot); + })); }; render(); } diff --git a/development-system/tests/PerspektivwerkRoute.Tests.ps1 b/development-system/tests/PerspektivwerkRoute.Tests.ps1 index e11f1cd..11a98cf 100644 --- a/development-system/tests/PerspektivwerkRoute.Tests.ps1 +++ b/development-system/tests/PerspektivwerkRoute.Tests.ps1 @@ -28,6 +28,20 @@ Describe 'Perspektivwerk static route' { (Get-FileHash -LiteralPath $bookingStylesPath).Hash | Should Be (Get-FileHash -LiteralPath $contaoBookingStylesPath).Hash } + It 'keeps the enabled submit button visibly rendered' { + $script = Get-Content -LiteralPath $contaoBookingScriptPath -Raw + + $script | Should Match "submitButton\.style\.visibility = 'visible'" + $script | Should Match "actions\.style\.position = 'sticky'" + } + + It 'defines colours for the booking form action buttons' { + $styles = Get-Content -LiteralPath $contaoBookingStylesPath -Raw + + $styles | Should Match '\.sufw-booking__form-actions button\s*\{[^}]*background-color:\s*#08752a' + $styles | Should Match '\.sufw-booking__form-actions button\s*\{[^}]*color:\s*#fff' + } + It 'routes /perspektivwerk to the static entry point before the Contao fallback' { $htaccess = Get-Content -LiteralPath $htaccessPath -Raw $staticRouteIndex = $htaccess.IndexOf('RewriteRule ^perspektivwerk/?$ perspektivwerk/index.html [L]') diff --git a/development-system/tests/booking.test.mjs b/development-system/tests/booking.test.mjs index e52ae20..7c36850 100644 --- a/development-system/tests/booking.test.mjs +++ b/development-system/tests/booking.test.mjs @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import test from 'node:test'; -import { getSlotsForDate } from '../public/booking/booking.js'; +import { bookingConfirmationMessage, canSubmitBookingForm, formatDateKey, getSlotsForDate, validateBookingField, validateBookingForm } from '../public/booking/booking.js'; test('liefert für einen Beispieltag verfügbare und belegte Slots', () => { const slots = getSlotsForDate('perspektivwerk', '2026-08-25'); @@ -14,3 +14,70 @@ test('liefert für einen Beispieltag verfügbare und belegte Slots', () => { test('liefert für einen Tag ohne Termin keine Slots', () => { assert.deepEqual(getSlotsForDate('produktionsschule', '2026-08-20'), []); }); + +test('verschiebt Kalendertage in der Sommerzeit nicht auf den Vortag', () => { + process.env.TZ = 'Europe/Berlin'; + + assert.equal(formatDateKey(new Date(2026, 7, 24)), '2026-08-24'); +}); + +test('liefert Termine im aktuellen und folgenden Monat', () => { + assert.ok(getSlotsForDate('perspektivwerk', '2026-08-24').length >= 2); + assert.ok(getSlotsForDate('perspektivwerk', '2026-08-28').length >= 2); + assert.ok(getSlotsForDate('perspektivwerk', '2026-09-02').length >= 2); + assert.ok(getSlotsForDate('perspektivwerk', '2026-09-15').length >= 2); + assert.ok(getSlotsForDate('perspektivwerk', '2026-09-29').length >= 2); +}); + +test('validiert die Pflichtangaben der Buchungsmaske', () => { + assert.deepEqual( + validateBookingForm({ name: '', email: 'ungültig', privacyAccepted: false }), + { + name: 'Bitte geben Sie Ihren Namen ein.', + email: 'Bitte geben Sie eine gültige E-Mail-Adresse ein.', + privacy: 'Bitte bestätigen Sie die Datenschutzhinweise.' + } + ); +}); + +test('akzeptiert die vollständigen Pflichtangaben der Buchungsmaske', () => { + assert.deepEqual( + validateBookingForm({ name: 'Max Mustermann', email: 'max@example.org', privacyAccepted: true }), + {} + ); +}); + +test('lehnt ein eingegebenes Alter außerhalb von 12 bis 112 ab', () => { + assert.equal( + validateBookingForm({ name: 'Max Mustermann', email: 'max@example.org', age: '11', privacyAccepted: true }).age, + 'Bitte geben Sie ein Alter zwischen 12 und 112 Jahren ein.' + ); + assert.equal( + validateBookingForm({ name: 'Max Mustermann', email: 'max@example.org', age: '113', privacyAccepted: true }).age, + 'Bitte geben Sie ein Alter zwischen 12 und 112 Jahren ein.' + ); +}); + +test('akzeptiert ein leeres oder gültiges optionales Alter', () => { + assert.deepEqual(validateBookingForm({ name: 'Max Mustermann', email: 'max@example.org', age: '', privacyAccepted: true }), {}); + assert.deepEqual(validateBookingForm({ name: 'Max Mustermann', email: 'max@example.org', age: '12', privacyAccepted: true }), {}); + assert.deepEqual(validateBookingForm({ name: 'Max Mustermann', email: 'max@example.org', age: '112', privacyAccepted: true }), {}); +}); + +test('validiert optionale Telefonnummern direkt am Feld', () => { + assert.equal(validateBookingField('phone', 'abc'), 'Bitte geben Sie eine gültige Telefonnummer ein.'); + assert.equal(validateBookingField('phone', '+49 351 123456'), ''); + assert.equal(validateBookingField('phone', ''), ''); +}); + +test('gibt den Absenden-Button erst nach DSGVO-Einwilligung frei', () => { + assert.equal(canSubmitBookingForm(false), false); + assert.equal(canSubmitBookingForm(true), true); +}); + +test('zeigt nach dem Absenden eine Bestätigung ohne Mockup-Hinweis', () => { + const message = bookingConfirmationMessage('Erstgespräch'); + + assert.match(message, /erfolgreich übermittelt/); + assert.doesNotMatch(message, /Vorschau|Mockup/i); +});