Files
UmbraTrans/web/assets/admin.js
2026-09-26 07:57:11 -07:00

47 lines
1.6 KiB
JavaScript

const $ = (selector, root = document) => root.querySelector(selector);
const $$ = (selector, root = document) => [...root.querySelectorAll(selector)];
function showToast(message) {
const toast = $('#toast');
if (!toast) return;
toast.textContent = message;
toast.classList.add('toast--visible');
window.clearTimeout(showToast.timer);
showToast.timer = window.setTimeout(() => toast.classList.remove('toast--visible'), 3600);
}
const modal = $('#account-modal');
const openModal = $('#open-account-modal');
const closeModal = $('#close-account-modal');
const cancelModal = $('#cancel-account-modal');
const form = $('#account-form');
function setModal(open) {
if (!modal) return;
modal.hidden = !open;
document.body.classList.toggle('modal-open', open);
if (open) $('#account-name')?.focus();
}
openModal?.addEventListener('click', () => setModal(true));
closeModal?.addEventListener('click', () => setModal(false));
cancelModal?.addEventListener('click', () => setModal(false));
modal?.addEventListener('click', (event) => {
if (event.target === modal) setModal(false);
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape') setModal(false);
});
form?.addEventListener('submit', (event) => {
event.preventDefault();
const oidc = $('#oidc-enrollment')?.checked;
setModal(false);
form.reset();
showToast(oidc ? 'Prototype OIDC enrollment flow submitted locally.' : 'Prototype temporary-password flow submitted locally.');
});
$$('[data-demo-action]').forEach((button) => {
button.addEventListener('click', () => showToast(button.dataset.demoAction));
});