|
|
|
|
@ -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();
|
|
|
|
|
|