LuminaWebsite/assets/js/warehouse.js
Maaxxs 3e025b811e Lagerhaus: stock and history of the legion's items
A new page records items handed in (item, quantity, when, and from whom -
a website account or a free-text name) and taken out (when, now or entered
by hand, and optionally to whom). Stock is always computed from the
movements, withdrawals can't exceed it, and a deposit can only be deleted
once nothing of it has been taken out. Stock is shown as cards with the item
picture and quantity, name and category below, plus search and a category
filter; the history lists every movement with who entered it.

The item list holds 2,301 weapons, armor pieces, accessories and consumables
read from the Aion 2 wiki's MediaWiki API, with each item's icon downscaled
to 128px under assets/images/warehouse/. It is loaded into the database on
first visit and again whenever the JSON changes. Unknown names can be added
as custom items after a confirmation, since the wiki lists no materials.

warehouse.view and warehouse.manage are new permissions. Missing core
permissions are now created automatically and granted to the Administrator
group, and the two tables are created like the other schema additions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 08:46:40 +02:00

101 lines
3.8 KiB
JavaScript

(function () {
'use strict';
// ---- Dialoge Einlagern / Entnehmen ----
function openModal(id, trigger) {
var modal = document.getElementById(id);
if (!modal) return;
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 first = modal.querySelector('input:not([type="hidden"]):not([value]), select, input[type="text"]');
if (first) first.focus();
}
document.querySelectorAll('[data-open-modal]').forEach(function (button) {
button.addEventListener('click', function () {
openModal(button.dataset.openModal, button);
});
});
document.querySelectorAll('.modal-overlay').forEach(function (modal) {
var close = modal.querySelector('.modal-close');
if (close) close.addEventListener('click', function () { modal.hidden = true; });
modal.addEventListener('click', function (event) {
if (event.target === modal) modal.hidden = true;
});
});
document.addEventListener('keydown', function (event) {
if (event.key !== 'Escape') return;
document.querySelectorAll('.modal-overlay:not([hidden])').forEach(function (modal) {
modal.hidden = true;
});
});
// Entnehmen: hoechstens so viel wie auf Lager.
var outItem = document.getElementById('out-item');
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;
if (max) {
outQuantity.max = max;
if (parseInt(outQuantity.value, 10) > parseInt(max, 10)) outQuantity.value = max;
} else {
outQuantity.removeAttribute('max');
}
};
outItem.addEventListener('change', applyMax);
applyMax();
}
// Konto oder Name: wer ein Konto waehlt, braucht keinen Namen mehr.
document.querySelectorAll('.warehouse-counterpart').forEach(function (box) {
var select = box.querySelector('select');
var name = box.querySelector('input');
if (!select || !name) return;
var sync = function () {
name.disabled = select.value !== '';
if (name.disabled) name.value = '';
};
select.addEventListener('change', sync);
sync();
});
// ---- Bestand filtern ----
var search = document.getElementById('warehouse-search');
var category = document.getElementById('warehouse-category');
var table = document.getElementById('warehouse-stock');
var noMatch = document.getElementById('warehouse-no-match');
if (!search || !category || !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)
&& (cat === '' || row.dataset.category === cat);
row.hidden = !show;
if (show) visible++;
});
if (noMatch) noMatch.hidden = visible > 0;
}
search.addEventListener('input', filter);
category.addEventListener('change', filter);
})();