Variant distribution: treat redirect as success, refresh modal in place, toasts above modal (inside dialog); asset v32
This commit is contained in:
@@ -468,7 +468,7 @@ code.code { padding: 0.125rem 0.5rem; border-radius: var(--radius-xs); font-fami
|
||||
.cell-btn.st.dim::before { background: var(--c-border-strong); }
|
||||
.mini-count { font-size: 0.72rem; margin-left: 0.15rem; color: var(--c-text-muted); }
|
||||
.defense-cell-timer { font-variant-numeric: tabular-nums; }
|
||||
.lab-head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
|
||||
.lab-head-actions { display: flex; gap: 0.2rem; }
|
||||
.btn btn-secondary btn-sm p-2 {
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
min-width: 1.5rem; height: 1.5rem; padding: 0 0.3rem; cursor: pointer;
|
||||
|
||||
@@ -209,7 +209,20 @@ function attachCommentAutocomplete(input) {
|
||||
/* ---------- Удаление подсказки комментария и всплывающие уведомления ---------- */
|
||||
|
||||
function showToast(text, kind) {
|
||||
var host = $id('toast-host');
|
||||
// уведомления должны быть видны поверх открытой модалки: кладём их в сам <dialog>
|
||||
// (элемент верхнего слоя), иначе они оказываются под ним
|
||||
var dlg = document.querySelector('dialog[open]');
|
||||
var host = null;
|
||||
if (dlg) {
|
||||
host = dlg.querySelector('.toast-host');
|
||||
if (!host) {
|
||||
host = document.createElement('div');
|
||||
host.className = 'toast-host';
|
||||
dlg.appendChild(host);
|
||||
}
|
||||
} else {
|
||||
host = $id('toast-host');
|
||||
}
|
||||
if (!host) return;
|
||||
var toast = document.createElement('div');
|
||||
toast.className = 'toast-item ' + (kind === 'error' ? 'toast-error' : 'toast-success');
|
||||
@@ -663,8 +676,15 @@ document.addEventListener('submit', function (ev) {
|
||||
var btn = form.querySelector('button[type="submit"]');
|
||||
if (btn) btn.disabled = true;
|
||||
fetch(form.action, { method: 'POST', body: new FormData(form), headers: { 'X-Requested-With': 'fetch' } })
|
||||
.then(function (r) { if (r.redirected) throw new Error('сессия истекла — обновите страницу'); return r.text(); })
|
||||
.then(function () { return refreshAssignModal(form.getAttribute('data-refresh')); })
|
||||
.then(function (r) { if (!r.ok) throw new Error('HTTP ' + r.status); return r.text(); })
|
||||
.then(function (html) {
|
||||
// эндпоинты отвечают редиректом на страницу лабы — это норма, не ошибка;
|
||||
// flash-сообщение забираем из отданного HTML
|
||||
var err = /<div[^>]*class="[^"]*toast-item toast-error[^"]*"[^>]*>\s*<span class="toast-text">([^<]*)</.exec(html);
|
||||
var ok = /<span class="toast-text">([^<]*)<\/span>/.exec(html);
|
||||
showToast(err ? err[1].trim() : (ok ? ok[1].trim() : 'Сохранено'), err ? 'error' : 'success');
|
||||
return refreshAssignModal(form.getAttribute('data-refresh'));
|
||||
})
|
||||
.catch(function (e) { showToast('Не удалось сохранить: ' + e.message, 'error'); })
|
||||
.finally(function () { if (btn) btn.disabled = false; });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user