feat(inout): 발주 메일 미리보기에서 본문 바로 고치기
미리보기 창을 눌러 글·표를 고치면 고친 본문 그대로 발송(안 고치면 서버 본문). 서버가 허용 태그·인라인 서식만 남기고 글 버전도 다시 만든다. [원래 본문으로]·닫을 때 확인. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+40
-6
@@ -731,7 +731,7 @@
|
||||
// (입고 담당 본인 Gmail, 받는 사람 = 옵션 → 물류센터 이메일, 참조 기본 = 옵션 값, 본문에 입고증 사진)
|
||||
const mailBtn = document.getElementById("io-mail-btn"), mailDlg = document.getElementById("io-mail");
|
||||
if (mailBtn && mailDlg) {
|
||||
const om = initMail(mailDlg, { param: "mail", what: "발주 메일" });
|
||||
const om = initMail(mailDlg, { param: "mail", what: "발주 메일", editable: true });
|
||||
const url = "/inout/orders/" + mailBtn.dataset.order + "/mail";
|
||||
mailBtn.addEventListener("click", function () { om.open(url); });
|
||||
if (mailBtn.dataset.open === "1") om.open(url);
|
||||
@@ -749,7 +749,7 @@
|
||||
const body = dlg.querySelector("[data-mail-body]"), foot = dlg.querySelector("[data-mail-foot]");
|
||||
const msgEl = dlg.querySelector(".io-dlg-msg"), sendBtn = dlg.querySelector("[data-mail-send]");
|
||||
const titleEl = dlg.querySelector("[data-mail-title]");
|
||||
let base = "", data = null, sent = false;
|
||||
let base = "", data = null, sent = false, edited = false;
|
||||
function say(text, bad) { msgEl.textContent = text || ""; msgEl.hidden = !text; msgEl.classList.toggle("is-bad", !!bad); }
|
||||
function esc(s) { const d = document.createElement("div"); d.textContent = s == null ? "" : String(s); return d.innerHTML; }
|
||||
function field(name) { return body.querySelector('[data-mail-field="' + name + '"]'); }
|
||||
@@ -794,10 +794,43 @@
|
||||
(notice ? '<p class="io-mail-notice">' + esc(notice) + "</p>" : "") +
|
||||
(receipt && data.photos_skipped ? '<p class="io-hint">HEIC 등 본문에 넣지 못하는 입고증 사진 ' + esc(data.photos_skipped) + "장은 빠집니다(입고 기록에는 그대로).</p>" : "") +
|
||||
(sentList ? '<div class="io-mail-sentlist"><b>보낸 기록</b><ul>' + sentList + "</ul></div>" : "") +
|
||||
'<iframe class="io-mail-preview" sandbox title="메일 본문 미리보기"></iframe>';
|
||||
body.querySelector(".io-mail-preview").srcdoc = data.html;
|
||||
(cfg.editable ? '<div class="io-mail-edit-bar"><span>본문을 눌러 바로 고칠 수 있습니다 — 고친 내용 그대로 보냅니다.</span>' +
|
||||
'<button type="button" class="io-link-btn" data-mail-reset hidden>원래 본문으로</button></div>' : "") +
|
||||
'<iframe class="io-mail-preview" title="메일 본문 미리보기"></iframe>';
|
||||
edited = false;
|
||||
setupPreview(body.querySelector(".io-mail-preview"), data.html);
|
||||
sendBtn.textContent = (data.sent || []).length ? "다시 발송" : "메일 발송";
|
||||
}
|
||||
// 발주 메일 본문 고치기(2026-10-27) — 미리보기 iframe 을 designMode 로. 스크립트는 막고(allow-scripts 없음) 부모만 문서에 손댈 수 있게
|
||||
// allow-same-origin. 보낼 때 고쳤으면 body HTML 을 같이 보낸다(서버가 허용 태그·서식만 남김).
|
||||
function setupPreview(ifr, html) {
|
||||
ifr.setAttribute("sandbox", cfg.editable ? "allow-same-origin" : "");
|
||||
if (!cfg.editable) { ifr.srcdoc = html; return; }
|
||||
const reset = body.querySelector("[data-mail-reset]");
|
||||
ifr.addEventListener("load", function () {
|
||||
const doc = ifr.contentDocument;
|
||||
if (!doc) return;
|
||||
doc.designMode = "on";
|
||||
doc.body.style.outline = "none";
|
||||
doc.addEventListener("input", function () { edited = true; reset.hidden = false; });
|
||||
});
|
||||
reset.onclick = async function () {
|
||||
if (!(await confirmMsg("고친 내용을 버리고 원래 본문으로 되돌릴까요?"))) return;
|
||||
edited = false;
|
||||
reset.hidden = true;
|
||||
ifr.srcdoc = data.html;
|
||||
};
|
||||
ifr.srcdoc = html;
|
||||
}
|
||||
function editedHtml() {
|
||||
const ifr = body.querySelector(".io-mail-preview");
|
||||
return cfg.editable && edited && ifr && ifr.contentDocument ? ifr.contentDocument.body.innerHTML : "";
|
||||
}
|
||||
async function close() {
|
||||
if (edited && !sent && !(await confirmMsg("고친 본문은 저장되지 않습니다. 닫을까요?"))) return;
|
||||
edited = false;
|
||||
dlg.close();
|
||||
}
|
||||
async function open(url, title) {
|
||||
base = url;
|
||||
if (title && titleEl) titleEl.textContent = title;
|
||||
@@ -815,7 +848,7 @@
|
||||
say("보내는 중…");
|
||||
try {
|
||||
const res = await fetch(base, { method: "POST", headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ to: to, cc: cc, resend: !!resend }) });
|
||||
body: JSON.stringify({ to: to, cc: cc, resend: !!resend, html: editedHtml() || undefined }) });
|
||||
const out = await res.json();
|
||||
if (out.resend_needed) {
|
||||
say("");
|
||||
@@ -838,7 +871,8 @@
|
||||
await load();
|
||||
say("Gmail 연결을 끊었습니다.");
|
||||
});
|
||||
dlg.addEventListener("click", function (e) { if (e.target.closest("[data-close]")) dlg.close(); });
|
||||
dlg.addEventListener("click", function (e) { if (e.target.closest("[data-close]")) close(); });
|
||||
dlg.addEventListener("cancel", function (e) { if (edited && !sent) { e.preventDefault(); close(); } }); // Esc
|
||||
dlg.addEventListener("close", function () {
|
||||
const url = new URL(location.href);
|
||||
const had = url.searchParams.has(cfg.param);
|
||||
|
||||
Reference in New Issue
Block a user