fix(frontend): 修复前台页面编辑弹窗并 1:1 复刻参考主题
远端加载的弹窗在 admin-ajax 上下文里拿不到查询对象,enabled() 恒为假,直接返回 success:false;而 AksrtRequest.responseError 只读 message/data.message,读不到 msg,遂报「请求失败(HTTP 200)」。 改为参考主题原生架构:wp_footer 直出 #modal_admin_set,提交走 vendored main.js 的 aksrt_ajax 契约,不再有 AJAX 取 HTML。 对齐参考主题 zib-frontend-set.php: - 弹窗补齐 aria-hidden=false、win-ajax-replace、role=document - 隐藏字段改用 taxonomy + post_type - 字段顺序与 is_page 分支(标题样式、widgets_register、容器位置) - 多选 checkbox 改 name="id[]",描述允许富文本 - 模块布局指向定制器小工具面板 - term 保存使用 POST 的 taxonomy 字段 清理不再使用的 assets/js/page-admin-set.js。 新增 frontend-page-edit-harness.php 覆盖门禁、渲染与各保存分支。
This commit is contained in:
1 parent
b75bf197a3
commit
12f60897d9
4 files changed
+630
-207
No files matched your search
@@ -1,63 +0,0 @@
|
||||
/**
|
||||
* AKSRT Page Admin Set — 前端页面编辑弹窗提交(后台「扩展&增强 → 系统工具」)。
|
||||
*
|
||||
* 弹窗内容由 PageAdminSet::ajax_modal() 经 aksrt-modal-runtime 注入,
|
||||
* 这里只负责表单提交:序列化 → admin-ajax → 成功后刷新页面。
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
(function (window, document) {
|
||||
'use strict';
|
||||
|
||||
function notify(message, type) {
|
||||
if (typeof window.notyf === 'function') {
|
||||
window.notyf(message, type || 'error', 4, 'aksrt-page-admin-set-toast');
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('submit', function (event) {
|
||||
var form = event.target.closest('form.aksrt-admin-set-form');
|
||||
if (!form) return;
|
||||
event.preventDefault();
|
||||
|
||||
var submitButton = form.querySelector('.aksrt-admin-set-submit');
|
||||
if (submitButton && submitButton.disabled) return;
|
||||
if (submitButton) submitButton.disabled = true;
|
||||
|
||||
var action = (form.querySelector('input[name="action"]') || {}).value || '';
|
||||
var ajaxUrl = (window.aksrtData && window.aksrtData.ajaxUrl) || (window._win && window._win.ajax_url) || '';
|
||||
if (!ajaxUrl) {
|
||||
notify('请求地址缺失', 'error');
|
||||
if (submitButton) submitButton.disabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var url = ajaxUrl + (ajaxUrl.indexOf('?') === -1 ? '?' : '&') + 'action=' + encodeURIComponent(action);
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: new FormData(form),
|
||||
})
|
||||
.then(function (response) {
|
||||
return response.json().catch(function () { return {}; }).then(function (payload) {
|
||||
if (!response.ok || !payload || !payload.success) {
|
||||
throw new Error((payload && payload.data && payload.data.msg) || '保存失败,请重试');
|
||||
}
|
||||
return payload;
|
||||
});
|
||||
})
|
||||
.then(function (payload) {
|
||||
var data = payload.data || {};
|
||||
notify(data.msg || '保存成功', 'success');
|
||||
if (data.reload !== false) {
|
||||
window.setTimeout(function () { window.location.reload(); }, 600);
|
||||
} else if (submitButton) {
|
||||
submitButton.disabled = false;
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
notify(error.message || '保存失败,请重试', 'error');
|
||||
if (submitButton) submitButton.disabled = false;
|
||||
});
|
||||
});
|
||||
})(window, document);
|
||||
Reference in new issue
Block a user