Anhänger-anlegen-Button kompakt in den Kopfbereich integrieren

This commit is contained in:
OpenCode 2026-11-13 01:28:34 +01:00
parent b05bda7c96
commit e3d328f55a
4 changed files with 170 additions and 150 deletions

View file

@ -89,7 +89,7 @@ function url(string $path = '/'): string
}
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
const DIC_ASSET_VERSION = '5';
const DIC_ASSET_VERSION = '7';
function asset(string $path): string
{

View file

@ -25,129 +25,135 @@ $createError = static fn (string $key): string => (string) ($createErrors[$key]
</div>
<?php endif; ?>
<details class="card create-trailer"<?= $createErrors ? ' open' : '' ?>>
<summary class="create-trailer__summary">
<span class="create-trailer__title">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg>
Anhänger anlegen
</span>
<span class="create-trailer__hint">Nur bei Bedarf – z. B. für einen zusätzlichen Mietanhänger.</span>
<svg class="ico create-trailer__chevron" aria-hidden="true"><use href="#i-right"/></svg>
</summary>
<div class="create-trailer__body">
<p class="muted small">Neue Anhänger stehen sofort im Kalender und in der Buchungsmaske zur Auswahl. Die Sortierung bestimmt die Reihenfolge der Zeilen.</p>
<?php if ($createErrors): ?>
<div class="alert alert--error" role="alert" style="margin-top: 14px">
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
<div><strong>Bitte die markierten Felder prüfen.</strong>
<?php foreach ($createErrors as $message): ?><p><?= e($message) ?></p><?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<form method="post" action="<?= e(url('/admin/trailers')) ?>" class="form-grid" data-color-row>
<?= csrf_field() ?>
<input type="hidden" name="action" value="create">
<label class="field<?= $createError('label') !== '' ? ' has-error' : '' ?>">
<span>Bezeichnung</span>
<input type="text" name="label" value="<?= e($createValues['label']) ?>" maxlength="40" required placeholder="z. B. Nr. 9">
<?php if ($createError('label')): ?><em class="field-error"><?= e($createError('label')) ?></em><?php endif; ?>
</label>
<label class="field<?= $createError('color_name') !== '' ? ' has-error' : '' ?>">
<span>Farbname</span>
<input type="text" name="color_name" value="<?= e($createValues['color_name']) ?>" maxlength="40" required placeholder="z. B. Türkis">
<?php if ($createError('color_name')): ?><em class="field-error"><?= e($createError('color_name')) ?></em><?php endif; ?>
</label>
<div class="field<?= $createError('color_hex') !== '' ? ' has-error' : '' ?>">
<span>Farbe</span>
<span class="trailer-admin__color">
<input type="color" value="<?= e($createValues['color_hex']) ?>" data-color-sync aria-label="Farbe für den neuen Anhänger">
<input type="text" name="color_hex" value="<?= e($createValues['color_hex']) ?>" maxlength="7" pattern="#[0-9a-fA-F]{6}" class="color-hex" data-color-text aria-label="Farbe als Hex-Wert">
</span>
<span class="trailer-admin__preview" data-color-preview style="--trailer: <?= e($createValues['color_hex']) ?>; --trailer-text: <?= e(contrast_color($createValues['color_hex'])) ?>">
<span class="trailer-dot" style="--trailer: <?= e($createValues['color_hex']) ?>"></span>
<span data-color-preview-label><?= e($createValues['label'] ?: 'Neuer Anhänger') ?></span>
</span>
<?php if ($createError('color_hex')): ?><em class="field-error"><?= e($createError('color_hex')) ?></em><?php endif; ?>
</div>
<label class="field">
<span>Sortierung</span>
<input type="number" name="sort_order" value="<?= (int) $createValues['sort_order'] ?>" step="10">
</label>
<div class="field">
<span>Status</span>
<label class="check check--boxed">
<input type="hidden" name="active" value="0">
<input type="checkbox" name="active" value="1"<?= (int) $createValues['active'] === 1 ? ' checked' : '' ?>>
<span>Anhänger ist aktiv</span>
</label>
</div>
<div class="field field--wide">
<button class="btn primary" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Anhänger anlegen</button>
</div>
</form>
</div>
</details>
<form method="post" action="<?= e(url('/admin/trailers')) ?>" class="panel" style="margin-top: 16px">
<?= csrf_field() ?>
<input type="hidden" name="action" value="update">
<section class="panel">
<div class="panel__head">
<div>
<h2>Anhänger &amp; Farben</h2>
<p>Inaktive Anhänger erscheinen nicht in der Buchungsmaske; historische Buchungen bleiben erhalten.</p>
</div>
<button class="btn primary" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Speichern</button>
<div class="panel__actions">
<details class="create-trailer" <?= $createErrors ? 'open' : '' ?>>
<summary class="btn small create-trailer__summary">
<svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Anhänger anlegen
</summary>
<div class="create-trailer__body">
<div class="create-trailer__body-head">
<div>
<strong>Neuer Anhänger</strong>
<span>Er steht sofort im Kalender und in der Buchungsmaske zur Auswahl.</span>
</div>
<span class="muted small">Sortierung bestimmt die Zeilenreihenfolge</span>
</div>
<?php if ($createErrors): ?>
<div class="alert alert--error" role="alert">
<svg class="ico" aria-hidden="true"><use href="#i-alert"/></svg>
<div><strong>Bitte die markierten Felder prüfen.</strong>
<?php foreach ($createErrors as $message): ?><p><?= e($message) ?></p><?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<form method="post" action="<?= e(url('/admin/trailers')) ?>" class="form-grid" data-color-row>
<?= csrf_field() ?>
<input type="hidden" name="action" value="create">
<label class="field<?= $createError('label') !== '' ? ' has-error' : '' ?>">
<span>Bezeichnung</span>
<input type="text" name="label" value="<?= e($createValues['label']) ?>" maxlength="40" required placeholder="z. B. Nr. 9">
<?php if ($createError('label')): ?><em class="field-error"><?= e($createError('label')) ?></em><?php endif; ?>
</label>
<label class="field<?= $createError('color_name') !== '' ? ' has-error' : '' ?>">
<span>Farbname</span>
<input type="text" name="color_name" value="<?= e($createValues['color_name']) ?>" maxlength="40" required placeholder="z. B. Türkis">
<?php if ($createError('color_name')): ?><em class="field-error"><?= e($createError('color_name')) ?></em><?php endif; ?>
</label>
<div class="field<?= $createError('color_hex') !== '' ? ' has-error' : '' ?>">
<span>Farbe</span>
<span class="trailer-admin__color">
<input type="color" value="<?= e($createValues['color_hex']) ?>" data-color-sync aria-label="Farbe für den neuen Anhänger">
<input type="text" name="color_hex" value="<?= e($createValues['color_hex']) ?>" maxlength="7" pattern="#[0-9a-fA-F]{6}" class="color-hex" data-color-text aria-label="Farbe als Hex-Wert">
</span>
<span class="trailer-admin__preview" data-color-preview style="--trailer: <?= e($createValues['color_hex']) ?>; --trailer-text: <?= e(contrast_color($createValues['color_hex'])) ?>">
<span class="trailer-dot" style="--trailer: <?= e($createValues['color_hex']) ?>"></span>
<span data-color-preview-label><?= e($createValues['label'] ?: 'Neuer Anhänger') ?></span>
</span>
<?php if ($createError('color_hex')): ?><em class="field-error"><?= e($createError('color_hex')) ?></em><?php endif; ?>
</div>
<label class="field">
<span>Sortierung</span>
<input type="number" name="sort_order" value="<?= (int) $createValues['sort_order'] ?>" step="10">
</label>
<div class="field">
<span>Status</span>
<label class="check check--boxed">
<input type="hidden" name="active" value="0">
<input type="checkbox" name="active" value="1"<?= (int) $createValues['active'] === 1 ? ' checked' : '' ?>>
<span>Anhänger ist aktiv</span>
</label>
</div>
<div class="field field--wide">
<button class="btn primary" type="submit"><svg class="ico" aria-hidden="true"><use href="#i-plus"/></svg> Anhänger anlegen</button>
</div>
</form>
</div>
</details>
<button class="btn primary" type="submit" form="trailer-bulk-form">
<svg class="ico" aria-hidden="true"><use href="#i-check"/></svg> Speichern
</button>
</div>
</div>
<div class="trailer-admin">
<div class="trailer-admin__head" aria-hidden="true">
<span>Farbe</span>
<span>Bezeichnung</span>
<span>Farbname</span>
<span>Sortierung</span>
<span>Aktiv</span>
<span>Vorschau</span>
<span>Aktion</span>
</div>
<?php foreach ($rows as $row): ?>
<?php $id = (int) $row['id']; ?>
<div class="trailer-admin__row<?= $fieldError($id) !== '' ? ' has-error' : '' ?>" data-color-row>
<span class="trailer-admin__color">
<input type="color" value="<?= e($row['color_hex']) ?>" data-color-sync aria-label="Farbe für <?= e($row['label']) ?>">
<input type="text" name="color_hex[<?= $id ?>]" value="<?= e($row['color_hex']) ?>" maxlength="7" pattern="#[0-9a-fA-F]{6}" class="color-hex" data-color-text aria-label="Farbe als Hex-Wert">
</span>
<input type="text" name="label[<?= $id ?>]" value="<?= e($row['label']) ?>" maxlength="40" required aria-label="Bezeichnung">
<input type="text" name="color_name[<?= $id ?>]" value="<?= e($row['color_name']) ?>" maxlength="40" required aria-label="Farbname">
<input type="number" name="sort_order[<?= $id ?>]" value="<?= (int) $row['sort_order'] ?>" step="10" aria-label="Sortierung">
<label class="check trailer-admin__active">
<input type="hidden" name="active[<?= $id ?>]" value="0">
<input type="checkbox" name="active[<?= $id ?>]" value="1"<?= (int) $row['active'] === 1 ? ' checked' : '' ?>>
<span class="sr-only"><?= e($row['label']) ?> ist aktiv</span>
</label>
<span class="trailer-admin__preview" data-color-preview style="--trailer: <?= e($row['color_hex']) ?>; --trailer-text: <?= e(contrast_color($row['color_hex'])) ?>">
<span class="trailer-dot" style="--trailer: <?= e($row['color_hex']) ?>"></span>
<?= e($row['label']) ?>
</span>
<?php if ((int) $row['booking_count'] === 0): ?>
<button class="link-button small" type="submit" form="delete-trailer-<?= $id ?>"><svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Löschen</button>
<?php else: ?>
<span class="muted small" title="<?= (int) $row['booking_count'] ?> Buchung(en) verweisen auf diesen Anhänger"><?= (int) $row['booking_count'] ?> Buchung<?= (int) $row['booking_count'] === 1 ? '' : 'en' ?></span>
<?php endif; ?>
<?php if ($fieldError($id)): ?><em class="field-error"><?= e($fieldError($id)) ?></em><?php endif; ?>
<form id="trailer-bulk-form" method="post" action="<?= e(url('/admin/trailers')) ?>">
<?= csrf_field() ?>
<input type="hidden" name="action" value="update">
<div class="trailer-admin">
<div class="trailer-admin__head" aria-hidden="true">
<span>Farbe</span>
<span>Bezeichnung</span>
<span>Farbname</span>
<span>Sortierung</span>
<span>Aktiv</span>
<span>Vorschau</span>
<span>Aktion</span>
</div>
<?php endforeach; ?>
</div>
<p class="muted small">Hinweis: Die Farbe wird bei allen Buchungen dieses Anhängers sofort übernommen. Der Buchungstext selbst bleibt unverändert.</p>
</form>
<?php foreach ($rows as $row): ?>
<?php $id = (int) $row['id']; ?>
<div class="trailer-admin__row<?= $fieldError($id) !== '' ? ' has-error' : '' ?>" data-color-row>
<span class="trailer-admin__color">
<input type="color" value="<?= e($row['color_hex']) ?>" data-color-sync aria-label="Farbe für <?= e($row['label']) ?>">
<input type="text" name="color_hex[<?= $id ?>]" value="<?= e($row['color_hex']) ?>" maxlength="7" pattern="#[0-9a-fA-F]{6}" class="color-hex" data-color-text aria-label="Farbe als Hex-Wert">
</span>
<input type="text" name="label[<?= $id ?>]" value="<?= e($row['label']) ?>" maxlength="40" required aria-label="Bezeichnung">
<input type="text" name="color_name[<?= $id ?>]" value="<?= e($row['color_name']) ?>" maxlength="40" required aria-label="Farbname">
<input type="number" name="sort_order[<?= $id ?>]" value="<?= (int) $row['sort_order'] ?>" step="10" aria-label="Sortierung">
<label class="check trailer-admin__active">
<input type="hidden" name="active[<?= $id ?>]" value="0">
<input type="checkbox" name="active[<?= $id ?>]" value="1"<?= (int) $row['active'] === 1 ? ' checked' : '' ?>>
<span class="sr-only"><?= e($row['label']) ?> ist aktiv</span>
</label>
<span class="trailer-admin__preview" data-color-preview style="--trailer: <?= e($row['color_hex']) ?>; --trailer-text: <?= e(contrast_color($row['color_hex'])) ?>">
<span class="trailer-dot" style="--trailer: <?= e($row['color_hex']) ?>"></span>
<?= e($row['label']) ?>
</span>
<?php if ((int) $row['booking_count'] === 0): ?>
<button class="link-button small" type="submit" form="delete-trailer-<?= $id ?>"><svg class="ico" aria-hidden="true"><use href="#i-trash"/></svg> Löschen</button>
<?php else: ?>
<span class="muted small" title="<?= (int) $row['booking_count'] ?> Buchung(en) verweisen auf diesen Anhänger"><?= (int) $row['booking_count'] ?> Buchung<?= (int) $row['booking_count'] === 1 ? '' : 'en' ?></span>
<?php endif; ?>
<?php if ($fieldError($id)): ?><em class="field-error"><?= e($fieldError($id)) ?></em><?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<p class="muted small">Hinweis: Die Farbe wird bei allen Buchungen dieses Anhängers sofort übernommen. Der Buchungstext selbst bleibt unverändert.</p>
</form>
</section>
<?php foreach ($rows as $row): ?>
<?php if ((int) $row['booking_count'] === 0): ?>

View file

@ -688,25 +688,32 @@ a .ico, button .ico { pointer-events: none; }
.reminder-note { display: flex; gap: 10px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; background: var(--ice-50); border: 1px solid var(--ice-200); color: var(--brand-800); font-size: .82rem; max-width: 900px; }
/* --------------------------------------------------------------- Admin */
.create-trailer { padding: 0; overflow: hidden; }
.panel__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; position: relative; }
.create-trailer { position: relative; }
.create-trailer__summary {
list-style: none; cursor: pointer;
display: flex; align-items: center; gap: 11px;
padding: 17px 22px;
transition: background .15s;
}
.create-trailer__summary::-webkit-details-marker { display: none; }
.create-trailer__summary:hover { background: var(--ice-50); }
.create-trailer__title {
display: inline-flex; align-items: center; gap: 8px;
font-family: var(--font-display); font-weight: 800; font-size: 1rem; color: var(--ink);
.create-trailer__summary::marker { content: ''; }
.create-trailer[open] .create-trailer__summary {
background: var(--ice-100); border-color: var(--ice-300); color: var(--brand-700);
}
.create-trailer__title .ico { color: var(--brand); }
.create-trailer__hint { font-size: .8rem; color: var(--muted); }
.create-trailer__chevron { margin-left: auto; color: var(--muted); transform: rotate(90deg); transition: transform .2s; }
.create-trailer[open] .create-trailer__chevron { transform: rotate(-90deg); }
.create-trailer__body { padding: 0 22px 22px; border-top: 1px solid var(--line-soft); }
.create-trailer__body > .muted { padding-top: 14px; margin-bottom: 14px; }
.create-trailer__body {
position: absolute; right: 0; top: calc(100% + 10px); z-index: 60;
width: min(660px, calc(100vw - 32px));
padding: 20px; background: #fff;
border: 1px solid var(--line); border-radius: var(--radius-lg);
box-shadow: var(--shadow-lg);
}
.create-trailer__body-head {
display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
margin-bottom: 16px;
}
.create-trailer__body-head strong { display: block; font-family: var(--font-display); font-size: 1rem; color: var(--ink); }
.create-trailer__body-head span { display: block; color: var(--muted); font-size: .8rem; margin-top: 2px; }
.create-trailer__body-head > .muted { margin-top: 0; white-space: nowrap; }
.create-trailer__body .form-grid { gap: 12px 14px; }
.create-trailer__body .trailer-admin__preview { margin-top: 2px; }
.admin-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.admin-nav a { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; font-size: .84rem; font-weight: 600; color: var(--ink-2); }
@ -901,9 +908,15 @@ a .ico, button .ico { pointer-events: none; }
.trailer-admin__row > .link-button, .trailer-admin__row > .muted { grid-column: 1 / -1; }
.trailer-admin__row input[type="number"] { width: 100%; }
.admin-nav { overflow-x: auto; flex-wrap: nowrap; }
.create-trailer__summary { padding: 14px 16px; }
.create-trailer__hint { display: none; }
.create-trailer__body { padding: 0 16px 16px; }
.panel__head { flex-wrap: wrap; }
.panel__actions { width: 100%; }
.create-trailer[open] { flex: 1 1 100%; order: 2; }
.create-trailer__body {
position: static; width: 100%; margin-top: 10px;
padding: 16px; box-shadow: var(--shadow-sm);
}
.create-trailer__body-head { flex-direction: column; gap: 4px; }
.create-trailer__body-head > .muted { white-space: normal; }
.admin-nav a { flex: 0 0 auto; }
.panel-head { padding: 16px 16px 12px; }
.panel-head h2 { font-size: 1.15rem; }

View file

@ -6,7 +6,7 @@
* zwischengespeichert, damit niemand veraltete Buchungen sieht.
*/
const VERSION = 'dic-v5';
const VERSION = 'dic-v7';
const CACHE = VERSION;
const BASE = new URL(self.registration.scope).pathname.replace(/\/$/, '');
@ -76,23 +76,24 @@ async function cacheFirst(event, request) {
return (await network) || new Response('', { status: 504, statusText: 'Offline' });
}
async function staleWhileRevalidate(event, request) {
async function assetResponse(request) {
const cache = await caches.open(CACHE);
const cached = await cache.match(request, { ignoreSearch: true });
const network = fetch(request)
.then((response) => {
if (response && response.ok) {
cache.put(cacheKey(request), response.clone());
}
return response;
})
.catch(() => null);
if (cached) {
event.waitUntil(network);
return cached;
// Exakter Treffer inklusive Versions-Query. Dadurch wird nach einem
// Deployment sofort die neue Datei geladen statt noch einmal die alte.
const exact = await cache.match(request);
if (exact) {
return exact;
}
try {
const response = await fetch(request);
if (response && response.ok) {
cache.put(request, response.clone());
}
return response;
} catch (error) {
const fallback = await cache.match(request, { ignoreSearch: true });
return fallback || new Response('', { status: 504, statusText: 'Offline' });
}
return (await network) || new Response('', { status: 504, statusText: 'Offline' });
}
async function navigate(request) {
@ -130,7 +131,7 @@ self.addEventListener('fetch', (event) => {
}
if (url.pathname.startsWith(assetPrefix)) {
event.respondWith(staleWhileRevalidate(event, request));
event.respondWith(assetResponse(request));
return;
}