From c6a92e347fbca551621e627c6c2c6c09dd13c3f6 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Tue, 17 Nov 2026 14:11:53 +0100 Subject: [PATCH] Redesign the image section of the slide form Show a dropzone (with drag and drop) while a slide has no image and a row with preview, replace and remove buttons otherwise. A newly chosen file is previewed right away. Placement is picked from tiles with a small sketch instead of long radio labels, technical details move into a collapsible help. The section gets full-width dividers, and the modal a slim scrollbar. Co-Authored-By: Claude Sonnet 5.5 --- docs/images.md | 5 +- templates/element/slide_image_fields.php | 128 +++++++++------ tests/TestCase/Controller/SlideImageTest.php | 2 +- webroot/css/plenario.css | 58 ++++++- webroot/js/plenario.js | 156 ++++++++++++++----- 5 files changed, 257 insertions(+), 92 deletions(-) diff --git a/docs/images.md b/docs/images.md index 8f43460..2815765 100644 --- a/docs/images.md +++ b/docs/images.md @@ -9,7 +9,10 @@ Ein Bild pro Folie: Upload, Verarbeitung, Auslieferung und Löschregeln. Ablage `{Plenario.images.path}/{poll_id}/{24 Hex}.webp` (Standard `data/uploads`, Docker `/data/uploads`) **außerhalb von `webroot/`**, ausgeliefert über `participate:image` (`/p/{code}/img/{file}`, auch für Presenter und Einbettung; nur Dateien dieser Umfrage, `immutable` gecacht, kein Cookie). Jedes neue Bild bekommt einen neuen Namen → neue URL, ersetzte Bilder sind sofort 404. - Eine Bildbeschreibung wird bewusst nicht abgefragt (`image_alt` bleibt `""`, die Spalte ist ungenutzt): Bilder sind Beamer-Dekoration. Nie Pflichtfelder zum Bild einführen, die den Upload verwerfen: das Dateifeld lässt sich nach einem Fehler nicht neu füllen. Die Frage nach der Platzierung (`data-image-layout`) blendet `initImageFields()` nur ein, wenn ein Bild vorhanden (und nicht zum Entfernen markiert) oder eine Datei gewählt ist; ohne JavaScript bleibt sie sichtbar. Layout `image_layout` (`top`|`side`|`full`, `full` nur + Eine Bildbeschreibung wird bewusst nicht abgefragt (`image_alt` bleibt `""`, die Spalte ist ungenutzt): Bilder sind Beamer-Dekoration. Nie Pflichtfelder zum Bild einführen, die den Upload verwerfen: das Dateifeld lässt sich nach einem Fehler nicht neu füllen. Der Formularbereich (`element/slide_image_fields`) ist ein eigener Abschnitt: ohne Bild eine Dropzone (Label auf dem versteckten + Dateifeld `#image-file`, Drag & Drop), mit Bild eine Zeile aus Vorschau, „Ersetzen“ und „Entfernen“; eine gewählte Datei wird sofort als + Vorschau gezeigt (`initImageFields()`, ersetzt `remove_image` per Button, die Checkbox bleibt für den Betrieb ohne JavaScript). Die Platzierung + (`data-image-layout`, Kacheln mit Mini-Skizze, echte Radios) blendet `initImageFields()` nur ein, wenn ein Bild vorhanden (und nicht zum Entfernen markiert) oder eine Datei gewählt ist; ohne JavaScript bleibt sie sichtbar. Layout `image_layout` (`top`|`side`|`full`, `full` nur Inhaltsfolien, `null` = Standard je Typ: Inhaltsfolie `side`, sonst `top`; `Slide::imageLayout()`); `side` gilt nur für die Bühne (CSS `stage--img-*`), Teilnehmende sehen das Bild immer oben (`element/slide_image`). Kontingent `Plenario.images.maxPerPoll` Folien mit Bild. Im State steht `slide.image` = `{url, alt, layout, width, height}` (`PollStateService::slidePayload()`). diff --git a/templates/element/slide_image_fields.php b/templates/element/slide_image_fields.php index 4731cb4..8d06d5d 100644 --- a/templates/element/slide_image_fields.php +++ b/templates/element/slide_image_fields.php @@ -1,7 +1,8 @@ getData('image_layout'), Slide::IMAGE_LA ? (string)$request->getData('image_layout') : $slide->imageLayout(); $layouts = [ - Slide::IMAGE_TOP => __('Oben (über den Antworten bzw. Ergebnissen)'), - Slide::IMAGE_SIDE => __('Daneben (Bild links, Text und Ergebnis rechts)'), + Slide::IMAGE_TOP => [__('Oben'), ''], + Slide::IMAGE_SIDE => [__('Daneben'), ''], ]; if ($slide->type === Slide::TYPE_CONTENT) { - $layouts[Slide::IMAGE_FULL] = __('Bildschirm füllen (Bild so groß wie möglich)'); + $layouts[Slide::IMAGE_FULL] = [__('Vollbild'), '']; } $imageError = $slide->getError('image'); $maxMb = (int)round((int)Configure::read('Plenario.images.maxUploadBytes', 10 * 1024 * 1024) / 1024 / 1024); +$imageUrl = $hasImage + ? $this->Url->build(['_name' => 'participate:image', 'code' => $poll->join_code, 'file' => $slide->image]) + : ''; ?> -
> - +
> +
+

- -
- <?= h((string)$slide->image_alt) ?> -
- -
- Form->control('remove_image', [ - 'type' => 'checkbox', - 'label' => __('Bild entfernen'), - 'value' => '1', - 'hiddenField' => false, - 'checked' => false, - ]) ?> - - -
+ + -
- - > -

- -
- + + + > + + + +
> +
+ > +
+
+

image_width, (int)$slide->image_height)) : '' ?>

+
+ + + +
+ Form->control('remove_image', [ + 'type' => 'checkbox', + 'label' => __('Bild entfernen'), + 'value' => '1', + 'hiddenField' => false, + 'checked' => false, + ]) ?> +
+ + +
+
-
+ +
+
+ +

+
+
+ +
- Form->radio('image_layout', array_map( - fn($value, $text) => ['value' => $value, 'text' => $text], - array_keys($layouts), - $layouts, - ), ['value' => $layout]) ?> +
+ [$text, $shapes]) : ?> + + +

+
diff --git a/tests/TestCase/Controller/SlideImageTest.php b/tests/TestCase/Controller/SlideImageTest.php index a14a466..5aff409 100644 --- a/tests/TestCase/Controller/SlideImageTest.php +++ b/tests/TestCase/Controller/SlideImageTest.php @@ -328,6 +328,6 @@ class SlideImageTest extends TestCase $this->assertResponseOk(); $this->assertResponseContains('enctype="multipart/form-data"'); $this->assertResponseContains('name="remove_image"'); - $this->assertResponseContains('Bildschirm füllen'); + $this->assertResponseContains('value="full"'); } } diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css index e9cd850..455a48a 100644 --- a/webroot/css/plenario.css +++ b/webroot/css/plenario.css @@ -816,6 +816,8 @@ body.present { .modal::backdrop { background: rgba(10, 12, 30, .55); } .modal__panel { max-height: calc(100dvh - 24px); overflow: auto; + /* slim scrollbar in the theme colours instead of the bright system one */ + scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 55%, transparent) transparent; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); } @@ -836,12 +838,54 @@ body:has(dialog[open]) { overflow: hidden; } /* slide images: participant page and slide form */ .slide-image { margin: 1em 0; } .slide-image img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 8px; } -.image-fields, .image-fields__layout { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; } +/* Full width dividers: reach through the 24px padding of .card. */ +.image-section { margin: 24px -24px; padding: 16px 24px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); } +.image-fields, .image-layout { border: 0; padding: 0; margin: 0; min-width: 0; } .image-fields > legend { font-weight: 600; padding: 0; margin-bottom: .5em; } -.image-fields__layout > legend { padding: 0; margin-bottom: .25em; } -.image-fields__current { margin: 0 0 .75em; } +.image-fields__optional { font-weight: 400; color: var(--muted); } +.image-layout { margin-top: 16px; } +.image-layout > legend { font-weight: 600; padding: 0; margin-bottom: .5em; } +.image-layout .hint { margin-bottom: 0; } + +/* dropzone (no image yet) */ +.image-drop { + display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; + padding: 20px 16px; border: 2px dashed var(--border); border-radius: 10px; + color: var(--muted); cursor: pointer; +} +.image-drop[hidden] { display: none; } +.image-drop:hover, .image-drop.is-dragover, .image-fields:has(input[type="file"]:focus-visible) .image-drop { + border-color: var(--primary); background: var(--primary-soft); color: var(--text); +} +.image-fields:has(input[type="file"]:focus-visible) .image-drop { outline: 3px solid var(--primary); outline-offset: 2px; } +.image-drop__title { font-weight: 600; color: var(--text); } +.image-drop__hint { font-size: .875rem; } + +/* current or chosen image: thumbnail, info, buttons */ +.image-fields__row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; } +.image-fields__row[hidden] { display: none; } +.image-fields__row.is-dragover { border-color: var(--primary); background: var(--primary-soft); } +.image-fields__current { margin: 0; flex: none; } +.image-fields__current img { display: block; max-width: 160px; max-height: 110px; width: auto; height: auto; border-radius: 6px; background: var(--surface-2); } .image-fields__current.is-removed img { opacity: .3; filter: grayscale(1); } -.image-fields__remove { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 0 0 1em; } -.image-fields__remove .button { display: inline-flex; align-items: center; gap: 6px; } -.image-fields__remove .hint { margin: 0; } -.image-fields__current img { display: block; max-width: 100%; max-height: 180px; width: auto; height: auto; border-radius: 6px; } +.image-fields__side { flex: 1 1 200px; min-width: 0; } +.image-fields__info { margin: 0 0 8px; font-size: .875rem; color: var(--muted); overflow-wrap: anywhere; } +.image-fields__buttons { display: flex; flex-wrap: wrap; gap: 8px; } +.image-fields__buttons .button { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; } +.image-fields:has(input[type="file"]:focus-visible) .image-fields__buttons [data-image-pick] { outline: 3px solid var(--primary); outline-offset: 2px; } +.image-fields__remove { margin: 0; } +.image-fields__help { margin-top: 8px; font-size: .875rem; color: var(--muted); } +.image-fields__help summary { cursor: pointer; width: fit-content; } +.image-fields__help .hint { margin: .5em 0 0; } + +/* placement tiles (radios) */ +.image-layout__tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; max-width: 420px; } +.image-layout__tile { + display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 8px; + border: 2px solid var(--border); border-radius: 8px; cursor: pointer; color: var(--muted); font-size: .9rem; +} +.image-layout__tile svg { max-width: 100%; height: auto; } +.image-layout__tile svg .img { fill: var(--primary); opacity: .45; } +.image-layout__tile:hover { border-color: var(--primary); } +.image-layout__tile:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--text); font-weight: 600; } +.image-layout__tile:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; } diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index e2579e0..d94b4b7 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -2279,51 +2279,132 @@ // ------------------------------------------------------------------ slide form - /** Slide image: a trash button toggles the "remove image" checkbox (the checkbox stays for use without JavaScript). */ - function initImageRemove(box) { - var checkbox = box.querySelector('input[type="checkbox"]'); - var button = box.querySelector('[data-image-remove-button]'); - var status = box.querySelector('[data-image-remove-status]'); - var figure = box.parentNode.querySelector('.image-fields__current'); - if (!checkbox || !button) { - return; - } - var field = checkbox.closest('.input'); - if (field) { - field.hidden = true; - } - button.hidden = false; - button.addEventListener('click', function () { - checkbox.checked = !checkbox.checked; - button.setAttribute('aria-pressed', checkbox.checked ? 'true' : 'false'); - button.querySelector('[data-label]').textContent = button.getAttribute(checkbox.checked ? 'data-label-undo' : 'data-label-remove'); - if (figure) { - figure.classList.toggle('is-removed', checkbox.checked); - } - if (status) { - status.textContent = checkbox.checked ? 'Das Bild wird beim Speichern entfernt.' : ''; - } - }); - } - /** - * Slide image: the placement question only makes sense with an image, i.e. an existing one that is not - * marked for removal, or a newly selected file. Without JavaScript it stays visible. + * Slide image section: dropzone (also drag and drop) while there is no image, otherwise a row with + * preview and replace/remove buttons. A newly chosen file is previewed right away. The placement + * question only shows with an image (existing and not marked for removal, or a chosen file). + * Without JavaScript the label opens the file dialog, the checkbox removes and the placement stays visible. */ function initImageFields(box) { - var layout = box.querySelector('[data-image-layout]'); var file = box.querySelector('input[type="file"]'); - var remove = box.querySelector('input[name="remove_image"]'); - if (!layout || !file) { + var layout = box.querySelector('[data-image-layout]'); + var drop = box.querySelector('[data-image-drop]'); + var row = box.querySelector('[data-image-row]'); + var img = box.querySelector('[data-image-figure] img'); + var figure = box.querySelector('[data-image-figure]'); + var info = box.querySelector('[data-image-info]'); + var pick = box.querySelector('[data-image-pick]'); + var button = box.querySelector('[data-image-remove-button]'); + var checkbox = box.querySelector('input[name="remove_image"]'); + if (!file || !layout || !drop || !row || !img || !button) { return; } var hasImage = box.hasAttribute('data-has-image'); - function update() { - var removed = !!remove && remove.checked; - layout.hidden = !(file.files && file.files.length > 0) && !(hasImage && !removed); + var original = img.getAttribute('data-image-original') || ''; + var width = img.getAttribute('width'); + var height = img.getAttribute('height'); + var objectUrl = null; + + // The checkbox is replaced by the button (it stays in the form and is toggled by it). + var removeBox = box.querySelector('[data-image-remove]'); + if (removeBox) { + removeBox.hidden = true; } - box.addEventListener('change', update); - box.addEventListener('click', update); + var extra = box.querySelector('[data-image-drop-extra]'); + if (extra) { + extra.hidden = false; + } + button.hidden = false; + + function formatSize(bytes) { + return bytes < 1048576 ? Math.max(1, Math.round(bytes / 1024)) + ' KB' : (bytes / 1048576).toFixed(1).replace('.', ',') + ' MB'; + } + + function update() { + var chosen = !!file.files && file.files.length > 0; + var removed = !!checkbox && checkbox.checked && !chosen; + if (objectUrl) { + URL.revokeObjectURL(objectUrl); + objectUrl = null; + } + if (chosen) { + objectUrl = URL.createObjectURL(file.files[0]); + img.src = objectUrl; + img.removeAttribute('width'); + img.removeAttribute('height'); + } else { + img.src = original; + if (width && height) { + img.setAttribute('width', width); + img.setAttribute('height', height); + } + } + var showRow = chosen || hasImage; + var focusLost = row.hidden === false && !showRow; + row.hidden = !showRow; + drop.hidden = showRow; + figure.classList.toggle('is-removed', removed); + if (info) { + info.textContent = chosen + ? info.getAttribute('data-text-new') + ' ' + file.files[0].name + ' (' + formatSize(file.files[0].size) + ')' + : (removed ? info.getAttribute('data-text-removed') : (hasImage ? info.getAttribute('data-text-current') : '')); + } + if (pick) { + pick.textContent = pick.getAttribute(chosen || !hasImage ? 'data-label-choose' : 'data-label-replace'); + } + button.querySelector('[data-label]').textContent = button.getAttribute(chosen ? 'data-label-discard' : (removed ? 'data-label-undo' : 'data-label-remove')); + if (!chosen && checkbox) { + button.setAttribute('aria-pressed', removed ? 'true' : 'false'); + } else { + button.removeAttribute('aria-pressed'); + } + layout.hidden = !chosen && !(hasImage && !removed); + if (focusLost) { + file.focus(); + } + } + + file.addEventListener('change', function () { + if (file.files && file.files.length > 0 && checkbox) { + // A new image replaces the old one, so "remove" no longer applies. + checkbox.checked = false; + } + update(); + }); + button.addEventListener('click', function () { + if (file.files && file.files.length > 0) { + file.value = ''; + } else if (checkbox) { + checkbox.checked = !checkbox.checked; + } + update(); + }); + + [drop, row].forEach(function (zone) { + zone.addEventListener('dragover', function (event) { + event.preventDefault(); + zone.classList.add('is-dragover'); + }); + zone.addEventListener('dragleave', function () { + zone.classList.remove('is-dragover'); + }); + zone.addEventListener('drop', function (event) { + event.preventDefault(); + zone.classList.remove('is-dragover'); + var dropped = event.dataTransfer && event.dataTransfer.files; + if (!dropped || dropped.length === 0 || typeof DataTransfer === 'undefined') { + return; + } + try { + var transfer = new DataTransfer(); + transfer.items.add(dropped[0]); + file.files = transfer.files; + file.dispatchEvent(new Event('change', {bubbles: true})); + } catch (e) { + // Browser without assignable file lists: the file dialog still works. + } + }); + }); update(); } @@ -2967,7 +3048,6 @@ initCopy(root); root.querySelectorAll('[data-youtube-form]').forEach(initYouTubeForm); root.querySelectorAll('[data-quiz-options]').forEach(initQuizOptions); - root.querySelectorAll('[data-image-remove]').forEach(initImageRemove); root.querySelectorAll('[data-image-fields]').forEach(initImageFields); root.querySelectorAll('[data-sortable]').forEach(initSortable); root.querySelectorAll('[data-order-options]').forEach(initOrderOptions);