diff --git a/assets/css/style.css b/assets/css/style.css index 7e4adf4..7580764 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -735,6 +735,19 @@ input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.4); } +.group-picker-option.locked, +.group-picker-option:disabled { + opacity: 0.5; + cursor: not-allowed; + color: var(--text-muted); +} + +.group-picker-option.locked:hover, +.group-picker-option:disabled:hover { + border-color: var(--border); + transform: none; +} + /* Grid-Zellen sind gleich breit (1fr), aber Buttons schrumpfen sich sonst ueber die globale "button"-Regel auf ihre Textbreite (width: fit-content) und wirken dadurch unterschiedlich gross - deshalb hier explizit 100%. */ diff --git a/assets/js/raids.js b/assets/js/raids.js index 76e4ca2..eaf4301 100644 --- a/assets/js/raids.js +++ b/assets/js/raids.js @@ -23,18 +23,23 @@ var selectedClass = null; var selectedGroup = null; // null = automatisch zuteilen - function makeGroupButton(label, value, isSelected) { + function makeGroupButton(label, value, isSelected, isLocked) { var btn = document.createElement('button'); btn.type = 'button'; - btn.className = 'group-picker-option' + (isSelected ? ' selected' : ''); - btn.textContent = label; + btn.className = 'group-picker-option' + (isSelected ? ' selected' : '') + (isLocked ? ' locked' : ''); + btn.textContent = isLocked ? label + ' 🔒' : label; btn.setAttribute('data-group', value === null ? '' : String(value)); - btn.addEventListener('click', function () { - selectedGroup = value; - groupPicker.querySelectorAll('.group-picker-option').forEach(function (b) { - b.classList.toggle('selected', b === btn); + 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; } @@ -49,15 +54,26 @@ } 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)); + groupPicker.appendChild(makeGroupButton('Automatisch', null, selectedGroup === null, false)); groups.forEach(function (name, index) { - groupPicker.appendChild(makeGroupButton(name, index + 1, selectedGroup === index + 1)); + var groupNumber = index + 1; + groupPicker.appendChild(makeGroupButton(name, groupNumber, selectedGroup === groupNumber, lockedGroups.indexOf(groupNumber) !== -1)); }); - groupPicker.appendChild(makeGroupButton('Ersatzbank', 0, selectedGroup === 0)); + 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); diff --git a/raid_signup_action.php b/raid_signup_action.php index faa4af8..7a0e9d6 100644 --- a/raid_signup_action.php +++ b/raid_signup_action.php @@ -32,8 +32,12 @@ try { $signups = is_array($raid['signups'] ?? null) ? $raid['signups'] : []; $discordId = (int) $user['discord_id']; + $lockedGroups = is_array($raid['locked_groups'] ?? null) ? array_map('intval', $raid['locked_groups']) : []; + $openGroups = $maxGroups >= 1 ? array_values(array_diff(range(1, $maxGroups), $lockedGroups)) : []; + $wantsAuto = $groupRaw === null || $groupRaw === '' || $groupRaw === 'auto'; $matchedWish = true; + $wishRejectReason = null; // 'locked' | 'full' $requestGroup = null; if (!$wantsAuto) { @@ -42,14 +46,26 @@ try { json_response(false, 'Ungültige Gruppe ausgewählt.'); } - if (raid_wish_is_sensible($signups, $discordId, $class, $desiredGroup)) { + if ($desiredGroup > 0 && in_array($desiredGroup, $lockedGroups, true)) { + $requestGroup = null; // Gesperrte Gruppe: wie eine nicht erfuellbare Wunschgruppe behandeln + $matchedWish = false; + $wishRejectReason = 'locked'; + } elseif (raid_wish_is_sensible($signups, $discordId, $class, $desiredGroup)) { $requestGroup = $desiredGroup; } else { $requestGroup = null; // Bot automatisch zuteilen lassen $matchedWish = false; + $wishRejectReason = 'full'; } } + // Ist keine einzige Gruppe offen (alle gesperrt oder der Raid hat gar keine + // Gruppen), landet man deterministisch auf der Ersatzbank, statt auf eine + // automatische Zuteilung in eine gesperrte Gruppe zu hoffen. + if ($requestGroup === null && empty($openGroups)) { + $requestGroup = 0; + } + $assigned = raid_signup($raidId, $discordId, (string) $user['discord_username'], $class, $requestGroup); $assignedGroup = (int) ($assigned['group'] ?? 0); @@ -62,7 +78,10 @@ try { 'matched_wish' => true, ]); } else { - json_response(true, 'Deine Wunschgruppe war schon voll besetzt für diese Rolle, daher wurdest du automatisch zugeteilt: ' + $reasonText = $wishRejectReason === 'locked' + ? 'Deine Wunschgruppe ist gesperrt' + : 'Deine Wunschgruppe war schon voll besetzt für diese Rolle'; + json_response(true, $reasonText . ', daher wurdest du automatisch zugeteilt: ' . $assignedGroupLabel . '. Melde dich gerne beim Raid-Lead, falls du eine Anpassung möchtest.', [ 'group' => $assignedGroup, 'matched_wish' => false, diff --git a/raids.php b/raids.php index 49871f1..86c82ad 100644 --- a/raids.php +++ b/raids.php @@ -150,6 +150,7 @@ include __DIR__ . '/includes/header.php';