Roles at the default weight (1) are no longer listed - only roles with
an explicit, non-default point value show up, each editable/removable
inline. A new green "+ Rolle hinzufuegen" button opens a two-step popup:
pick one or more still-unconfigured roles, then set a single point
value applied to all of them at once (new report_action.php action
add_weights). Fixed two CSS specificity bugs while building this
(input[type=text] beating a plain class on width, and the generic
form{flex-direction:column} rule leaking into the inline edit row).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
89 lines
2.9 KiB
JavaScript
89 lines
2.9 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
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);
|
|
}
|
|
|
|
function openModal() {
|
|
resetModal();
|
|
modal.hidden = false;
|
|
}
|
|
|
|
function closeModal() {
|
|
modal.hidden = true;
|
|
}
|
|
|
|
addBtn.addEventListener('click', openModal);
|
|
closeBtn.addEventListener('click', closeModal);
|
|
modal.addEventListener('click', function (e) {
|
|
if (e.target === modal) closeModal();
|
|
});
|
|
|
|
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();
|
|
});
|
|
})();
|