Redesign raid group editor and keep editor mode open while dragging
Two changes to the raid editor (raids.php/raids.js): - Moving a member via drag&drop no longer reloads the page. It now patches the DOM in place (moves the list item, updates each group's member count/empty-state, and adjusts the header's "X / Y angemeldet" badge when bench vs. a real group is involved), so the editor panel stays open and multiple members can be reshuffled without re-entering edit mode each time. The form's own "Speichern" still reloads on success, since that's the point where the edit is actually committed. - Replaces the single comma-separated "Gruppennamen" text field and the separate "Gruppen sperren" checkbox grid with one row per group (name input + inline lock toggle + remove button), plus a "+ Gruppe hinzufügen" button to append a new row. Group names and locked_groups are now read from these rows on submit instead of parsing a comma-separated string. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
5bf1f271dc
commit
b5fec1d3c7
3 changed files with 179 additions and 20 deletions
|
|
@ -676,6 +676,57 @@ input:focus, select:focus, textarea:focus {
|
||||||
|
|
||||||
.raid-edit-form .actions { align-items: center; }
|
.raid-edit-form .actions { align-items: center; }
|
||||||
|
|
||||||
|
.group-editor { margin-bottom: 1rem; }
|
||||||
|
|
||||||
|
.group-editor-rows {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin: 0.5rem 0 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-editor-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-editor-name {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-editor-lock {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 38px;
|
||||||
|
height: 38px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
background: var(--bg-panel-alt);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 6px;
|
||||||
|
color: var(--text-muted);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: color 0.15s ease, border-color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-editor-lock.checked {
|
||||||
|
color: var(--gold);
|
||||||
|
border-color: var(--gold);
|
||||||
|
background: rgba(201, 162, 39, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-editor-lock-checkbox {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
opacity: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-editor-remove { flex-shrink: 0; }
|
||||||
|
|
||||||
.raid-premade-form {
|
.raid-premade-form {
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
padding-top: 1rem;
|
padding-top: 1rem;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,11 @@
|
||||||
|
|
||||||
var csrfToken = (document.querySelector('meta[name="csrf-token"]') || {}).content || '';
|
var csrfToken = (document.querySelector('meta[name="csrf-token"]') || {}).content || '';
|
||||||
|
|
||||||
|
// Fuer JS-generierte Gruppen-Editor-Zeilen (siehe unten) - identisch zu icon('lock')/icon('x')
|
||||||
|
// aus includes/functions.php, damit neu hinzugefuegte Zeilen genauso aussehen wie die vom Server gerenderten.
|
||||||
|
var ICON_LOCK = '<svg class="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="11" width="16" height="9" rx="2"/><path d="M7.5 11V7.5a4.5 4.5 0 0 1 9 0V11"/></svg>';
|
||||||
|
var ICON_X = '<svg class="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>';
|
||||||
|
|
||||||
function postJson(url, data) {
|
function postJson(url, data) {
|
||||||
data.csrf_token = csrfToken;
|
data.csrf_token = csrfToken;
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
|
|
@ -153,8 +158,17 @@
|
||||||
form.addEventListener('submit', function (e) {
|
form.addEventListener('submit', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var feedback = form.querySelector('.raid-edit-feedback');
|
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); });
|
var groupNames = [];
|
||||||
|
var lockedGroups = [];
|
||||||
|
form.querySelectorAll('.group-editor-row').forEach(function (row) {
|
||||||
|
var name = row.querySelector('.group-editor-name').value.trim();
|
||||||
|
if (name === '') return; // leere Zeilen werden beim Speichern ignoriert
|
||||||
|
groupNames.push(name);
|
||||||
|
if (row.querySelector('.group-editor-lock-checkbox').checked) {
|
||||||
|
lockedGroups.push(groupNames.length);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
feedback.textContent = 'Wird gespeichert …';
|
feedback.textContent = 'Wird gespeichert …';
|
||||||
postJson('/raid_edit_action.php', {
|
postJson('/raid_edit_action.php', {
|
||||||
|
|
@ -163,7 +177,7 @@
|
||||||
date_raw: form.date_raw.value,
|
date_raw: form.date_raw.value,
|
||||||
requirements: form.requirements.value,
|
requirements: form.requirements.value,
|
||||||
gearscore: form.gearscore.value,
|
gearscore: form.gearscore.value,
|
||||||
group_names: form.group_names.value,
|
group_names: groupNames.join(', '),
|
||||||
max_slots: form.max_slots.value,
|
max_slots: form.max_slots.value,
|
||||||
locked_groups: lockedGroups
|
locked_groups: lockedGroups
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
|
|
@ -177,6 +191,41 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---- Gruppen-Editor: Zeilen hinzufuegen/entfernen ----
|
||||||
|
function createGroupEditorRow(name) {
|
||||||
|
var row = document.createElement('div');
|
||||||
|
row.className = 'group-editor-row';
|
||||||
|
row.innerHTML =
|
||||||
|
'<input type="text" class="group-editor-name" placeholder="Gruppenname">' +
|
||||||
|
'<label class="group-editor-lock" title="Gruppe sperren"><input type="checkbox" class="group-editor-lock-checkbox">' + ICON_LOCK + '</label>' +
|
||||||
|
'<button type="button" class="icon-button group-editor-remove" title="Gruppe entfernen">' + ICON_X + '</button>';
|
||||||
|
row.querySelector('.group-editor-name').value = name || '';
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.group-editor').forEach(function (editor) {
|
||||||
|
var rows = editor.querySelector('.group-editor-rows');
|
||||||
|
var addBtn = editor.querySelector('.group-editor-add');
|
||||||
|
|
||||||
|
addBtn.addEventListener('click', function () {
|
||||||
|
var row = createGroupEditorRow('');
|
||||||
|
rows.appendChild(row);
|
||||||
|
row.querySelector('.group-editor-name').focus();
|
||||||
|
});
|
||||||
|
|
||||||
|
rows.addEventListener('click', function (e) {
|
||||||
|
var removeBtn = e.target.closest('.group-editor-remove');
|
||||||
|
if (!removeBtn) return;
|
||||||
|
if (rows.querySelectorAll('.group-editor-row').length <= 1) return; // mindestens eine Gruppe muss bleiben
|
||||||
|
removeBtn.closest('.group-editor-row').remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
rows.addEventListener('change', function (e) {
|
||||||
|
if (!e.target.classList.contains('group-editor-lock-checkbox')) return;
|
||||||
|
e.target.closest('.group-editor-lock').classList.toggle('checked', e.target.checked);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// ---- Premade einladen ----
|
// ---- Premade einladen ----
|
||||||
document.querySelectorAll('.raid-premade-form').forEach(function (form) {
|
document.querySelectorAll('.raid-premade-form').forEach(function (form) {
|
||||||
form.addEventListener('submit', function (e) {
|
form.addEventListener('submit', function (e) {
|
||||||
|
|
@ -218,6 +267,29 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Aktualisiert Mitgliederzahl, Leer-Hinweis und Liste einer Gruppe nach einem
|
||||||
|
// Verschieben, ohne die Seite neu zu laden - der Editor-Modus bleibt so
|
||||||
|
// erhalten und man kann mehrere Spieler hintereinander verschieben.
|
||||||
|
function updateZoneAfterMove(zone) {
|
||||||
|
var count = zone.querySelectorAll('.raid-signup-item').length;
|
||||||
|
var countEl = zone.querySelector('.raid-group-count');
|
||||||
|
if (countEl) countEl.textContent = '(' + count + ')';
|
||||||
|
|
||||||
|
var list = zone.querySelector('.raid-signup-list');
|
||||||
|
var hint = zone.querySelector('.raid-empty-hint');
|
||||||
|
if (count === 0) {
|
||||||
|
if (list) list.remove();
|
||||||
|
if (!hint) {
|
||||||
|
hint = document.createElement('p');
|
||||||
|
hint.className = 'text-muted raid-empty-hint';
|
||||||
|
hint.textContent = 'Keine Anmeldungen';
|
||||||
|
zone.appendChild(hint);
|
||||||
|
}
|
||||||
|
} else if (hint) {
|
||||||
|
hint.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.querySelectorAll('.raid-drop-zone').forEach(function (zone) {
|
document.querySelectorAll('.raid-drop-zone').forEach(function (zone) {
|
||||||
var isLocked = zone.getAttribute('data-locked') === '1';
|
var isLocked = zone.getAttribute('data-locked') === '1';
|
||||||
|
|
||||||
|
|
@ -245,15 +317,49 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var itemEl = null;
|
||||||
|
card.querySelectorAll('.raid-signup-item').forEach(function (li) {
|
||||||
|
if (li.getAttribute('data-user-id') === String(payload.userId)) itemEl = li;
|
||||||
|
});
|
||||||
|
if (!itemEl) return;
|
||||||
|
|
||||||
|
var sourceZone = itemEl.closest('.raid-drop-zone');
|
||||||
|
if (sourceZone === zone) return;
|
||||||
|
|
||||||
postJson('/raid_move_action.php', {
|
postJson('/raid_move_action.php', {
|
||||||
raid_id: payload.raidId,
|
raid_id: payload.raidId,
|
||||||
user_id: payload.userId,
|
user_id: payload.userId,
|
||||||
group: zone.getAttribute('data-group')
|
group: zone.getAttribute('data-group')
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
if (result.status === 'success') {
|
if (result.status !== 'success') {
|
||||||
window.location.reload();
|
|
||||||
} else {
|
|
||||||
alert(result.message || 'Verschieben fehlgeschlagen.');
|
alert(result.message || 'Verschieben fehlgeschlagen.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var list = zone.querySelector('.raid-signup-list');
|
||||||
|
if (!list) {
|
||||||
|
list = document.createElement('ul');
|
||||||
|
list.className = 'raid-signup-list';
|
||||||
|
zone.appendChild(list);
|
||||||
|
}
|
||||||
|
list.appendChild(itemEl);
|
||||||
|
|
||||||
|
updateZoneAfterMove(sourceZone);
|
||||||
|
updateZoneAfterMove(zone);
|
||||||
|
|
||||||
|
// Ersatzbank zaehlt nicht als aktive Anmeldung - Kopfzeilen-Badge nur
|
||||||
|
// anpassen, wenn Quelle/Ziel zwischen Bank und echter Gruppe wechseln
|
||||||
|
// und die Klasse nicht "Ausstehend" ist.
|
||||||
|
var className = itemEl.getAttribute('data-class');
|
||||||
|
var sourceIsBench = sourceZone.getAttribute('data-group') === '0';
|
||||||
|
var targetIsBench = zone.getAttribute('data-group') === '0';
|
||||||
|
if (className !== 'Ausstehend' && sourceIsBench !== targetIsBench) {
|
||||||
|
var badge = card.querySelector('.raid-count-badge');
|
||||||
|
var match = badge && badge.textContent.match(/(-?\d+)\s*\/\s*(\d+)/);
|
||||||
|
if (match) {
|
||||||
|
var active = parseInt(match[1], 10) + (targetIsBench ? -1 : 1);
|
||||||
|
badge.textContent = active + ' / ' + match[2] + ' angemeldet';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).catch(function () {
|
}).catch(function () {
|
||||||
alert('Verbindung fehlgeschlagen.');
|
alert('Verbindung fehlgeschlagen.');
|
||||||
|
|
|
||||||
30
raids.php
30
raids.php
|
|
@ -159,7 +159,7 @@ include __DIR__ . '/includes/header.php';
|
||||||
<?php if ($isArchived): ?>
|
<?php if ($isArchived): ?>
|
||||||
<span class="badge badge-disabled">Archiviert<?= $archivedAt ? ' (' . e((string) $archivedAt) . ')' : '' ?></span>
|
<span class="badge badge-disabled">Archiviert<?= $archivedAt ? ' (' . e((string) $archivedAt) . ')' : '' ?></span>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<span class="badge"><?= $activeCount ?> / <?= $maxSlots ?> angemeldet</span>
|
<span class="badge raid-count-badge"><?= $activeCount ?> / <?= $maxSlots ?> angemeldet</span>
|
||||||
<?php if ($canEditThis): ?>
|
<?php if ($canEditThis): ?>
|
||||||
<button type="button" class="icon-button raid-edit-toggle" title="Bearbeiten">
|
<button type="button" class="icon-button raid-edit-toggle" title="Bearbeiten">
|
||||||
<?= icon('edit') ?>
|
<?= icon('edit') ?>
|
||||||
|
|
@ -222,21 +222,23 @@ include __DIR__ . '/includes/header.php';
|
||||||
<label>Anforderungen</label>
|
<label>Anforderungen</label>
|
||||||
<input type="text" name="requirements" value="<?= e($requirements) ?>">
|
<input type="text" name="requirements" value="<?= e($requirements) ?>">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<label>Gruppennamen (kommagetrennt)</label>
|
|
||||||
<input type="text" name="group_names" value="<?= e(implode(', ', $groupNames)) ?>">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="group-editor">
|
||||||
<label>Gruppen sperren</label>
|
<label>Gruppen</label>
|
||||||
<div class="checkbox-grid">
|
<div class="group-editor-rows">
|
||||||
<?php foreach ($groupNames as $index => $groupName): ?>
|
<?php foreach ($groupNames as $index => $groupName): ?>
|
||||||
<label>
|
<div class="group-editor-row">
|
||||||
<input type="checkbox" name="locked_groups[]" value="<?= $index + 1 ?>" <?= in_array($index + 1, $lockedGroups, true) ? 'checked' : '' ?>>
|
<input type="text" class="group-editor-name" value="<?= e($groupName) ?>" placeholder="Gruppenname">
|
||||||
<?= e($groupName) ?>
|
<?php $isRowLocked = in_array($index + 1, $lockedGroups, true); ?>
|
||||||
</label>
|
<label class="group-editor-lock<?= $isRowLocked ? ' checked' : '' ?>" title="Gruppe sperren">
|
||||||
|
<input type="checkbox" class="group-editor-lock-checkbox" <?= $isRowLocked ? 'checked' : '' ?>>
|
||||||
|
<?= icon('lock') ?>
|
||||||
|
</label>
|
||||||
|
<button type="button" class="icon-button group-editor-remove" title="Gruppe entfernen"><?= icon('x') ?></button>
|
||||||
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
|
<button type="button" class="button-secondary group-editor-add">+ Gruppe hinzufügen</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<button type="submit">Speichern</button>
|
<button type="submit">Speichern</button>
|
||||||
|
|
@ -271,7 +273,7 @@ include __DIR__ . '/includes/header.php';
|
||||||
<?php foreach ($groupNames as $index => $groupName): ?>
|
<?php foreach ($groupNames as $index => $groupName): ?>
|
||||||
<?php $members = $signupsByGroup[$index + 1] ?? []; $isLockedGroup = in_array($index + 1, $lockedGroups, true); ?>
|
<?php $members = $signupsByGroup[$index + 1] ?? []; $isLockedGroup = in_array($index + 1, $lockedGroups, true); ?>
|
||||||
<div class="raid-group raid-drop-zone<?= $isLockedGroup ? ' raid-group-locked' : '' ?>" data-group="<?= $index + 1 ?>" data-locked="<?= $isLockedGroup ? '1' : '0' ?>">
|
<div class="raid-group raid-drop-zone<?= $isLockedGroup ? ' raid-group-locked' : '' ?>" data-group="<?= $index + 1 ?>" data-locked="<?= $isLockedGroup ? '1' : '0' ?>">
|
||||||
<h3><?= e($groupName) ?> (<?= count($members) ?>)<?= $isLockedGroup ? ' ' . icon('lock') : '' ?></h3>
|
<h3><?= e($groupName) ?> <span class="raid-group-count">(<?= count($members) ?>)</span><?= $isLockedGroup ? ' ' . icon('lock') : '' ?></h3>
|
||||||
<?php if (empty($members)): ?>
|
<?php if (empty($members)): ?>
|
||||||
<p class="text-muted raid-empty-hint">Keine Anmeldungen</p>
|
<p class="text-muted raid-empty-hint">Keine Anmeldungen</p>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
|
|
@ -280,7 +282,7 @@ include __DIR__ . '/includes/header.php';
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<div class="raid-group raid-group-bench raid-drop-zone" data-group="0">
|
<div class="raid-group raid-group-bench raid-drop-zone" data-group="0">
|
||||||
<h3>Ersatzbank (<?= count($benchSignups) ?>)</h3>
|
<h3>Ersatzbank <span class="raid-group-count">(<?= count($benchSignups) ?>)</span></h3>
|
||||||
<?php if (empty($benchSignups)): ?>
|
<?php if (empty($benchSignups)): ?>
|
||||||
<p class="text-muted raid-empty-hint">Keine Anmeldungen</p>
|
<p class="text-muted raid-empty-hint">Keine Anmeldungen</p>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue