Add a mobile-friendly move dropdown alongside raid editor drag&drop

Native HTML5 drag&drop doesn't work on touch devices at all, so
moving players between groups in editor mode was effectively unusable
on mobile. Each signup item now also gets a compact <select> (built
from the same data-groups/data-locked-groups already used for the
signup modal) that moves the player on change - works via tap on
mobile and click on desktop, and excludes locked groups as targets
except the player's own current one.

Extracted the shared move logic (API call + DOM patch for counts/
empty-state/header badge) from the drag&drop drop handler into
moveSignupTo(), reused by both the drop handler and the new dropdown
instead of duplicating it.

The select is hidden outside editor mode and switches to a full-width
row below the name under 480px so it's easier to tap; verified via a
local preview at both desktop and mobile (375px) viewport sizes,
including that locked groups are correctly excluded from the options.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Maaxxs 2026-09-19 13:58:22 +02:00
parent 40d8bec259
commit f8d4d21fed
2 changed files with 139 additions and 40 deletions

View file

@ -466,9 +466,34 @@ input:focus, select:focus, textarea:focus {
.raid-group li { .raid-group li {
display: flex; display: flex;
align-items: center; align-items: center;
flex-wrap: wrap;
gap: 0.3rem;
margin-bottom: 0.4rem; margin-bottom: 0.4rem;
} }
/* Mobile-/Touch-Alternative zum Drag&Drop: natives HTML5-Drag&Drop funktioniert
auf Touch-Geraeten nicht, daher gibt es im Editor-Modus zusaetzlich dieses
Dropdown pro Spieler. Ausserhalb des Editor-Modus bleibt es versteckt. */
.raid-move-select {
display: none;
width: auto;
max-width: 110px;
margin-left: auto;
padding: 0.15rem 0.3rem;
font-size: 0.75rem;
border-radius: 4px;
}
.raid-card.editing .raid-move-select { display: block; }
@media (max-width: 480px) {
.raid-move-select {
max-width: none;
flex: 1 1 100%;
margin-left: 1.75rem;
}
}
.class-icon { .class-icon {
width: 28px; width: 28px;
height: 28px; height: 28px;

View file

@ -341,6 +341,52 @@
} }
} }
// Fuehrt das eigentliche Verschieben aus (API-Call + DOM-Patch) - gemeinsam
// genutzt von Drag&Drop (Maus) und dem Verschieben-Dropdown (Touch/Mobile,
// da natives HTML5-Drag&Drop auf Touch-Geraeten nicht funktioniert).
function moveSignupTo(card, itemEl, targetZone) {
var sourceZone = itemEl.closest('.raid-drop-zone');
if (!sourceZone || sourceZone === targetZone) {
return Promise.resolve();
}
return postJson('/raid_move_action.php', {
raid_id: card.getAttribute('data-raid-id'),
user_id: itemEl.getAttribute('data-user-id'),
group: targetZone.getAttribute('data-group')
}).then(function (result) {
if (result.status !== 'success') {
throw new Error(result.message || 'Verschieben fehlgeschlagen.');
}
var list = targetZone.querySelector('.raid-signup-list');
if (!list) {
list = document.createElement('ul');
list.className = 'raid-signup-list';
targetZone.appendChild(list);
}
list.appendChild(itemEl);
updateZoneAfterMove(sourceZone);
updateZoneAfterMove(targetZone);
// 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 = targetZone.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';
}
}
});
}
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';
@ -374,47 +420,75 @@
}); });
if (!itemEl) return; if (!itemEl) return;
var sourceZone = itemEl.closest('.raid-drop-zone'); moveSignupTo(card, itemEl, zone).catch(function (err) {
if (sourceZone === zone) return; alert(err.message || 'Verschieben fehlgeschlagen.');
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') {
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 () {
alert('Verbindung fehlgeschlagen.');
}); });
}); });
}); });
// ---- Verschieben-Dropdown pro Spieler (Mobile/Touch-Alternative zum Drag&Drop) ----
document.querySelectorAll('.raid-card').forEach(function (card) {
if (!card.querySelector('.raid-edit-toggle')) return; // kein Editor-Modus fuer diesen Raid
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 = [];
}
card.querySelectorAll('.raid-signup-item[draggable="true"]').forEach(function (item) {
var currentZone = item.closest('.raid-drop-zone');
var currentGroup = currentZone ? currentZone.getAttribute('data-group') : '';
var select = document.createElement('select');
select.className = 'raid-move-select';
select.title = 'In andere Gruppe verschieben';
groups.forEach(function (name, index) {
var groupNumber = index + 1;
if (lockedGroups.indexOf(groupNumber) !== -1 && String(groupNumber) !== currentGroup) {
return; // gesperrte Gruppen nicht als Ziel anbieten
}
var opt = document.createElement('option');
opt.value = String(groupNumber);
opt.textContent = name;
if (String(groupNumber) === currentGroup) opt.selected = true;
select.appendChild(opt);
});
var benchOpt = document.createElement('option');
benchOpt.value = '0';
benchOpt.textContent = 'Ersatzbank';
if (currentGroup === '0') benchOpt.selected = true;
select.appendChild(benchOpt);
// Verhindert, dass ein Klick/Tap auf das Dropdown gleichzeitig einen
// Drag auf dem umgebenden <li> auf dem Desktop auslöst.
select.addEventListener('mousedown', function (e) { e.stopPropagation(); });
select.addEventListener('click', function (e) { e.stopPropagation(); });
select.addEventListener('change', function () {
var targetZone = card.querySelector('.raid-drop-zone[data-group="' + select.value + '"]');
if (!targetZone) return;
var previousValue = currentGroup;
select.disabled = true;
moveSignupTo(card, item, targetZone).then(function () {
currentGroup = select.value;
select.disabled = false;
}).catch(function (err) {
alert(err.message || 'Verschieben fehlgeschlagen.');
select.value = previousValue;
select.disabled = false;
});
});
item.appendChild(select);
});
});
})(); })();