From a0603095a35473a6479beb612bc2ed7b33298260 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 7 May 2026 00:23:45 +0300 Subject: Task 61 extract frontend utilities --- web/js/admin.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'web/js/admin.js') diff --git a/web/js/admin.js b/web/js/admin.js index bc2913a..86ad471 100644 --- a/web/js/admin.js +++ b/web/js/admin.js @@ -1,4 +1,5 @@ import { API } from './api.js'; +import { escapeHtml, toast } from './utils.js'; export function initAdmin() { const btn = document.getElementById('admin-toggle'); @@ -54,16 +55,12 @@ async function refreshAdmin() { } catch (err) { toast(err.message, 'error'); } } -function esc(s) { - return (s ?? '').replace(/[&<>"']/g, (c) => ({ '&':'&','<':'<','>':'>','"':'"',"'":''' }[c])); -} - function renderUsers(users) { const el = document.getElementById('admin-users'); if (!el) return; el.innerHTML = ``; @@ -102,12 +99,12 @@ function renderPermissions(data) { let html = ''; data.users.forEach((u) => { - html += ``; + html += ``; }); html += ''; data.sets.forEach((s) => { - html += ``; + html += ``; data.users.forEach((u) => { const role = roleMap[s.id]?.[u.id] || ''; const selectId = `perm-${s.id}-${u.id}`; @@ -152,8 +149,8 @@ function renderTrash(data) { } el.innerHTML = `

Trash

`; @@ -169,11 +166,3 @@ function renderTrash(data) { }); }); } - -function toast(msg, type = 'info') { - const t = document.getElementById('toast'); - if (!t) return; - t.textContent = msg; - t.className = 'toast show ' + type; - setTimeout(() => t.classList.remove('show'), 2800); -} -- cgit v1.2.3
Set${esc(u.username)}${escapeHtml(u.username)}
${esc(s.name)}
${escapeHtml(s.name)}