(selectEl, onMetaUpdate)
| 1015 | } |
| 1016 | |
| 1017 | export async function populateAdminUserHubSelect(selectEl, onMetaUpdate) { |
| 1018 | if (!selectEl) return; |
| 1019 | |
| 1020 | selectEl.innerHTML = `<option value="">${tf("loading", "Loading…")}</option>`; |
| 1021 | |
| 1022 | try { |
| 1023 | const usersRaw = await fetchAllUsers(); |
| 1024 | const list = Array.isArray(usersRaw) |
| 1025 | ? usersRaw |
| 1026 | : (usersRaw && Array.isArray(usersRaw.users) ? usersRaw.users : []); |
| 1027 | |
| 1028 | const current = (localStorage.getItem("username") || "").trim(); |
| 1029 | |
| 1030 | selectEl.innerHTML = ""; |
| 1031 | const normalized = list |
| 1032 | .map(u => { |
| 1033 | if (typeof u === "string") return { username: u, isAdmin: false }; |
| 1034 | return { |
| 1035 | username: u.username || u.user || "", |
| 1036 | isAdmin: isAdminUser(u) |
| 1037 | }; |
| 1038 | }) |
| 1039 | .filter(u => u.username); |
| 1040 | |
| 1041 | if (typeof onMetaUpdate === 'function') { |
| 1042 | onMetaUpdate(normalized); |
| 1043 | } |
| 1044 | |
| 1045 | normalized.forEach(u => { |
| 1046 | const opt = document.createElement("option"); |
| 1047 | opt.value = u.username; |
| 1048 | opt.textContent = u.isAdmin ? `${u.username} (admin)` : u.username; |
| 1049 | if (current && u.username === current) { |
| 1050 | opt.dataset.currentUser = "1"; |
| 1051 | } |
| 1052 | selectEl.appendChild(opt); |
| 1053 | }); |
| 1054 | |
| 1055 | if (!selectEl.value && selectEl.options.length > 0) { |
| 1056 | selectEl.selectedIndex = 0; |
| 1057 | } |
| 1058 | } catch (e) { |
| 1059 | console.error("populateAdminUserHubSelect error", e); |
| 1060 | selectEl.innerHTML = `<option value="">${tf("error_loading_users", "Error loading users")}</option>`; |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | export function openUserPermissionsModal(initialUser = null) { |
| 1065 | let userPermissionsModal = document.getElementById("userPermissionsModal"); |
no test coverage detected