fix(profile): match account submit buttons
This commit is contained in:
@@ -40,6 +40,11 @@
|
||||
if (window.AKSRTCaptcha) window.AKSRTCaptcha.reset(scene, scope);
|
||||
}
|
||||
|
||||
function setSettingsSubmitLabel(button, text) {
|
||||
var label = button && button.querySelector('[data-aksrt-settings-submit-label]');
|
||||
if (label) label.textContent = text;
|
||||
}
|
||||
|
||||
/* ==================== Dashboard 导航 ==================== */
|
||||
function initDashboardNavigation() {
|
||||
if (document.documentElement.dataset.aksrtUserCenterNavigationInitialized === 'true') return;
|
||||
@@ -907,7 +912,8 @@
|
||||
fm.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
var btn = fm.querySelector('[type=submit]');
|
||||
var orig = btn ? btn.textContent : '';
|
||||
var submitLabel = btn && btn.querySelector('[data-aksrt-settings-submit-label]');
|
||||
var orig = submitLabel ? submitLabel.textContent : '';
|
||||
var toastId = fid === 'pwd-form'
|
||||
? 'aksrt-settings-password-toast'
|
||||
: 'aksrt-settings-email-toast';
|
||||
@@ -924,40 +930,40 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (btn) { btn.disabled = true; btn.textContent = i18n.submitting || '提交中...'; }
|
||||
notyf(i18n.submitting || '正在提交…', 'load', '', toastId);
|
||||
var scene = fid === 'pwd-form' ? 'change_password' : 'change_email';
|
||||
runCaptcha(scene, fm).then(function(captchaPayload) {
|
||||
if (captchaPayload === null) {
|
||||
if (btn) { btn.disabled = false; btn.textContent = orig; }
|
||||
return null;
|
||||
}
|
||||
if (container.dataset && container.dataset.aksrtSettingsModalClosed === 'true') return null;
|
||||
var modalShell = fm.closest('.aksrt-user-settings-modal');
|
||||
if (modalShell && modalShell.dataset.aksrtSettingsModalClosed === 'true') return null;
|
||||
var d = new FormData(fm);
|
||||
d.set('action', act);
|
||||
d.set('_settings_nonce', settingsNonce);
|
||||
Object.keys(captchaPayload || {}).forEach(function(key) { d.set(key, captchaPayload[key]); });
|
||||
return fetch(ajaxUrl, { method: 'POST', credentials: 'same-origin', body: d });
|
||||
})
|
||||
if (btn) { btn.disabled = true; setSettingsSubmitLabel(btn, i18n.submitting || '提交中...'); }
|
||||
notyf(i18n.submitting || '正在提交…', 'load', '', toastId);
|
||||
var scene = fid === 'pwd-form' ? 'change_password' : 'change_email';
|
||||
runCaptcha(scene, fm).then(function(captchaPayload) {
|
||||
if (captchaPayload === null) {
|
||||
if (btn) { btn.disabled = false; setSettingsSubmitLabel(btn, orig); }
|
||||
return null;
|
||||
}
|
||||
if (container.dataset && container.dataset.aksrtSettingsModalClosed === 'true') return null;
|
||||
var modalShell = fm.closest('.aksrt-user-settings-modal');
|
||||
if (modalShell && modalShell.dataset.aksrtSettingsModalClosed === 'true') return null;
|
||||
var d = new FormData(fm);
|
||||
d.set('action', act);
|
||||
d.set('_settings_nonce', settingsNonce);
|
||||
Object.keys(captchaPayload || {}).forEach(function(key) { d.set(key, captchaPayload[key]); });
|
||||
return fetch(ajaxUrl, { method: 'POST', credentials: 'same-origin', body: d });
|
||||
})
|
||||
.then(function(r) { return r ? r.json() : null; })
|
||||
.then(function(r) {
|
||||
if (!r) return;
|
||||
if (btn) { btn.disabled = false; btn.textContent = orig; }
|
||||
if (r.success) {
|
||||
notyf((r.data && r.data.message) || '操作成功', 'success', 5, toastId);
|
||||
var activeModal = window.AksrtModalRuntime && window.AksrtModalRuntime.getActive();
|
||||
if (activeModal && activeModal.classList.contains('aksrt-user-settings-modal') && activeModal.contains(fm)) {
|
||||
window.AksrtModalRuntime.close('settings-submit');
|
||||
if (btn) { btn.disabled = false; setSettingsSubmitLabel(btn, orig); }
|
||||
if (r.success) {
|
||||
notyf((r.data && r.data.message) || '操作成功', 'success', 5, toastId);
|
||||
var activeModal = window.AksrtModalRuntime && window.AksrtModalRuntime.getActive();
|
||||
if (activeModal && activeModal.classList.contains('aksrt-user-settings-modal') && activeModal.contains(fm)) {
|
||||
window.AksrtModalRuntime.close('settings-submit');
|
||||
}
|
||||
if (r.data && r.data.redirect_to) setTimeout(function() { window.location.href = r.data.redirect_to; }, 2500);
|
||||
} else {
|
||||
notyf((r.data && r.data.message) || i18n.operationFailed || '操作失败', 'danger', 5, toastId);
|
||||
}
|
||||
if (r.data && r.data.redirect_to) setTimeout(function() { window.location.href = r.data.redirect_to; }, 2500);
|
||||
} else {
|
||||
notyf((r.data && r.data.message) || i18n.operationFailed || '操作失败', 'danger', 5, toastId);
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch(function() {
|
||||
if (btn) { btn.disabled = false; btn.textContent = orig; }
|
||||
if (btn) { btn.disabled = false; setSettingsSubmitLabel(btn, orig); }
|
||||
notyf(i18n.networkError || '网络错误', 'danger', 5, toastId);
|
||||
})
|
||||
.finally(function() {
|
||||
@@ -1207,10 +1213,11 @@
|
||||
return;
|
||||
}
|
||||
var submitBtn = form.querySelector('[type="submit"]');
|
||||
var submitIdleText = submitBtn ? submitBtn.textContent : '';
|
||||
var submitLabel = submitBtn && submitBtn.querySelector('[data-aksrt-settings-submit-label]');
|
||||
var submitIdleText = submitLabel ? submitLabel.textContent : '';
|
||||
if (submitBtn) {
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = '绑定中...';
|
||||
submitBtn.disabled = true;
|
||||
setSettingsSubmitLabel(submitBtn, '绑定中...');
|
||||
}
|
||||
function doBind(captcha) {
|
||||
var toastId = 'aksrt-settings-phone-bind-toast';
|
||||
@@ -1240,14 +1247,14 @@
|
||||
notyf((res.json && (res.json.message || res.json.error)) || '绑定失败', 'danger', 5, toastId);
|
||||
if (submitBtn) {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = submitIdleText;
|
||||
setSettingsSubmitLabel(submitBtn, submitIdleText);
|
||||
}
|
||||
})
|
||||
.catch(function () {
|
||||
notyf('网络错误', 'danger', 5, toastId);
|
||||
if (submitBtn) {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = '确认绑定';
|
||||
setSettingsSubmitLabel(submitBtn, submitIdleText);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1255,7 +1262,7 @@
|
||||
if (captchaPayload === null) {
|
||||
if (submitBtn) {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = submitIdleText;
|
||||
setSettingsSubmitLabel(submitBtn, submitIdleText);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user