lesson-topic: автозаполнение темы модуля на главной по отчёту о занятии

This commit is contained in:
dev
2026-11-24 12:30:27 +03:00
parent 36baa45cd8
commit d7f4a4b457
7 changed files with 466 additions and 2 deletions
+23
View File
@@ -12,6 +12,8 @@ const moduleAttachments = new Map();
let moduleSearchTimer = null;
let moduleSearchSeq = 0;
let moduleOptionsKey = '';
let moduleTouched = false;
let moduleAutofillSeq = 0;
const toast = document.getElementById('toast');
const camVideo = document.getElementById('camVideo');
const camCanvas = document.getElementById('camCanvas');
@@ -405,6 +407,22 @@ async function resolveModuleId(name) {
return exact ? exact.id : null;
}
async function applyModuleTopicAutofill() {
const groupId = parseInt(groupInput.value, 10);
if (!Number.isFinite(groupId) || groupId <= 0) return;
const seq = ++moduleAutofillSeq;
try {
const res = await fetch(`${API}/api/public/lesson-topic?group_id=${groupId}`);
if (!res.ok) return;
const data = await res.json();
const bare = String((data && data.topic) || '').trim();
if (seq !== moduleAutofillSeq || moduleTouched || moduleInput.value.trim() || !bare) return;
if (!findModuleId(bare)) return;
moduleInput.value = bare;
updateAttachHint();
} catch (e) { return; }
}
(async () => {
await initDateTime();
try {
@@ -437,6 +455,7 @@ async function resolveModuleId(name) {
groupInput.innerHTML = '<option value="" disabled selected>Нет активных групп</option>';
}
}
await applyModuleTopicAutofill();
try {
const fRes = await fetch(`${API}/api/public-settings`);
const f = await fRes.json();
@@ -561,6 +580,7 @@ function finishEntrySent() {
clearPendingEntry();
try {
form.reset();
moduleTouched = false;
removePhoto();
clearFiles();
updateAttachHint();
@@ -676,6 +696,7 @@ document.getElementById('filesBtn').addEventListener('click', () => document.get
document.getElementById('cancelCamBtn').addEventListener('click', closeCam);
document.getElementById('captureBtn').addEventListener('click', capture);
moduleInput.addEventListener('input', () => {
moduleTouched = true;
updateAttachHint();
clearTimeout(moduleSearchTimer);
const q = moduleInput.value.trim();
@@ -688,6 +709,7 @@ moduleInput.addEventListener('input', () => {
}, 250);
});
moduleInput.addEventListener('change', () => {
moduleTouched = true;
clearTimeout(moduleSearchTimer);
moduleSearchSeq++;
updateAttachHint();
@@ -699,6 +721,7 @@ moduleInput.addEventListener('focus', async () => {
if (seq !== moduleSearchSeq) return;
if (list) renderModuleOptions(list);
});
groupInput.addEventListener('change', applyModuleTopicAutofill);
(async () => {
const fab = document.getElementById('bmFab');