feat(notice): urgent notices centered on every ERP screen until acknowledged

- Super admin only: /notice/ page (title, body with images, show time KST, all or picked people,
  preview, edit with optional re-show, cancel/undo, per-person acknowledgement status)
- Shown on every ERP page (erp_base, main, admin) dead center; [확인] only (no Esc/backdrop close),
  queue in order, ack failure keeps the dialog, closes when acked/cancelled elsewhere
- project_db migration 024 (urgent_notices, targets, acks, images as bytea); shares ProjectStore.pool
- Body sanitized like task descriptions, images restricted to /notice/images/{id}, type sniffed
- Entry points: ERP sidebar foot and Project options dialog (super admin)
- Docs (NOTICE_MODULE, DEPLOYMENT 024, overview, CLAUDE.md); tests (DB-less, real PostgreSQL, jsdom)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 14:07:10 +09:00
parent 1759e00213
commit 2aa6b6efae
22 changed files with 1489 additions and 2 deletions
+221
View File
@@ -0,0 +1,221 @@
// 긴급 공지 관리(/notice/, 수퍼관리자) — 만들기·고치기·취소·이미지·미리 보기·확인 현황.
(function () {
"use strict";
const root = document.getElementById("ntc-root");
if (!root) return;
const $ = function (id) { return document.getElementById(id); };
const people = {};
(window.NTC_PEOPLE || []).forEach(function (p) { people[String(p.email).toLowerCase()] = p.name; });
const nameOf = function (e) { return people[String(e).toLowerCase()] || String(e).split("@")[0]; };
const esc = function (s) {
return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
return { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c];
});
};
const shortWhen = function (iso) {
const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(iso || "");
return m ? m[1] + "-" + m[2] + "-" + m[3] + " " + m[4] + ":" + m[5] : "";
};
async function api(method, url, body, isForm) {
const opts = { method: method, credentials: "same-origin", headers: {} };
if (body !== undefined) {
if (isForm) opts.body = body;
else { opts.headers["Content-Type"] = "application/json"; opts.body = JSON.stringify(body); }
}
const res = await fetch(url, opts);
let data = null;
try { data = await res.json(); } catch (_) {}
if (!res.ok) {
const d = data && data.detail;
throw new Error(typeof d === "string" ? d : "HTTP " + res.status);
}
return data || {};
}
const title = $("ntc-title"), body = $("ntc-body"), showAt = $("ntc-show-at"), idEl = $("ntc-id");
const peopleBox = $("ntc-people"), msg = $("ntc-msg"), save = $("ntc-save");
const say = function (text, ok) { msg.textContent = text || ""; msg.hidden = !text; msg.style.color = ok ? "#1f7a3a" : ""; };
function toAll() { return root.querySelector('input[name="ntc-to"]:checked').value === "all"; }
root.querySelectorAll('input[name="ntc-to"]').forEach(function (r) {
r.addEventListener("change", function () { peopleBox.hidden = toAll(); });
});
// ── 본문 편집 — 굵게, 이미지(버튼·붙여넣기·끌어 놓기 → 서버에 올리고 주소로 넣는다) ──
root.querySelector('[data-cmd="bold"]').addEventListener("click", function () { body.focus(); document.execCommand("bold"); });
let savedRange = null;
body.addEventListener("keyup", keepRange);
body.addEventListener("mouseup", keepRange);
body.addEventListener("blur", keepRange);
function keepRange() {
const s = window.getSelection();
if (s.rangeCount && body.contains(s.getRangeAt(0).commonAncestorContainer)) savedRange = s.getRangeAt(0).cloneRange();
}
function insertNode(node) {
body.focus();
const s = window.getSelection();
let r = savedRange && body.contains(savedRange.commonAncestorContainer) ? savedRange : null;
if (!r) { r = document.createRange(); r.selectNodeContents(body); r.collapse(false); }
r.deleteContents();
r.insertNode(node);
r.setStartAfter(node); r.collapse(true);
s.removeAllRanges(); s.addRange(r);
savedRange = r.cloneRange();
}
let uploading = 0;
async function uploadImages(files) {
for (const f of files) {
if (!/^image\/(png|jpeg|gif|webp)$/.test(f.type)) { say("이미지(png·jpg·gif·webp)만 넣을 수 있습니다: " + f.name); continue; }
uploading++;
save.disabled = true;
try {
const fd = new FormData();
fd.append("file", f, f.name || "image");
const res = await api("POST", "/notice/api/images", fd, true);
const img = document.createElement("img");
img.src = res.image.url;
img.alt = f.name || "";
insertNode(img);
say("");
} catch (e) { say("이미지를 올리지 못했습니다: " + e.message); }
finally { uploading--; if (!uploading) save.disabled = false; }
}
}
$("ntc-image-btn").addEventListener("click", function () { keepRange(); $("ntc-image-file").click(); });
$("ntc-image-file").addEventListener("change", function (e) { uploadImages(Array.from(e.target.files || [])); e.target.value = ""; });
body.addEventListener("paste", function (e) {
const files = Array.from((e.clipboardData && e.clipboardData.files) || []).filter(function (f) { return /^image\//.test(f.type); });
if (files.length) { e.preventDefault(); keepRange(); uploadImages(files); }
});
body.addEventListener("dragover", function (e) { e.preventDefault(); });
body.addEventListener("drop", function (e) {
const files = Array.from((e.dataTransfer && e.dataTransfer.files) || []).filter(function (f) { return /^image\//.test(f.type); });
if (files.length) { e.preventDefault(); keepRange(); uploadImages(files); }
});
// ── 저장(만들기·고치기) ──
function payload() {
return {
title: title.value.trim(), body_html: body.innerHTML, show_at: showAt.value || "",
to_all: toAll(),
targets: Array.from(peopleBox.querySelectorAll("input:checked")).map(function (c) { return c.value; }),
reshow: $("ntc-reshow").checked,
};
}
function resetForm() {
idEl.value = ""; title.value = ""; body.innerHTML = ""; showAt.value = "";
root.querySelector('input[name="ntc-to"][value="all"]').checked = true;
peopleBox.hidden = true;
peopleBox.querySelectorAll("input").forEach(function (c) { c.checked = false; });
$("ntc-reshow").checked = false; $("ntc-reshow-row").hidden = true;
$("ntc-form-title").textContent = "새 긴급 공지";
save.textContent = "공지 만들기";
savedRange = null;
}
$("ntc-reset").addEventListener("click", function () { resetForm(); say(""); });
let saving = false;
save.addEventListener("click", async function () {
if (saving || uploading) return;
const p = payload();
if (!p.title) { say("제목을 입력하세요."); title.focus(); return; }
if (!p.to_all && !p.targets.length) { say("받는 사람을 한 명 이상 고르거나 '전체'를 고르세요."); return; }
saving = true; save.disabled = true;
try {
const id = idEl.value;
if (id) await api("PUT", "/notice/api/notices/" + id, p);
else await api("POST", "/notice/api/notices", p);
resetForm();
say(id ? "공지를 고쳤습니다." : "공지를 만들었습니다. 띄울 시각이 되면 받는 사람 화면 가운데에 나타납니다.", true);
await loadList();
} catch (e) { say("저장하지 못했습니다: " + e.message); }
finally { saving = false; save.disabled = false; }
});
// ── 미리 보기 — 받는 사람 화면과 같은 모양 ──
$("ntc-preview").addEventListener("click", function () { preview(title.value.trim() || "(제목 없음)", body.innerHTML); });
function preview(t, html) {
const box = document.createElement("div");
box.className = "erp-notice-backdrop";
box.innerHTML = '<div class="erp-notice-card" role="dialog" aria-modal="true">' +
'<div class="erp-notice-head"><span class="erp-notice-badge">긴급 공지 · 미리 보기</span></div>' +
'<h2 class="erp-notice-title"></h2><div class="erp-notice-body"></div>' +
'<div class="erp-notice-foot"><span class="erp-notice-meta">받는 사람 화면에는 [확인]만 있습니다</span>' +
'<button type="button" class="erp-notice-ok">닫기</button></div></div>';
box.querySelector(".erp-notice-title").textContent = t;
box.querySelector(".erp-notice-body").innerHTML = html; // 저장하면 서버가 다시 정리한다
document.body.appendChild(box);
const ok = box.querySelector(".erp-notice-ok");
ok.addEventListener("click", function () { box.remove(); });
box.addEventListener("keydown", function (e) { if (e.key === "Escape") box.remove(); });
ok.focus();
}
// ── 목록 ──
let list = [];
function stateOf(n) {
if (n.cancelled_at) return ["is-cancelled", "취소됨"];
if (new Date(n.show_at) > new Date()) return ["is-scheduled", "예약 " + shortWhen(n.show_at)];
return ["is-live", "표시 중"];
}
function render() {
const box = $("ntc-list");
if (!list.length) { box.textContent = "아직 공지가 없습니다."; return; }
box.innerHTML = list.map(function (n) {
const st = stateOf(n);
const acked = Object.keys(n.acks || {});
const who = n.to_all ? "전체" : n.targets.map(nameOf).join(", ");
const ackLine = n.to_all ? "확인 " + acked.length + "명"
: "확인 " + n.targets.filter(function (e) { return n.acks[e]; }).length + " / " + n.targets.length + "명";
const rows = (n.to_all ? acked : n.targets).map(function (e) {
return n.acks[e] ? "<li>" + esc(nameOf(e)) + " — " + esc(shortWhen(n.acks[e])) + "</li>"
: '<li class="is-no">' + esc(nameOf(e)) + " — 아직 확인 안 함</li>";
}).join("");
return '<div class="ntc-item" data-id="' + n.id + '">' +
'<div class="ntc-item-head"><span class="ntc-state ' + st[0] + '">' + esc(st[1]) + "</span>" +
'<span class="ntc-item-title">' + esc(n.title) + "</span>" +
'<span class="ntc-item-acts">' +
'<button type="button" class="erp-btn erp-btn-outline" data-act="preview">미리 보기</button>' +
'<button type="button" class="erp-btn erp-btn-outline" data-act="edit">고치기</button>' +
'<button type="button" class="erp-btn erp-btn-outline" data-act="cancel">' + (n.cancelled_at ? "취소 되돌리기" : "취소") + "</button>" +
"</span></div>" +
'<div class="ntc-item-meta">띄울 시각 ' + esc(shortWhen(n.show_at)) + " · 받는 사람 " + esc(who) +
" · 만든 사람 " + esc(nameOf(n.created_by)) + "</div>" +
'<details class="ntc-acks"><summary>' + esc(ackLine) + "</summary><ul>" + (rows || "<li>아직 없습니다</li>") + "</ul></details>" +
"</div>";
}).join("");
}
async function loadList() {
try { list = (await api("GET", "/notice/api/notices")).notices || []; render(); }
catch (e) { $("ntc-list").textContent = "목록을 읽지 못했습니다: " + e.message; }
}
$("ntc-list").addEventListener("click", async function (e) {
const b = e.target.closest("[data-act]");
if (!b) return;
const n = list.find(function (x) { return String(x.id) === b.closest(".ntc-item").dataset.id; });
if (!n) return;
if (b.dataset.act === "preview") { preview(n.title, n.body_html); return; }
if (b.dataset.act === "edit") {
idEl.value = n.id; title.value = n.title; body.innerHTML = n.body_html; showAt.value = (n.show_at || "").slice(0, 16);
root.querySelector('input[name="ntc-to"][value="' + (n.to_all ? "all" : "some") + '"]').checked = true;
peopleBox.hidden = n.to_all;
peopleBox.querySelectorAll("input").forEach(function (c) { c.checked = n.targets.indexOf(c.value.toLowerCase()) >= 0; });
$("ntc-reshow-row").hidden = false; $("ntc-reshow").checked = false;
$("ntc-form-title").textContent = "공지 고치기";
save.textContent = "고친 내용 저장";
say("");
title.focus();
return;
}
if (b.dataset.act === "cancel") {
const cancel = !n.cancelled_at;
if (cancel) {
const q = "'" + n.title + "' 공지를 취소할까요? 아직 확인하지 않은 사람에게도 더 뜨지 않습니다.";
const yes = window.erpConfirm ? await window.erpConfirm(q, { okText: "공지 취소", cancelText: "닫기" }) : window.confirm(q);
if (!yes) return;
}
b.disabled = true;
try { await api("POST", "/notice/api/notices/" + n.id + "/cancel", { cancel: cancel }); await loadList(); }
catch (err) { say("처리하지 못했습니다: " + err.message); b.disabled = false; }
}
});
loadList();
})();
+82
View File
@@ -0,0 +1,82 @@
/* 긴급 공지 — 화면 가로·세로 정가운데(erp-notice.js). 화면 배율(.erp-app zoom) 밖 body 에 붙는다. */
.erp-notice-backdrop {
position: fixed; inset: 0; z-index: 6000;
display: flex; align-items: center; justify-content: center;
padding: 16px; box-sizing: border-box;
background: rgba(15, 17, 21, .5);
}
.erp-notice-backdrop[hidden] { display: none; }
.erp-notice-card {
width: min(640px, 100%); max-height: min(86vh, 900px); box-sizing: border-box;
display: flex; flex-direction: column; gap: 10px;
padding: 22px 24px 18px; border-radius: 14px; background: #fff; color: #1e1f21;
box-shadow: 0 18px 50px rgba(0, 0, 0, .35); border-top: 6px solid #e5484d;
animation: erp-notice-in .18s ease-out;
}
@keyframes erp-notice-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.erp-notice-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.erp-notice-badge {
display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
background: #fde8e8; color: #c62a2f; font-size: 12.5px; font-weight: 800;
}
.erp-notice-count { font-size: 12.5px; font-weight: 700; color: #6b7079; }
.erp-notice-title { margin: 0; font-size: 20px; font-weight: 800; line-height: 1.35; word-break: keep-all; overflow-wrap: anywhere; }
.erp-notice-body {
flex: 1 1 auto; min-height: 0; overflow: auto; font-size: 14.5px; line-height: 1.65; color: #2b2f36;
overflow-wrap: anywhere;
}
.erp-notice-body p { margin: 0 0 .6em; }
.erp-notice-body img { display: block; max-width: 100%; height: auto; margin: 8px 0; border-radius: 8px; }
.erp-notice-body a { color: #3b6fd8; }
.erp-notice-error { margin: 0; padding: 6px 10px; border-radius: 6px; background: #fdecec; color: #b42318; font-size: 13px; }
.erp-notice-error[hidden] { display: none; }
.erp-notice-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 6px; border-top: 1px solid #eceef1; }
.erp-notice-meta { font-size: 12.5px; color: #6b7079; }
.erp-notice-ok {
min-width: 96px; padding: 9px 20px; border: none; border-radius: 8px; cursor: pointer;
background: #e5484d; color: #fff; font-size: 14.5px; font-weight: 800;
}
.erp-notice-ok:hover { background: #d23c41; }
.erp-notice-ok:focus-visible { outline: 3px solid rgba(229, 72, 77, .35); outline-offset: 2px; }
.erp-notice-ok:disabled { opacity: .6; cursor: default; }
/* 관리 화면(/notice/) */
.ntc-wrap { display: grid; grid-template-columns: minmax(360px, 520px) 1fr; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .ntc-wrap { grid-template-columns: 1fr; } }
.ntc-card { background: #fff; border: 1px solid #e6e8eb; border-radius: 12px; padding: 18px; }
.ntc-card h2 { margin: 0 0 12px; font-size: 16px; }
.ntc-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; font-weight: 700; color: #3b4048; }
.ntc-field input[type=text], .ntc-field input[type=datetime-local] {
font: inherit; font-weight: 500; padding: 8px 10px; border: 1px solid #d5d9de; border-radius: 8px;
}
.ntc-editor-bar { display: flex; gap: 4px; }
.ntc-editor-bar button { padding: 4px 10px; border: 1px solid #d5d9de; border-radius: 6px; background: #fff; cursor: pointer; font: inherit; font-size: 12.5px; }
.ntc-editor {
min-height: 160px; max-height: 420px; overflow: auto; padding: 10px 12px; border: 1px solid #d5d9de; border-radius: 8px;
font-weight: 400; font-size: 14px; line-height: 1.6; color: #2b2f36; outline: none;
}
.ntc-editor:focus { border-color: #7b68ee; box-shadow: 0 0 0 3px rgba(123, 104, 238, .15); }
.ntc-editor:empty::before { content: attr(data-placeholder); color: #a0a5ad; }
.ntc-editor img { max-width: 100%; height: auto; border-radius: 6px; }
.ntc-targets { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.ntc-people { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 10px; max-height: 220px; overflow: auto;
padding: 8px; border: 1px solid #e6e8eb; border-radius: 8px; }
.ntc-people[hidden] { display: none; }
.ntc-people label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; }
.ntc-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.ntc-msg { margin: 8px 0 0; font-size: 13px; color: #b42318; }
.ntc-msg[hidden] { display: none; }
.ntc-list { display: flex; flex-direction: column; gap: 10px; }
.ntc-item { border: 1px solid #e6e8eb; border-radius: 10px; padding: 12px 14px; }
.ntc-item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ntc-item-title { font-weight: 800; font-size: 14.5px; }
.ntc-state { padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 800; }
.ntc-state.is-live { background: #fde8e8; color: #c62a2f; }
.ntc-state.is-scheduled { background: #e8efff; color: #3456b8; }
.ntc-state.is-cancelled { background: #eef0f2; color: #6b7079; }
.ntc-item-meta { margin-top: 4px; font-size: 12.5px; color: #6b7079; }
.ntc-item-acts { margin-left: auto; display: flex; gap: 6px; }
.ntc-acks { margin-top: 8px; font-size: 12.5px; color: #3b4048; }
.ntc-acks summary { cursor: pointer; font-weight: 700; }
.ntc-acks ul { margin: 6px 0 0; padding-left: 18px; }
.ntc-acks .is-no { color: #b42318; }
+118
View File
@@ -0,0 +1,118 @@
// 긴급 공지 — ERP 모든 화면(erp_base.html) 가운데에 띄운다(2026-10-12).
// · GET /notice/api/pending — 띄울 시각이 지났고 아직 [확인] 안 한 내 공지(오래된 것부터). 30초마다·창을 다시 볼 때.
// · [확인]을 누를 때까지 닫히지 않는다(Esc·바깥 클릭으로 안 닫힘). 여러 건이면 차례대로(1/3).
// · [확인] = POST /notice/api/{id}/ack — 실패하면 창을 그대로 두고 알린다. 다른 탭에서 확인하면 이 탭도 다음 확인 때 닫힌다.
// · 본문 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 { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[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 : [];
// 다른 탭·다른 곳에서 확인했거나 취소된 공지는 닫는다
if (shown && !queue.some(function (n) { return n.id === shown.id; })) close();
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) {
shown = n;
if (!box) {
box = document.createElement("div");
box.className = "erp-notice-backdrop";
box.innerHTML =
'<div class="erp-notice-card" role="alertdialog" aria-modal="true" aria-labelledby="erp-notice-title">' +
'<div class="erp-notice-head"><span class="erp-notice-badge">긴급 공지</span><span class="erp-notice-count" hidden></span></div>' +
'<h2 class="erp-notice-title" id="erp-notice-title"></h2>' +
'<div class="erp-notice-body"></div>' +
'<p class="erp-notice-error" role="alert" hidden></p>' +
'<div class="erp-notice-foot"><span class="erp-notice-meta"></span>' +
'<button type="button" class="erp-notice-ok">확인</button></div></div>';
document.body.appendChild(box); // 화면 배율(.erp-app zoom) 밖 — 늘 화면 정가운데
box.querySelector(".erp-notice-ok").addEventListener("click", ack);
// [확인] 전에는 닫지 않는다 — Esc 는 막고, 포커스는 창 안에
box.addEventListener("keydown", function (e) {
if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); }
if (e.key === "Tab") { e.preventDefault(); box.querySelector(".erp-notice-ok").focus(); }
});
}
box.querySelector(".erp-notice-title").textContent = n.title || "";
box.querySelector(".erp-notice-body").innerHTML = n.body_html || ""; // 서버가 정리한 HTML
box.querySelector(".erp-notice-meta").textContent =
[who(n.created_by), when(n.show_at)].filter(Boolean).join(" · ");
box.querySelector(".erp-notice-error").hidden = true;
box.querySelector(".erp-notice-body").scrollTop = 0;
box.hidden = false;
paintCount();
const ok = box.querySelector(".erp-notice-ok");
ok.disabled = false;
ok.focus();
}
function close() {
shown = null;
if (box) box.hidden = true;
}
async function ack() {
if (!shown) return;
const n = shown, ok = box.querySelector(".erp-notice-ok"), err = box.querySelector(".erp-notice-error");
ok.disabled = true;
err.hidden = true;
try {
const res = await fetch("/notice/api/" + n.id + "/ack", { method: "POST", credentials: "same-origin" });
if (!res.ok && res.status !== 404) throw new Error("HTTP " + res.status); // 404 = 취소·삭제됨 — 닫는다
try { localStorage.setItem("erp_notice_ack", String(n.id) + ":" + Date.now()); } catch (_) {}
queue = queue.filter(function (x) { return x.id !== n.id; });
if (queue.length) open(queue[0]); else close();
} catch (e) {
err.textContent = "확인을 저장하지 못했습니다. 다시 눌러 주세요. (" + e.message + ")";
err.hidden = false;
ok.disabled = false;
ok.focus();
}
}
window.addEventListener("storage", function (e) { if (e.key === "erp_notice_ack") poll(); });
document.addEventListener("visibilitychange", function () { if (!document.hidden) poll(); });
if (window.__ERP_NOTICE_TEST__) window.__erpNotice = { poll: poll, state: function () { return { queue: queue, shown: shown, stopped: stopped }; } };
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", poll);
else poll();
})();