The Wunschgruppe picker let members select a locked group, and the signup endpoint didn't check locked_groups at all, so the wish could still go through. Locked groups are now passed to the frontend and rendered disabled with a lock icon, and the server rejects a locked group the same way it already rejects a role-capped one. When every group is locked (or the raid has none), the signup is now assigned straight to the Ersatzbank instead of relying on the bot's own auto-assign to skip locked groups. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
261 lines
10 KiB
JavaScript
261 lines
10 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
var csrfToken = (document.querySelector('meta[name="csrf-token"]') || {}).content || '';
|
|
|
|
function postJson(url, data) {
|
|
data.csrf_token = csrfToken;
|
|
return fetch(url, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(data)
|
|
}).then(function (response) {
|
|
return response.json();
|
|
});
|
|
}
|
|
|
|
// ---- Anmelde-Popup ----
|
|
var modal = document.getElementById('raid-signup-modal');
|
|
var groupPicker = document.getElementById('raid-signup-group-picker');
|
|
var feedbackEl = document.getElementById('raid-signup-feedback');
|
|
var confirmBtn = document.getElementById('raid-signup-confirm');
|
|
var currentRaidId = null;
|
|
var selectedClass = null;
|
|
var selectedGroup = null; // null = automatisch zuteilen
|
|
|
|
function makeGroupButton(label, value, isSelected, isLocked) {
|
|
var btn = document.createElement('button');
|
|
btn.type = 'button';
|
|
btn.className = 'group-picker-option' + (isSelected ? ' selected' : '') + (isLocked ? ' locked' : '');
|
|
btn.textContent = isLocked ? label + ' 🔒' : label;
|
|
btn.setAttribute('data-group', value === null ? '' : String(value));
|
|
if (isLocked) {
|
|
btn.disabled = true;
|
|
btn.title = 'Diese Gruppe ist gesperrt und kann nicht ausgewählt werden.';
|
|
} else {
|
|
btn.addEventListener('click', function () {
|
|
selectedGroup = value;
|
|
groupPicker.querySelectorAll('.group-picker-option').forEach(function (b) {
|
|
b.classList.toggle('selected', b === btn);
|
|
});
|
|
});
|
|
}
|
|
return btn;
|
|
}
|
|
|
|
function openSignupModal(card) {
|
|
if (!modal) return;
|
|
currentRaidId = card.getAttribute('data-raid-id');
|
|
selectedClass = card.getAttribute('data-my-class') || null;
|
|
|
|
var groups = [];
|
|
try {
|
|
groups = JSON.parse(card.getAttribute('data-groups') || '[]');
|
|
} catch (e) {
|
|
groups = [];
|
|
}
|
|
var lockedGroups = [];
|
|
try {
|
|
lockedGroups = JSON.parse(card.getAttribute('data-locked-groups') || '[]');
|
|
} catch (e) {
|
|
lockedGroups = [];
|
|
}
|
|
var myGroup = card.getAttribute('data-my-group') || '';
|
|
selectedGroup = myGroup === '' ? null : parseInt(myGroup, 10);
|
|
// Eine bereits gewaehlte, aber inzwischen gesperrte Gruppe zaehlt nicht mehr als Auswahl.
|
|
if (selectedGroup && lockedGroups.indexOf(selectedGroup) !== -1) {
|
|
selectedGroup = null;
|
|
}
|
|
|
|
groupPicker.innerHTML = '';
|
|
groupPicker.appendChild(makeGroupButton('Automatisch', null, selectedGroup === null, false));
|
|
groups.forEach(function (name, index) {
|
|
var groupNumber = index + 1;
|
|
groupPicker.appendChild(makeGroupButton(name, groupNumber, selectedGroup === groupNumber, lockedGroups.indexOf(groupNumber) !== -1));
|
|
});
|
|
groupPicker.appendChild(makeGroupButton('Ersatzbank', 0, selectedGroup === 0, false));
|
|
|
|
modal.querySelectorAll('.class-picker-option').forEach(function (btn) {
|
|
btn.classList.toggle('selected', btn.getAttribute('data-class') === selectedClass);
|
|
});
|
|
|
|
feedbackEl.textContent = '';
|
|
feedbackEl.className = 'raid-modal-feedback';
|
|
modal.hidden = false;
|
|
}
|
|
|
|
function closeSignupModal() {
|
|
if (modal) modal.hidden = true;
|
|
}
|
|
|
|
document.querySelectorAll('.raid-open-signup').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
var card = btn.closest('.raid-card');
|
|
if (card) openSignupModal(card);
|
|
});
|
|
});
|
|
|
|
if (modal) {
|
|
modal.querySelector('.modal-close').addEventListener('click', closeSignupModal);
|
|
modal.addEventListener('click', function (e) {
|
|
if (e.target === modal) closeSignupModal();
|
|
});
|
|
|
|
modal.querySelectorAll('.class-picker-option').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
selectedClass = btn.getAttribute('data-class');
|
|
modal.querySelectorAll('.class-picker-option').forEach(function (b) {
|
|
b.classList.toggle('selected', b === btn);
|
|
});
|
|
});
|
|
});
|
|
|
|
confirmBtn.addEventListener('click', function () {
|
|
if (!selectedClass) {
|
|
feedbackEl.textContent = 'Bitte zuerst eine Klasse auswählen.';
|
|
feedbackEl.className = 'raid-modal-feedback error';
|
|
return;
|
|
}
|
|
confirmBtn.disabled = true;
|
|
feedbackEl.textContent = 'Wird gesendet …';
|
|
feedbackEl.className = 'raid-modal-feedback';
|
|
|
|
postJson('/raid_signup_action.php', {
|
|
raid_id: currentRaidId,
|
|
class: selectedClass,
|
|
group: selectedGroup
|
|
}).then(function (result) {
|
|
feedbackEl.textContent = result.message || '';
|
|
feedbackEl.className = 'raid-modal-feedback ' + (result.status === 'success' ? 'success' : 'error');
|
|
if (result.status === 'success') {
|
|
setTimeout(function () { window.location.reload(); }, 1400);
|
|
} else {
|
|
confirmBtn.disabled = false;
|
|
}
|
|
}).catch(function () {
|
|
feedbackEl.textContent = 'Verbindung fehlgeschlagen. Bitte erneut versuchen.';
|
|
feedbackEl.className = 'raid-modal-feedback error';
|
|
confirmBtn.disabled = false;
|
|
});
|
|
});
|
|
}
|
|
|
|
// ---- Editor-Modus ----
|
|
document.querySelectorAll('.raid-edit-toggle').forEach(function (btn) {
|
|
btn.addEventListener('click', function () {
|
|
var card = btn.closest('.raid-card');
|
|
if (card) card.classList.toggle('editing');
|
|
});
|
|
});
|
|
|
|
// ---- Raid bearbeiten (Formular) ----
|
|
document.querySelectorAll('.raid-edit-form').forEach(function (form) {
|
|
form.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
var feedback = form.querySelector('.raid-edit-feedback');
|
|
var lockedGroups = Array.prototype.slice.call(form.querySelectorAll('input[name="locked_groups[]"]:checked'))
|
|
.map(function (cb) { return parseInt(cb.value, 10); });
|
|
|
|
feedback.textContent = 'Wird gespeichert …';
|
|
postJson('/raid_edit_action.php', {
|
|
raid_id: form.getAttribute('data-raid-id'),
|
|
title: form.title.value,
|
|
date_raw: form.date_raw.value,
|
|
requirements: form.requirements.value,
|
|
gearscore: form.gearscore.value,
|
|
group_names: form.group_names.value,
|
|
max_slots: form.max_slots.value,
|
|
locked_groups: lockedGroups
|
|
}).then(function (result) {
|
|
feedback.textContent = result.message || '';
|
|
if (result.status === 'success') {
|
|
setTimeout(function () { window.location.reload(); }, 900);
|
|
}
|
|
}).catch(function () {
|
|
feedback.textContent = 'Verbindung fehlgeschlagen.';
|
|
});
|
|
});
|
|
});
|
|
|
|
// ---- Premade einladen ----
|
|
document.querySelectorAll('.raid-premade-form').forEach(function (form) {
|
|
form.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
var feedback = form.querySelector('.raid-premade-feedback');
|
|
feedback.textContent = 'Wird eingeladen …';
|
|
|
|
postJson('/raid_premade_invite_action.php', {
|
|
raid_id: form.getAttribute('data-raid-id'),
|
|
premade_id: form.premade_id.value,
|
|
group: form.group.value
|
|
}).then(function (result) {
|
|
feedback.textContent = result.message || '';
|
|
if (result.status === 'success') {
|
|
setTimeout(function () { window.location.reload(); }, 1200);
|
|
}
|
|
}).catch(function () {
|
|
feedback.textContent = 'Verbindung fehlgeschlagen.';
|
|
});
|
|
});
|
|
});
|
|
|
|
// ---- Drag & Drop (nur im Editor-Modus) ----
|
|
document.querySelectorAll('.raid-signup-item').forEach(function (item) {
|
|
item.addEventListener('dragstart', function (e) {
|
|
var card = item.closest('.raid-card');
|
|
if (!card || !card.classList.contains('editing')) {
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
e.dataTransfer.setData('text/plain', JSON.stringify({
|
|
raidId: card.getAttribute('data-raid-id'),
|
|
userId: item.getAttribute('data-user-id')
|
|
}));
|
|
item.classList.add('dragging');
|
|
});
|
|
item.addEventListener('dragend', function () {
|
|
item.classList.remove('dragging');
|
|
});
|
|
});
|
|
|
|
document.querySelectorAll('.raid-drop-zone').forEach(function (zone) {
|
|
zone.addEventListener('dragover', function (e) {
|
|
var card = zone.closest('.raid-card');
|
|
if (!card || !card.classList.contains('editing')) return;
|
|
e.preventDefault();
|
|
zone.classList.add('drag-over');
|
|
});
|
|
zone.addEventListener('dragleave', function () {
|
|
zone.classList.remove('drag-over');
|
|
});
|
|
zone.addEventListener('drop', function (e) {
|
|
e.preventDefault();
|
|
zone.classList.remove('drag-over');
|
|
var card = zone.closest('.raid-card');
|
|
if (!card || !card.classList.contains('editing')) return;
|
|
|
|
var raw = e.dataTransfer.getData('text/plain');
|
|
if (!raw) return;
|
|
var payload;
|
|
try {
|
|
payload = JSON.parse(raw);
|
|
} catch (err) {
|
|
return;
|
|
}
|
|
|
|
postJson('/raid_move_action.php', {
|
|
raid_id: payload.raidId,
|
|
user_id: payload.userId,
|
|
group: zone.getAttribute('data-group')
|
|
}).then(function (result) {
|
|
if (result.status === 'success') {
|
|
window.location.reload();
|
|
} else {
|
|
alert(result.message || 'Verschieben fehlgeschlagen.');
|
|
}
|
|
}).catch(function () {
|
|
alert('Verbindung fehlgeschlagen.');
|
|
});
|
|
});
|
|
});
|
|
})();
|