A text input above the table filters rows client-side as you type, matching against both the reported and the reporter name (each row carries lowercased data-reported-name/data-reporter-name attributes). Shows a "no matches" message when the filter empties the table. Also consolidated the previously duplicated reports.js <script> include into a single unconditional one at the bottom of the page, since the filter needs it regardless of reports.manage permission. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
151 lines
5.9 KiB
JavaScript
151 lines
5.9 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
// ---- "Rolle hinzufügen" (Punkte-Gewichtung, zweistufiges Popup) ----
|
|
function initAddWeightModal() {
|
|
var modal = document.getElementById('report-add-role-modal');
|
|
var addBtn = document.getElementById('report-add-role-btn');
|
|
if (!modal || !addBtn) return;
|
|
|
|
var step1 = modal.querySelector('.report-role-step[data-step="1"]');
|
|
var step2 = modal.querySelector('.report-role-step[data-step="2"]');
|
|
var nextBtn = document.getElementById('report-role-step1-next');
|
|
var backBtn = document.getElementById('report-role-step2-back');
|
|
var submitBtn = document.getElementById('report-role-step2-submit');
|
|
var summaryEl = document.getElementById('report-role-step2-summary');
|
|
var pointsInput = document.getElementById('report-role-points');
|
|
var form = document.getElementById('report-add-role-form');
|
|
var pointsField = document.getElementById('report-add-role-points-field');
|
|
var idsContainer = document.getElementById('report-add-role-ids-container');
|
|
var closeBtn = modal.querySelector('.modal-close');
|
|
var checkboxes = modal.querySelectorAll('input[name="role_ids[]"]');
|
|
|
|
function showStep(n) {
|
|
step1.hidden = n !== 1;
|
|
step2.hidden = n !== 2;
|
|
}
|
|
|
|
function updateNextState() {
|
|
var anyChecked = Array.prototype.some.call(checkboxes, function (cb) { return cb.checked; });
|
|
nextBtn.disabled = !anyChecked;
|
|
}
|
|
|
|
function resetModal() {
|
|
checkboxes.forEach(function (cb) { cb.checked = false; });
|
|
pointsInput.value = '1';
|
|
updateNextState();
|
|
showStep(1);
|
|
}
|
|
|
|
addBtn.addEventListener('click', function () {
|
|
resetModal();
|
|
modal.hidden = false;
|
|
});
|
|
closeBtn.addEventListener('click', function () { modal.hidden = true; });
|
|
modal.addEventListener('click', function (e) {
|
|
if (e.target === modal) modal.hidden = true;
|
|
});
|
|
|
|
checkboxes.forEach(function (cb) {
|
|
cb.addEventListener('change', updateNextState);
|
|
});
|
|
|
|
nextBtn.addEventListener('click', function () {
|
|
var names = [];
|
|
checkboxes.forEach(function (cb) {
|
|
if (cb.checked) names.push(cb.getAttribute('data-role-name') || '');
|
|
});
|
|
summaryEl.textContent = names.join(', ');
|
|
showStep(2);
|
|
});
|
|
|
|
backBtn.addEventListener('click', function () {
|
|
showStep(1);
|
|
});
|
|
|
|
submitBtn.addEventListener('click', function () {
|
|
var points = pointsInput.value.trim();
|
|
if (points === '' || isNaN(Number(points))) {
|
|
pointsInput.focus();
|
|
return;
|
|
}
|
|
|
|
idsContainer.innerHTML = '';
|
|
checkboxes.forEach(function (cb) {
|
|
if (!cb.checked) return;
|
|
var hidden = document.createElement('input');
|
|
hidden.type = 'hidden';
|
|
hidden.name = 'role_ids[]';
|
|
hidden.value = cb.value;
|
|
idsContainer.appendChild(hidden);
|
|
});
|
|
pointsField.value = points;
|
|
form.submit();
|
|
});
|
|
}
|
|
|
|
// ---- "Rolle ausschließen" (Timeout-Ausnahmen, einstufiges Popup) ----
|
|
function initAddExclusionModal() {
|
|
var modal = document.getElementById('report-add-exclusion-modal');
|
|
var addBtn = document.getElementById('report-add-exclusion-btn');
|
|
if (!modal || !addBtn) return;
|
|
|
|
var closeBtn = modal.querySelector('.modal-close');
|
|
var submitBtn = document.getElementById('report-exclusion-submit');
|
|
var form = document.getElementById('report-add-exclusion-form');
|
|
var idsContainer = document.getElementById('report-add-exclusion-ids-container');
|
|
var checkboxes = modal.querySelectorAll('input[name="role_ids[]"]');
|
|
|
|
addBtn.addEventListener('click', function () {
|
|
checkboxes.forEach(function (cb) { cb.checked = false; });
|
|
modal.hidden = false;
|
|
});
|
|
closeBtn.addEventListener('click', function () { modal.hidden = true; });
|
|
modal.addEventListener('click', function (e) {
|
|
if (e.target === modal) modal.hidden = true;
|
|
});
|
|
|
|
submitBtn.addEventListener('click', function () {
|
|
idsContainer.innerHTML = '';
|
|
var anyChecked = false;
|
|
checkboxes.forEach(function (cb) {
|
|
if (!cb.checked) return;
|
|
anyChecked = true;
|
|
var hidden = document.createElement('input');
|
|
hidden.type = 'hidden';
|
|
hidden.name = 'role_ids[]';
|
|
hidden.value = cb.value;
|
|
idsContainer.appendChild(hidden);
|
|
});
|
|
if (!anyChecked) return;
|
|
form.submit();
|
|
});
|
|
}
|
|
|
|
// ---- Nach Nutzer filtern (gemeldet oder Melder) ----
|
|
function initUserFilter() {
|
|
var input = document.getElementById('report-user-filter');
|
|
var rows = document.querySelectorAll('.report-row');
|
|
var emptyMessage = document.getElementById('report-filter-empty');
|
|
if (!input || !rows.length) return;
|
|
|
|
input.addEventListener('input', function () {
|
|
var query = input.value.trim().toLowerCase();
|
|
var visibleCount = 0;
|
|
|
|
rows.forEach(function (row) {
|
|
var matches = query === ''
|
|
|| (row.getAttribute('data-reported-name') || '').indexOf(query) !== -1
|
|
|| (row.getAttribute('data-reporter-name') || '').indexOf(query) !== -1;
|
|
row.hidden = !matches;
|
|
if (matches) visibleCount++;
|
|
});
|
|
|
|
if (emptyMessage) emptyMessage.hidden = visibleCount !== 0;
|
|
});
|
|
}
|
|
|
|
initAddWeightModal();
|
|
initAddExclusionModal();
|
|
initUserFilter();
|
|
})();
|