add: Kalendereinträge, Eingabeformular und Absenden-Button
This commit is contained in:
1 parent
6a9d31ca5e
commit
037ea11de5
7 files changed
+1173
-30
No files matched your search
@@ -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 = `
|
||||
<section class="sufw-booking__form">
|
||||
<header class="sufw-booking__form-header">
|
||||
<p class="sufw-booking__eyebrow">Termin angefragt</p>
|
||||
<h2 id="sufw-booking-confirmation-title">Vielen Dank für Ihre Anfrage</h2>
|
||||
<p>${escapeHtml(bookingConfirmationMessage(slot.title))}</p>
|
||||
</header>
|
||||
<p class="sufw-booking__appointment"><strong>${escapeHtml(projectTitle)}</strong><br>${escapeHtml(dateFormatter.format(parseDate(slot.date)))} · ${escapeHtml(slot.start)} Uhr · ${escapeHtml(slot.title)}</p>
|
||||
<p>Wir senden Ihnen eine E-Mail zur Bestätigung Ihres Termins.</p>
|
||||
<div class="sufw-booking__form-actions"><button type="button" data-close-confirmation>Schließen</button></div>
|
||||
</section>`;
|
||||
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 = `
|
||||
<form class="sufw-booking__form" novalidate>
|
||||
<header class="sufw-booking__form-header">
|
||||
<p class="sufw-booking__eyebrow">Termin anfragen</p>
|
||||
<h2 id="sufw-booking-form-title">Ihre Angaben</h2>
|
||||
<p class="sufw-booking__appointment"><strong>${escapeHtml(projectTitle)}</strong><br>${escapeHtml(dateFormatter.format(parseDate(slot.date)))} · ${escapeHtml(slot.start)} Uhr · ${escapeHtml(slot.title)}</p>
|
||||
</header>
|
||||
<p class="sufw-booking__required"><span aria-hidden="true">*</span> Pflichtfeld</p>
|
||||
<div class="sufw-booking__form-grid">
|
||||
<label>Vor- und Nachname <span aria-hidden="true">*</span><input name="name" type="text" autocomplete="name" required></label>
|
||||
<label>E-Mail-Adresse <span aria-hidden="true">*</span><input name="email" type="email" autocomplete="email" required></label>
|
||||
<label>Telefonnummer <span class="sufw-booking__optional">freiwillig</span><input name="phone" type="tel" autocomplete="tel"></label>
|
||||
<label>Alter <span class="sufw-booking__optional">freiwillig</span><input name="age" type="number" min="12" max="112" inputmode="numeric"></label>
|
||||
</div>
|
||||
<label>Nachricht <span class="sufw-booking__optional">freiwillig</span><textarea name="message" rows="4"></textarea></label>
|
||||
<label>Ansprechperson bei Agentur für Arbeit oder Jobcenter <span class="sufw-booking__optional">freiwillig</span><input name="caseWorker" type="text"></label>
|
||||
<label class="sufw-booking__consent"><input name="privacy" type="checkbox" value="accepted" required><span>Ich habe die Datenschutzhinweise nach Art. 13 DSGVO gelesen und stimme der Verarbeitung meiner Angaben zur Terminanfrage zu. <span aria-hidden="true">*</span></span></label>
|
||||
<div class="sufw-booking__form-actions"><button type="button" class="sufw-booking__secondary" data-close-dialog>Abbrechen</button><button type="submit" data-submit-booking disabled>Terminanfrage absenden</button></div>
|
||||
</form>`;
|
||||
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 = `
|
||||
<section class="sufw-booking" aria-labelledby="sufw-booking-title">
|
||||
<header class="sufw-booking__header">
|
||||
<p class="sufw-booking__eyebrow">Terminbuchung – Vorschau</p>
|
||||
<p class="sufw-booking__eyebrow">Terminbuchung</p>
|
||||
<h2 id="sufw-booking-title">${project === 'perspektivwerk' ? 'PerspektivWerk' : 'Produktionsschule'}</h2>
|
||||
<p>Wählen Sie einen Tag. Freie Termine sind mit „frei“ gekennzeichnet.</p>
|
||||
</header>
|
||||
@@ -73,7 +276,7 @@ function renderComponent(container) {
|
||||
</div>
|
||||
<section class="sufw-booking__slots" aria-labelledby="sufw-slot-title">
|
||||
<h3 id="sufw-slot-title">Termine am ${selectedLabel}</h3>
|
||||
${slots.length ? `<ul>${slots.map((slot) => `<li><button type="button" class="sufw-booking__slot" data-slot-id="${slot.id}" ${slot.status === 'booked' ? 'disabled aria-disabled="true"' : ''}><strong>${slot.start} Uhr</strong><span>${slot.title}</span><em>${slot.status === 'available' ? 'Verfügbar' : 'Belegt'}</em></button></li>`).join('')}</ul>` : '<p class="sufw-booking__empty-state">Für diesen Tag liegen in der Vorschau keine Termine vor.</p>'}
|
||||
${slots.length ? `<ul>${slots.map((slot) => `<li><button type="button" class="sufw-booking__slot" data-slot-id="${slot.id}" ${slot.status === 'booked' ? 'disabled aria-disabled="true"' : ''}><strong>${slot.start} Uhr</strong><span>${slot.title}</span><em>${slot.status === 'available' ? 'Verfügbar' : 'Belegt'}</em></button></li>`).join('')}</ul>` : '<p class="sufw-booking__empty-state">Für diesen Tag liegen keine Termine vor.</p>'}
|
||||
<p class="sufw-booking__status" role="status" aria-live="polite"></p>
|
||||
</section>
|
||||
</section>`;
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user