Asked for: "füge ein, dass man sich für premaids auch bewerben kann" - every premade with a free place takes
applications unless its lead switches them off, and the bot sends DMs (a new application to the lead, a decline
to the applicant). Later: "man soll sich auch auf reserveplätze bewerben können".
- includes/premade_applications.php: the applications live on the website (premade_applications: premade ID and
name, lead at that time, applicant, class, wished place group/reserve, message, status open/accepted/declined/
withdrawn/closed, reason, who decided when; premade_options.applications_open). Rules: one open application
per premade, at most 3 open in total, 7 days pause after a decline by the same premade, none while invited,
when full or switched off. premade_applications_sync() matches them with the bot: applications of dissolved
premades are closed, whoever is in the premade by now counts as accepted, name and lead stay current,
decisions expire after 30 days.
- premades.php: "Bewerben" under every other premade with a free place. The popup asks for the place (group or
reserve, taken places greyed out; the group is preselected unless it is full), the class (main preselected)
and an optional message. "Meine Bewerbungen" lists the own ones with the answer for 14 days, withdrawing
works there and on the card. Leads and the leadership (premades.manage) see open applications on the card,
also outside the edit mode, with a "Reserve" tag and a confirmation that names the place; their number shows
at the menu item "Premades" (premades without a lead count for the leadership). The edit mode switches
applications off and on.
- premade_action.php: apply (checks the rules and the chosen place again), withdraw, application_accept (the
bot puts the applicant on the wished place, on the other one if it was taken meanwhile; an open invitation
becomes the membership on its place), application_decline (optional reason), applications_toggle. An
invitation to someone with an open application carries its class, also when accepted in Discord.
Dissolving a premade closes its applications, a new lead takes over the open ones.
- includes/raids_api.php: add_premade_member() passes the wished place and returns the place the bot gave;
premade_free_slots().
- Bot (already deployed, with a backup): POST /api/premades/{id}/applications sends the DMs (to the lead with
place, class, message and a link to the card; to the applicant with the reason), POST /members with source
"application" tells the applicant where they ended up and, when the leadership accepted, the lead;
add_premade_member() takes the wished place. If the bot cannot send a DM, the application is stored anyway.
- Live updates of the page and the menu number, schema version 62 (tables also in sql/schema.sql).
- Privacy: privacy policy (what is stored, who sees it, for how long), data export section premade_bewerbungen,
account deletion, data reset area "Premade-Bewerbungen".
- Patch notes and README.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
317 lines
15 KiB
JavaScript
317 lines
15 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
function openModal(modal) {
|
|
if (modal) modal.hidden = false;
|
|
}
|
|
|
|
function closeModal(modal) {
|
|
if (modal) modal.hidden = true;
|
|
}
|
|
|
|
function wireModal(modal) {
|
|
if (!modal) return;
|
|
var closeBtn = modal.querySelector('.modal-close');
|
|
if (closeBtn) closeBtn.addEventListener('click', function () { closeModal(modal); });
|
|
modal.addEventListener('click', function (e) {
|
|
if (e.target === modal) closeModal(modal);
|
|
});
|
|
}
|
|
|
|
// ---- Drag & Drop in der Premade (nur im Bearbeiten-Modus) ----
|
|
// Aus der Gruppe auf die Reserve (ein bisheriger Reservist tauscht in die Gruppe), von der Reserve auf
|
|
// einen freien Platz der Gruppe oder auf ein Mitglied - dann tauschen die beiden. In der Gruppe selbst
|
|
// tauschen zwei Mitglieder die Plaetze, auf einen freien Platz gezogen geht es ans Ende. Der Lead bleibt
|
|
// vorne. Gespeichert wird ueber das versteckte Formular (Aktion "move" bzw. "reorder").
|
|
var moveForm = document.getElementById('premade-move-form');
|
|
var drag = null;
|
|
var overSlot = null;
|
|
|
|
function moveFor(slot) {
|
|
if (!drag || !slot || slot === drag.el || slot.closest('.premade-panel') !== drag.panel) return null;
|
|
var toReserve = slot.getAttribute('data-slot-reserve') === '1';
|
|
var other = slot.getAttribute('data-slot-user');
|
|
if (!drag.reserve) {
|
|
if (toReserve) return { action: 'move', userId: drag.userId, reserve: '1' };
|
|
if (other) return { action: 'reorder', userId: drag.userId, targetUserId: other };
|
|
return slot.hasAttribute('data-slot-empty') && !drag.last ? { action: 'reorder', userId: drag.userId, direction: 'end' } : null;
|
|
}
|
|
if (toReserve || slot.hasAttribute('data-slot-lead')) return null;
|
|
if (slot.hasAttribute('data-slot-empty')) return { action: 'move', userId: drag.userId, reserve: '0' };
|
|
return other ? { action: 'move', userId: other, reserve: '1' } : null;
|
|
}
|
|
|
|
function setOver(slot) {
|
|
if (overSlot === slot) return;
|
|
if (overSlot) overSlot.classList.remove('is-drop-over');
|
|
overSlot = slot;
|
|
if (overSlot) overSlot.classList.add('is-drop-over');
|
|
}
|
|
|
|
function endDrag() {
|
|
setOver(null);
|
|
if (drag) {
|
|
drag.el.classList.remove('is-dragging');
|
|
drag.panel.querySelectorAll('.is-drop-candidate').forEach(function (slot) { slot.classList.remove('is-drop-candidate'); });
|
|
}
|
|
drag = null;
|
|
}
|
|
|
|
function submitMove(premadeId, move) {
|
|
if (!moveForm) return;
|
|
document.getElementById('premade-move-action').value = move.action;
|
|
document.getElementById('premade-move-premade-id').value = premadeId;
|
|
document.getElementById('premade-move-user-id').value = move.userId;
|
|
document.getElementById('premade-move-reserve').value = move.reserve || '';
|
|
document.getElementById('premade-move-target-user-id').value = move.targetUserId || '';
|
|
document.getElementById('premade-move-direction').value = move.direction || '';
|
|
moveForm.submit();
|
|
}
|
|
|
|
function wireDragAndDrop(panel) {
|
|
panel.addEventListener('dragstart', function (e) {
|
|
var el = e.target.closest ? e.target.closest('[data-slot-user]') : null;
|
|
if (!el || !panel.classList.contains('is-editing')) return;
|
|
var group = panel.querySelectorAll('[data-slot-user][data-slot-reserve="0"]');
|
|
drag = { panel: panel, el: el, userId: el.getAttribute('data-slot-user'), reserve: el.getAttribute('data-slot-reserve') === '1',
|
|
last: group.length > 0 && group[group.length - 1] === el };
|
|
el.classList.add('is-dragging');
|
|
e.dataTransfer.effectAllowed = 'move';
|
|
try {
|
|
e.dataTransfer.setData('text/plain', drag.userId);
|
|
// Die ganze Karte mitziehen, nicht nur das angefasste Profilbild
|
|
var rect = el.getBoundingClientRect();
|
|
e.dataTransfer.setDragImage(el, e.clientX - rect.left, e.clientY - rect.top);
|
|
} catch (err) { /* aeltere Browser: Standardbild */ }
|
|
panel.querySelectorAll('.premade-slot').forEach(function (slot) {
|
|
if (moveFor(slot)) slot.classList.add('is-drop-candidate');
|
|
});
|
|
});
|
|
panel.addEventListener('dragover', function (e) {
|
|
if (!drag) return;
|
|
var slot = e.target.closest ? e.target.closest('.premade-slot') : null;
|
|
if (slot && moveFor(slot)) {
|
|
e.preventDefault();
|
|
e.dataTransfer.dropEffect = 'move';
|
|
setOver(slot);
|
|
} else {
|
|
setOver(null);
|
|
}
|
|
});
|
|
panel.addEventListener('dragleave', function (e) {
|
|
if (!e.relatedTarget || !panel.contains(e.relatedTarget)) setOver(null);
|
|
});
|
|
panel.addEventListener('drop', function (e) {
|
|
var slot = e.target.closest ? e.target.closest('.premade-slot') : null;
|
|
var move = moveFor(slot);
|
|
if (!move) return;
|
|
e.preventDefault();
|
|
var premadeId = panel.getAttribute('data-premade-id');
|
|
endDrag();
|
|
submitMove(premadeId, move);
|
|
});
|
|
panel.addEventListener('dragend', endDrag);
|
|
}
|
|
|
|
// ---- Bearbeiten-Modus pro Premade (bleibt nach dem Neuladen durch eine Aktion offen) ----
|
|
var EDIT_KEY = 'premades-editing';
|
|
function loadEditing() {
|
|
try { return JSON.parse(sessionStorage.getItem(EDIT_KEY) || '[]'); } catch (e) { return []; }
|
|
}
|
|
function saveEditing(ids) {
|
|
try { sessionStorage.setItem(EDIT_KEY, JSON.stringify(ids)); } catch (e) { /* egal */ }
|
|
}
|
|
var editingIds = loadEditing();
|
|
|
|
document.querySelectorAll('.premade-panel').forEach(function (panel) {
|
|
var toggle = panel.querySelector('.premade-edit-toggle');
|
|
if (!toggle) return;
|
|
var id = panel.getAttribute('data-premade-id');
|
|
function setEditing(on) {
|
|
panel.classList.toggle('is-editing', on);
|
|
toggle.setAttribute('aria-pressed', on ? 'true' : 'false');
|
|
toggle.title = on ? 'Bearbeiten beenden' : 'Premade bearbeiten';
|
|
// Verschieben nur im Bearbeiten-Modus
|
|
panel.querySelectorAll('[data-slot-user]').forEach(function (slot) { slot.draggable = on; });
|
|
}
|
|
setEditing(editingIds.indexOf(id) !== -1);
|
|
toggle.addEventListener('click', function () {
|
|
var on = !panel.classList.contains('is-editing');
|
|
setEditing(on);
|
|
editingIds = editingIds.filter(function (x) { return x !== id; });
|
|
if (on) editingIds.push(id);
|
|
saveEditing(editingIds);
|
|
});
|
|
wireDragAndDrop(panel);
|
|
});
|
|
|
|
// ---- Mitglied einladen ----
|
|
var inviteModal = document.getElementById('premade-invite-modal');
|
|
var inviteForm = document.getElementById('premade-invite-form');
|
|
var invitePremadeIdField = document.getElementById('premade-invite-premade-id');
|
|
var inviteUserIdField = document.getElementById('premade-invite-user-id');
|
|
|
|
wireModal(inviteModal);
|
|
|
|
// Die Leitung teilt direkt ein (data-direct="1"), ein Lead verschickt eine Einladung.
|
|
var inviteDirect = false;
|
|
|
|
document.querySelectorAll('.premade-slot-invite-btn').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
invitePremadeIdField.value = btn.getAttribute('data-premade-id') || '';
|
|
inviteDirect = btn.getAttribute('data-direct') === '1';
|
|
// Nur Spieler zeigen, die in genau diese Gruppe passen
|
|
var allowed = (btn.getAttribute('data-candidates') || '').split(',');
|
|
if (inviteModal) {
|
|
inviteModal.querySelectorAll('.premade-invite-option').forEach(function (option) {
|
|
option.hidden = allowed.indexOf(option.getAttribute('data-user-id')) === -1;
|
|
});
|
|
var title = inviteModal.querySelector('.premade-invite-title');
|
|
var hint = inviteModal.querySelector('.premade-invite-hint');
|
|
if (title) title.textContent = inviteDirect ? 'Spieler einteilen' : 'Mitglied einladen';
|
|
if (hint) {
|
|
hint.textContent = hint.getAttribute(inviteDirect ? 'data-direct-text' : 'data-invite-text')
|
|
+ (btn.getAttribute('data-reserve') === '1' ? ' ' + hint.getAttribute('data-reserve-text') : '');
|
|
}
|
|
}
|
|
openModal(inviteModal);
|
|
});
|
|
});
|
|
|
|
if (inviteModal) {
|
|
inviteModal.querySelectorAll('.premade-invite-option').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
// Die Auswahl verschickt sofort eine Discord-PN - deshalb vorher nachfragen.
|
|
var name = btn.getAttribute('data-user-name') || 'dieses Mitglied';
|
|
var question = inviteDirect
|
|
? name + ' wirklich in die Premade einteilen?\n\nDas Mitglied wird per Discord-PN benachrichtigt.'
|
|
: name + ' wirklich in die Premade einladen?\n\nDas Mitglied wird per Discord-PN benachrichtigt.';
|
|
window.luminaDialog.confirm(question, {
|
|
title: inviteDirect ? 'Spieler einteilen' : 'Mitglied einladen',
|
|
okLabel: inviteDirect ? 'Einteilen' : 'Einladen'
|
|
}).then(function (ok) {
|
|
if (!ok) return;
|
|
inviteUserIdField.value = btn.getAttribute('data-user-id') || '';
|
|
inviteForm.submit();
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
// ---- Aufloesen durch die Leitung (mit Begruendung fuer den Lead) ----
|
|
var dissolveModal = document.getElementById('premade-dissolve-modal');
|
|
wireModal(dissolveModal);
|
|
if (dissolveModal) {
|
|
var dissolveCancel = dissolveModal.querySelector('.modal-cancel');
|
|
if (dissolveCancel) dissolveCancel.addEventListener('click', function () { closeModal(dissolveModal); });
|
|
}
|
|
|
|
document.querySelectorAll('.premade-dissolve-btn').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
if (!dissolveModal) return;
|
|
document.getElementById('premade-dissolve-premade-id').value = btn.getAttribute('data-premade-id') || '';
|
|
dissolveModal.querySelector('.premade-dissolve-name').textContent = btn.getAttribute('data-premade-name') || '';
|
|
var reason = document.getElementById('premade-dissolve-reason');
|
|
reason.value = '';
|
|
openModal(dissolveModal);
|
|
reason.focus();
|
|
});
|
|
});
|
|
|
|
// ---- Bewerben: Klasse und Nachricht an den Lead ----
|
|
var applyModal = document.getElementById('premade-apply-modal');
|
|
wireModal(applyModal);
|
|
if (applyModal) {
|
|
var applyCancel = applyModal.querySelector('.modal-cancel');
|
|
if (applyCancel) applyCancel.addEventListener('click', function () { closeModal(applyModal); });
|
|
}
|
|
|
|
document.querySelectorAll('.premade-apply-btn').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
if (!applyModal) return;
|
|
document.getElementById('premade-apply-premade-id').value = btn.getAttribute('data-premade-id') || '';
|
|
applyModal.querySelector('.premade-apply-name').textContent = btn.getAttribute('data-premade-name') || '';
|
|
// Platz: nur freie sind waehlbar - vorausgewaehlt die Gruppe, ist sie voll die Reserve
|
|
var groupFree = btn.getAttribute('data-group-free') !== '0';
|
|
var reserveFree = btn.getAttribute('data-reserve-free') !== '0';
|
|
applyModal.querySelectorAll('input[name="slot"]').forEach(function (radio) {
|
|
radio.disabled = !(radio.value === 'reserve' ? reserveFree : groupFree);
|
|
radio.checked = radio.value === (groupFree ? 'group' : 'reserve');
|
|
});
|
|
openModal(applyModal);
|
|
document.getElementById('premade-apply-message').focus();
|
|
});
|
|
});
|
|
|
|
// ---- Klasse wechseln (Symbol im eigenen Platz) ----
|
|
var classModal = document.getElementById('premade-class-modal');
|
|
var classForm = document.getElementById('premade-class-form');
|
|
var classPremadeIdField = document.getElementById('premade-class-premade-id');
|
|
var classValueField = document.getElementById('premade-class-value');
|
|
|
|
wireModal(classModal);
|
|
|
|
document.querySelectorAll('.premade-class-switch').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
classPremadeIdField.value = btn.getAttribute('data-premade-id') || '';
|
|
var currentClass = btn.getAttribute('data-current-class') || '';
|
|
if (classModal) {
|
|
classModal.querySelectorAll('.class-picker-option').forEach(function (option) {
|
|
option.classList.toggle('selected', option.getAttribute('data-class') === currentClass);
|
|
});
|
|
}
|
|
openModal(classModal);
|
|
});
|
|
});
|
|
|
|
if (classModal) {
|
|
classModal.querySelectorAll('.class-picker-option').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
// Die schon gewaehlte Klasse nochmal anklicken schliesst nur das Fenster
|
|
if (btn.classList.contains('selected')) {
|
|
closeModal(classModal);
|
|
return;
|
|
}
|
|
classValueField.value = btn.getAttribute('data-class') || '';
|
|
classForm.submit();
|
|
});
|
|
});
|
|
}
|
|
|
|
// ---- Banner: Vorschau beim Auswaehlen und beim Verschieben des Bildausschnitts ----
|
|
// Nach dem Speichern (Seite laedt neu) ist der Banner-Bereich wieder offen.
|
|
var BANNER_OPEN_KEY = 'lumina.premadeBannerOpen';
|
|
document.querySelectorAll('.premade-banner-edit').forEach(function (details) {
|
|
var panel = details.closest('.premade-panel');
|
|
var id = panel ? panel.getAttribute('data-premade-id') : '';
|
|
try {
|
|
if (sessionStorage.getItem(BANNER_OPEN_KEY) === id) {
|
|
details.open = true;
|
|
sessionStorage.removeItem(BANNER_OPEN_KEY);
|
|
}
|
|
} catch (e) { /* egal */ }
|
|
details.querySelectorAll('form').forEach(function (form) {
|
|
form.addEventListener('submit', function () {
|
|
try { sessionStorage.setItem(BANNER_OPEN_KEY, id); } catch (e) { /* egal */ }
|
|
});
|
|
});
|
|
|
|
var form = details.querySelector('.premade-banner-form');
|
|
var preview = form.querySelector('.premade-banner-preview');
|
|
var focus = form.querySelector('.premade-banner-focus');
|
|
function update() {
|
|
var checked = form.querySelector('input[name="banner"]:checked');
|
|
var url = checked ? checked.getAttribute('data-url') || '' : '';
|
|
preview.style.setProperty('--banner-image', url ? 'url("' + url + '")' : 'none');
|
|
preview.style.setProperty('--banner-focus', focus.value + '%');
|
|
preview.classList.toggle('is-empty', !url);
|
|
focus.disabled = !url;
|
|
form.querySelectorAll('.background-option').forEach(function (option) {
|
|
option.classList.toggle('is-selected', !!checked && option.contains(checked));
|
|
});
|
|
}
|
|
form.addEventListener('change', update);
|
|
focus.addEventListener('input', update);
|
|
update();
|
|
});
|
|
})();
|