LuminaWebsite/assets/js/shop.js
Maaxxs c4f94bf84a Member feedback: raid input checks and fixed raid points, premades in the raid form, live raid page, Lumina-style dialogs, leadership calendar entries, class-based weapon picker, map and tactics fixes
- Raids: "Max. Spieler" only whole numbers up to groups x 5 (max. 10 groups / 50), gearscore only a number; fixed +1 Lumipunkt per participation, other values only with the new raids.points permission; pick an existing premade per group when creating a raid; unchanged legacy values no longer block editing
- Raid page updates itself every 15 s while visible (raids_live.php, cards rendered by includes/raid_card.php), open editors and confirm dialogs are kept
- Restore takes the new raid_id from the bot (archived messages are now deleted in Discord) and moves settings, attendance and awards; website signups send the server display name
- Premades: dissolve by leadership needs a reason, lead gets DMs on join/assign/decline/remove (source/actor_id sent to the bot), transfer picker skips players who already lead a group, website accept keeps the one-group rule, no commas in names
- Site-wide Lumina dialog (assets/js/confirm-dialog.js) replaces confirm/prompt/alert via data-confirm; error flashes are a dialog you confirm with OK
- Calendar: audience per entry (all / leadership takes part / internal) with the new calendar.leadership permission; day cells list all entries and scroll
- Gear planner: main-hand picker filtered by the set's class, mismatches marked, "keine Klasse" option, link to an external skill/Daevanion plan per set
- Map: correct kisk icons (Elyos on Verteron/Abyss, Altgard fixed), per-map max zoom and bounded panning, German texts, data source note
- Tactics: toolbar as a uniform grid, whole-tactic copy, automatic versions with restore and a 90-day trash, official tactics protected
- Global thin gold scrollbars, readable hover colours, "Sedes Luminis" spelling, patch notes and README, schema version 34

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 16:12:18 +02:00

207 lines
9.1 KiB
JavaScript

(function () {
'use strict';
function formatPoints(value) {
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.');
}
// ---- Dialoge ----
function closeModal(modal) { modal.hidden = true; }
document.querySelectorAll('.modal-overlay').forEach(function (modal) {
var close = modal.querySelector('.modal-close');
if (close) close.addEventListener('click', function () { closeModal(modal); });
modal.addEventListener('click', function (event) {
if (event.target === modal) closeModal(modal);
});
});
document.addEventListener('keydown', function (event) {
if (event.key !== 'Escape') return;
document.querySelectorAll('.modal-overlay:not([hidden])').forEach(closeModal);
});
// ---- Shop: Beantragen ----
var buyModal = document.getElementById('shop-buy-modal');
if (buyModal) {
var buyItem = document.getElementById('shop-buy-item');
var buyName = document.getElementById('shop-buy-name');
var buyQuantity = document.getElementById('shop-buy-quantity');
var buyTotal = document.getElementById('shop-buy-total');
var price = 0;
var updateTotal = function () {
var qty = parseInt(buyQuantity.value, 10) || 0;
buyTotal.textContent = formatPoints(Math.max(0, qty) * price);
};
var openBuy = function (button, keepValues) {
buyItem.value = button.dataset.itemId;
buyName.textContent = button.dataset.itemName;
price = parseInt(button.dataset.price, 10) || 0;
buyQuantity.max = button.dataset.max;
if (!keepValues) {
buyQuantity.value = 1;
document.getElementById('shop-buy-note').value = '';
}
updateTotal();
buyModal.hidden = false;
buyQuantity.focus();
buyQuantity.select();
};
document.querySelectorAll('.shop-buy').forEach(function (button) {
button.addEventListener('click', function () { openBuy(button, false); });
});
buyQuantity.addEventListener('input', updateTotal);
// Nach einem Fehler ist der Dialog schon offen - Preis und Hoechstmenge nachladen.
if (!buyModal.hidden) {
var current = document.querySelector('.shop-buy[data-item-id="' + buyItem.value + '"]');
if (current) openBuy(current, true); else buyModal.hidden = true;
}
}
// ---- Shop: Suche und Kategorie ----
var search = document.getElementById('shop-search');
var grid = document.getElementById('shop-items');
if (search && grid) {
var category = document.getElementById('shop-category');
var noMatch = document.getElementById('shop-no-match');
var count = document.getElementById('shop-count');
var total = grid.querySelectorAll('.shop-card').length;
var cat = '';
var filter = function () {
var term = search.value.trim().toLowerCase();
var visible = 0;
grid.querySelectorAll('.shop-card').forEach(function (card) {
var show = (term === '' || card.dataset.name.indexOf(term) !== -1)
&& (cat === '' || card.dataset.category === cat);
card.hidden = !show;
if (show) visible++;
});
if (noMatch) noMatch.hidden = visible > 0;
if (count) {
count.textContent = visible === total
? total + (total === 1 ? ' Gegenstand' : ' Gegenstände')
: visible + ' von ' + total;
}
};
search.addEventListener('input', filter);
// Kategorien im Kasten links: Klick waehlt aus (und markiert den Eintrag)
if (category) {
category.addEventListener('click', function (event) {
var button = event.target.closest('.shop-category');
if (!button) return;
cat = button.dataset.value;
category.querySelectorAll('.shop-category').forEach(function (b) {
var on = b === button;
b.classList.toggle('active', on);
b.setAttribute('aria-pressed', String(on));
});
filter();
});
}
}
// Antraege ablehnen/stornieren: den Grund fragt data-confirm-input ab (assets/js/confirm-dialog.js).
// ---- Antraege: Teilbewilligung - Kosten passend zur eingegebenen Anzahl anzeigen ----
document.querySelectorAll('.shop-approve-quantity').forEach(function (input) {
var form = input.closest('form');
var orderId = form.querySelector('input[name="order_id"]').value;
var price = document.querySelector('[data-order-price="' + orderId + '"]');
var amount = price ? price.lastChild : null;
var unit = parseInt(input.dataset.unitPrice, 10) || 0;
var update = function () {
var qty = Math.min(parseInt(input.value, 10) || 0, parseInt(input.max, 10));
if (amount) amount.textContent = ' ' + formatPoints(Math.max(0, qty) * unit);
};
input.addEventListener('input', update);
update();
});
// ---- Verwaltung: Gegenstand anlegen / bearbeiten ----
var itemModal = document.getElementById('shop-item-modal');
if (itemModal) {
var form = document.getElementById('shop-item-form');
var title = document.getElementById('shop-item-title');
var mode = form.elements.stock_mode;
var applyMode = function () {
itemModal.querySelectorAll('[data-mode-field]').forEach(function (field) {
field.hidden = field.dataset.modeField !== mode.value;
});
var hint = itemModal.querySelector('[data-mode-hint]');
if (hint) hint.textContent = mode.value === 'warehouse' ? '(Pflicht - daraus kommt der Bestand)' : '(optional, für das Bild)';
form.elements.warehouse_item.required = mode.value === 'warehouse';
};
mode.addEventListener('change', applyMode);
var fill = function (data) {
data = data || {};
form.elements.item_id.value = data.id || '';
form.elements.name.value = data.name || '';
form.elements.category_id.value = data.category_id || '';
form.elements.description.value = data.description || '';
form.elements.price.value = data.price !== undefined ? data.price : '';
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();
};
document.querySelectorAll('[data-open-modal="shop-item-modal"]').forEach(function (button) {
button.addEventListener('click', function () {
fill(button.dataset.item ? JSON.parse(button.dataset.item) : null);
itemModal.hidden = false;
form.elements.name.focus();
});
});
if (itemModal.dataset.old) {
fill(JSON.parse(itemModal.dataset.old));
} else {
applyMode();
}
}
// ---- Verwaltung: aus dem Lagerhaus uebernehmen ----
var importModal = document.getElementById('shop-import-modal');
if (importModal) {
document.querySelectorAll('[data-open-modal="shop-import-modal"]').forEach(function (button) {
button.addEventListener('click', function () { importModal.hidden = false; });
});
var checks = importModal.querySelectorAll('.shop-import-check');
var all = document.getElementById('shop-import-all');
var priceFor = function (check) {
return importModal.querySelector('input[name="prices[' + check.value + ']"]');
};
// Wer einen Gegenstand auswaehlt, muss einen Preis angeben.
checks.forEach(function (check) {
check.addEventListener('change', function () {
priceFor(check).required = check.checked;
all.checked = Array.prototype.every.call(checks, function (c) { return c.checked; });
});
});
all.addEventListener('change', function () {
checks.forEach(function (check) {
check.checked = all.checked;
priceFor(check).required = all.checked;
});
});
document.getElementById('shop-import-apply').addEventListener('click', function () {
var value = document.getElementById('shop-import-price').value;
if (value === '') return;
checks.forEach(function (check) {
if (check.checked) priceFor(check).value = value;
});
});
}
})();