Selektor auch für Waffen und Rüstung, fest auf die jeweilige Art vorgefiltert
This commit is contained in:
parent
a121b8c202
commit
c0756971cf
5 changed files with 247 additions and 40 deletions
|
|
@ -1,62 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Selektor-Schirm: Ausrüstung aus dem Katalog ins Inventar übernehmen.
|
||||
* Selektor-Schirm: Ausrüstung aus dem Katalog übernehmen.
|
||||
*
|
||||
* Wird aus views/character_edit.php eingebunden; erwartet $base, $character,
|
||||
* $itemCatalog, $itemCatalogCount, $itemFilters und $itemSelectorOpen.
|
||||
* Wird aus views/character_edit.php eingebunden; erwartet $base, $character und
|
||||
* $selector (Konfiguration aus item_selector_config()). Derselbe Schirm dient
|
||||
* dem Inventar sowie – fest auf eine Art vorgefiltert – der Bewaffnung und der
|
||||
* Rüstung.
|
||||
*
|
||||
* Gefiltert wird serverseitig über GET-Parameter (item_kind/item_avail/item_q),
|
||||
* Gefiltert wird serverseitig über GET-Parameter (<key>_kind/<key>_avail/<key>_q),
|
||||
* damit der Katalog auch mit hunderten Einträgen ohne JavaScript bedienbar
|
||||
* bleibt. Die Auswahl selbst ist ein POST auf /characters/{id}/items/from-catalog.
|
||||
* bleibt. Die Auswahl selbst ist ein POST auf $selector['action'].
|
||||
*
|
||||
* @var string $base
|
||||
* @var array $character
|
||||
* @var list<array<string,mixed>> $itemCatalog
|
||||
* @var int $itemCatalogCount
|
||||
* @var array{kind:string,availability:string,needle:string} $itemFilters
|
||||
* @var bool $itemSelectorOpen
|
||||
* @var array{key:string,title:string,action:string,anchor:string,kinds:list<string>|null,filters:array<string,mixed>,catalog:list<array<string,mixed>>,count:int,open:bool} $selector
|
||||
*/
|
||||
$availabilityShort = ['methaven' => 'Methaven', 'garana' => 'Garana', 'selten' => 'selten'];
|
||||
$filterUrl = $base . '/edit';
|
||||
$selKey = (string) $selector['key'];
|
||||
$selKinds = $selector['kinds'];
|
||||
$selFilters = $selector['filters'];
|
||||
$selCatalog = $selector['catalog'];
|
||||
$selCount = (int) $selector['count'];
|
||||
$selAnchor = (string) $selector['anchor'];
|
||||
?>
|
||||
<dialog class="selector" id="item-selector" aria-labelledby="item-selector-title"<?= $itemSelectorOpen ? ' data-autopen' : '' ?>>
|
||||
<dialog class="selector" id="<?= e($selKey) ?>-selector" aria-labelledby="<?= e($selKey) ?>-selector-title"<?= $selector['open'] ? ' data-autopen' : '' ?>>
|
||||
<div class="selector-head">
|
||||
<h2 id="item-selector-title">Ausrüstung aus dem Katalog</h2>
|
||||
<h2 id="<?= e($selKey) ?>-selector-title"><?= e((string) $selector['title']) ?></h2>
|
||||
<button class="btn btn-small" type="button" data-dialog-close>Schließen</button>
|
||||
</div>
|
||||
<div class="selector-body">
|
||||
<form method="get" action="<?= e($filterUrl) ?>" class="selector-filters">
|
||||
<label class="field">
|
||||
<span>Suche</span>
|
||||
<input type="search" name="item_q" value="<?= e($itemFilters['needle']) ?>" placeholder="Name oder Notiz …" autocomplete="off">
|
||||
<input type="search" name="<?= e($selKey) ?>_q" value="<?= e($selFilters['needle']) ?>" placeholder="Name oder Notiz …" autocomplete="off">
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Art</span>
|
||||
<select name="item_kind">
|
||||
<option value="">Alle Arten</option>
|
||||
<?php foreach (WS_ITEM_CATEGORIES as $category): ?>
|
||||
<option value="<?= e($category) ?>"<?= $itemFilters['kind'] === $category ? ' selected' : '' ?>><?= e($category) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php if ($selKinds === null): ?>
|
||||
<select name="<?= e($selKey) ?>_kind">
|
||||
<option value="">Alle Arten</option>
|
||||
<?php foreach (WS_ITEM_CATEGORIES as $category): ?>
|
||||
<option value="<?= e($category) ?>"<?= $selFilters['kind'] === $category ? ' selected' : '' ?>><?= e($category) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php else: ?>
|
||||
<input type="text" value="<?= e(implode(' + ', $selKinds)) ?>" readonly>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<label class="field">
|
||||
<span>Verfügbarkeit</span>
|
||||
<select name="item_avail">
|
||||
<select name="<?= e($selKey) ?>_avail">
|
||||
<option value="">Alle (auch Seltenes)</option>
|
||||
<?php foreach (WS_ITEM_AVAILABILITY as $key => $label): ?>
|
||||
<option value="<?= e($key) ?>"<?= $itemFilters['availability'] === $key ? ' selected' : '' ?>><?= e($label) ?></option>
|
||||
<option value="<?= e($key) ?>"<?= $selFilters['availability'] === $key ? ' selected' : '' ?>><?= e($label) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</label>
|
||||
<div class="selector-filter-actions">
|
||||
<button class="btn btn-small" type="submit">Filtern</button>
|
||||
<a class="btn btn-small" href="<?= e($filterUrl . '#inventar') ?>">Zurücksetzen</a>
|
||||
<a class="btn btn-small" href="<?= e($filterUrl . '#' . $selAnchor) ?>">Zurücksetzen</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<p class="selector-hint muted">
|
||||
<?= count($itemCatalog) ?> von <?= (int) $itemCatalogCount ?> Gegenständen
|
||||
<?php if ((int) $itemCatalogCount > count($itemCatalog)): ?>
|
||||
<?= count($selCatalog) ?> von <?= $selCount ?> Gegenständen
|
||||
<?php if ($selCount > count($selCatalog)): ?>
|
||||
– Suche oder Filter eingrenzen, um mehr zu sehen.
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
|
|
@ -66,13 +75,13 @@ $filterUrl = $base . '/edit';
|
|||
(10 Münzen ≈ 1 Pfund).
|
||||
</p>
|
||||
|
||||
<form method="post" action="<?= e($base . '/items/from-catalog') ?>">
|
||||
<form method="post" action="<?= e(url($selector['action'])) ?>">
|
||||
<?= csrf_field() ?>
|
||||
<div class="selector-groups">
|
||||
<?php $lastKind = ''; ?>
|
||||
<?php foreach ($itemCatalog as $entry): ?>
|
||||
<?php foreach ($selCatalog as $entry): ?>
|
||||
<?php $kind = (string) $entry['kind']; ?>
|
||||
<?php if ($kind !== $lastKind): ?>
|
||||
<?php if ($kind !== $lastKind && $selKinds === null): ?>
|
||||
<?php $lastKind = $kind; ?>
|
||||
<p class="selector-group"><?= e($kind) ?></p>
|
||||
<?php endif; ?>
|
||||
|
|
@ -90,7 +99,7 @@ $filterUrl = $base . '/edit';
|
|||
</span>
|
||||
</button>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($itemCatalog === []): ?>
|
||||
<?php if ($selCatalog === []): ?>
|
||||
<p class="selector-empty">Kein Gegenstand passt zu Suche und Filtern.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue