Migrate Laysense to upstream LaySite 1.4.3 with external site data
This commit is contained in:
+79
-4
@@ -1,6 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
jQuery(function ($) {
|
||||
const $actionDialog = $('#admin-action-dialog');
|
||||
const $actionField = $actionDialog.find('[data-action-field]');
|
||||
const $actionValue = $actionField.find('[data-action-value]');
|
||||
|
||||
window.laySiteAction = function ({title, message = '', label, value = '', readOnly = false, accept = '确定'}) {
|
||||
const dialog = $actionDialog.get(0);
|
||||
if (!dialog || dialog.open) return Promise.resolve(null);
|
||||
const hasInput = Boolean(label);
|
||||
$actionDialog.find('[data-action-title]').text(title);
|
||||
$actionDialog.find('[data-action-message]').text(message).prop('hidden', !message);
|
||||
$actionDialog.find('[data-action-label]').text(label || '');
|
||||
$actionField.prop('hidden', !hasInput);
|
||||
$actionValue.val(value).prop({disabled: !hasInput, readOnly});
|
||||
$actionDialog.find('[data-action-accept]').text(accept);
|
||||
return new Promise((resolve) => {
|
||||
dialog.returnValue = '';
|
||||
$actionDialog.one('close', () => {
|
||||
resolve(dialog.returnValue === 'accept' ? (hasInput ? $actionValue.val() : true) : null);
|
||||
});
|
||||
dialog.showModal();
|
||||
if (hasInput) $actionValue.trigger('focus').trigger('select');
|
||||
else $actionDialog.find('[data-action-cancel]').trigger('focus');
|
||||
});
|
||||
};
|
||||
$actionDialog.on('click', '[data-action-cancel]', () => $actionDialog.get(0).close());
|
||||
|
||||
$('[data-page-layout-editor]').each(function () {
|
||||
const {pageLayoutEditor: kind, defaultId} = this.dataset;
|
||||
const $link = $(this);
|
||||
$('#studio-page-settings').on('change', '[name="' + kind + '_choice"]', function () {
|
||||
const id = this.value || defaultId;
|
||||
$link.prop('hidden', this.value === 'hidden')
|
||||
.attr('href', id && this.value !== 'hidden' ? '/admin/pages/layout--' + kind + '-' + id : '/admin/new-page?type=' + kind);
|
||||
});
|
||||
});
|
||||
$('[data-new-page-type]').on('change', function () {
|
||||
const ordinary = this.value === 'page';
|
||||
$(this.form).find('[data-new-page-slug]').prop('hidden', !ordinary)
|
||||
.find('input').prop({required: ordinary, disabled: !ordinary});
|
||||
$('[data-open-page-templates]').prop('disabled', !ordinary);
|
||||
}).trigger('change');
|
||||
$('[data-provider-settings]').each(function () {
|
||||
const $settings = $(this);
|
||||
const $mode = $settings.find('[name=provider_mode]');
|
||||
$mode.on('change.layoutProvider', () => {
|
||||
const mode = $mode.val();
|
||||
$settings.find('[data-provider-field]').prop('hidden', !mode);
|
||||
$settings.find('[data-provider-mode]').each(function () {
|
||||
$(this).prop('hidden', this.dataset.providerMode !== mode);
|
||||
});
|
||||
}).triggerHandler('change.layoutProvider');
|
||||
});
|
||||
|
||||
$('[data-page-list]').each(function () {
|
||||
const $panel = $(this);
|
||||
const $search = $panel.find('[data-page-search]');
|
||||
@@ -62,28 +115,48 @@ jQuery(function ($) {
|
||||
$feedback.text(message);
|
||||
if (status === 401) {
|
||||
$feedback.append(' ', $('<a>', {
|
||||
href: '/admin/login', target: '_blank', rel: 'noopener', text: '打开登录页'
|
||||
href: '/admin/login', target: '_blank', rel: 'noopener noreferrer', text: '打开登录页'
|
||||
}));
|
||||
}
|
||||
$feedback.prop('hidden', false).trigger('focus');
|
||||
}
|
||||
|
||||
function designFieldError($form, response) {
|
||||
if (!response?.field) return false;
|
||||
const $feedback = $form.find('[data-field-error]').filter(function () {
|
||||
return this.dataset.fieldError === response.field;
|
||||
});
|
||||
$feedback.text(response.message).prop('hidden', false);
|
||||
if (!$feedback.is(':visible')) return false;
|
||||
|
||||
$form.find('[aria-describedby]').filter(function () {
|
||||
return this.getAttribute('aria-describedby') === $feedback.attr('id');
|
||||
}).attr('aria-invalid', 'true');
|
||||
$feedback.trigger('focus');
|
||||
return true;
|
||||
}
|
||||
|
||||
document.addEventListener('invalid', (event) => {
|
||||
if (event.target.form?.method.toLowerCase() === 'post') clearSavedStatus();
|
||||
}, true);
|
||||
|
||||
$('form[method="post"]').on('submit', function (event) {
|
||||
$('form[method="post"]').on('submit', async function (event) {
|
||||
event.preventDefault();
|
||||
const $form = $(this);
|
||||
if ($form.attr('aria-busy') === 'true') return;
|
||||
const submitter = event.originalEvent?.submitter;
|
||||
if (submitter?.dataset.confirm && !window.confirm(submitter.dataset.confirm)) return;
|
||||
if (submitter?.dataset.confirm && !await window.laySiteAction({
|
||||
title: '确认操作', message: submitter.dataset.confirm,
|
||||
accept: submitter.getAttribute('aria-label') || submitter.textContent.trim() || '确定',
|
||||
})) return;
|
||||
clearSavedStatus();
|
||||
const action = $form.attr('action');
|
||||
const isLogin = action === '/admin/login';
|
||||
const $submit = $form.find(':submit:enabled');
|
||||
const multipart = $form.attr('enctype') === 'multipart/form-data';
|
||||
$form.attr('aria-busy', 'true').children('.ajax-feedback').prop('hidden', true);
|
||||
$form.find('[data-field-error]').text('').prop('hidden', true);
|
||||
$form.find('[aria-describedby^="design-error-"]').removeAttr('aria-invalid');
|
||||
$submit.prop('disabled', true);
|
||||
$form.triggerHandler('studio:busy', [true]);
|
||||
|
||||
@@ -123,7 +196,9 @@ jQuery(function ($) {
|
||||
return;
|
||||
}
|
||||
finish();
|
||||
formError($form, response?.message || '请求未完成,请稍后重试。', request.status);
|
||||
if (!designFieldError($form, response)) {
|
||||
formError($form, response?.message || '请求未完成,请稍后重试。', request.status);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user