feat(notice): reuse project editor, date popup and member picker on the notice page
- Notice body uses the task description editor (createDescEditor, shared toolbar partial project/_desc_fmtbar.html): bold/italic/underline/strike, text color/size, lists, checklist, quote, link, clear format, image button/paste with resize; images upload to /notice/api/images - Show date uses the project date popup (enhanceDateInput) plus a time field - Recipients rendered like the project member picker (icon + name + check) - project.js exposes window.PJLib; PJ_LIB_ONLY runs only shared tooltips on non-project pages - Centered notice renders checklist/quote/list styles outside project pages too - Task window editor behavior unchanged (jsdom + Chrome regressions pass) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
// 긴급 공지 관리(/notice/, 수퍼관리자) — 만들기·고치기·취소·이미지·미리 보기·확인 현황.
|
||||
// 긴급 공지 관리(/notice/, 수퍼관리자) — 만들기·고치기·취소·미리 보기·확인 현황.
|
||||
// 내용 편집기·날짜 팝업·받는 사람 고르기는 프로젝트 화면 부품 그대로(window.PJLib — project.js, PJ_LIB_ONLY):
|
||||
// · 내용 = 작업 설명란과 같은 편집기(굵게·기울임·밑줄·취소선·글자 색/크기·목록·체크리스트·인용·링크·서식 지우기·이미지
|
||||
// 붙여넣기/버튼·크기 조절), 이미지는 /notice/api/images 로 올린다.
|
||||
// · 띄울 날짜 = 아사나식 날짜 팝업(공휴일·오늘·지우기), 시각은 옆 칸.
|
||||
// · 받는 사람 = 프로젝트 멤버 고르기와 같은 아이콘 + 이름 + 체크.
|
||||
(function () {
|
||||
"use strict";
|
||||
const root = document.getElementById("ntc-root");
|
||||
if (!root) return;
|
||||
if (!root || !window.PJLib) return;
|
||||
const L = window.PJLib;
|
||||
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 people = window.NTC_PEOPLE || [];
|
||||
const byEmail = {};
|
||||
people.forEach(function (p) { byEmail[String(p.email).toLowerCase()] = p; });
|
||||
const nameOf = function (e) { const p = byEmail[String(e).toLowerCase()]; return p ? p.name : String(e).split("@")[0]; };
|
||||
const esc = function (s) {
|
||||
return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
|
||||
return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c];
|
||||
@@ -32,94 +39,65 @@
|
||||
return data || {};
|
||||
}
|
||||
|
||||
const title = $("ntc-title"), body = $("ntc-body"), showAt = $("ntc-show-at"), idEl = $("ntc-id");
|
||||
const title = $("ntc-title"), dateEl = $("ntc-date"), timeEl = $("ntc-time"), 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" : ""; };
|
||||
const say = function (text, ok) { msg.textContent = text || ""; msg.hidden = !text; msg.classList.toggle("is-ok", !!ok); };
|
||||
|
||||
// ── 내용 — 작업 설명란 편집기 ──
|
||||
const editor = L.createDescEditor({
|
||||
box: $("ntc-body"), fmtbar: $("ntc-fmtbar"), imgInput: $("ntc-img-input"), hint: $("ntc-hint"), mentions: false,
|
||||
uploadImage: async function (file) {
|
||||
const fd = new FormData();
|
||||
fd.append("file", file, file.name || "image");
|
||||
return (await api("POST", "/notice/api/images", fd, true)).image.url;
|
||||
},
|
||||
});
|
||||
// ── 날짜 — 프로젝트 날짜 팝업 ──
|
||||
L.enhanceDateInput(dateEl, { placeholder: "날짜(비우면 바로)" });
|
||||
// ── 받는 사람 — 프로젝트 멤버 고르기 모양 ──
|
||||
peopleBox.innerHTML = people.map(L.memberPickHtml).join("") || '<span class="pj-empty-sm">등록된 사람이 없습니다.</span>';
|
||||
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 picked() {
|
||||
return Array.from(peopleBox.querySelectorAll("input[type=checkbox]:checked")).map(function (c) { return c.value; });
|
||||
}
|
||||
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();
|
||||
function setPicked(emails) {
|
||||
const want = (emails || []).map(function (e) { return String(e).toLowerCase(); });
|
||||
peopleBox.querySelectorAll("input[type=checkbox]").forEach(function (c) { c.checked = want.indexOf(c.value.toLowerCase()) >= 0; });
|
||||
}
|
||||
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 showAtValue() {
|
||||
// 날짜를 비우면 바로(서버가 지금으로), 날짜만 있으면 그날 00:00, 시각까지 있으면 그 시각 — 모두 한국시간
|
||||
return dateEl.value ? dateEl.value + "T" + (timeEl.value || "00:00") : "";
|
||||
}
|
||||
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,
|
||||
title: title.value.trim(), body_html: editor.getHtml(), show_at: showAtValue(),
|
||||
to_all: toAll(), targets: picked(), reshow: $("ntc-reshow").checked,
|
||||
};
|
||||
}
|
||||
function resetForm() {
|
||||
idEl.value = ""; title.value = ""; body.innerHTML = ""; showAt.value = "";
|
||||
idEl.value = ""; title.value = ""; editor.setHtml(""); dateEl.value = ""; timeEl.value = "";
|
||||
root.querySelector('input[name="ntc-to"][value="all"]').checked = true;
|
||||
peopleBox.hidden = true;
|
||||
peopleBox.querySelectorAll("input").forEach(function (c) { c.checked = false; });
|
||||
setPicked([]);
|
||||
$("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; }
|
||||
if (saving) return;
|
||||
saving = true; save.disabled = true;
|
||||
try {
|
||||
await editor.whenIdle(); // 이미지 올리는 중이면 끝난 뒤 저장(빠진 채 저장되지 않게)
|
||||
const p = payload();
|
||||
if (!p.title) { say("제목을 입력하세요."); title.focus(); return; }
|
||||
if (!p.to_all && !p.targets.length) { say("받는 사람을 한 명 이상 고르거나 '전체'를 고르세요."); return; }
|
||||
const id = idEl.value;
|
||||
if (id) await api("PUT", "/notice/api/notices/" + id, p);
|
||||
else await api("POST", "/notice/api/notices", p);
|
||||
@@ -131,7 +109,7 @@
|
||||
});
|
||||
|
||||
// ── 미리 보기 — 받는 사람 화면과 같은 모양 ──
|
||||
$("ntc-preview").addEventListener("click", function () { preview(title.value.trim() || "(제목 없음)", body.innerHTML); });
|
||||
$("ntc-preview").addEventListener("click", function () { preview(title.value.trim() || "(제목 없음)", editor.getHtml()); });
|
||||
function preview(t, html) {
|
||||
const box = document.createElement("div");
|
||||
box.className = "erp-notice-backdrop";
|
||||
@@ -173,9 +151,9 @@
|
||||
'<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>" +
|
||||
'<button type="button" class="pj-btn pj-btn-sm" data-act="preview">미리 보기</button>' +
|
||||
'<button type="button" class="pj-btn pj-btn-sm" data-act="edit">고치기</button>' +
|
||||
'<button type="button" class="pj-btn pj-btn-sm" 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>" +
|
||||
@@ -194,10 +172,11 @@
|
||||
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);
|
||||
idEl.value = n.id; title.value = n.title; editor.setHtml(n.body_html);
|
||||
dateEl.value = (n.show_at || "").slice(0, 10); timeEl.value = (n.show_at || "").slice(11, 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; });
|
||||
setPicked(n.targets);
|
||||
$("ntc-reshow-row").hidden = false; $("ntc-reshow").checked = false;
|
||||
$("ntc-form-title").textContent = "공지 고치기";
|
||||
save.textContent = "고친 내용 저장";
|
||||
|
||||
Reference in New Issue
Block a user