forge
Explore
Log in

Don't you dare go Hollow

im-web: open admin confirms in a top-layer dialog

Browse files at this commit

9afcded6583f5835ae79a07872573ab9d730766eAhmet Kaan GümüşParent: 66482f0
position:fixed confirms inside the scrolling users table resolved
against that box, so Disable landed off the page. Every admin overlay
now opens a popover; the top layer's containing block is the viewport.
crates/im-web/assets/main.cssmodified+27 -30
@@ -1135,50 +1135,47 @@ body:has(.log-list) .admin-card:has(.log-list) {
1135 background: var(--danger-tint-alt);1135 background: var(--danger-tint-alt);
1136 }1136 }
1137 1137
1138-.admin-confirm {1138+.admin-dialog {
1139- position: relative;1139+ width: min(240px, 100vw - 32px);
1140- display: inline-flex;1140+ height: fit-content;
1141+ max-height: min(85vh, 85dvh);
1142+ margin: auto;
1143+ inset: 0;
1144+ padding: 12px;
1145+ border: 1px solid var(--border-strong);
1146+ border-radius: var(--radius);
1147+ background: var(--surface);
1148+ color: var(--ink);
1149+ box-shadow: var(--shadow-2);
1150+ overflow: auto;
1141 }1151 }
1142-.admin-confirm summary {1152+.admin-dialog::backdrop {
1143- list-style: none;1153+ background: rgba(0, 0, 0, 0.45);
1144- display: inline-flex;
1145- align-items: center;
1146- box-sizing: border-box;
1147 }1154 }
1148-.admin-confirm summary::-webkit-details-marker {1155+.admin-dialog .admin-action {
1149- display: none;1156+ width: 100%;
1157+ height: 30px;
1150 }1158 }
1151-.admin-confirm[open] summary {1159+
1152- background: var(--panel-sunken);1160+.admin-dialog-wide {
1161+ width: min(420px, 100vw - 32px);
1153 }1162 }
1154 1163
1155-.admin-confirm-pop {1164+.admin-dialog:popover-open {
1156- position: fixed;
1157- top: 50%;
1158- left: 50%;
1159- transform: translate(-50%, -50%);
1160- z-index: 30;
1161- width: 240px;
1162- padding: 12px;
1163- background: var(--surface);
1164- border: 1px solid var(--border-strong);
1165- border-radius: var(--radius);
1166- box-shadow: var(--shadow-2);
1167 display: flex;1165 display: flex;
1168 flex-direction: column;1166 flex-direction: column;
1169 gap: 8px;1167 gap: 8px;
1170- font-size: 12px;
1171-}
1172-.admin-confirm-pop .admin-action {
1173- width: 100%;
1174- height: 30px;
1175 }1168 }
1176 1169
1177-.admin-confirm-title {1170+.admin-dialog-title {
1178 font-weight: 600;1171 font-weight: 600;
1179 color: var(--ink);1172 color: var(--ink);
1180 }1173 }
1181 1174
1175+.admin-action:has(+ .admin-dialog:popover-open) {
1176+ background: var(--panel-sunken);
1177+}
1178+
1182 .admin-sessions {1179 .admin-sessions {
1183 display: inline-block;1180 display: inline-block;
1184 vertical-align: top;1181 vertical-align: top;
crates/im-web/src/admin.rsmodified+71 -31
@@ -51,11 +51,50 @@ fn escape(raw: &str) -> String {
51 .replace('\'', "'")51 .replace('\'', "'")
52 }52 }
53 53
54-/// One row action as a two-step disclosure — iz's `confirm-details` idiom:54+/// One admin overlay. The panel is a top-layer popover, not a positioned
55-/// the summary is the word ("Delete"), the opened panel says what it costs55+/// descendant of the row. `position: fixed` inside `.admin-table-wrap` (a
56-/// and holds the button that actually does it. The eight `&str`s travel as56+/// scroll container) or a table cell resolves `top`/`left` against that box
57+/// as soon as an ancestor creates a containing block — a transform, a
58+/// filter, or the table itself in some engines — so a "centered" confirm
59+/// lands off the page. The top layer's containing block is the viewport.
60+/// Every admin overlay goes through [`admin_dialog`]. Do not emit a
61+/// positioned panel inside a row.
62+struct AdminDialog<'a> {
63+ id: &'a str,
64+ word: &'a str,
65+ extra_class: &'a str,
66+ title: &'a str,
67+ body: &'a str,
68+ wide: bool,
69+}
70+
71+/// Stable, attribute-safe id. The field value may be escaped HTML; the
72+/// popover id must not be, and two different values must not collide.
73+fn dialog_id(action: &str, field: &str, id: &str) -> String {
74+ let raw = format!("{action}\0{field}\0{id}");
75+ let hash = raw.bytes().fold(0xcbf29ce484222325u64, |hash, byte| {
76+ (hash ^ u64::from(byte)).wrapping_mul(0x100000001b3)
77+ });
78+ format!("d{hash:x}")
79+}
80+
81+fn admin_dialog(ask: AdminDialog<'_>) -> String {
82+ let wide = if ask.wide { " admin-dialog-wide" } else { "" };
83+ format!(
84+ r#"<button type="button" class="admin-action{extra}" popovertarget="{id}">{word}</button><div id="{id}" popover="auto" class="admin-dialog{wide}"><div class="admin-dialog-title">{title}</div>{body}</div>"#,
85+ extra = ask.extra_class,
86+ id = ask.id,
87+ word = ask.word,
88+ title = ask.title,
89+ body = ask.body,
90+ wide = wide,
91+ )
92+}
93+
94+/// One row action as a two-step confirm. The word opens the dialog; the
95+/// dialog holds the button that actually posts. Eight `&str`s travel as
57 /// named fields: eight positional parameters tripped the too-many-arguments96 /// named fields: eight positional parameters tripped the too-many-arguments
58-/// lint, and the names read better at the call sites anyway.97+/// lint.
59 struct ConfirmAction<'a> {98 struct ConfirmAction<'a> {
60 field: &'a str,99 field: &'a str,
61 id: &'a str,100 id: &'a str,
@@ -77,28 +116,25 @@ fn confirm_action(ask: ConfirmAction<'_>) -> String {
77 cost,116 cost,
78 confirm,117 confirm,
79 } = ask;118 } = ask;
80- format!(119+ let dialog = dialog_id(action, field, id);
81- r#"<details class="admin-confirm"><summary class="admin-action{extra_class}">{word}</summary><div class="admin-confirm-pop"><div class="admin-confirm-title">{title}</div><div class="muted">{cost}</div><form method="post" action="{action}"><input type="hidden" name="{field}" value="{id}"><button class="admin-action{extra_class}" type="submit">{confirm}</button></form></div></details>"#120+ let body = format!(
82- )121+ r#"<div class="muted">{cost}</div><form method="post" action="{action}"><input type="hidden" name="{field}" value="{id}"><button class="admin-action{extra_class}" type="submit">{confirm}</button></form>"#
122+ );
123+ admin_dialog(AdminDialog {
124+ id: &dialog,
125+ word,
126+ extra_class,
127+ title,
128+ body: &body,
129+ wide: false,
130+ })
83 }131 }
84-/// The panel's live wiring moved into the shell: `layout::live_script` runs132+/// Outside-click and Escape on a confirm are the popover's own light
85-/// on every signed-in page and morphs through `__imRefresh`. What stays here133+/// dismiss — no script. What stays here is the one bit the markup cannot do
86-/// is the one bit of behavior the no-script markup cannot do itself — an open134+/// itself: the show-once banner's copy button.
87-/// confirm disclosure closes on outside click and Escape.
88 const ADMIN_SCRIPT: &str = r#"<script>(function () {135 const ADMIN_SCRIPT: &str = r#"<script>(function () {
89 if (window.__imAdmin) { return; }136 if (window.__imAdmin) { return; }
90 window.__imAdmin = true;137 window.__imAdmin = true;
91- document.addEventListener('click', function (e) {
92- document.querySelectorAll('.admin-confirm[open]').forEach(function (d) {
93- if (!d.contains(e.target)) { d.removeAttribute('open'); }
94- });
95- }, true);
96- document.addEventListener('keydown', function (e) {
97- if (e.key !== 'Escape') { return; }
98- document.querySelectorAll('.admin-confirm[open]').forEach(function (d) { d.removeAttribute('open'); });
99- }, true);
100- // The show-once banner's copy button: copies the secret beside it, flips
101- // its label, and works without script too — the value is selectable text.
102 document.addEventListener('click', function (e) {138 document.addEventListener('click', function (e) {
103 var b = e.target.closest && e.target.closest('.admin-copy');139 var b = e.target.closest && e.target.closest('.admin-copy');
104 if (!b) { return; }140 if (!b) { return; }
@@ -352,10 +388,8 @@ async fn users_section(
352 let actions = if user.id == me.id {388 let actions = if user.id == me.id {
353 format!(r#"<span class="muted">{}</span>"#, t(lang, Key::YouWord))389 format!(r#"<span class="muted">{}</span>"#, t(lang, Key::YouWord))
354 } else {390 } else {
355- // Every row action is a two-step disclosure — iz's391+ // Every row action opens the shared top-layer dialog. The word
356- // confirm-details idiom: the summary is the word, the panel holds392+ // is the trigger; the dialog holds the button that posts.
357- // the button that actually does it. No script required; the live
358- // script adds outside-click closing on top.
359 let toggle = if user.disabled {393 let toggle = if user.disabled {
360 confirm_action(ConfirmAction {394 confirm_action(ConfirmAction {
361 field: "user",395 field: "user",
@@ -526,15 +560,21 @@ async fn services_section(
526 mib = if limit_unit == "MiB" { " selected" } else { "" },560 mib = if limit_unit == "MiB" { " selected" } else { "" },
527 gib = if limit_unit == "GiB" { " selected" } else { "" },561 gib = if limit_unit == "GiB" { " selected" } else { "" },
528 );562 );
529- let edit = format!(563+ let edit_body = format!(
530- r#"<details class="admin-confirm"><summary class="admin-action">{edit_word}</summary><div class="admin-confirm-pop"><div class="admin-confirm-title">{edit_title}</div><form method="post" action="/admin/services_edit" class="admin-form"><input type="hidden" name="key" value="{key}"><label class="auth-field"><span class="auth-label">{name_label}</span><input class="auth-input auth-input-mono" type="text" name="name" value="{name}" required></label>{address_field}{limit_field}<button class="admin-action" type="submit">{save}</button></form></div></details>"#,564+ r#"<form method="post" action="/admin/services_edit" class="admin-form"><input type="hidden" name="key" value="{key}"><label class="auth-field"><span class="auth-label">{name_label}</span><input class="auth-input auth-input-mono" type="text" name="name" value="{name}" required></label>{address_field}{limit_field}<button class="admin-action" type="submit">{save}</button></form>"#,
531- edit_word = t(lang, Key::EditWord),
532- edit_title = i18n::edit_service_title(lang, &name),
533 key = key,565 key = key,
534 name = name,566 name = name,
535 name_label = t(lang, Key::NameCol),567 name_label = t(lang, Key::NameCol),
536 save = t(lang, Key::SaveButton),568 save = t(lang, Key::SaveButton),
537 );569 );
570+ let edit = admin_dialog(AdminDialog {
571+ id: &dialog_id("/admin/services_edit", "key", &key),
572+ word: t(lang, Key::EditWord),
573+ extra_class: "",
574+ title: &i18n::edit_service_title(lang, &name),
575+ body: &edit_body,
576+ wide: true,
577+ });
538 let up = format!(578 let up = format!(
539 r#"<form method="post" action="/admin/services_move"><input type="hidden" name="key" value="{key}"><input type="hidden" name="dir" value="up"><button class="admin-action" type="submit" aria-label="{up_label}">&#8593;</button></form>"#,579 r#"<form method="post" action="/admin/services_move"><input type="hidden" name="key" value="{key}"><input type="hidden" name="dir" value="up"><button class="admin-action" type="submit" aria-label="{up_label}">&#8593;</button></form>"#,
540 key = key,580 key = key,
@@ -673,7 +713,7 @@ async fn services_section(
673 ))713 ))
674 }714 }
675 715
676-/// A client's Rotate/Revoke pair, as the two-step disclosures — the same716+/// A client's Rotate/Revoke pair, both top-layer confirms — the same
677 /// controls on a linked service row and on a credential-only row.717 /// controls on a linked service row and on a credential-only row.
678 fn client_controls(client_id: &str, name_html: &str, lang: i18n::Lang) -> String {718 fn client_controls(client_id: &str, name_html: &str, lang: i18n::Lang) -> String {
679 let rotate = confirm_action(ConfirmAction {719 let rotate = confirm_action(ConfirmAction {
style/main.scssmodified+32 -40
@@ -1190,55 +1190,47 @@ body:has(.log-list) {
1190 &:hover { background: var(--danger-tint-alt); }1190 &:hover { background: var(--danger-tint-alt); }
1191 }1191 }
1192 1192
1193-// The two-step row action, iz's confirm-details: the summary wears the1193+// Admin overlays are top-layer popovers. Do not position one with
1194-// button skin; the popover names the cost and holds the real button.1194+// `top`/`left`/`transform`: a `position: fixed` panel inside
1195-.admin-confirm {1195+// `.admin-table-wrap` (overflow) or a table cell resolves those against
1196- position: relative;1196+// that box as soon as an ancestor creates a containing block, and the
1197- display: inline-flex;1197+// confirm lands off the page. Centering here is the top layer's own
1198-1198+// `inset: 0; margin: auto`. New row overlays go through `admin_dialog`.
1199- // The summary wears the button skin verbatim — a native summary is a1199+.admin-dialog {
1200- // list-item, and without inline-flex it stands a few pixels off the real1200+ width: min(240px, calc(100vw - 32px));
1201- // buttons beside it.1201+ height: fit-content;
1202- summary {1202+ max-height: min(85vh, 85dvh);
1203- list-style: none;1203+ margin: auto;
1204- display: inline-flex;1204+ inset: 0;
1205- align-items: center;
1206- box-sizing: border-box;
1207-
1208- &::-webkit-details-marker { display: none; }
1209- }
1210-
1211- &[open] summary { background: var(--panel-sunken); }
1212-}
1213-
1214-.admin-confirm-pop {
1215- // Viewport-fixed and centered, iz's delete-confirm model: position:fixed
1216- // escapes every overflow ancestor, and the table wrap is a scroll
1217- // container (it takes the tables' sideways scroll) — an absolutely
1218- // anchored pop inside it would grow that scroll area instead of
1219- // overlaying the page. Centered also reads as the page's one dialog and
1220- // is row-agnostic: the first row's pop and the last row's pop land the
1221- // same, at any width.
1222- position: fixed;
1223- top: 50%;
1224- left: 50%;
1225- transform: translate(-50%, -50%);
1226- z-index: 30;
1227- width: 240px;
1228 padding: 12px;1205 padding: 12px;
1229- background: var(--surface);
1230 border: 1px solid var(--border-strong);1206 border: 1px solid var(--border-strong);
1231 border-radius: var(--radius);1207 border-radius: var(--radius);
1208+ background: var(--surface);
1209+ color: var(--ink);
1232 box-shadow: var(--shadow-2);1210 box-shadow: var(--shadow-2);
1211+ overflow: auto;
1212+
1213+ &::backdrop { background: rgb(0 0 0 / 0.45); }
1214+
1215+ .admin-action { width: 100%; height: 30px; }
1216+}
1217+
1218+.admin-dialog-wide { width: min(420px, calc(100vw - 32px)); }
1219+
1220+// Flex only while open. An author `display` on the closed popover can beat
1221+// the UA `[popover]:not(:popover-open) { display: none }` and leave the
1222+// panel sitting in the row.
1223+.admin-dialog:popover-open {
1233 display: flex;1224 display: flex;
1234 flex-direction: column;1225 flex-direction: column;
1235 gap: 8px;1226 gap: 8px;
1236- font-size: 12px;
1237-
1238- .admin-action { width: 100%; height: 30px; }
1239 }1227 }
1240 1228
1241-.admin-confirm-title { font-weight: 600; color: var(--ink); }1229+.admin-dialog-title { font-weight: 600; color: var(--ink); }
1230+
1231+.admin-action:has(+ .admin-dialog:popover-open) {
1232+ background: var(--panel-sunken);
1233+}
1242 1234
1243 // Under each person's row two folds share one strip — the live sessions and1235 // Under each person's row two folds share one strip — the live sessions and
1244 // the address edit. Each details sits inline so the summaries read as a row1236 // the address edit. Each details sits inline so the summaries read as a row