- 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>
247 lines
10 KiB
JavaScript
247 lines
10 KiB
JavaScript
/**
|
|
* Rueckfragen und Meldungen im Lumina-Stil statt der Browser-Fenster confirm()/prompt()/alert().
|
|
* Wird auf allen Seiten geladen (includes/footer.php).
|
|
*
|
|
* Im Skript:
|
|
* luminaDialog.confirm('Termin löschen?', { title: 'Termin löschen', danger: true, okLabel: 'Löschen' })
|
|
* .then(function (ok) { ... }); // true / false
|
|
* luminaDialog.prompt('Warum?', { placeholder: '…', required: 5, multiline: true })
|
|
* .then(function (text) { ... }); // Text oder null (abgebrochen)
|
|
* luminaDialog.alert('Das hat nicht geklappt.', { tone: 'error' });
|
|
*
|
|
* Im HTML (ohne eigenes Skript) - an <form> oder an einem Absende-Knopf:
|
|
* data-confirm="Text" Rueckfrage vor dem Absenden
|
|
* data-confirm-title="…" Ueberschrift (sonst "Bist du sicher?")
|
|
* data-confirm-ok="Löschen" Beschriftung des OK-Knopfs
|
|
* data-confirm-danger roter OK-Knopf (Loeschen & Co.)
|
|
* data-confirm-input="reason" zusaetzlich ein Textfeld - der Text landet im Formularfeld "reason"
|
|
* data-confirm-placeholder="…" Platzhalter dafuer
|
|
*
|
|
* Fehlermeldungen der Seite (set_flash('error', …)) zeigt includes/header.php als Daten-Block
|
|
* #flash-errors - sie erscheinen hier als Meldung, die man mit OK bestaetigen muss.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
var open = null; // gerade offener Dialog - es gibt immer nur einen
|
|
var queue = []; // weitere warten, bis er zu ist
|
|
var counter = 0;
|
|
|
|
function el(tag, className, text) {
|
|
var node = document.createElement(tag);
|
|
if (className) node.className = className;
|
|
if (text !== undefined) node.textContent = text;
|
|
return node;
|
|
}
|
|
|
|
function show(kind, message, opts) {
|
|
opts = opts || {};
|
|
return new Promise(function (resolve) {
|
|
var request = { kind: kind, message: String(message || ''), opts: opts, resolve: resolve };
|
|
if (open) {
|
|
queue.push(request);
|
|
} else {
|
|
render(request);
|
|
}
|
|
});
|
|
}
|
|
|
|
function render(request) {
|
|
var kind = request.kind;
|
|
var opts = request.opts;
|
|
var id = 'lumina-dialog-' + (++counter);
|
|
var previousFocus = document.activeElement;
|
|
|
|
var overlay = el('div', 'lumina-dialog-overlay');
|
|
var box = el('div', 'lumina-dialog' + (opts.tone === 'error' ? ' lumina-dialog-error' : '') + (opts.danger ? ' lumina-dialog-danger' : ''));
|
|
box.setAttribute('role', kind === 'alert' ? 'alertdialog' : 'dialog');
|
|
box.setAttribute('aria-modal', 'true');
|
|
box.setAttribute('aria-labelledby', id + '-title');
|
|
box.setAttribute('aria-describedby', id + '-text');
|
|
|
|
var defaultTitle = kind === 'alert'
|
|
? (opts.tone === 'error' ? 'Das hat nicht geklappt' : 'Hinweis')
|
|
: (kind === 'prompt' ? 'Bitte angeben' : 'Bist du sicher?');
|
|
var title = el('h2', 'lumina-dialog-title', opts.title || defaultTitle);
|
|
title.id = id + '-title';
|
|
var text = el('p', 'lumina-dialog-text', request.message);
|
|
text.id = id + '-text';
|
|
box.appendChild(title);
|
|
if (request.message !== '') box.appendChild(text);
|
|
|
|
var field = null;
|
|
if (kind === 'prompt') {
|
|
field = opts.multiline ? el('textarea', 'lumina-dialog-input') : el('input', 'lumina-dialog-input');
|
|
if (!opts.multiline) field.type = 'text';
|
|
if (opts.multiline) field.rows = 3;
|
|
field.placeholder = opts.placeholder || '';
|
|
field.value = opts.value || '';
|
|
if (opts.maxlength) field.maxLength = opts.maxlength;
|
|
field.setAttribute('aria-label', opts.title || request.message || 'Eingabe');
|
|
box.appendChild(field);
|
|
}
|
|
|
|
var actions = el('div', 'lumina-dialog-actions');
|
|
var cancelBtn = null;
|
|
if (kind !== 'alert') {
|
|
cancelBtn = el('button', 'button-secondary', opts.cancelLabel || 'Abbrechen');
|
|
cancelBtn.type = 'button';
|
|
actions.appendChild(cancelBtn);
|
|
}
|
|
var okBtn = el('button', opts.danger ? 'button-danger' : '', opts.okLabel || (kind === 'alert' ? 'OK' : (opts.danger ? 'Löschen' : 'Bestätigen')));
|
|
okBtn.type = 'button';
|
|
actions.appendChild(okBtn);
|
|
box.appendChild(actions);
|
|
overlay.appendChild(box);
|
|
|
|
var minLength = kind === 'prompt' ? (parseInt(opts.required, 10) || 0) : 0;
|
|
function validate() {
|
|
if (field && minLength > 0) okBtn.disabled = field.value.trim().length < minLength;
|
|
}
|
|
if (field) field.addEventListener('input', validate);
|
|
validate();
|
|
|
|
function finish(confirmed) {
|
|
if (open !== overlay) return;
|
|
open = null;
|
|
window.removeEventListener('keydown', onKey, true);
|
|
document.body.classList.remove('lumina-dialog-open');
|
|
overlay.classList.remove('visible');
|
|
setTimeout(function () {
|
|
if (overlay.parentNode) overlay.parentNode.removeChild(overlay);
|
|
}, 180);
|
|
if (previousFocus && typeof previousFocus.focus === 'function' && document.contains(previousFocus)) {
|
|
previousFocus.focus();
|
|
}
|
|
if (kind === 'confirm') request.resolve(!!confirmed);
|
|
else if (kind === 'prompt') request.resolve(confirmed ? field.value.trim() : null);
|
|
else request.resolve();
|
|
if (queue.length) render(queue.shift());
|
|
}
|
|
|
|
function onKey(e) {
|
|
if (e.key === 'Escape') {
|
|
// Nur diesen Dialog schliessen, nicht ein Popup darunter
|
|
e.preventDefault();
|
|
e.stopImmediatePropagation();
|
|
finish(kind === 'alert');
|
|
return;
|
|
}
|
|
if (e.key === 'Enter' && field && e.target === field && !opts.multiline) {
|
|
e.preventDefault();
|
|
if (!okBtn.disabled) finish(true);
|
|
return;
|
|
}
|
|
if (e.key === 'Tab') {
|
|
// Fokus bleibt im Dialog
|
|
var focusable = Array.prototype.filter.call(box.querySelectorAll('button, input, textarea'), function (node) {
|
|
return !node.disabled;
|
|
});
|
|
if (!focusable.length) return;
|
|
var first = focusable[0];
|
|
var last = focusable[focusable.length - 1];
|
|
if (e.shiftKey && document.activeElement === first) {
|
|
e.preventDefault();
|
|
last.focus();
|
|
} else if (!e.shiftKey && document.activeElement === last) {
|
|
e.preventDefault();
|
|
first.focus();
|
|
}
|
|
}
|
|
}
|
|
|
|
okBtn.addEventListener('click', function () {
|
|
finish(true);
|
|
});
|
|
if (cancelBtn) {
|
|
cancelBtn.addEventListener('click', function () {
|
|
finish(false);
|
|
});
|
|
}
|
|
// Klick daneben bricht eine Rueckfrage ab - eine Meldung muss man mit OK bestaetigen.
|
|
overlay.addEventListener('click', function (e) {
|
|
if (e.target === overlay && kind !== 'alert') finish(false);
|
|
});
|
|
|
|
open = overlay;
|
|
window.addEventListener('keydown', onKey, true);
|
|
document.body.appendChild(overlay);
|
|
document.body.classList.add('lumina-dialog-open');
|
|
requestAnimationFrame(function () {
|
|
overlay.classList.add('visible');
|
|
});
|
|
// Bei Loeschen & Co. liegt der Fokus auf "Abbrechen", damit Enter nichts Endgueltiges tut.
|
|
(field || (opts.danger && cancelBtn) || okBtn).focus();
|
|
}
|
|
|
|
window.luminaDialog = {
|
|
confirm: function (message, opts) { return show('confirm', message, opts); },
|
|
prompt: function (message, opts) { return show('prompt', message, opts); },
|
|
alert: function (message, opts) { return show('alert', message, opts); }
|
|
};
|
|
|
|
// ---- Formulare mit data-confirm ----
|
|
var PASS_MS = 30000;
|
|
|
|
window.addEventListener('submit', function (event) {
|
|
var form = event.target;
|
|
if (!(form instanceof HTMLFormElement)) return;
|
|
var submitter = event.submitter || null;
|
|
var source = submitter && submitter.hasAttribute('data-confirm') ? submitter
|
|
: (form.hasAttribute('data-confirm') ? form : null);
|
|
if (!source) return;
|
|
// Schon bestaetigt (zweiter Durchlauf nach OK, z.B. auch nach dem Verkleinern von Bildern)?
|
|
if (Date.now() - (parseInt(form.dataset.confirmPassed || '0', 10)) < PASS_MS) return;
|
|
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
if (open) return; // Doppelklick
|
|
|
|
var inputName = source.getAttribute('data-confirm-input');
|
|
var opts = {
|
|
title: source.getAttribute('data-confirm-title') || undefined,
|
|
okLabel: source.getAttribute('data-confirm-ok') || undefined,
|
|
danger: source.hasAttribute('data-confirm-danger'),
|
|
placeholder: source.getAttribute('data-confirm-placeholder') || '',
|
|
multiline: true,
|
|
maxlength: 255
|
|
};
|
|
var message = source.getAttribute('data-confirm');
|
|
var question = inputName ? window.luminaDialog.prompt(message, opts) : window.luminaDialog.confirm(message, opts);
|
|
|
|
question.then(function (result) {
|
|
if (result === false || result === null) return;
|
|
if (inputName) {
|
|
var field = form.elements.namedItem(inputName);
|
|
if (field) field.value = result;
|
|
}
|
|
form.dataset.confirmPassed = String(Date.now());
|
|
if (form.requestSubmit) {
|
|
if (submitter) form.requestSubmit(submitter); else form.requestSubmit();
|
|
} else {
|
|
form.submit();
|
|
}
|
|
});
|
|
}, true);
|
|
|
|
// Seite aus dem Zurueck-Cache: wieder nachfragen
|
|
window.addEventListener('pageshow', function () {
|
|
document.querySelectorAll('form[data-confirm-passed]').forEach(function (form) {
|
|
delete form.dataset.confirmPassed;
|
|
});
|
|
});
|
|
|
|
// ---- Fehlermeldungen der Seite ----
|
|
var errors = document.getElementById('flash-errors');
|
|
if (errors) {
|
|
var messages = [];
|
|
try {
|
|
messages = JSON.parse(errors.textContent || '[]');
|
|
} catch (e) {
|
|
messages = [];
|
|
}
|
|
if (messages.length) {
|
|
window.luminaDialog.alert(messages.join('\n\n'), { tone: 'error' });
|
|
}
|
|
}
|
|
})();
|