Merge pull request 'Update slide list and edit slide form without page reloads' (#57) from feature/hide-slides into main
CI / Deploy / test (push) Successful in 58s
CI / Deploy / deploy (push) Successful in 6s

Reviewed-on: #57
This commit was merged in pull request #57.
This commit is contained in:
gnilebein committed 2026-11-11 20:29:04 +01:00
commit 0294744281
9 files changed
+403 -32

No files matched your search

+9
View File
@@ -269,6 +269,15 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
externen Ressourcen, keine CSS-Variablen, Schrift DejaVu Sans; Seitenzahlen setzt `PdfView::addPageNumbers()`.
Tests prüfen das HTML über `PlenarioTestTrait::exportHtml()` (das PDF selbst ist nicht durchsuchbar).
- **Dashboard ohne Neuladen** (`initAdminDashboard()`, `Fragments` in `plenario.js`): Formulare in `[data-live]` (Folienliste, Kopf)
und das Folienformular im `<dialog>` laufen per `fetch` mit Header `X-Fragment`; `AdminAppController::beforeRender()` nimmt dann
das Layout `fragment` (nur Inhalt + Flash). Die Server-Aktionen bleiben normale POST + Redirect, das JS tauscht die Bereiche
`[data-refresh="head|slides|flash"]` (als DOM-Knoten, nie `innerHTML`) und stellt den Fokus wieder her. Bearbeiten/Anlegen:
Links mit `data-modal` laden das Formular (`[data-modal-content]`) in den Dialog; Validierungsfehler kommen als Formular
zurück (Dialog bleibt offen), Erfolg als Dashboard-Fragment (Dialog schließt). Ohne JS funktioniert alles als normale Seite.
**Buttons mit Bestätigung** nutzen `Form->postButton()` + `data-confirm` (CakePHPs `postLink`/`confirm` erzeugt ein Inline-`onclick`,
das die CSP blockiert); das JS fragt per `window.confirm()` vor dem Absenden. Tests: `AdminFragmentTest.php`.
### Neuen Folientyp hinzufügen (Checkliste)
1. Konstante + Label + Beschreibung + `DEFAULT_SETTINGS` in `src/Model/Entity/Slide.php`
+4
View File
@@ -71,6 +71,10 @@ abstract class AdminAppController extends AppController
{
parent::beforeRender($event);
$this->response = $this->protect($this->response);
// plenario.js asks for a fragment to update the open page without reloading it.
if ($this->request->getHeaderLine('X-Fragment') !== '') {
$this->viewBuilder()->setLayout('fragment');
}
}
/**
+29 -20
View File
@@ -17,7 +17,7 @@ $this->assign('noindex', '1');
$url = fn(string $name, array $params = []) => ['_name' => $name, 'token' => $adminToken] + $params;
$hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide->isInteractive() && $slide->isPrivate()) !== [];
?>
<div class="admin-head">
<div class="admin-head" data-refresh="head" data-live>
<div>
<p class="eyebrow"><?= __('Verwaltung') ?></p>
<h1><?= h($poll->title) ?></h1>
@@ -37,7 +37,7 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
<a class="button button--primary" target="_blank" rel="noopener"
href="<?= $this->Url->build($url('admin:present')) ?>">▶ <?= __('Präsentieren') ?></a>
<?php if ($poll->current_slide_id !== null) : ?>
<?= $this->Form->postLink('⏸ ' . __('Pause'), $url('admin:control'), [
<?= $this->Form->postButton('⏸ ' . __('Pause'), $url('admin:control'), [
'data' => ['action' => 'stop'],
'class' => 'button',
'title' => __('Keine Folie zeigen – Teilnehmende sehen eine Pause-Seite'),
@@ -64,6 +64,7 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
</div>
<?php endif; ?>
<div data-refresh="slides" data-live>
<?php if (count($slides) > 1) : ?>
<p class="muted slide-list__hint" data-sortable-hint hidden><?= __('Tipp: Folien am Griff ⠿ ziehen, um die Reihenfolge zu ändern (oder Griff fokussieren und Pfeiltasten nutzen).') ?></p>
<?php endif; ?>
@@ -109,7 +110,7 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
<?php if ($slide->isPrivate()) : ?><span class="badge" title="<?= __('In der Präsentation zunächst verborgen, für Teilnehmende nie sichtbar') ?>">🔒 <?= $slide->type === 'scale' ? __('intern') : __('anonym') ?></span><?php endif; ?>
<?php endif; ?>
</div>
<a class="slide-item__title" href="<?= $this->Url->build($url('slides:edit', ['id' => $slide->id])) ?>"><?= h($slide->question) ?></a>
<a class="slide-item__title" data-modal href="<?= $this->Url->build($url('slides:edit', ['id' => $slide->id])) ?>"><?= h($slide->question) ?></a>
<?php if ($slide->type === 'choice' && $slide->slide_options) : ?>
<p class="slide-item__options muted"><?= h(implode(' · ', array_map(fn($o) => $o->label, $slide->slide_options))) ?></p>
<?php elseif ($slide->isQuiz() && $slide->slide_options) : ?>
@@ -135,7 +136,7 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
</div>
<div class="slide-item__actions">
<?php if (!$isCurrent && !$slide->is_hidden) : ?>
<?= $this->Form->postLink('▶', $url('admin:control'), [
<?= $this->Form->postButton('▶', $url('admin:control'), [
'data' => ['action' => 'goto', 'slide_id' => $slide->id],
'class' => 'button button--small button--icon',
'title' => __('Live: diese Folie jetzt den Teilnehmenden zeigen'),
@@ -147,53 +148,54 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
<a class="button button--small button--icon" href="<?= $this->Url->build($url('slides:answers', ['id' => $slide->id])) ?>"
title="<?= h($answersLabel) ?>" aria-label="<?= h(__('{0} der Folie „{1}“ ansehen', $answersLabel, $slide->question)) ?>">📊</a>
<?php endif; ?>
<a class="button button--small button--icon" href="<?= $this->Url->build($url('slides:edit', ['id' => $slide->id])) ?>"
<a class="button button--small button--icon" data-modal href="<?= $this->Url->build($url('slides:edit', ['id' => $slide->id])) ?>"
title="<?= __('Bearbeiten') ?>" aria-label="<?= h(__('Folie „{0}“ bearbeiten', $slide->question)) ?>">✎</a>
<?= $this->Form->postLink('⧉', $url('slides:duplicate', ['id' => $slide->id]), [
<?= $this->Form->postButton('⧉', $url('slides:duplicate', ['id' => $slide->id]), [
'class' => 'button button--small button--icon',
'title' => __('Duplizieren: Kopie direkt dahinter anlegen (ohne Antworten)'),
'aria-label' => __('Folie „{0}“ duplizieren', $slide->question),
]) ?>
<?php if ($slide->is_hidden) : ?>
<?= $this->Form->postLink('👁', $url('slides:visibility', ['id' => $slide->id]), [
<?= $this->Form->postButton('👁', $url('slides:visibility', ['id' => $slide->id]), [
'data' => ['hidden' => 0],
'class' => 'button button--small button--icon',
'title' => __('Einblenden: Folie wieder in die Präsentation aufnehmen'),
'aria-label' => __('Folie „{0}“ einblenden', $slide->question),
]) ?>
<?php else : ?>
<?= $this->Form->postLink('⊘', $url('slides:visibility', ['id' => $slide->id]), [
<?= $this->Form->postButton('⊘', $url('slides:visibility', ['id' => $slide->id]), [
'data' => ['hidden' => 1],
'class' => 'button button--small button--icon',
'title' => __('Ausblenden: Folie behalten, aber beim Präsentieren überspringen'),
'aria-label' => __('Folie „{0}“ ausblenden', $slide->question),
'confirm' => $isCurrent ? __('Diese Folie ist gerade live. Ausblenden und die Umfrage pausieren?') : null,
'data-confirm' => $isCurrent ? __('Diese Folie ist gerade live. Ausblenden und die Umfrage pausieren?') : null,
]) ?>
<?php endif; ?>
<?php if ($count > 0) : ?>
<?= $this->Form->postLink('↺', $url('slides:reset', ['id' => $slide->id]), [
<?= $this->Form->postButton('↺', $url('slides:reset', ['id' => $slide->id]), [
'class' => 'button button--small button--icon',
'title' => __('Zurücksetzen: alle Antworten dieser Folie löschen'),
'aria-label' => __('Antworten der Folie „{0}“ zurücksetzen', $slide->question),
'confirm' => __('Alle {0} Antworten dieser Folie löschen?', $count),
'data-confirm' => __('Alle {0} Antworten dieser Folie löschen?', $count),
]) ?>
<?php endif; ?>
<?= $this->Form->postLink('🗑', $url('slides:delete', ['id' => $slide->id]), [
<?= $this->Form->postButton('🗑', $url('slides:delete', ['id' => $slide->id]), [
'class' => 'button button--small button--icon button--danger',
'title' => __('Löschen'),
'aria-label' => __('Folie „{0}“ löschen', $slide->question),
'confirm' => __('Folie „{0}“ inkl. aller Antworten löschen?', $slide->question),
'data-confirm' => __('Folie „{0}“ inkl. aller Antworten löschen?', $slide->question),
]) ?>
</div>
</li>
<?php endforeach; ?>
</ol>
<p class="sr-only" role="status" aria-live="polite" data-sortable-status></p>
</div>
<h3><?= __('Neue Folie') ?></h3>
<div class="type-picker">
<?php foreach ($typeLabels as $type => $label) : ?>
<a class="type-card type-card--<?= h($type) ?>" href="<?= $this->Url->build($url('slides:add', ['?' => ['type' => $type]])) ?>">
<a class="type-card type-card--<?= h($type) ?>" data-modal href="<?= $this->Url->build($url('slides:add', ['?' => ['type' => $type]])) ?>">
<strong><?= h($label) ?></strong>
<span><?= h($typeDescriptions[$type]) ?></span>
</a>
@@ -244,9 +246,9 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
<p class="hint"><?= __('Jede Folie hat einen eigenen Einbett-Link (unter „Einbett-Link“ in der Folienliste). Füge ihn z. B. in Canva als Einbettung auf einer Folie ein.') ?></p>
<p class="hint"><?= __('Sobald die eingebettete Folie im Vortrag zu sehen ist, wird sie live geschaltet. Bei allen anderen Folien sehen Teilnehmende eine Pause-Seite.') ?></p>
<p class="hint"><?= __('Der Link zeigt nur diese Folie und kann sie live schalten – die Umfrage bearbeiten kann damit niemand.') ?></p>
<?= $this->Form->postLink(__('Neue Einbett-Links erzeugen'), $url('admin:rotate-embed'), [
<?= $this->Form->postButton(__('Neue Einbett-Links erzeugen'), $url('admin:rotate-embed'), [
'class' => 'button button--small',
'confirm' => __('Neue Einbett-Links erzeugen? Alle bisher eingebetteten Folien funktionieren danach nicht mehr.'),
'data-confirm' => __('Neue Einbett-Links erzeugen? Alle bisher eingebetteten Folien funktionieren danach nicht mehr.'),
]) ?>
</section>
@@ -279,18 +281,18 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
<section class="card card--danger">
<h2><?= __('Sicherheit') ?></h2>
<p class="hint"><?= __('Link versehentlich geteilt? Erzeuge einen neuen – der alte wird sofort ungültig.') ?></p>
<?= $this->Form->postLink(__('Neuen Admin-Link erzeugen'), $url('admin:rotate'), [
<?= $this->Form->postButton(__('Neuen Admin-Link erzeugen'), $url('admin:rotate'), [
'class' => 'button button--small',
'confirm' => __('Neuen Admin-Link erzeugen? Der aktuelle Link funktioniert danach nicht mehr.'),
'data-confirm' => __('Neuen Admin-Link erzeugen? Der aktuelle Link funktioniert danach nicht mehr.'),
]) ?>
<h3><?= __('Umfrage zurücksetzen') ?></h3>
<p class="hint"><?= __('Löscht alle Antworten aller Folien, z. B. für eine neue Gruppe. Folien und Einstellungen bleiben erhalten.') ?></p>
<?php if ($responseCounts !== []) : ?>
<p class="hint"><?= $this->Html->link(__('Ergebnisse vorher als PDF sichern'), '#export') ?></p>
<?= $this->Form->postLink(__('Alle Antworten löschen'), $url('admin:reset'), [
<?= $this->Form->postButton(__('Alle Antworten löschen'), $url('admin:reset'), [
'class' => 'button button--small button--danger',
'confirm' => __('Alle Antworten aller Folien unwiderruflich löschen?'),
'data-confirm' => __('Alle Antworten aller Folien unwiderruflich löschen?'),
]) ?>
<?php else : ?>
<p class="hint"><em><?= __('Noch nichts zurückzusetzen: Es gibt keine Antworten.') ?></em></p>
@@ -308,3 +310,10 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
</section>
</aside>
</div>
<?php // Slide form in a dialog (loaded via fetch, see [data-modal] in plenario.js); without JS the links open the full page. ?>
<dialog class="modal" data-modal-dialog aria-labelledby="modal-title">
<button type="button" class="modal__close button button--ghost button--icon" data-modal-close
aria-label="<?= h(__('Schließen')) ?>" title="<?= h(__('Schließen (Esc)')) ?>">✕</button>
<div data-modal-body></div>
</dialog>
+3 -3
View File
@@ -26,9 +26,9 @@ $optionsError = $slide->getError('options_text');
?>
<p><a href="<?= $this->Url->build(['_name' => 'admin', 'token' => $adminToken]) ?>">← <?= __('Zurück zu „{0}“', h($poll->title)) ?></a></p>
<section class="card card--form">
<section class="card card--form" data-modal-content>
<p class="eyebrow"><?= h($slide->typeLabel()) ?></p>
<h1><?= $isNew ? __('Neue Folie') : __('Folie bearbeiten') ?></h1>
<h1 id="modal-title"><?= $isNew ? __('Neue Folie') : __('Folie bearbeiten') ?></h1>
<?= $this->Form->create($slide, ['url' => $formUrl]) ?>
<?= $this->Form->hidden('type') ?>
@@ -337,7 +337,7 @@ $optionsError = $slide->getError('options_text');
<div class="form-actions">
<?= $this->Form->button($isNew ? __('Folie anlegen') : __('Speichern'), ['class' => 'button button--primary']) ?>
<a class="button button--ghost" href="<?= $this->Url->build(['_name' => 'admin', 'token' => $adminToken]) ?>"><?= __('Abbrechen') ?></a>
<a class="button button--ghost" data-modal-close href="<?= $this->Url->build(['_name' => 'admin', 'token' => $adminToken]) ?>"><?= __('Abbrechen') ?></a>
</div>
<?= $this->Form->end() ?>
</section>
+1 -1
View File
@@ -36,7 +36,7 @@ $title = $this->fetch('title');
</div>
</header>
<main class="container main">
<?= $this->Flash->render() ?>
<div data-refresh="flash"><?= $this->Flash->render() ?></div>
<?= $this->fetch('content') ?>
</main>
<footer class="site-footer container">
+10
View File
@@ -0,0 +1,10 @@
<?php
/**
* Layout for admin fragments (header "X-Fragment"): only the page content and the flash messages,
* which plenario.js merges into the open page (see [data-refresh] regions) or shows in the dialog.
*
* @var \App\View\AppView $this
*/
?>
<div data-refresh="flash"><?= $this->Flash->render() ?></div>
<?= $this->fetch('content') ?>
@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\Controller;
use App\Model\Entity\Slide;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
/**
* Dashboard updates without reloading: fragments (header X-Fragment) and the slide form in a dialog.
*/
class AdminFragmentTest extends TestCase
{
use IntegrationTestTrait;
use PlenarioTestTrait;
/**
* @var list<string>
*/
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
protected function setUp(): void
{
parent::setUp();
$this->enableCsrfToken();
}
public function testFragmentContainsRegionsButNoPageFrame(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->get("/admin/$token");
$this->assertResponseOk();
$this->assertResponseContains('data-refresh="slides"');
$this->assertResponseContains('data-refresh="head"');
$this->assertResponseContains('data-refresh="flash"');
$this->assertResponseNotContains('<html');
$this->assertResponseNotContains('site-header');
}
public function testFullPageKeepsFrameAndRegions(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$this->get("/admin/$token");
$this->assertResponseContains('<html');
$this->assertResponseContains('data-refresh="flash"');
$this->assertResponseContains('<dialog');
}
public function testActionsUseNoInlineHandlers(): void
{
[$poll, $token] = $this->createPoll();
$this->createSlide($poll, Slide::TYPE_CHOICE);
$this->get("/admin/$token");
$this->assertResponseNotContains('onclick=');
$this->assertResponseContains('data-confirm=');
}
public function testSlideFormFragmentIsTheDialogContent(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->get("/admin/$token/slides/{$slide->id}/edit");
$this->assertResponseOk();
$this->assertResponseContains('data-modal-content');
$this->assertResponseNotContains('site-header');
}
public function testValidationErrorKeepsTheFormInTheFragment(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->post("/admin/$token/slides/{$slide->id}/edit", ['question' => '']);
$this->assertResponseOk();
$this->assertResponseContains('data-modal-content');
$this->assertResponseContains('Bitte prüfe deine Eingaben.');
}
public function testSuccessfulSaveRedirectsToTheDashboard(): void
{
[$poll, $token] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_OPEN);
$this->configRequest(['headers' => ['X-Fragment' => '1']]);
$this->post("/admin/$token/slides/{$slide->id}/edit", ['question' => 'Neue Frage']);
$this->assertRedirect(['_name' => 'admin', 'token' => $token]);
}
}
+14
View File
@@ -740,3 +740,17 @@ body.present {
.theme-switch { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 40px; height: 40px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--text); font: inherit; font-size: .9rem; cursor: pointer; }
.theme-switch:hover { border-color: var(--primary); }
.theme-switch__icon { font-size: 1.3em; line-height: 1; }
/* Slide form in a dialog (admin dashboard) */
.modal {
width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; overflow: auto;
border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.modal::backdrop { background: rgba(10, 12, 30, .55); }
.modal .card--form { max-width: none; margin: 0; border: 0; box-shadow: none; background: transparent; }
.modal__close { position: sticky; top: 8px; float: right; margin: 8px 8px 0 0; z-index: 1; }
.modal .message { margin: 16px 16px 0; cursor: default; }
body:has(dialog[open]) { overflow: hidden; }
.slide-item__actions form { display: contents; }
.slide-item__actions button:disabled, .admin-head__actions button:disabled { opacity: .6; cursor: progress; }
+228 -8
View File
@@ -13,6 +13,10 @@
* - [data-sortable] admin slide list: drag & drop / arrow keys via [data-drag-handle], POSTs ids[] to the URL
* - [data-order-options] slide form of ordering slides: sortable rows (correct order), "add entry"
* - [data-order-form] participant answer of ordering slides: sortable items posting order[]
* - [data-live] admin dashboard: forms inside (hide, delete, duplicate, …) run via fetch and refresh
* the [data-refresh] regions instead of reloading the page (header X-Fragment)
* - [data-modal] link whose target page (slide form) opens in the <dialog data-modal-dialog>
* - [data-confirm] on a submit button: window.confirm() before the form is sent (replaces inline onclick, CSP)
* - [data-theme-switch] cycles the colour scheme (data-theme on <html>, stored in localStorage),
* see templates/element/theme_init.php for the pre-paint part
*
@@ -1125,8 +1129,8 @@
}
}
function initCopy() {
document.querySelectorAll('[data-copy]').forEach(function (button) {
function initCopy(root) {
(root || document).querySelectorAll('[data-copy]').forEach(function (button) {
button.addEventListener('click', function () { copyFrom(button); });
});
}
@@ -2483,8 +2487,228 @@
button.hidden = false;
}
// ------------------------------------------------------------------ admin dashboard without reloads
/**
* Loads server-rendered admin pages as fragments (layout "fragment": content + flash only)
* and merges them into the open page. The HTML comes from our own templates (escaped there);
* it is adopted as DOM nodes, never written with innerHTML.
*/
var Fragments = {
request: function (url, options) {
options = options || {};
return fetch(url, {
method: options.method || 'GET',
body: options.body,
credentials: 'same-origin',
cache: 'no-store',
headers: { Accept: 'text/html', 'X-Fragment': '1', 'X-CSRF-Token': csrfToken() }
}).then(function (response) {
if (!response.ok) {
throw new Error('HTTP ' + response.status);
}
return response.text();
}).then(function (html) {
return new DOMParser().parseFromString(html, 'text/html');
});
},
/** Replaces the [data-refresh] regions (all, or only `names`) with those of `doc`. */
apply: function (doc, names) {
doc.querySelectorAll('[data-refresh]').forEach(function (fresh) {
var name = fresh.getAttribute('data-refresh');
var old = document.querySelector('[data-refresh="' + name + '"]');
if (!old || (names && names.indexOf(name) < 0)) {
return;
}
var node = document.importNode(fresh, true);
old.replaceWith(node);
initWidgets(node);
});
},
/** Shows an error where the user is looking (dialog or flash area). */
fail: function (container, text) {
var message = el('div', { class: 'message error', role: 'alert', 'data-dismiss': '', text: text });
container.insertBefore(message, container.firstChild);
}
};
function initAdminDashboard() {
var dialog = document.querySelector('[data-modal-dialog]');
var body = dialog ? dialog.querySelector('[data-modal-body]') : null;
var dirty = false;
var focusId = null;
function flashArea() {
return document.querySelector('[data-refresh="flash"]') || document.body;
}
/** Keeps the keyboard position after a list refresh: same button, else the slide, else the next slide. */
function restoreFocus(target) {
if (!target) {
return;
}
var item = target.id ? document.querySelector('[data-slide-id="' + target.id + '"]') : null;
var node = null;
if (item) {
node = (target.action && item.querySelector('form[action="' + target.action + '"] button'))
|| item.querySelector('.slide-item__title');
} else if (target.nextId) {
node = document.querySelector('[data-slide-id="' + target.nextId + '"] .slide-item__title');
}
if (node) {
node.focus();
}
}
function refreshList() {
return Fragments.request(window.location.href).then(function (doc) {
Fragments.apply(doc, ['head', 'slides']);
});
}
function openModal(doc) {
var content = doc.querySelector('[data-modal-content]');
var flash = doc.querySelector('[data-refresh="flash"]');
body.replaceChildren();
if (flash && flash.childNodes.length) {
// Shown inside the dialog (validation errors), not as flash of the page behind it.
var notes = document.importNode(flash, true);
notes.removeAttribute('data-refresh');
body.appendChild(notes);
}
body.appendChild(document.importNode(content, true));
initWidgets(body);
dirty = false;
if (!dialog.open) {
dialog.showModal();
}
dialog.scrollTop = 0;
}
function requestClose() {
if (dirty && !window.confirm('Änderungen verwerfen?')) {
return;
}
dialog.close();
}
/** Result of a POST: either the dashboard (done) or a form (open in the dialog). */
function handle(doc, source) {
if (doc.querySelector('[data-modal-content]')) {
// A form: validation errors (dialog stays open) or the copy of a duplicated slide.
var wasOpen = dialog.open;
openModal(doc);
return wasOpen ? null : refreshList();
}
Fragments.apply(doc);
if (dialog && dialog.open) {
dirty = false;
dialog.close();
}
restoreFocus(source);
return null;
}
document.addEventListener('submit', function (event) {
var form = event.target;
var submitter = event.submitter || form.querySelector('button[type=submit], button:not([type])');
var confirmText = submitter && submitter.getAttribute('data-confirm');
if (confirmText && !window.confirm(confirmText)) {
event.preventDefault();
return;
}
var inDialog = dialog !== null && dialog.contains(form);
if (!inDialog && !form.closest('[data-live]')) {
return; // plain form: normal navigation
}
event.preventDefault();
if (form.hasAttribute('aria-busy')) {
return;
}
var item = form.closest('[data-slide-id]');
var next = item ? item.nextElementSibling : null;
var source = inDialog ? { id: focusId } : {
id: item ? item.getAttribute('data-slide-id') : null,
action: form.getAttribute('action'),
nextId: next ? next.getAttribute('data-slide-id') : null
};
form.setAttribute('aria-busy', 'true');
if (submitter) {
submitter.disabled = true;
}
Fragments.request(form.action, { method: 'POST', body: new FormData(form) })
.then(function (doc) { return handle(doc, source); })
.catch(function () {
form.removeAttribute('aria-busy');
if (submitter) {
submitter.disabled = false;
}
Fragments.fail(inDialog ? body : flashArea(), 'Das hat nicht geklappt. Bitte lade die Seite neu und versuche es noch einmal.');
});
});
if (!dialog) {
return;
}
document.addEventListener('click', function (event) {
var link = event.target.closest ? event.target.closest('a[data-modal]') : null;
if (!link || event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
return;
}
event.preventDefault();
var item = link.closest('[data-slide-id]');
focusId = item ? item.getAttribute('data-slide-id') : null;
Fragments.request(link.href).then(openModal).catch(function () {
window.location.href = link.href; // no dialog possible: open the page as usual
});
});
dialog.addEventListener('click', function (event) {
if (event.target.closest('[data-modal-close]')) {
event.preventDefault();
requestClose();
}
});
// Only a click that starts and ends on the backdrop closes (not a text selection dragged outside).
var pressedOnBackdrop = false;
dialog.addEventListener('mousedown', function (event) { pressedOnBackdrop = event.target === dialog; });
dialog.addEventListener('click', function (event) {
if (event.target === dialog && pressedOnBackdrop) {
requestClose();
}
});
dialog.addEventListener('cancel', function (event) {
if (dirty && !window.confirm('Änderungen verwerfen?')) {
event.preventDefault();
}
});
dialog.addEventListener('close', function () {
body.replaceChildren();
dirty = false;
});
body.addEventListener('input', function () { dirty = true; });
body.addEventListener('change', function () { dirty = true; });
}
// ------------------------------------------------------------------ boot
/** Initialises the widgets inside `root` (the whole page at boot, or a freshly inserted fragment). */
function initWidgets(root) {
initCopy(root);
root.querySelectorAll('[data-youtube-form]').forEach(initYouTubeForm);
root.querySelectorAll('[data-quiz-options]').forEach(initQuizOptions);
root.querySelectorAll('[data-sortable]').forEach(initSortable);
root.querySelectorAll('[data-order-options]').forEach(initOrderOptions);
root.querySelectorAll('[data-scale-style]').forEach(initScaleStyle);
}
// Flash messages: click hides them (delegated, no inline handlers because of the CSP).
document.addEventListener('click', function (event) {
var message = event.target.closest ? event.target.closest('[data-dismiss]') : null;
@@ -2495,16 +2719,12 @@
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('[data-theme-switch]').forEach(initThemeSwitch);
initCopy();
initWidgets(document);
initShare();
document.querySelectorAll('[data-youtube-form]').forEach(initYouTubeForm);
initAdminDashboard();
document.querySelectorAll('[data-presenter]').forEach(initPresenter);
document.querySelectorAll('[data-participant]').forEach(initParticipant);
document.querySelectorAll('[data-quiz-options]').forEach(initQuizOptions);
document.querySelectorAll('[data-sortable]').forEach(initSortable);
document.querySelectorAll('[data-order-options]').forEach(initOrderOptions);
document.querySelectorAll('[data-order-form]').forEach(initOrderForm);
document.querySelectorAll('[data-scale-style]').forEach(initScaleStyle);
// Prevent double submits of vote forms.
document.querySelectorAll('.vote-form').forEach(function (form) {