diff --git a/index.html b/index.html index 3288eba..3550f0e 100644 --- a/index.html +++ b/index.html @@ -351,13 +351,17 @@ let db = { checks: [], templates: [], typicalRemarks: [] }; async function load() { - const res = await fetch("/api/data"); - db = await res.json(); - updateStats(); - renderRecentChecks(); - renderTemplates(); - renderRemarksDb(); - populateQuestionTypes(); + try { + const res = await fetch("/api/data"); + db = await res.json(); + updateStats(); + renderRecentChecks(); + renderTemplates(); + renderRemarksDb(); + populateQuestionTypes(); + } catch (err) { + console.error("Ошибка загрузки данных:", err); + } } function updateStats() { @@ -407,33 +411,48 @@ const formData = new FormData(e.target); const data = Object.fromEntries(formData.entries()); - const res = await fetch("/api/checks", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(data) - }); - const result = await res.json(); - if (result.ok) { - currentCheckId = result.check.id; - showView("check-detail"); - loadCheckDetail(currentCheckId); + try { + const res = await fetch("/api/checks", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data) + }); + const result = await res.json(); + if (result.ok) { + currentCheckId = result.check.id; + showView("check-detail"); + loadCheckDetail(currentCheckId); + } else { + alert("Ошибка создания проверки: " + (result.error || "Неизвестная ошибка")); + } + } catch (err) { + alert("Ошибка создания проверки: " + err.message); } }); async function loadCheckDetail(id) { - const res = await fetch(`/api/checks/${id}`); - const check = await res.json(); - if (!check.id) return; - - document.getElementById("detail-title").textContent = check.question || "Проверка"; - const statusEl = document.getElementById("detail-status"); - const statusClass = check.status === "Готово к комиссии" ? "status-green" : check.status === "На доработке" ? "status-red" : "status-yellow"; - statusEl.innerHTML = `${check.status || "Новая"}`; - - renderDocuments(check.documents || []); - renderCompleteness(check); - renderRemarks(check.remarks || []); - renderReport(check); + try { + const res = await fetch(`/api/checks/${id}`); + const check = await res.json(); + if (!check || !check.id) { + alert("Проверка не найдена"); + showView("checks"); + return; + } + + document.getElementById("detail-title").textContent = check.question || "Проверка"; + const statusEl = document.getElementById("detail-status"); + const statusClass = check.status === "Готово к комиссии" ? "status-green" : check.status === "На доработке" ? "status-red" : "status-yellow"; + statusEl.innerHTML = `${check.status || "Новая"}`; + + renderDocuments(check.documents || []); + renderCompleteness(check); + renderRemarks(check.remarks || []); + renderReport(check); + } catch (err) { + console.error("Ошибка загрузки проверки:", err); + alert("Ошибка загрузки данных проверки"); + } } function renderDocuments(docs) { @@ -474,11 +493,12 @@ } function renderRemarks(remarks) { + const safeText = (text) => String(text || "").replace(/"/g, '"').replace(/'/g, '''); document.getElementById("remarks-list").innerHTML = remarks.map(r => `