diff --git a/html/users.html b/html/users.html index 1a4f423..ca2133b 100644 --- a/html/users.html +++ b/html/users.html @@ -24,7 +24,10 @@ The directory is one wide table, so the column exceptions live here: email is the one cell long enough to stretch a row, and the two role dropdowns need room for "Assistant Project Manager" without pushing Actions off screen. */ - #users-table table td:nth-child(3){ max-width:230px; overflow:hidden; text-overflow:ellipsis; } + /* The email cell, by its class: CR-020's selection column moved it from third to + fourth on the managers' table, and a position-based rule would have followed + the wrong column. */ + #users-table table td.ell{ max-width:230px; overflow:hidden; text-overflow:ellipsis; } #users-banner:not(:empty), #scope-banner:not(:empty){ margin-bottom:var(--s3); } #nu-projects{ margin-top:var(--s2); } #nu-projects .pickrow{ padding:var(--s1) var(--s1); } @@ -33,6 +36,43 @@ #nu-project-list{ max-height:200px; overflow:auto; border:1px solid var(--border); } .whoami-chip{ font-size:12px; color:var(--muted); } .whoami-chip strong{ color:var(--text); } + + /* CR-020: row selection and the bulk bar. Tokens only (the token rule). */ + #sel-banner:not(:empty), #bulk-banner:not(:empty){ margin-bottom:var(--s3); } + #bulk-banner ul{ margin:var(--s1) 0 0; padding-left:var(--s5); font-weight:400; } + table.grid th.selcell, table.grid td.selcell{ width:1%; padding:0 var(--s1); text-align:center; } + /* The label is the hit area: the 16px box alone is under the 24px floor. */ + .selhit{ display:inline-flex; align-items:center; justify-content:center; + min-width:28px; min-height:28px; cursor:pointer; } + .selhit input{ width:16px; height:16px; margin:0; accent-color:var(--accent); cursor:pointer; } + .selhit input:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; } + .selhit input:disabled{ cursor:default; } + /* Not --accent-soft: that is the admin pill's own fill (console.css, hover note). */ + table.grid tbody tr.is-selected td{ background:var(--cds-layer-selected); } + table.grid tbody tr.is-selected td.selcell{ box-shadow:inset 3px 0 0 var(--accent); } + .bulkbar{ border:1px solid var(--accent); border-left:3px solid var(--accent); + background:var(--surface); padding:var(--s2) var(--s3); margin:0 0 var(--s3); } + .bulkbar[hidden]{ display:none; } + .bulkhead{ display:flex; align-items:center; justify-content:space-between; gap:var(--s2); + flex-wrap:wrap; margin-bottom:var(--s2); } + .bulkgroup{ display:flex; flex-wrap:wrap; align-items:center; gap:var(--s2); + padding:var(--s2) 0; border-top:1px solid var(--border); } + .bulkgroup > .bulklabel{ font-size:12px; font-weight:600; color:var(--muted); min-width:110px; } + .bulkgroup select{ height:var(--ctl); padding:0 var(--s1) 0 var(--s2); font:inherit; font-size:13px; + border:1px solid var(--border-strong); border-radius:0; background:var(--surface); color:var(--text); + max-width:100%; } + .bulkgroup select:focus-visible{ outline:2px solid var(--accent); outline-offset:-2px; } + /* The bulk delete dialog lists every affected username; a long list scrolls + inside the dialog instead of pushing its buttons off the screen. */ + #wp-dlg-msg{ max-height:50vh; overflow:auto; } + @media (max-width:620px){ + .bulkgroup > .bulklabel{ min-width:0; flex:1 1 100%; } + .bulkgroup select, .bulkgroup button{ flex:1 1 100%; } + } + @media (pointer:coarse){ + .selhit{ min-width:44px; min-height:44px; } + .bulkbar button, .bulkgroup select{ min-height:44px; } + } @@ -63,8 +103,9 @@
- - +
+ + +
+
Loading…
diff --git a/html/users.js b/html/users.js index 20ecb3e..064d6d0 100644 --- a/html/users.js +++ b/html/users.js @@ -23,6 +23,10 @@ let _users = []; // the directory as the server scoped it let _scope = null; // GET /api/auth/user-scope let _meId = null; +// CR-020: the rows checked for a bulk action. Client-side UI state only - every +// bulk action is decided and audited by the server, row by row (T12.1). +let _selected = new Set(); +let _shownSelectable = []; // ids the current filter shows AND this caller may select // ── boot ────────────────────────────────────────────────────────────────────── async function boot(){ @@ -90,11 +94,100 @@ async function loadUsers(){ } banner('users-banner','', ''); _users = json; + // Fresh data: any earlier selection may name accounts that changed or are gone. + clearSelection(false); renderUsers(); } function manages(){ return !!(_scope && _scope.can_manage_users); } +// ── selection (CR-020, T12.2) ───────────────────────────────────────────────── +// A row is selectable when this caller may change the account. Your own row is +// not: every bulk action that could touch it (disable, demote, delete) is refused +// for your own account, so offering it would only produce a guaranteed failure. +function selectable(u){ return manages() && !!u.manageable && u.id !== _meId; } + +// The search box and the filter both decide which rows are shown. Changing either +// clears the selection (decided 2026-10-06), so no row hidden by the filter can +// stay selected and be acted on without being seen. +function filterChanged(){ + const had = _selected.size; + clearSelection(false); + renderUsers(); + banner('sel-banner', '', had ? 'Selection cleared: the filter changed. Select the rows again.' : ''); +} + +function clearSelection(announce){ + const had = _selected.size; + _selected = new Set(); + updateSelectionUI(); + banner('sel-banner', '', (announce && had) ? 'Selection cleared.' : ''); +} + +function setRowSelected(id, on){ + if(on) _selected.add(id); else _selected.delete(id); +} + +// Select-all acts on the rows the filter shows, never on the whole directory. +function toggleSelectAll(on){ + _shownSelectable.forEach(id => setRowSelected(id, on)); + banner('sel-banner', '', ''); + updateSelectionUI(); +} + +// Reflect _selected into the page without re-rendering the table, so keyboard +// focus stays on the checkbox that was just used. +function updateSelectionUI(){ + const wrap = document.getElementById('users-table'); + if(wrap){ + wrap.querySelectorAll('input.selbox').forEach(cb => { + const on = _selected.has(cb.dataset.id); + cb.checked = on; + const tr = cb.closest('tr'); + if(tr) tr.classList.toggle('is-selected', on); + }); + const all = document.getElementById('sel-all'); + if(all){ + const n = _shownSelectable.filter(id => _selected.has(id)).length; + all.checked = n > 0 && n === _shownSelectable.length; + all.indeterminate = n > 0 && n < _shownSelectable.length; + all.disabled = !_shownSelectable.length; + } + } + const bar = document.getElementById('bulk-bar'); + if(bar){ + const n = _selected.size; + bar.hidden = n === 0; + const c = document.getElementById('bulk-count'); + if(c) c.textContent = n + ' selected'; + } +} + +// One listener for every checkbox in the table (event delegation): no ids are +// bound into inline handlers, so there is nothing to escape. +document.addEventListener('change', e => { + const t = e.target; + if(!(t instanceof HTMLInputElement)) return; + if(t.id === 'sel-all'){ toggleSelectAll(t.checked); return; } + if(t.classList.contains('selbox')){ + setRowSelected(t.dataset.id, t.checked); + banner('sel-banner', '', ''); + updateSelectionUI(); + } +}); + +function selCell(u){ + if(!selectable(u)){ + const why = u.id === _meId ? 'Your own account: change it one setting at a time' + : (u.manage_blocked_reason || 'You cannot change this account'); + return ''+ + ''; + } + return ''; +} + function renderUsers(){ const wrap = document.getElementById('users-table'); const q = ((document.getElementById('user-search')||{}).value||'').trim().toLowerCase(); @@ -116,7 +209,8 @@ function renderUsers(){ (u.project_role||'')+' '+roleLabel(u.role)).toLowerCase().indexOf(q) >= 0; }); const count = '
'+list.length+' of '+total+' '+(total===1?'person':'people')+'
'; - if(!list.length){ wrap.innerHTML = count+'
Nothing matches.
'; return; } + _shownSelectable = list.filter(selectable).map(u => u.id); + if(!list.length){ wrap.innerHTML = count+'
Nothing matches.
'; updateSelectionUI(); return; } const head = manages() ? ['Username','Name','Email', @@ -130,9 +224,16 @@ function renderUsers(){ 'Status']; const ths = head.map(h => Array.isArray(h) ? ''+uesc(h[0])+'' : ''+uesc(h)+'').join(''); + // CR-020: a selection column for anyone who manages accounts. Select-all names + // how many rows it covers, because it covers only what the filter shows. + const selTh = manages() + ? '' + : ''; const rows = list.map(manages() ? managerRow : readonlyRow).join(''); - wrap.innerHTML = count+'
'+ths+ + wrap.innerHTML = count+'
'+selTh+ths+ ''+rows+'
'+legend(); + updateSelectionUI(); } function legend(){ @@ -189,6 +290,7 @@ function managerRow(u){ if(!can && !me) actions.push('read-only'); return ''+ + selCell(u)+ ''+uesc(u.username)+''+(me?'you':'')+''+ ''+uesc(u.full_name||'')+''+ // The address is truncated with the full value on the title: a long one used to