diff --git a/assets/css/style.css b/assets/css/style.css
index 88a7b70..f01baef 100644
--- a/assets/css/style.css
+++ b/assets/css/style.css
@@ -4875,3 +4875,87 @@ input[type="file"]::file-selector-button {
.list-toolbar-meta { width: 100%; }
.list-toolbar-meta .members-segment { max-width: 100%; overflow-x: auto; }
}
+
+/* ---- Auswahlfeld fuer Gegenstaende (assets/js/item-picker.js) ---- */
+.item-picker .search-field input { border-radius: 10px; }
+.item-picker-icon { display: contents; }
+
+.item-picker-preview {
+ width: 24px !important;
+ height: 24px !important;
+ left: 0.6rem !important;
+ border-radius: 5px;
+ object-fit: contain;
+}
+
+.item-picker-list {
+ position: fixed;
+ z-index: 1100;
+ margin: 0;
+ padding: 0.35rem;
+ list-style: none;
+ overflow-y: auto;
+ background: rgba(30, 30, 30, 0.97);
+ border: 1px solid rgba(201, 162, 39, 0.35);
+ border-radius: 12px;
+ box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
+ backdrop-filter: blur(10px);
+ animation: item-picker-in 0.12s ease-out;
+}
+
+.item-picker-list[hidden] { display: none; }
+
+@keyframes item-picker-in {
+ from { opacity: 0; transform: translateY(-4px); }
+ to { opacity: 1; transform: none; }
+}
+
+.item-picker-option {
+ display: flex;
+ align-items: center;
+ gap: 0.7rem;
+ padding: 0.45rem 0.6rem;
+ border-radius: 8px;
+ cursor: pointer;
+}
+
+.item-picker-option:hover { background: rgba(255, 255, 255, 0.05); }
+.item-picker-option.active { background: rgba(201, 162, 39, 0.16); }
+
+.item-picker-thumb {
+ flex-shrink: 0;
+ width: 34px;
+ height: 34px;
+ border-radius: 7px;
+ object-fit: contain;
+ background: rgba(255, 255, 255, 0.04);
+ border: 1px solid var(--border);
+}
+
+.item-picker-thumb-empty {
+ display: grid;
+ place-items: center;
+ color: var(--gold);
+ font-weight: 700;
+ border-style: dashed;
+}
+
+.item-picker-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
+.item-picker-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.item-picker-name mark { background: none; color: var(--gold); font-weight: 700; }
+.item-picker-meta { font-size: 0.78rem; color: var(--text-muted); }
+
+.item-picker-qty {
+ flex-shrink: 0;
+ padding: 0.1rem 0.55rem;
+ border-radius: 999px;
+ background: rgba(76, 175, 80, 0.14);
+ color: #8fd392;
+ font-size: 0.75rem;
+ white-space: nowrap;
+}
+
+.item-picker-note { padding: 0.55rem 0.7rem; color: var(--text-muted); font-size: 0.85rem; }
+
+/* Bestand: Suche und Kategorie-Chips */
+.warehouse-filters.list-toolbar { margin: 1rem 0; }
diff --git a/assets/js/item-picker.js b/assets/js/item-picker.js
new file mode 100644
index 0000000..e3ac0a2
--- /dev/null
+++ b/assets/js/item-picker.js
@@ -0,0 +1,273 @@
+/**
+ * Auswahlfeld fuer Lagerhaus-Gegenstaende: Suchfeld mit aufklappender Liste (Bild, Name,
+ * Kategorie, Bestand) statt Datalist oder Dropdown. Tastatur: Pfeile, Enter, Escape.
+ *
+ * Markup:
+ * name - der Text selbst wird gesendet (freie Eingabe erlaubt, z.B. neue Gegenstaende)
+ * id - ein verstecktes Feld bekommt die ID; nur Eintraege aus der Liste sind gueltig
+ * submit - wie name, schickt nach der Auswahl das Formular ab (Suche im Verlauf)
+ * Optional data-picker-empty: Text, wenn nichts passt.
+ * Von aussen: element.itemPicker.set(idOderName) und element.itemPicker.refresh().
+ */
+(function () {
+ 'use strict';
+
+ var MAX_SHOWN = 60;
+
+ function norm(value) {
+ return String(value || '').toLowerCase().normalize('NFD').replace(/[̀-ͯ]/g, '');
+ }
+
+ function formatQty(qty) {
+ return Number(qty).toLocaleString('de-DE');
+ }
+
+ // Name mit hervorgehobenem Suchbegriff (als Textknoten, kein innerHTML mit Benutzerdaten)
+ function highlighted(name, query) {
+ var span = document.createElement('span');
+ span.className = 'item-picker-name';
+ var at = query ? norm(name).indexOf(query) : -1;
+ if (at === -1) {
+ span.textContent = name;
+ return span;
+ }
+ var mark = document.createElement('mark');
+ mark.textContent = name.slice(at, at + query.length);
+ span.appendChild(document.createTextNode(name.slice(0, at)));
+ span.appendChild(mark);
+ span.appendChild(document.createTextNode(name.slice(at + query.length)));
+ return span;
+ }
+
+ function thumb(item) {
+ if (item.icon) {
+ var img = document.createElement('img');
+ img.className = 'item-picker-thumb';
+ img.src = item.icon;
+ img.alt = '';
+ img.loading = 'lazy';
+ return img;
+ }
+ var empty = document.createElement('span');
+ empty.className = 'item-picker-thumb item-picker-thumb-empty';
+ empty.textContent = item.name.charAt(0).toUpperCase();
+ return empty;
+ }
+
+ function ItemPicker(root) {
+ var source = document.getElementById(root.dataset.pickerItems);
+ var input = root.querySelector('.item-picker-input');
+ if (!source || !input) return;
+
+ var items = JSON.parse(source.textContent || '[]');
+ items.forEach(function (item) { item.key = norm(item.name); item.catKey = norm(item.category); });
+
+ var mode = root.dataset.pickerMode || 'name';
+ var hidden = root.querySelector('input[type="hidden"]');
+ var iconSlot = root.querySelector('.item-picker-icon');
+ var searchIcon = iconSlot ? iconSlot.innerHTML : '';
+ var emptyText = root.dataset.pickerEmpty || 'Kein Gegenstand gefunden.';
+
+ var list = document.createElement('ul');
+ list.className = 'item-picker-list';
+ list.id = (input.id || 'item-picker-' + Math.random().toString(36).slice(2)) + '-list';
+ list.setAttribute('role', 'listbox');
+ list.hidden = true;
+ document.body.appendChild(list);
+
+ input.setAttribute('role', 'combobox');
+ input.setAttribute('aria-autocomplete', 'list');
+ input.setAttribute('aria-expanded', 'false');
+ input.setAttribute('aria-controls', list.id);
+ input.setAttribute('autocomplete', 'off');
+
+ var matches = [];
+ var active = -1;
+
+ function findItem(value) {
+ var key = norm(String(value).trim());
+ for (var i = 0; i < items.length; i++) {
+ if (String(items[i].id) === String(value) || items[i].key === key) return items[i];
+ }
+ return null;
+ }
+
+ function refresh() {
+ var item = findItem(input.value);
+ if (iconSlot) {
+ iconSlot.innerHTML = '';
+ if (item && item.icon) {
+ var img = document.createElement('img');
+ img.className = 'icon item-picker-preview';
+ img.src = item.icon;
+ img.alt = '';
+ iconSlot.appendChild(img);
+ } else {
+ iconSlot.innerHTML = searchIcon;
+ }
+ }
+ if (mode === 'id' && hidden) {
+ var id = item ? String(item.id) : '';
+ if (hidden.value !== id) {
+ hidden.value = id;
+ hidden.dataset.max = item && item.qty != null ? item.qty : '';
+ hidden.dispatchEvent(new Event('change'));
+ }
+ input.setCustomValidity(id || !input.required ? '' : 'Bitte einen Gegenstand aus der Liste wählen.');
+ }
+ }
+
+ function position() {
+ var rect = input.getBoundingClientRect();
+ var below = window.innerHeight - rect.bottom;
+ list.style.left = rect.left + 'px';
+ list.style.width = rect.width + 'px';
+ if (below < 240 && rect.top > below) {
+ list.style.top = 'auto';
+ list.style.bottom = (window.innerHeight - rect.top + 6) + 'px';
+ list.style.maxHeight = Math.min(340, rect.top - 12) + 'px';
+ } else {
+ list.style.bottom = 'auto';
+ list.style.top = (rect.bottom + 6) + 'px';
+ list.style.maxHeight = Math.min(340, below - 12) + 'px';
+ }
+ }
+
+ function render() {
+ var query = norm(input.value.trim());
+ var starts = [];
+ var contains = [];
+ items.forEach(function (item) {
+ if (!query) contains.push(item);
+ else if (item.key.indexOf(query) === 0) starts.push(item);
+ else if (item.key.indexOf(query) !== -1 || item.catKey.indexOf(query) !== -1) contains.push(item);
+ });
+ var all = starts.concat(contains);
+ matches = all.slice(0, MAX_SHOWN);
+ active = matches.length && query ? 0 : -1;
+
+ list.innerHTML = '';
+ matches.forEach(function (item, index) {
+ var li = document.createElement('li');
+ li.className = 'item-picker-option';
+ li.id = list.id + '-' + index;
+ li.setAttribute('role', 'option');
+ li.appendChild(thumb(item));
+ var text = document.createElement('span');
+ text.className = 'item-picker-text';
+ text.appendChild(highlighted(item.name, query));
+ var meta = document.createElement('span');
+ meta.className = 'item-picker-meta';
+ meta.textContent = item.category;
+ text.appendChild(meta);
+ li.appendChild(text);
+ if (item.qty != null) {
+ var qty = document.createElement('span');
+ qty.className = 'item-picker-qty';
+ qty.textContent = formatQty(item.qty) + ' auf Lager';
+ li.appendChild(qty);
+ }
+ li.addEventListener('mousedown', function (event) { event.preventDefault(); });
+ li.addEventListener('click', function () { choose(item); });
+ list.appendChild(li);
+ });
+
+ if (!matches.length) {
+ var none = document.createElement('li');
+ none.className = 'item-picker-note';
+ none.textContent = emptyText;
+ list.appendChild(none);
+ } else if (all.length > matches.length) {
+ var more = document.createElement('li');
+ more.className = 'item-picker-note';
+ more.textContent = '… und ' + (all.length - matches.length) + ' weitere - weiter tippen zum Eingrenzen';
+ list.appendChild(more);
+ }
+ highlight();
+ }
+
+ function highlight() {
+ Array.prototype.forEach.call(list.querySelectorAll('.item-picker-option'), function (li, index) {
+ var on = index === active;
+ li.classList.toggle('active', on);
+ li.setAttribute('aria-selected', String(on));
+ if (on) li.scrollIntoView({ block: 'nearest' });
+ });
+ if (active >= 0) input.setAttribute('aria-activedescendant', list.id + '-' + active);
+ else input.removeAttribute('aria-activedescendant');
+ }
+
+ function open() {
+ render();
+ list.hidden = false;
+ input.setAttribute('aria-expanded', 'true');
+ position();
+ window.addEventListener('scroll', position, true);
+ window.addEventListener('resize', position);
+ }
+
+ function close() {
+ list.hidden = true;
+ input.setAttribute('aria-expanded', 'false');
+ window.removeEventListener('scroll', position, true);
+ window.removeEventListener('resize', position);
+ }
+
+ function choose(item, silent) {
+ input.value = item.name;
+ refresh();
+ close();
+ input.dispatchEvent(new Event('change', { bubbles: true }));
+ if (!silent && mode === 'submit' && input.form) input.form.submit();
+ }
+
+ input.addEventListener('input', function () {
+ refresh();
+ open();
+ });
+ input.addEventListener('click', function () {
+ if (list.hidden) open();
+ });
+ input.addEventListener('change', refresh);
+ input.addEventListener('blur', close);
+
+ input.addEventListener('keydown', function (event) {
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
+ event.preventDefault();
+ if (list.hidden) { open(); return; }
+ if (!matches.length) return;
+ active = event.key === 'ArrowDown'
+ ? (active + 1) % matches.length
+ : (active <= 0 ? matches.length - 1 : active - 1);
+ highlight();
+ } else if (event.key === 'Enter' && !list.hidden && active >= 0) {
+ event.preventDefault();
+ choose(matches[active]);
+ } else if (event.key === 'Escape' && !list.hidden) {
+ // Nur die Liste schliessen, nicht gleich den ganzen Dialog
+ event.stopPropagation();
+ close();
+ } else if (event.key === 'Tab') {
+ close();
+ }
+ });
+
+ // Vorbelegung (z.B. nach einem Fehler): ID im versteckten Feld -> Name anzeigen
+ if (mode === 'id' && hidden && hidden.value && !input.value) {
+ var initial = findItem(hidden.value);
+ if (initial) input.value = initial.name;
+ }
+ refresh();
+
+ root.itemPicker = {
+ set: function (value) {
+ var item = findItem(value);
+ if (item) choose(item, true);
+ else { input.value = value; refresh(); }
+ },
+ refresh: refresh
+ };
+ }
+
+ document.querySelectorAll('.item-picker').forEach(ItemPicker);
+})();
diff --git a/assets/js/shop.js b/assets/js/shop.js
index 53d86c1..4c5b875 100644
--- a/assets/js/shop.js
+++ b/assets/js/shop.js
@@ -137,6 +137,10 @@
mode.value = data.stock_mode || 'manual';
form.elements.stock.value = data.stock !== undefined ? data.stock : 0;
form.elements.warehouse_item.value = data.warehouse_item || '';
+ // Bild in den Auswahlfeldern passend zum eingetragenen Gegenstand
+ form.querySelectorAll('.item-picker').forEach(function (picker) {
+ if (picker.itemPicker) picker.itemPicker.refresh();
+ });
form.elements.active.checked = data.active === undefined ? true : !!data.active;
title.textContent = data.id ? 'Gegenstand bearbeiten' : 'Gegenstand anlegen';
applyMode();
diff --git a/assets/js/warehouse.js b/assets/js/warehouse.js
index 5113d69..0c08a15 100644
--- a/assets/js/warehouse.js
+++ b/assets/js/warehouse.js
@@ -8,19 +8,14 @@
modal.hidden = false;
// Aus einer Bestandszeile heraus: Gegenstand gleich vorauswaehlen.
- if (trigger && trigger.dataset.itemId) {
- var select = modal.querySelector('select[name="item_id"]');
- if (select) {
- select.value = trigger.dataset.itemId;
- select.dispatchEvent(new Event('change'));
- }
- }
- if (trigger && trigger.dataset.itemName) {
- var input = modal.querySelector('input[name="item"]');
- if (input) input.value = trigger.dataset.itemName;
+ var picker = modal.querySelector('.item-picker');
+ var preset = trigger ? (trigger.dataset.itemId || trigger.dataset.itemName) : '';
+ if (picker && picker.itemPicker && preset) {
+ picker.itemPicker.set(preset);
}
- var first = modal.querySelector('input:not([type="hidden"]):not([value]), select, input[type="text"]');
+ // Vorausgewaehlt: gleich zur Anzahl, sonst ins Suchfeld
+ var first = preset ? modal.querySelector('input[type="number"]') : modal.querySelector('.item-picker-input, input[type="text"]');
if (first) first.focus();
}
@@ -50,8 +45,7 @@
var outQuantity = document.getElementById('out-quantity');
if (outItem && outQuantity) {
var applyMax = function () {
- var option = outItem.options[outItem.selectedIndex];
- var max = option ? option.getAttribute('data-max') : null;
+ var max = outItem.dataset.max;
if (max) {
outQuantity.max = max;
if (parseInt(outQuantity.value, 10) > parseInt(max, 10)) outQuantity.value = max;
@@ -81,11 +75,11 @@
var category = document.getElementById('warehouse-category');
var table = document.getElementById('warehouse-stock');
var noMatch = document.getElementById('warehouse-no-match');
- if (!search || !category || !table) return;
+ var cat = '';
+ if (!search || !table) return;
function filter() {
var term = search.value.trim().toLowerCase();
- var cat = category.value;
var visible = 0;
table.querySelectorAll('.warehouse-card').forEach(function (row) {
var show = (term === '' || row.dataset.name.indexOf(term) !== -1)
@@ -97,5 +91,17 @@
}
search.addEventListener('input', filter);
- category.addEventListener('change', filter);
+ if (category) {
+ category.addEventListener('click', function (event) {
+ var chip = event.target.closest('button');
+ if (!chip) return;
+ cat = chip.dataset.value;
+ category.querySelectorAll('button').forEach(function (b) {
+ var on = b === chip;
+ b.classList.toggle('active', on);
+ b.setAttribute('aria-pressed', String(on));
+ });
+ filter();
+ });
+ }
})();
diff --git a/includes/warehouse.php b/includes/warehouse.php
index 6b78b70..06f8187 100644
--- a/includes/warehouse.php
+++ b/includes/warehouse.php
@@ -258,6 +258,30 @@ function warehouse_icon_html(?string $icon, string $name, int $size): string
. icon('box') . '';
}
+/**
+ * Gegenstaende als JSON fuer die Auswahlliste (assets/js/item-picker.js), direkt in ein
+ *
@@ -296,5 +303,6 @@ include __DIR__ . '/includes/header.php';
+
diff --git a/warehouse.php b/warehouse.php
index 24d8c82..f090ccc 100644
--- a/warehouse.php
+++ b/warehouse.php
@@ -63,7 +63,13 @@ $page = min($pageCount, max(1, (int) ($_GET['page'] ?? 1)));
$movements = warehouse_movements($historyFilter, $perPage, ($page - 1) * $perPage, $historySort);
// Fuer die Formulare: alle Gegenstaende (Vorschlagsliste) und die Konten der Website.
-$allItems = $canManage ? db()->query('SELECT name FROM warehouse_items ORDER BY name')->fetchAll(PDO::FETCH_COLUMN) : [];
+$allItems = $canManage ? db()->query('SELECT id, name, category, icon FROM warehouse_items ORDER BY name')->fetchAll() : [];
+$stockById = array_map('intval', array_column($stock, 'quantity', 'id'));
+// Vorschlaege fuer die Suche im Verlauf: nur Gegenstaende, die schon einmal bewegt wurden.
+$historyItems = db()->query(
+ 'SELECT i.id, i.name, i.category, i.icon FROM warehouse_items i
+ WHERE EXISTS (SELECT 1 FROM warehouse_movements m WHERE m.item_id = i.id) ORDER BY i.name'
+)->fetchAll();
$members = $canManage ? db()->query(
"SELECT id, COALESCE(NULLIF(display_name, ''), username) AS name FROM users
WHERE status = 'active' ORDER BY name"
@@ -75,8 +81,10 @@ unset($_SESSION['warehouse_form']);
$openForm = (string) ($old['form'] ?? '');
$categoriesInStock = [];
+$categoryCounts = [];
foreach ($itemStock as $row) {
$categoriesInStock[$row['category']] = warehouse_category_label((string) $row['category']);
+ $categoryCounts[$row['category']] = ($categoryCounts[$row['category']] ?? 0) + 1;
}
asort($categoriesInStock);
@@ -149,14 +157,19 @@ include __DIR__ . '/includes/header.php';
-