|
40 | 40 | }); |
41 | 41 |
|
42 | 42 | initMonthReopenUserPicker(); |
| 43 | + initAppAdminsPicker(); |
43 | 44 | initAccessGroupsPicker(); |
44 | 45 | } |
45 | 46 |
|
| 47 | + function initAppAdminsPicker() { |
| 48 | + const search = Utils.$('#appAdminUsersSearch'); |
| 49 | + const list = Utils.$('#appAdminUsersList'); |
| 50 | + const empty = Utils.$('#appAdminUsersEmpty'); |
| 51 | + const countEl = Utils.$('#appAdminUsersCount'); |
| 52 | + const l10n = window.ArbeitszeitCheck && window.ArbeitszeitCheck.l10n ? window.ArbeitszeitCheck.l10n : {}; |
| 53 | + if (!search || !list) { |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + const items = Array.prototype.slice.call(list.querySelectorAll('.access-groups-item')); |
| 58 | + const checkboxes = Array.prototype.slice.call(list.querySelectorAll('input[name="appAdminUserIds[]"]')); |
| 59 | + |
| 60 | + function updateCount() { |
| 61 | + if (!countEl) { |
| 62 | + return; |
| 63 | + } |
| 64 | + const selectedCount = checkboxes.filter(function(box) { return box.checked; }).length; |
| 65 | + if (selectedCount === 0) { |
| 66 | + countEl.textContent = l10n.appAdminsAllAdmins || 'No app admins selected (all Nextcloud admins are allowed).'; |
| 67 | + return; |
| 68 | + } |
| 69 | + const template = l10n.appAdminsSelected || '%s app admin(s) selected'; |
| 70 | + countEl.textContent = template.indexOf('%s') !== -1 |
| 71 | + ? template.replace('%s', String(selectedCount)) |
| 72 | + : String(selectedCount) + ' ' + template; |
| 73 | + } |
| 74 | + |
| 75 | + function applyFilter() { |
| 76 | + const q = String(search.value || '').trim().toLowerCase(); |
| 77 | + let visible = 0; |
| 78 | + items.forEach(function(item) { |
| 79 | + const haystack = String(item.getAttribute('data-app-admin-search') || ''); |
| 80 | + const show = q === '' || haystack.indexOf(q) !== -1; |
| 81 | + item.hidden = !show; |
| 82 | + if (show) { |
| 83 | + visible++; |
| 84 | + } |
| 85 | + }); |
| 86 | + if (empty) { |
| 87 | + empty.hidden = visible !== 0; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + Utils.on(search, 'input', applyFilter); |
| 92 | + checkboxes.forEach(function(box) { |
| 93 | + Utils.on(box, 'change', updateCount); |
| 94 | + }); |
| 95 | + |
| 96 | + updateCount(); |
| 97 | + applyFilter(); |
| 98 | + } |
| 99 | + |
46 | 100 | function initAccessGroupsPicker() { |
47 | 101 | const search = Utils.$('#accessAllowedGroupsSearch'); |
48 | 102 | const list = Utils.$('#accessAllowedGroupsList'); |
|
136 | 190 | ? [] |
137 | 191 | : (Array.isArray(accessGroupsRaw) ? accessGroupsRaw : [accessGroupsRaw]); |
138 | 192 | delete formData['accessAllowedGroups[]']; |
| 193 | + const appAdminRaw = formData['appAdminUserIds[]']; |
| 194 | + formData.appAdminUserIds = appAdminRaw === undefined |
| 195 | + ? [] |
| 196 | + : (Array.isArray(appAdminRaw) ? appAdminRaw : [appAdminRaw]); |
| 197 | + delete formData['appAdminUserIds[]']; |
139 | 198 |
|
140 | 199 | // Convert numbers (use defaults on invalid/empty) |
141 | 200 | const num = (v, def) => { const n = parseFloat(v); return (Number.isFinite(n) ? n : def); }; |
|
0 commit comments