feat: Group functions in edit modal

This commit is contained in:
Flatlogic Bot 2026-01-10 10:21:12 +00:00
parent 3da7625d06
commit cdd041c172

View File

@ -601,19 +601,36 @@ document.addEventListener('DOMContentLoaded', function () {
const functionsSelect = document.getElementById('editRoles'); const functionsSelect = document.getElementById('editRoles');
functionsSelect.innerHTML = ''; // Clear existing options functionsSelect.innerHTML = ''; // Clear existing options
data.all_functions.forEach(func => { const functionsSelect = document.getElementById('editRoles');
const option = document.createElement('option'); functionsSelect.innerHTML = ''; // Clear existing options
option.value = func.id;
let textContent = func.name; // Group functions by group name
if (func.group_name) { const groupedFunctions = data.all_functions.reduce((acc, func) => {
textContent += ' (' + func.group_name + ')'; const groupName = func.group_name || 'Other';
if (!acc[groupName]) {
acc[groupName] = [];
} }
option.textContent = textContent; acc[groupName].push(func);
if (data.person_functions.map(String).includes(String(func.id))) { return acc;
option.selected = true; }, {});
}
functionsSelect.appendChild(option); // Populate the select with optgroups
}); for (const groupName in groupedFunctions) {
const optgroup = document.createElement('optgroup');
optgroup.label = groupName;
groupedFunctions[groupName].forEach(func => {
const option = document.createElement('option');
option.value = func.id;
option.textContent = func.name;
if (data.person_functions.map(String).includes(String(func.id))) {
option.selected = true;
}
optgroup.appendChild(option);
});
functionsSelect.appendChild(optgroup);
}
}); });
}); });
} }