refactor(admin): replace object storage native confirms

go
codex 3 weeks ago
parent da03a61b1a
commit 8d2df44d99

@ -762,6 +762,82 @@ body.os-drawer-open {
overflow: hidden;
}
.os-confirm-layer {
position: fixed;
z-index: 1090;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
}
.os-confirm-layer[hidden] {
display: none;
}
.os-confirm-backdrop {
position: absolute;
inset: 0;
width: 100%;
border: 0;
background: rgba(15, 32, 49, 0.56);
backdrop-filter: blur(2px);
}
.os-confirm-dialog {
position: relative;
display: grid;
grid-template-columns: auto minmax(0, 1fr);
gap: 15px;
width: min(470px, 100%);
padding: 24px;
border-radius: 16px;
background: #fff;
box-shadow: 0 28px 80px rgba(15, 32, 49, 0.28);
}
.os-confirm-icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 42px;
height: 42px;
border-radius: 12px;
color: #c13d3d;
background: #fff0f0;
font-size: 23px;
}
.os-confirm-dialog.is-primary .os-confirm-icon {
color: #0b858d;
background: #e9f8f8;
}
.os-confirm-copy h2 {
margin: 1px 0 7px;
color: #1d344b;
font-size: 19px;
}
.os-confirm-copy p {
margin: 0;
color: #6f8398;
font-size: 13px;
line-height: 1.65;
}
.os-confirm-actions {
display: flex;
grid-column: 1 / -1;
justify-content: flex-end;
gap: 9px;
padding-top: 4px;
}
body.os-dialog-open {
overflow: hidden;
}
@media (max-width: 1100px) {
.os-summary,
.os-connection-details {
@ -993,6 +1069,14 @@ body.os-drawer-open {
flex: 1 1 0;
}
.os-confirm-dialog {
padding: 20px;
}
.os-confirm-actions .btn {
flex: 1 1 0;
}
.os-cleanup-legend {
display: grid;
}

@ -33,7 +33,54 @@
node.className = 'os-notice is-show ' + (ok ? 'is-ok' : 'is-error');
}
function initializeConfiguration() {
function initializeConfirmation() {
var layer = document.getElementById('osConfirmDialog');
if (!layer) return null;
var dialog = layer.querySelector('[role="alertdialog"]');
var title = document.getElementById('osConfirmTitle');
var message = document.getElementById('osConfirmMessage');
var submit = document.getElementById('osConfirmSubmit');
var cancelButtons = layer.querySelectorAll('[data-os-confirm-cancel]');
var pending = null;
var previousFocus = null;
function close(result) {
if (!pending) return;
var resolve = pending;
pending = null;
layer.hidden = true;
document.body.classList.remove('os-dialog-open');
if (previousFocus && typeof previousFocus.focus === 'function') {
previousFocus.focus({ preventScroll: true });
}
previousFocus = null;
resolve(result);
}
cancelButtons.forEach(function (button) {
button.addEventListener('click', function () { close(false); });
});
submit.addEventListener('click', function () { close(true); });
document.addEventListener('keydown', function (event) {
if (event.key === 'Escape' && !layer.hidden) close(false);
});
return function confirmAction(options) {
if (pending) return Promise.resolve(false);
title.textContent = options.title;
message.textContent = options.message;
submit.textContent = options.confirmLabel;
submit.className = options.tone === 'primary' ? 'btn btn-primary' : 'btn btn-danger';
dialog.classList.toggle('is-primary', options.tone === 'primary');
previousFocus = document.activeElement;
layer.hidden = false;
document.body.classList.add('os-dialog-open');
submit.focus({ preventScroll: true });
return new Promise(function (resolve) { pending = resolve; });
};
}
function initializeConfiguration(confirmAction) {
var form = document.getElementById('objectStorageForm');
if (!form) return;
var notice = document.getElementById('osNotice');
@ -101,16 +148,23 @@
});
disableButton.addEventListener('click', function () {
if (!canManage || disableButton.disabled) return;
if (!window.confirm('确认停用对象存储?已保存的加密凭据不会被删除。')) return;
setBusy(true);
showNotice(notice, '正在停用对象存储...', true);
request('/admin/object-storage/disable', { expected_revision: revision() }).then(function (result) {
showNotice(notice, result.msg, true);
window.setTimeout(function () { window.location.reload(); }, 650);
}).catch(function (error) {
showNotice(notice, error.message, false);
setBusy(false);
if (!canManage || disableButton.disabled || !confirmAction) return;
confirmAction({
title: '停用对象存储',
message: '停用后云备份不会再使用当前连接;已加密保存的访问凭据不会被删除。',
confirmLabel: '确认停用',
tone: 'danger',
}).then(function (confirmed) {
if (!confirmed) return;
setBusy(true);
showNotice(notice, '正在停用对象存储...', true);
request('/admin/object-storage/disable', { expected_revision: revision() }).then(function (result) {
showNotice(notice, result.msg, true);
window.setTimeout(function () { window.location.reload(); }, 650);
}).catch(function (error) {
showNotice(notice, error.message, false);
setBusy(false);
});
});
});
}
@ -187,7 +241,7 @@
+ ' ' + units[index];
}
function initializeCleanupDebt() {
function initializeCleanupDebt(confirmAction) {
document.querySelectorAll('.os-byte-value').forEach(function (node) {
node.textContent = formatBytes(node.getAttribute('data-bytes'));
});
@ -199,18 +253,25 @@
document.querySelectorAll('.os-cleanup-retry').forEach(function (button) {
button.addEventListener('click', function () {
var backupId = String(button.getAttribute('data-backup-id') || '');
if (!/^\d+$/.test(backupId) || button.disabled) return;
if (!window.confirm('确认重新开启该对象的受控清理周期?系统仍会先完成稳定 HEAD 核对。')) return;
button.disabled = true;
showNotice(notice, '正在核对准确对象版本...', true);
request('/admin/object-storage/cleanup-debts/' + encodeURIComponent(backupId) + '/retry', {})
.then(function (result) {
showNotice(notice, result.msg, true);
window.setTimeout(function () { window.location.reload(); }, 700);
}).catch(function (error) {
showNotice(notice, error.message || '请求失败', false);
button.disabled = false;
});
if (!/^\d+$/.test(backupId) || button.disabled || !confirmAction) return;
confirmAction({
title: '重新开启清理核对',
message: '系统会先检查准确对象身份并等待第二次稳定证据;此操作不会直接重放原删除请求。',
confirmLabel: '开始核对',
tone: 'primary',
}).then(function (confirmed) {
if (!confirmed) return;
button.disabled = true;
showNotice(notice, '正在核对准确对象版本...', true);
request('/admin/object-storage/cleanup-debts/' + encodeURIComponent(backupId) + '/retry', {})
.then(function (result) {
showNotice(notice, result.msg, true);
window.setTimeout(function () { window.location.reload(); }, 700);
}).catch(function (error) {
showNotice(notice, error.message || '请求失败', false);
button.disabled = false;
});
});
});
});
}
@ -249,10 +310,11 @@
}
function initialize() {
var confirmAction = initializeConfirmation();
initializeTabs();
initializeConfigurationDrawer();
initializeConfiguration();
initializeCleanupDebt();
initializeConfiguration(confirmAction);
initializeCleanupDebt(confirmAction);
}
initialize();

@ -241,5 +241,17 @@
</div>
{/if}
<div class="os-confirm-layer" id="osConfirmDialog" hidden>
<button class="os-confirm-backdrop" type="button" data-os-confirm-cancel aria-label="取消操作"></button>
<section class="os-confirm-dialog" role="alertdialog" aria-modal="true" aria-labelledby="osConfirmTitle" aria-describedby="osConfirmMessage" tabindex="-1">
<span class="os-confirm-icon"><i class="mdi mdi-alert-outline"></i></span>
<div class="os-confirm-copy"><h2 id="osConfirmTitle">确认操作</h2><p id="osConfirmMessage"></p></div>
<div class="os-confirm-actions">
<button class="btn btn-light" type="button" data-os-confirm-cancel>取消</button>
<button class="btn btn-danger" id="osConfirmSubmit" type="button">确认</button>
</div>
</section>
</div>
<script src="/cloud/admin-object-storage.js?v={$venix_asset_version}"></script>
{include file='admin/static_footer.tpl'}

@ -79,6 +79,8 @@ $assert(str_contains($template, "admin_title value='对象存储'")
&& str_contains($template, '$item.next_check_at')
&& str_contains($template, '$item.attention_at')
&& !str_contains($template, '<table>')
&& str_contains($template, 'id="osConfirmDialog"')
&& str_contains($template, 'role="alertdialog"')
&& str_contains($template, '/cloud/admin-object-storage.css?v={$venix_asset_version}')
&& str_contains($template, '/cloud/admin-object-storage.js?v={$venix_asset_version}')
&& !str_contains($template, '<style>')
@ -87,6 +89,8 @@ $assert(str_contains($template, "admin_title value='对象存储'")
&& str_contains($pageJs, 'function initialize()')
&& str_contains($pageJs, 'function initializeTabs()')
&& str_contains($pageJs, 'function initializeConfigurationDrawer()')
&& str_contains($pageJs, 'function initializeConfirmation()')
&& !str_contains($pageJs, 'window.confirm(')
&& !str_contains($template, '$item.object_version_id'),
'Admin UI can expose credentials or lost its permission/test boundary.');
$assert(str_contains($controller, "'Cache-Control', 'private, no-store'")

@ -161,5 +161,8 @@ $assert(str_contains($html, 'window.ADMIN_CSRF_TOKEN ='),
'Shared administrator CSRF bootstrap is missing from object-storage page.');
$assert($xpath->query('//details[contains(concat(" ",normalize-space(@class)," ")," os-boundaries ")]')->length === 1,
'Object-storage runtime boundaries are not available as secondary detail.');
$assert($xpath->query('//*[@id="osConfirmDialog" and @hidden]//*[@role="alertdialog"]')->length === 1
&& $xpath->query('//*[@id="osConfirmSubmit"]')->length === 1,
'Object-storage destructive actions lost the accessible in-page confirmation dialog.');
echo "Object-storage administrator template rendering passed.\n";

Loading…
Cancel
Save