feat(dashboard): модал причины закрытия задачи и шага вместо prompt
This commit is contained in:
@@ -145,6 +145,19 @@
|
||||
</div>
|
||||
|
||||
<div class="toast" id="toast"></div>
|
||||
|
||||
<div class="modal-overlay" id="dashReasonModal">
|
||||
<div class="edit-modal" style="max-width:520px;width:min(92vw,520px)">
|
||||
<h3 id="dashReasonTitle" style="margin:0 0 10px 0">Укажите причину закрытия задачи</h3>
|
||||
<p id="dashReasonSub" style="font-size:13px;color:var(--muted);margin-bottom:12px"></p>
|
||||
<textarea id="dashReasonText" rows="4" style="width:100%;padding:8px 10px;border:1px solid var(--border);border-radius:8px;font:inherit;resize:vertical"></textarea>
|
||||
<div class="actions" style="justify-content:flex-end;gap:8px;margin-top:12px">
|
||||
<button type="button" class="cancel" id="dashReasonCancel">Отмена</button>
|
||||
<button type="button" class="btn" id="dashReasonSave">Сохранить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="vendor/lucide.min.js"></script>
|
||||
<script src="js/datetime.js"></script>
|
||||
<script src="admin.js"></script>
|
||||
|
||||
+64
-7
@@ -170,6 +170,7 @@ function parseTaskKey(key) {
|
||||
}
|
||||
|
||||
let currentPostTasks = [];
|
||||
let dashReasonPending = null;
|
||||
|
||||
function renderPostLessonTasks(rows) {
|
||||
const el = document.getElementById('postLessonTasks');
|
||||
@@ -358,21 +359,35 @@ if (postTasksContainer) {
|
||||
postTasksContainer.addEventListener('click', async (e) => {
|
||||
const closeBtn = e.target.closest('[data-close-task]');
|
||||
if (closeBtn) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const t = currentPostTasks.find(x => x.key === closeBtn.dataset.closeTask);
|
||||
let reason = '';
|
||||
if (t && !t.all_done) reason = prompt('Укажите причину закрытия задачи:') || '';
|
||||
try { await closeTaskWithReason(closeBtn.dataset.closeTask, reason); } catch (err) { showToast(err.message); }
|
||||
const modal = document.getElementById('dashReasonModal');
|
||||
const title = document.getElementById('dashReasonTitle');
|
||||
const sub = document.getElementById('dashReasonSub');
|
||||
const ta = document.getElementById('dashReasonText');
|
||||
if (t && !t.all_done && modal && title && sub && ta) {
|
||||
title.textContent = 'Укажите причину закрытия задачи';
|
||||
sub.textContent = `${esc(t.group_name || '')} · ${esc(t.lesson_date || '')}`;
|
||||
ta.value = '';
|
||||
dashReasonPending = { taskKey: closeBtn.dataset.closeTask, isTask: true };
|
||||
modal.classList.add('open');
|
||||
ta.focus();
|
||||
return;
|
||||
}
|
||||
try { await closeTaskWithReason(closeBtn.dataset.closeTask, ''); } catch (err) { showToast(err.message); }
|
||||
return;
|
||||
}
|
||||
const restoreBtn = e.target.closest('[data-restore-task]');
|
||||
if (restoreBtn) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
try { await reopenTask(restoreBtn.dataset.restoreTask); } catch (err) { showToast(err.message); }
|
||||
return;
|
||||
}
|
||||
const step = e.target.closest('[data-step-key]');
|
||||
if (step) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const t = currentPostTasks.find(x => x.key === step.dataset.taskKey);
|
||||
const s = t && t.steps.find(x => x.key === step.dataset.stepKey);
|
||||
@@ -380,8 +395,20 @@ if (postTasksContainer) {
|
||||
try { await saveStepState(step.dataset.taskKey, step.dataset.stepKey, false, ''); } catch (err) { showToast(err.message); }
|
||||
return;
|
||||
}
|
||||
const reason = prompt('Укажите причину закрытия шага:') || '';
|
||||
try { await saveStepState(step.dataset.taskKey, step.dataset.stepKey, true, reason); } catch (err) { showToast(err.message); }
|
||||
const modal2 = document.getElementById('dashReasonModal');
|
||||
const title2 = document.getElementById('dashReasonTitle');
|
||||
const sub2 = document.getElementById('dashReasonSub');
|
||||
const ta2 = document.getElementById('dashReasonText');
|
||||
if (t && s && modal2 && title2 && sub2 && ta2) {
|
||||
title2.textContent = `Причина закрытия шага: ${esc(s.label)}`;
|
||||
sub2.textContent = `${esc(t.group_name || '')} · ${esc(t.lesson_date || '')}`;
|
||||
ta2.value = s.reason || '';
|
||||
dashReasonPending = { taskKey: step.dataset.taskKey, stepKey: step.dataset.stepKey, isTask: false };
|
||||
modal2.classList.add('open');
|
||||
ta2.focus();
|
||||
return;
|
||||
}
|
||||
try { await saveStepState(step.dataset.taskKey, step.dataset.stepKey, true, ''); } catch (err) { showToast(err.message); }
|
||||
return;
|
||||
}
|
||||
const card = e.target.closest('.post-task[data-task-link]');
|
||||
@@ -401,8 +428,7 @@ const closeAllTasksBtn = document.getElementById('closeAllTasksBtn');
|
||||
if (closeAllTasksBtn) closeAllTasksBtn.addEventListener('click', async () => {
|
||||
for (const t of currentPostTasks) {
|
||||
if (!t.all_done) {
|
||||
const reason = prompt('Укажите причину закрытия задачи:') || '';
|
||||
try { await closeTaskWithReason(t.key, reason); } catch { /* ignore */ }
|
||||
try { await closeTaskWithReason(t.key, ''); } catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -425,6 +451,37 @@ document.addEventListener('click', function(e) {
|
||||
}
|
||||
});
|
||||
|
||||
const dashReasonSave = document.getElementById('dashReasonSave');
|
||||
const dashReasonCancel = document.getElementById('dashReasonCancel');
|
||||
const dashReasonModal = document.getElementById('dashReasonModal');
|
||||
if (dashReasonSave) dashReasonSave.addEventListener('click', async () => {
|
||||
if (!dashReasonPending) return;
|
||||
const ta = document.getElementById('dashReasonText');
|
||||
const reason = (ta && ta.value || '').trim();
|
||||
try {
|
||||
if (dashReasonPending.isTask) {
|
||||
await closeTaskWithReason(dashReasonPending.taskKey, reason);
|
||||
} else {
|
||||
await saveStepState(dashReasonPending.taskKey, dashReasonPending.stepKey, true, reason);
|
||||
}
|
||||
} catch (err) {
|
||||
showToast(err.message || 'Не удалось сохранить');
|
||||
return;
|
||||
}
|
||||
closeDashReasonModal();
|
||||
});
|
||||
if (dashReasonCancel) dashReasonCancel.addEventListener('click', closeDashReasonModal);
|
||||
if (dashReasonModal) dashReasonModal.addEventListener('click', (e) => { if (e.target === dashReasonModal) closeDashReasonModal(); });
|
||||
document.addEventListener('keydown', (e) => { if (e.key === 'Escape') closeDashReasonModal(); });
|
||||
|
||||
function closeDashReasonModal() {
|
||||
const modal = document.getElementById('dashReasonModal');
|
||||
if (modal) modal.classList.remove('open');
|
||||
dashReasonPending = null;
|
||||
const ta = document.getElementById('dashReasonText');
|
||||
if (ta) ta.value = '';
|
||||
}
|
||||
|
||||
(async () => {
|
||||
if (await checkAuth()) {
|
||||
buildSidebar(document.body.dataset.page);
|
||||
|
||||
Reference in New Issue
Block a user