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');
functionsSelect.innerHTML = ''; // Clear existing options
// Group functions by group name
const groupedFunctions = data.all_functions.reduce((acc, func) => {
const groupName = func.group_name || 'Other';
if (!acc[groupName]) {
acc[groupName] = [];
}
acc[groupName].push(func);
return acc;
}, {});
// 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'); const option = document.createElement('option');
option.value = func.id; option.value = func.id;
let textContent = func.name; option.textContent = func.name;
if (func.group_name) {
textContent += ' (' + func.group_name + ')';
}
option.textContent = textContent;
if (data.person_functions.map(String).includes(String(func.id))) { if (data.person_functions.map(String).includes(String(func.id))) {
option.selected = true; option.selected = true;
} }
functionsSelect.appendChild(option); optgroup.appendChild(option);
}); });
functionsSelect.appendChild(optgroup);
}
}); });
}); });
} }