// 긴급 공지 — ERP 모든 화면(erp_base.html) 가운데에 띄운다(2026-10-12). // · GET /notice/api/pending — 띄울 시각이 지났고 아직 [확인] 안 한 내 공지(오래된 것부터). 30초마다·창을 다시 볼 때. // · [확인]을 누를 때까지 닫히지 않는다(Esc·바깥 클릭으로 안 닫힘). 여러 건이면 차례대로(1/3). // · [확인] = POST /notice/api/{id}/ack — 실패하면 창을 그대로 두고 알린다. 다른 탭에서 확인하면 이 탭도 다음 확인 때 닫힌다. // · 공지마다 내용 버전(version = 고친 시각) — 띄운 공지가 고쳐지면 다음 확인 때 바뀐 내용으로 다시 그리고 "수정됨"을 알린다. // [확인]은 읽은 버전을 함께 보내, 그 사이 고쳐졌으면(409) 기록하지 않고 바뀐 내용을 다시 보여 준다(2026-10-15 검토 F07). // · 본문 HTML 은 서버가 정리한 것(이미지는 /notice/images/{id} 만). 수신함 오른쪽 작업 창(iframe) 안에서는 돌지 않는다. // · 024 미적용(503)·로그아웃(401)이면 조용히 멈춘다. (function () { "use strict"; if (window.top !== window) return; // iframe(수신함 작업 창 등) 안에서는 바깥 화면이 띄운다 const POLL_MS = 30000; let queue = [], shown = null, box = null, timer = 0, busy = false, stopped = false; function esc(s) { return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) { return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]; }); } function when(iso) { const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(iso || ""); return m ? m[2] + "/" + m[3] + " " + m[4] + ":" + m[5] : ""; } function who(email) { const id = String(email || "").split("@")[0]; return id ? id.charAt(0).toUpperCase() + id.slice(1) : ""; } function schedule() { clearTimeout(timer); if (!stopped) timer = setTimeout(poll, POLL_MS); } async function poll() { if (busy || stopped) return; if (document.hidden) { schedule(); return; } busy = true; try { const res = await fetch("/notice/api/pending", { headers: { Accept: "application/json" }, credentials: "same-origin" }); if (res.status === 401 || res.status === 403 || res.status === 503 || res.status === 404) { stopped = true; return; } if (!res.ok) return; const data = await res.json(); queue = Array.isArray(data.notices) ? data.notices : []; // 다른 탭·다른 곳에서 확인했거나 취소된 공지는 닫는다. 같은 공지라도 내용이 고쳐졌으면(버전이 다르면) 다시 그린다 const cur = shown ? queue.find(function (n) { return n.id === shown.id; }) : null; if (shown && !cur) close(); if (cur && (cur.version || "") !== (shown.version || "")) open(cur, true); else if (!shown && queue.length) open(queue[0]); else if (shown) paintCount(); } catch (_) { // 네트워크 오류는 다음 주기에 다시 } finally { busy = false; schedule(); } } function paintCount() { if (!box || !shown) return; const i = queue.findIndex(function (n) { return n.id === shown.id; }); const c = box.querySelector(".erp-notice-count"); c.textContent = queue.length > 1 ? (i + 1) + " / " + queue.length : ""; c.hidden = queue.length <= 1; } function open(n, updated) { shown = n; if (!box) { box = document.createElement("div"); box.className = "erp-notice-backdrop"; box.innerHTML = '
공지 내용이 수정되었습니다. 바뀐 내용을 확인한 뒤 [확인]을 눌러 주세요.
' + '' + '' + '