Expand Dock gallery with account workspace and identity states
This commit is contained in:
1 parent
d2002071e6
commit
c41a5e4276
71 files changed
+2254
-67
No files matched your search
+143
-48
@@ -1,7 +1,16 @@
|
||||
import { concepts, tokensFor, cssVars } from "../concepts/registry.js";
|
||||
import {
|
||||
createDemoIdentityAdapter,
|
||||
identityStates,
|
||||
} from "../patterns/demo-identity.js";
|
||||
import {
|
||||
createAccountUI,
|
||||
accountPageIds,
|
||||
} from "../components/account-pages.js";
|
||||
const identityAdapter = createDemoIdentityAdapter();
|
||||
const params = new URLSearchParams(location.search),
|
||||
concept = concepts.find((c) => c.id === params.get("concept")) || concepts[0];
|
||||
const theme = params.get("theme") === "dark" ? "dark" : "light",
|
||||
let theme = params.get("theme") === "dark" ? "dark" : "light",
|
||||
density = params.get("density") || "normal",
|
||||
locale = params.get("locale") === "en" ? "en" : "ru";
|
||||
const rawAccent = params.get("accent"),
|
||||
@@ -10,7 +19,7 @@ const rawAccent = params.get("accent"),
|
||||
: theme === "dark"
|
||||
? concept.darkAccent || concept.accent
|
||||
: concept.accent;
|
||||
const tokens = tokensFor(concept.id, theme, accent, density);
|
||||
let tokens = tokensFor(concept.id, theme, accent, density);
|
||||
document.documentElement.style.cssText = cssVars(tokens);
|
||||
document.documentElement.lang = locale;
|
||||
document.body.dataset.concept = concept.id;
|
||||
@@ -135,6 +144,7 @@ let page = [
|
||||
"auth",
|
||||
"components",
|
||||
"tokens",
|
||||
...accountPageIds,
|
||||
].includes(params.get("page"))
|
||||
? params.get("page")
|
||||
: "dashboard";
|
||||
@@ -153,8 +163,25 @@ const pageNames = {
|
||||
auth: t("Авторизация", "Sign in"),
|
||||
components: t("Компоненты", "Components"),
|
||||
tokens: t("Токены", "Tokens"),
|
||||
profile: t("Аккаунт", "Account"),
|
||||
security: t("Безопасность", "Security"),
|
||||
sessions: t("Устройства и сеансы", "Devices and sessions"),
|
||||
applications: t("Приложения", "Applications"),
|
||||
appearance: t("Оформление", "Appearance"),
|
||||
identity: t("Состояния входа", "Sign-in states"),
|
||||
};
|
||||
const icons = {
|
||||
profile:
|
||||
'<circle cx="12" cy="7" r="4"/><path d="M4 22v-3a8 8 0 0 1 16 0v3"/>',
|
||||
security:
|
||||
'<path d="m12 2 8 4v6c0 5-8 10-8 10S4 17 4 12V6Z"/><path d="m8 12 3 3 5-6"/>',
|
||||
sessions:
|
||||
'<rect x="2" y="3" width="16" height="12" rx="2"/><path d="M6 20h8M10 15v5"/><rect x="16" y="9" width="6" height="12" rx="1"/>',
|
||||
applications:
|
||||
'<rect x="3" y="3" width="7" height="7" rx="2"/><rect x="14" y="3" width="7" height="7" rx="2"/><rect x="3" y="14" width="7" height="7" rx="2"/><rect x="14" y="14" width="7" height="7" rx="2"/>',
|
||||
appearance: '<circle cx="12" cy="12" r="9"/><path d="M12 3v18"/>',
|
||||
identity:
|
||||
'<rect x="3" y="4" width="18" height="16" rx="3"/><circle cx="8" cy="10" r="2"/><path d="M5 16a3 3 0 0 1 6 0M14 9h4M14 13h4"/>',
|
||||
dashboard:
|
||||
'<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/>',
|
||||
users:
|
||||
@@ -183,21 +210,48 @@ function toast(message) {
|
||||
clearTimeout(toastTimer);
|
||||
toastTimer = setTimeout(() => ($("#toast").style.display = "none"), 3500);
|
||||
}
|
||||
function currentIdentity() {
|
||||
return identityAdapter.snapshot().account;
|
||||
}
|
||||
function accountName() {
|
||||
const a = currentIdentity();
|
||||
return a
|
||||
? `${a.firstName} ${a.lastName}`
|
||||
: t("Нет активного входа", "No active sign-in");
|
||||
}
|
||||
function accountInitials() {
|
||||
const a = currentIdentity();
|
||||
return a ? (a.firstName[0] || "") + (a.lastName[0] || "") : "a/";
|
||||
}
|
||||
function navigationPages() {
|
||||
return accountPageIds.includes(page)
|
||||
? ["profile", "security", "sessions", "applications", "appearance"]
|
||||
: ["dashboard", "users", "settings", "components", "tokens"];
|
||||
}
|
||||
function dockAccount() {
|
||||
return `<div class="dock-account-area"><div id="account-menu" class="account-menu" popover="auto" aria-label="${t("Меню аккаунта", "Account menu")}">
|
||||
<button autofocus data-action="profile">${icon("users")}<span>${t("Аккаунт", "Account")}</span></button>
|
||||
<button data-page="settings">${icon("settings")}<span>${t("Настройки", "Settings")}</span></button>
|
||||
<button autofocus data-page="profile">${icon("users")}<span>${t("Аккаунт", "Account")}</span></button>
|
||||
<button data-page="security">${icon("settings")}<span>${t("Настройки", "Settings")}</span></button>
|
||||
<button data-page="applications">${icon("applications")}<span>${t("Приложения", "Applications")}</span></button>
|
||||
<button data-action="shares">${icon("components")}<span>${t("Мои общие ресурсы", "My shares")}</span></button>
|
||||
<button data-page="dashboard">${icon("dashboard")}<span>${t("Панель управления", "Control panel")}</span></button>
|
||||
<button class="account-separator" data-action="switch-account">${icon("users")}<span>${t("Сменить аккаунт", "Switch account")}</span></button>
|
||||
<button class="account-separator" data-page="auth"><svg class="nav-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M9 4H4v16h5M13 7l5 5-5 5M8 12h11"/></svg><span>${t("Выйти", "Logout")}</span></button></div>
|
||||
<button class="dock-account" popovertarget="account-menu" aria-label="${t("Меню аккаунта Anna Volkova", "Anna Volkova account menu")}"><span class="avatar">AV</span><span class="account-identity"><b>Anna Volkova</b><small>anna@anidev.ru</small></span><span class="account-more" aria-hidden="true">···</span></button></div>`;
|
||||
${currentIdentity()?.roles.some((r) => ["Master Admin", "SSO Admin"].includes(r)) ? `<button data-page="dashboard">${icon("dashboard")}<span>${t("Панель управления", "Control panel")}</span></button>` : ""}
|
||||
<button class="account-separator" data-identity="switch">${icon("users")}<span>${t("Сменить аккаунт", "Switch account")}</span></button>
|
||||
<button class="account-separator" data-identity="logout"><svg class="nav-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M9 4H4v16h5M13 7l5 5-5 5M8 12h11"/></svg><span>${t("Выйти из SSO", "Sign out of SSO")}</span></button></div>
|
||||
<button class="dock-account" popovertarget="account-menu" aria-label="${escape(t("Меню аккаунта ", "Account menu ") + accountName())}"><span class="avatar">${currentIdentity()?.avatar ? `<img src="${escape(currentIdentity().avatar)}" alt="">` : escape(accountInitials())}</span><span class="account-identity"><b>${escape(accountName())}</b><small>${escape(currentIdentity()?.username || "Anidev Identity")}</small></span><span class="account-more" aria-hidden="true">···</span></button></div>`;
|
||||
}
|
||||
function nav() {
|
||||
return `<aside class="navigation" id="dock-navigation">${concept.id === "dock" ? wordmark : ""}${concept.id === "dock" ? `<button class="dock-toggle" data-action="dock-toggle" aria-expanded="false" aria-controls="dock-navigation" aria-label="${t("Развернуть меню", "Expand navigation")}" title="${t("Развернуть меню", "Expand navigation")}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><rect x="3" y="4" width="18" height="16" rx="3"/><path d="M9 4v16M14 9l3 3-3 3"/></svg><span>${t("Свернуть меню", "Collapse navigation")}</span></button>` : ""}${concept.id !== "dock" ? wordmark : ""}<div class="workspace-label">ANIDEV / PRODUCTION</div><nav aria-label="${t("Основная навигация", "Main navigation")}" class="nav-links">${["dashboard", "users", "settings", "components", "tokens"].map((p) => `<button data-page="${p}" ${page === p ? 'aria-current="page"' : ""} title="${pageNames[p]}" aria-label="${pageNames[p]}">${icon(p)}<span>${pageNames[p]}</span></button>`).join("")}</nav><div class="nav-bottom">eu-central-1<br>Workspace / Pro<br><button data-page="auth" style="font-size:12px;margin-top:15px">${t("Выйти", "Sign out")}</button></div>${concept.id === "dock" ? dockAccount() : ""}</aside>`;
|
||||
const dockBrand = `<button class="dock-toggle dock-brand wordmark" data-action="dock-toggle" aria-expanded="false" aria-controls="dock-navigation" aria-label="${t("Развернуть меню Anidev", "Expand Anidev navigation")}" title="${t("Навигация Anidev", "Anidev navigation")}"><b>a/</b><span>anidev</span></button>`;
|
||||
return `<aside class="navigation" id="dock-navigation">${concept.id === "dock" ? dockBrand : wordmark}<div class="workspace-label">ANIDEV / PRODUCTION</div><nav aria-label="${t("Основная навигация", "Main navigation")}" class="nav-links">${navigationPages()
|
||||
.map(
|
||||
(p) =>
|
||||
`<button data-page="${p}" ${page === p ? 'aria-current="page"' : ""} title="${pageNames[p]}" aria-label="${pageNames[p]}">${icon(p)}<span>${pageNames[p]}</span></button>`,
|
||||
)
|
||||
.join(
|
||||
"",
|
||||
)}</nav><div class="nav-bottom">eu-central-1<br>Workspace / Pro<br><button data-page="auth" style="font-size:12px;margin-top:15px">${t("Выйти", "Sign out")}</button></div>${concept.id === "dock" ? dockAccount() : ""}</aside>`;
|
||||
}
|
||||
function header() {
|
||||
return `<header class="app-header"><button class="mobile-menu" data-action="mobile-menu" aria-label="${t("Открыть навигацию", "Open navigation")}" aria-expanded="false">☰</button><div class="breadcrumb">Anidev <span aria-hidden="true">/</span> Production <span aria-hidden="true">/</span> ${pageNames[page]}</div><div class="header-actions"><button class="command-trigger" data-action="command">${t("Найти команду", "Find a command")} <kbd>⌘ K</kbd></button><button class="avatar" data-action="profile" aria-label="${t("Профиль Anna Volkova", "Anna Volkova profile")}">AV</button></div></header>`;
|
||||
return `<header class="app-header"><button class="mobile-menu" data-action="mobile-menu" aria-label="${t("Открыть навигацию", "Open navigation")}" aria-expanded="false">☰</button><div class="breadcrumb">Anidev <span aria-hidden="true">/</span> ${accountPageIds.includes(page) ? t("Личный кабинет", "My account") : "Production"} <span aria-hidden="true">/</span> ${pageNames[page]}</div><div class="header-actions"><button class="command-trigger" data-action="command">${t("Найти команду", "Find a command")} <kbd>⌘ K</kbd></button><button class="avatar" data-action="profile" aria-label="${escape(accountName())}">${escape(accountInitials())}</button></div></header>`;
|
||||
}
|
||||
const heading = (title, desc, actions = "") =>
|
||||
`<div class="page-heading"><div><div class="overline">ANIDEV://PRODUCTION/${page.toUpperCase()}</div><h1>${title}</h1><p>${desc}</p></div><div class="heading-actions">${actions}</div></div>`;
|
||||
@@ -206,7 +260,7 @@ let dockCloseTimer;
|
||||
function bindDockHover() {
|
||||
if (concept.id !== "dock" || !$(".dock-toggle")) return;
|
||||
const nav = $(".navigation");
|
||||
$(".dock-toggle").addEventListener("pointerenter", (e) => {
|
||||
nav.addEventListener("pointerenter", (e) => {
|
||||
if (
|
||||
e.pointerType !== "mouse" ||
|
||||
!matchMedia("(hover: hover) and (pointer: fine)").matches
|
||||
@@ -263,13 +317,31 @@ function render() {
|
||||
clearTimeout(dockCloseTimer);
|
||||
document.body.classList.remove("dock-open");
|
||||
document.title = `Anidev / ${concept.name} / ${pageNames[page]}`;
|
||||
const content = accountPageIds.includes(page)
|
||||
? accountUI.renderPage(page)
|
||||
: identityAdapter.snapshot().status !== "authenticated" &&
|
||||
!["components", "tokens", "auth"].includes(page)
|
||||
? accountUI.gate()
|
||||
: ["dashboard", "users", "settings"].includes(page) &&
|
||||
!currentIdentity()?.roles.some((r) =>
|
||||
["Master Admin", "SSO Admin"].includes(r),
|
||||
)
|
||||
? accountUI.gate("access_denied")
|
||||
: {
|
||||
dashboard,
|
||||
users: userScreen,
|
||||
settings: settingsScreen,
|
||||
components: componentScreen,
|
||||
tokens: tokenScreen,
|
||||
}[page]?.() || "";
|
||||
$("#app").innerHTML =
|
||||
page === "auth"
|
||||
? auth()
|
||||
: `<div class="shell">${nav()}${concept.id === "dock" ? `<button class="dock-scrim" data-action="dock-close" tabindex="-1" aria-label="${t("Закрыть меню", "Close navigation")}" aria-hidden="true"></button>` : ""}<div class="main-column">${header()}<main id="content" tabindex="-1">${{ dashboard, users: userScreen, settings: settingsScreen, components: componentScreen, tokens: tokenScreen }[page]()}</main></div></div>`;
|
||||
: `<div class="shell">${nav()}${concept.id === "dock" ? `<button class="dock-scrim" data-action="dock-close" tabindex="-1" aria-label="${t("Закрыть меню", "Close navigation")}" aria-hidden="true"></button>` : ""}<div class="main-column">${header()}<main id="content" tabindex="-1">${content}</main></div></div>`;
|
||||
bindForms();
|
||||
accountUI.bind(page);
|
||||
bindDockHover();
|
||||
if (page === "users") bindUsers();
|
||||
if (page === "users" && $("#user-search")) bindUsers();
|
||||
}
|
||||
function chart() {
|
||||
const values =
|
||||
@@ -422,7 +494,7 @@ function settingsScreen() {
|
||||
return `${heading(t("Настройки пространства", "Workspace settings"), t("Идентификация, безопасность и уведомления.", "Identity, security and notifications."))}<div class="page-body"><div class="tabs" role="tablist" aria-label="${t("Раздел настроек", "Settings section")}">${["general", "security", "notifications"].map((v, i) => `<button role="tab" id="tab-${v}" aria-controls="settings-panel" data-tab="${v}" aria-selected="${tab === v}" tabindex="${tab === v ? "0" : "-1"}">${[t("Основные", "General"), t("Безопасность", "Security"), t("Уведомления", "Notifications")][i]}</button>`).join("")}</div><section id="settings-panel" role="tabpanel" aria-labelledby="tab-${tab}" class="settings-layout"><div class="settings-copy"><h2>${tab === "general" ? t("Ваше пространство", "Your workspace") : tab === "security" ? t("Контроль доступа", "Access control") : t("Оповещения", "Notifications")}</h2><p>${tab === "general" ? t("Эти данные видны участникам организации.", "These details are visible to organization members.") : t("Изменения применяются к этому демо.", "Changes apply to this demo.")}</p></div><form id="settings-form">${tab === "general" ? `<label class="field">${t("Название", "Workspace name")}<input name="name" required maxlength="60" value="${escape(settings.name)}"></label><label class="field">${t("Идентификатор", "Workspace slug")}<input name="slug" required pattern="[a-z0-9-]+" value="${escape(settings.slug)}"><small>${t("Строчные латинские буквы, цифры и дефис.", "Lowercase letters, numbers and hyphens.")}</small></label><label class="field">${t("Регион данных", "Data region")}<select name="region"><option value="eu" ${settings.region === "eu" ? "selected" : ""}>Europe / Frankfurt</option><option value="us" ${settings.region === "us" ? "selected" : ""}>US / Virginia</option></select></label>` : tab === "security" ? `<div class="form-row"><label for="mfa"><b>${t("Двухфакторная авторизация", "Two-factor authentication")}</b><small style="display:block">${t("Обязательна для всех участников", "Required for all members")}</small></label><input class="switch" type="checkbox" role="switch" name="mfa" id="mfa" ${settings.mfa ? "checked" : ""}></div><div class="form-row"><label for="audit">${t("Журналировать действия", "Record audit events")}</label><input class="switch" type="checkbox" role="switch" name="audit" id="audit" ${settings.audit ? "checked" : ""}></div><button type="button" data-action="sessions">${t("Управление сессиями", "Manage sessions")}</button>` : `<label class="field">${t("Email для оповещений", "Alert email")}<input type="email" name="email" required value="${escape(settings.email)}"></label><div class="form-row"><input type="checkbox" id="incidents" checked><label for="incidents">${t("Инциденты и недоступность сервисов", "Incidents and service outages")}</label></div>`}<div class="form-footer"><button type="reset">${t("Отменить", "Cancel")}</button><button class="primary" type="submit">${t("Сохранить изменения", "Save changes")}</button></div></form></section></div>`;
|
||||
}
|
||||
function auth() {
|
||||
return `<main id="content" class="auth-layout" style="max-width:none;padding:0"><section class="auth-brand">${wordmark}<div class="auth-statement">${t("Ваша инфраструктура.<br>Под вашим контролем.", "Your infrastructure.<br>Under your control.")}</div><small>ANIDEV IDENTITY / ${t("ДЕМОНСТРАЦИЯ", "DEMONSTRATION")}</small></section><section class="auth-main"><form id="auth-form" class="auth-form"><h1>${t("Вход в Anidev", "Sign in to Anidev")}</h1><p>${t("Продолжите работу с вашим пространством.", "Continue to your workspace.")}</p><label class="field">Email<input name="email" type="email" autocomplete="username" placeholder="you@company.com" required></label><label class="field">${t("Пароль", "Password")}<input name="password" type="password" autocomplete="current-password" minlength="8" required aria-describedby="password-hint"><small id="password-hint">${t("Демо: любой email и пароль от 8 символов.", "Demo: any email and a password of 8+ characters.")}</small></label><div class="form-row"><input id="remember" type="checkbox"><label for="remember">${t("Запомнить меня", "Remember me")}</label><button class="row-action" type="button" data-action="recover">${t("Забыли пароль?", "Forgot password?")}</button></div><p class="error-text" id="auth-error" role="alert"></p><button class="primary" type="submit">${t("Войти", "Sign in")}</button><div class="auth-divider">${t("или корпоративный аккаунт", "or your company account")}</div><button type="button" class="sso" data-action="sso">${t("Войти через SSO", "Continue with SSO")}</button><div class="auth-foot"><span>© Anidev 2026</span><button class="row-action" type="button" data-page="dashboard">${t("Вернуться к обзору", "Back to overview")}</button></div></form></section></main>`;
|
||||
return `<main id="content" class="auth-layout" style="max-width:none;padding:0"><section class="auth-brand">${wordmark}<div class="auth-statement">${t("Ваша инфраструктура.<br>Под вашим контролем.", "Your infrastructure.<br>Under your control.")}</div><small>ANIDEV IDENTITY / ${t("ДЕМОНСТРАЦИЯ", "DEMONSTRATION")}</small></section><section class="auth-main"><form id="auth-form" class="auth-form"><h1>${t("Вход в Anidev", "Sign in to Anidev")}</h1><p>${t("Продолжите работу с вашим пространством.", "Continue to your workspace.")}</p><label class="field">${t("Username или email", "Username or email")}<input name="email" type="text" autocomplete="username" placeholder="anna.volkova" required></label><label class="field">${t("Пароль", "Password")}<input name="password" type="password" autocomplete="current-password" minlength="8" required aria-describedby="password-hint"><small id="password-hint">${t("Демо: anna.volkova или mikhail.orlov; пароль от 8 символов.", "Demo: anna.volkova or mikhail.orlov; password of 8+ characters.")}</small></label><div class="form-row"><input id="remember" type="checkbox"><label for="remember">${t("Запомнить меня", "Remember me")}</label><button class="row-action" type="button" data-action="recover">${t("Забыли пароль?", "Forgot password?")}</button></div><p class="error-text" id="auth-error" role="alert"></p><button class="primary" type="submit">${t("Войти", "Sign in")}</button><div class="auth-divider">${t("или корпоративный аккаунт", "or your company account")}</div><button type="button" class="sso" data-action="sso">${t("Войти через SSO", "Continue with SSO")}</button><div class="auth-foot"><span>© Anidev 2026</span><button class="row-action" type="button" data-page="dashboard">${t("Вернуться к обзору", "Back to overview")}</button></div></form></section></main>`;
|
||||
}
|
||||
function componentScreen() {
|
||||
return `${heading(t("Библиотека компонентов", "Component library"), t("Единые состояния. Шесть способов выражения.", "Shared states. Six ways of expressing them."), `<button data-action="command">${t("Команды", "Commands")} ⌘K</button>`)}<div class="page-body"><div class="library">
|
||||
@@ -493,13 +565,16 @@ function editUser(id) {
|
||||
if (!user) return;
|
||||
openDialog(
|
||||
escape(user.name),
|
||||
`<p>${escape(user.email)}</p><form id="edit-user"><label class="field">${t("Роль", "Role")}<select name="role">${["admin", "developer", "viewer"].map((r) => `<option value="${r}" ${user.role === r ? "selected" : ""}>${roleName(r)}</option>`).join("")}</select></label><label class="field">${t("Статус", "Status")}<select name="status">${["active", "invited", "suspended"].map((s) => `<option value="${s}" ${user.status === s ? "selected" : ""}>${statusName(s)}</option>`).join("")}</select></label><div class="form-footer"><button type="button" data-action="close">${t("Отмена", "Cancel")}</button><button type="submit" class="primary">${t("Сохранить", "Save")}</button></div></form>`,
|
||||
`<p>${escape(user.email)}</p><form id="edit-user"><label class="field">${t("Роль в пространстве", "Workspace role")}<select name="role">${["admin", "developer", "viewer"].map((r) => `<option value="${r}" ${user.role === r ? "selected" : ""}>${roleName(r)}</option>`).join("")}</select></label><label class="field">${t("Статус", "Status")}<select name="status">${["active", "invited", "suspended"].map((s) => `<option value="${s}" ${user.status === s ? "selected" : ""}>${statusName(s)}</option>`).join("")}</select></label>${accountUI.roleMarkup(id)}${accountUI.grantsMarkup(id)}<div class="form-footer"><button type="button" data-action="close">${t("Отмена", "Cancel")}</button><button type="submit" class="primary">${t("Сохранить", "Save")}</button></div></form>`,
|
||||
);
|
||||
$("#dialog").classList.add("identity-editor-dialog");
|
||||
accountUI.bindGrants(id, () => editUser(id));
|
||||
$("#edit-user").onsubmit = (e) => {
|
||||
e.preventDefault();
|
||||
const data = new FormData(e.target);
|
||||
user.role = data.get("role");
|
||||
user.status = data.get("status");
|
||||
identityAdapter.setUserRoles(id, data.getAll("ssoRole"));
|
||||
persist();
|
||||
$("#dialog").close();
|
||||
refreshUsers();
|
||||
@@ -576,12 +651,27 @@ function bindForms() {
|
||||
if ($("#auth-form"))
|
||||
$("#auth-form").onsubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
const identityRevision = identityAdapter.snapshot().revision;
|
||||
const b = e.target.querySelector("[type=submit]");
|
||||
b.disabled = true;
|
||||
b.setAttribute("aria-busy", "true");
|
||||
b.textContent = t("Вход…", "Signing in…");
|
||||
await new Promise((r) => setTimeout(r, 450));
|
||||
page = "dashboard";
|
||||
if (identityAdapter.snapshot().revision !== identityRevision) return;
|
||||
if (new FormData(e.target).get("password") === "wrong-password") {
|
||||
e.target.elements.password.value = "";
|
||||
$("#auth-error").textContent = t(
|
||||
"Неверный пароль. Попробуйте другой пароль для демо.",
|
||||
"Incorrect password. Try another password for this demo.",
|
||||
);
|
||||
e.target.elements.password.setAttribute("aria-invalid", "true");
|
||||
b.disabled = false;
|
||||
b.removeAttribute("aria-busy");
|
||||
b.textContent = t("Войти", "Sign in");
|
||||
return;
|
||||
}
|
||||
identityAdapter.signIn(new FormData(e.target).get("email"));
|
||||
page = "profile";
|
||||
render();
|
||||
toast(t("Демонстрационный вход выполнен", "Demo sign-in complete"));
|
||||
};
|
||||
@@ -617,6 +707,7 @@ function contextMenu(x, y) {
|
||||
menu.querySelector("button").focus();
|
||||
}
|
||||
document.addEventListener("click", async (e) => {
|
||||
if (await accountUI.handleClick(e)) return;
|
||||
const pageButton = e.target.closest("[data-page]");
|
||||
if (pageButton) {
|
||||
page = pageButton.dataset.page;
|
||||
@@ -658,33 +749,7 @@ document.addEventListener("click", async (e) => {
|
||||
`<p>${t("Общих ресурсов пока нет.", "No shared resources yet.")}</p><button data-action="close">${t("Закрыть", "Close")}</button>`,
|
||||
"drawer",
|
||||
),
|
||||
"switch-account": () => {
|
||||
setDockOpen(false, false);
|
||||
openDialog(
|
||||
t("Сменить аккаунт", "Switch account"),
|
||||
`<p>${t("Демонстрация SSO-переключения. Реальный провайдер не подключён.", "Demo SSO account switching. No live provider is connected.")}</p><div class="command-list"><button data-action="select-account" data-account="Anna Volkova">Anna Volkova <small>anna@anidev.ru</small></button><button data-action="select-account" data-account="Mikhail Orlov">Mikhail Orlov <small>mikhail@anidev.ru</small></button></div>`,
|
||||
);
|
||||
},
|
||||
"select-account": () => {
|
||||
const name = button.dataset.account;
|
||||
$("#dialog").close();
|
||||
document.querySelectorAll(".dock-account .avatar").forEach(
|
||||
(el) =>
|
||||
(el.textContent = name
|
||||
.split(" ")
|
||||
.map((v) => v[0])
|
||||
.join("")),
|
||||
);
|
||||
$(".account-identity b").textContent = name;
|
||||
$(".account-identity small").textContent = name.startsWith("Anna")
|
||||
? "anna@anidev.ru"
|
||||
: "mikhail@anidev.ru";
|
||||
$(".dock-account").setAttribute(
|
||||
"aria-label",
|
||||
t("Меню аккаунта ", "Account menu ") + name,
|
||||
);
|
||||
toast(t("Демо-аккаунт выбран: ", "Demo account selected: ") + name);
|
||||
},
|
||||
"switch-account": () => accountUI.switchAccount(),
|
||||
"dock-toggle": () => {
|
||||
if (dockHoverOpened) {
|
||||
dockHoverOpened = false;
|
||||
@@ -706,11 +771,7 @@ document.addEventListener("click", async (e) => {
|
||||
invite,
|
||||
command,
|
||||
activity: () => $("#activity").scrollIntoView({ behavior: "smooth" }),
|
||||
profile: () =>
|
||||
openDialog(
|
||||
"Anna Volkova",
|
||||
`<p>anna@anidev.ru</p><p>${roleName("admin")} · Anidev Production</p><button data-page="settings">${t("Настройки пространства", "Workspace settings")}</button><button data-page="auth">${t("Выйти", "Sign out")}</button>`,
|
||||
),
|
||||
profile: () => navigate("profile"),
|
||||
prev: () => {
|
||||
userPage--;
|
||||
refreshUsers();
|
||||
@@ -991,4 +1052,38 @@ addEventListener("storage", (e) => {
|
||||
} catch {}
|
||||
}
|
||||
});
|
||||
function navigate(next) {
|
||||
page = next;
|
||||
$("#dialog").close();
|
||||
render();
|
||||
$("#content")?.focus();
|
||||
}
|
||||
const accountUI = createAccountUI({
|
||||
adapter: identityAdapter,
|
||||
t,
|
||||
escape,
|
||||
heading,
|
||||
icon,
|
||||
openDialog,
|
||||
toast,
|
||||
render,
|
||||
navigate,
|
||||
setTheme: (mode) => {
|
||||
theme = mode;
|
||||
tokens = tokensFor(concept.id, theme, rawAccent || undefined, density);
|
||||
document.documentElement.style.cssText = cssVars(tokens);
|
||||
document.body.dataset.theme = theme;
|
||||
render();
|
||||
if (parent !== window)
|
||||
parent.postMessage({ type: "anidev-theme", theme }, location.origin);
|
||||
},
|
||||
});
|
||||
if (identityStates.includes(params.get("identityState")))
|
||||
identityAdapter.setScenario(params.get("identityState"));
|
||||
addEventListener("storage", (e) => {
|
||||
if (e.key === "anidev.identity.demo.v2") {
|
||||
$("#dialog").close();
|
||||
render();
|
||||
}
|
||||
});
|
||||
render();
|
||||
Reference in new issue
Block a user