LuminaWebsite/assets/js/contributions.js
Maaxxs 852eee357d Beitragspunkte for members, new Lumina logo
Members can be awarded contribution points for raids, events and other
activities, shown with a golden heart-shaped coin. An award has an occasion,
reason, date and points per member; members are picked with search and
select all/none, and choosing a raid preselects its participants (signed up
in a group and linked to a website account), fills in reason and date and
names participants without an account. The + on a member's card awards to
that member alone, negative points deduct, and awards can be deleted whole
or per member. Balances are always computed from the awards.

The ranking shows members as cards with gold/silver/bronze for the top three
and the viewer's own balance in the header and sidebar. With only
contributions.view it lists the best 25 places plus the viewer's own place;
contributions.view_all or contributions.manage show everyone. The history of
awards is paginated, using pagination now shared with the warehouse.

The sidebar shows the new logo, and the login page and mobile top bar a
wordmark cut from it with soft edges.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 09:23:55 +02:00

120 lines
5.1 KiB
JavaScript

(function () {
'use strict';
function matches(element, term) {
return term === '' || (element.dataset.name || '').indexOf(term) !== -1;
}
// ---- Rangliste durchsuchen ----
var rankingSearch = document.getElementById('contribution-search');
var ranking = document.getElementById('contribution-ranking');
if (rankingSearch && ranking) {
var noMatch = document.getElementById('contribution-no-match');
rankingSearch.addEventListener('input', function () {
var term = rankingSearch.value.trim().toLowerCase();
var visible = 0;
ranking.querySelectorAll('.contribution-card').forEach(function (card) {
card.hidden = !matches(card, term);
if (!card.hidden) visible++;
});
if (noMatch) noMatch.hidden = visible > 0;
});
}
// ---- Formular "Punkte vergeben" ----
var form = document.getElementById('contribution-form');
if (!form) return;
var picks = Array.prototype.slice.call(form.querySelectorAll('.contribution-pick'));
var boxes = picks.map(function (pick) { return pick.querySelector('input[type="checkbox"]'); });
var counter = document.getElementById('picker-count');
var pickerSearch = document.getElementById('picker-search');
var submit = document.getElementById('contribution-submit');
var pointsInput = document.getElementById('points');
function updateCount() {
var count = boxes.filter(function (box) { return box.checked; }).length;
counter.textContent = count === 0 ? '(keins ausgewählt)' : '(' + count + ' ausgewählt)';
picks.forEach(function (pick, i) { pick.classList.toggle('checked', boxes[i].checked); });
var points = parseInt(pointsInput.value, 10);
var label = 'Punkte vergeben';
if (count > 0 && points) {
label = points > 0
? points + ' Punkte an ' + count + (count === 1 ? ' Mitglied' : ' Mitglieder') + ' vergeben'
: Math.abs(points) + ' Punkte bei ' + count + (count === 1 ? ' Mitglied' : ' Mitgliedern') + ' abziehen';
}
submit.textContent = label;
}
boxes.forEach(function (box) { box.addEventListener('change', updateCount); });
pointsInput.addEventListener('input', updateCount);
pickerSearch.addEventListener('input', function () {
var term = pickerSearch.value.trim().toLowerCase();
picks.forEach(function (pick) { pick.hidden = !matches(pick, term); });
});
// "Alle" / "Keine" wirken nur auf die gerade sichtbaren (gefilterten) Mitglieder.
function setVisible(checked) {
picks.forEach(function (pick, i) {
if (!pick.hidden) boxes[i].checked = checked;
});
updateCount();
}
document.getElementById('picker-all').addEventListener('click', function () { setVisible(true); });
document.getElementById('picker-none').addEventListener('click', function () { setVisible(false); });
// ---- Anlass und Raid ----
var category = document.getElementById('category');
var raidField = document.getElementById('raid-field');
var raidSelect = document.getElementById('raid_id');
var raidInfo = document.getElementById('raid-info');
var titleInput = document.getElementById('title');
var timeInput = document.getElementById('awarded_at');
var raidsEl = document.getElementById('contribution-raids');
var raids = raidsEl ? JSON.parse(raidsEl.textContent) : [];
var autoTitle = '';
function toggleRaidField() {
raidField.hidden = category.value !== 'raid';
if (raidField.hidden && raidInfo) raidInfo.hidden = true;
}
category.addEventListener('change', toggleRaidField);
toggleRaidField();
if (raidSelect) {
raidSelect.addEventListener('change', function () {
var raid = raids.filter(function (r) { return String(r.id) === raidSelect.value; })[0];
if (!raid) {
raidInfo.hidden = true;
return;
}
// Teilnehmer des Raids auswaehlen, alle anderen abwaehlen.
boxes.forEach(function (box) {
box.checked = raid.participants.indexOf(parseInt(box.value, 10)) !== -1;
});
// Grund und Datum nur ueberschreiben, wenn nichts Eigenes eingetragen wurde.
if (titleInput.value === '' || titleInput.value === autoTitle) {
autoTitle = raid.title + (raid.date ? ' (' + raid.date + ')' : '');
titleInput.value = autoTitle;
}
if (raid.time) timeInput.value = raid.time;
var info = raid.participants.length + ' Teilnehmer ausgewählt.';
if (raid.bench.length) {
info += ' ' + raid.bench.length + ' auf der Ersatzbank (nicht ausgewählt).';
}
if (raid.withoutAccount.length) {
info += ' Ohne Website-Konto, daher keine Punkte möglich: ' + raid.withoutAccount.join(', ') + '.';
}
raidInfo.textContent = info;
raidInfo.hidden = false;
updateCount();
});
}
updateCount();
})();