Merge branch 'feat/inout-mail-toolbar'

This commit is contained in:
2026-10-27 13:04:08 +09:00
9 changed files with 194 additions and 15 deletions
+2
View File
@@ -34,6 +34,8 @@
- 보낸 기록·재발송 확인.
- **본문 고치기**(2026-10-27): 발주 메일 미리보기 iframe 이 `designMode`(sandbox `allow-same-origin`, 스크립트 없음) — 고치면 [원래 본문으로]·닫을 때 확인,
보낼 때만 `html` 을 함께 POST → `store.clean_mail_html`(허용 태그·표·인라인 서식만, url()·이벤트·스크립트 제거) + 글 버전 `mail_html_to_text`. 안 고치면 서버 본문 그대로. 입고 요청 메일은 고치기 없음(cid 사진).
**서식 막대**(`initMail` 안 `RTE_BAR`, 안내문 발송 편집기와 같은 구성: 크기·굵게·기울임·밑줄·취소선·글자/배경 색·정렬·목록·링크·서식 지우기·되돌리기) = iframe `execCommand`(styleWithCSS → span style).
Quill 은 표를 못 담아 안 씀. 크기는 fontSize 7 → px span 으로 바꿔 끼움. 선택은 본문 문서의 현재 선택 우선(막대 mousedown 때 기억은 대비용). 서버는 `text-decoration-line` → `text-decoration`.
- **입고 담당 발주 알림 자동 발송**(2026-10-19): 발주 메일이 나가면 같은 Gmail 로 옵션 → 담당자의 입고 담당들에게 따로 보냄 — 제목은 발주 메일과 같고 내용은 발주번호·발주일·제품 코드·제품명·수량만(`store.order_notice_mail`, `router._send_order_notice`). 실패해도 공장 메일은 그대로(안내만), 미리보기 창에 받을 사람 안내.
- **참조 기본값 `king@dbxcorp.co.kr`**(2026-10-19) — 미리보기 참조 칸에 미리 들어감, 옵션 → 공장 탭 "발주 메일 참조"에서 고침(`inout_settings` `order_mail_cc`, 행이 없으면 기본값 — 저장만 005 필요).
+2
View File
@@ -382,6 +382,8 @@ def _mail_style(value: str) -> str:
for decl in value.split(";"):
prop, _, val = decl.partition(":")
prop, val = prop.strip().lower(), val.strip()
if prop == "text-decoration-line": # 서식 막대(Chrome execCommand)가 밑줄·취소선을 이렇게 만든다 — 메일 프로그램은 text-decoration 만 아는 곳이 많다
prop = "text-decoration"
if prop in _MAIL_STYLE_PROPS and _MAIL_STYLE_VALUE_RE.match(val) and not re.search(r"url|expression|@import", val, re.I):
out.append(f"{prop}:{val}")
return ";".join(out)
+2 -2
View File
@@ -1,6 +1,6 @@
{% extends "erp_base.html" %}
{% from "inout/_macros.html" import order_badge, progress, due, n, ymd %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261027a" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261027b" />{% endblock %}
{% block content %}
<div class="io-split">{# 2열 — 왼쪽 화면 | 오른쪽 달력(2026-10-21) #}
@@ -71,4 +71,4 @@
{% include "inout/_calendar.html" %}
</div>
{% endblock %}
{% block scripts %}<script src="/static/inout.js?v=20261027a" defer></script>{% endblock %}
{% block scripts %}<script src="/static/inout.js?v=20261027b" defer></script>{% endblock %}
@@ -20,7 +20,7 @@
</footer>
</dialog>
{%- endmacro -%}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261027a" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261027b" />{% endblock %}
{% block content %}
{% set active = order.status in ('open', 'partial') %}
@@ -258,4 +258,4 @@
{% include "inout/_calendar.html" %}
</div>
{% endblock %}
{% block scripts %}<script src="/static/inout.js?v=20261027a" defer></script>{% endblock %}
{% block scripts %}<script src="/static/inout.js?v=20261027b" defer></script>{% endblock %}
@@ -1,5 +1,5 @@
{% extends "erp_base.html" %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261027a" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261027b" />{% endblock %}
{% block content %}
<div class="io-split">{# 2열 — 왼쪽 화면 | 오른쪽 달력(2026-10-21) #}
@@ -95,4 +95,4 @@
{% include "inout/_calendar.html" %}
</div>
{% endblock %}
{% block scripts %}<script src="/static/inout.js?v=20261027a" defer></script>{% endblock %}
{% block scripts %}<script src="/static/inout.js?v=20261027b" defer></script>{% endblock %}
@@ -1,6 +1,6 @@
{% extends "erp_base.html" %}
{% from "inout/_macros.html" import due, n, ymd %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261027a" />{% endblock %}
{% block head_extra %}<link rel="stylesheet" href="/static/inout.css?v=20261027b" />{% endblock %}
{% block content %}
<div class="io-split">{# 2열 — 왼쪽 화면 | 오른쪽 달력(2026-10-21) #}
@@ -91,4 +91,4 @@
{% include "inout/_calendar.html" %}
</div>
{% endblock %}
{% block scripts %}<script src="/static/inout.js?v=20261027a" defer></script>{% endblock %}
{% block scripts %}<script src="/static/inout.js?v=20261027b" defer></script>{% endblock %}
+17 -2
View File
@@ -192,8 +192,23 @@
.io-mail-fields input[readonly] { background: var(--color-ghost-gray); color: #3d3f42; }
.io-mail-sentlist { margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; background: #f3fbf5; border: 1px solid #cdeed6; font-size: 12.5px; }
.io-mail-sentlist ul { margin: 4px 0 0; padding-left: 18px; }
.io-mail-edit-bar { display: flex; align-items: center; gap: 12px; margin: 0 0 6px; font-size: 12.5px; color: var(--color-midtone-gray); }
.io-mail-edit-bar .io-link-btn { margin-left: auto; }
/* 발주 메일 본문 서식 막대(2026-10-27) */
.io-rte { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 4px 6px; border: 1px solid var(--color-subtle-ash); border-bottom: 0; border-radius: 8px 8px 0 0; background: #fafbfc; }
.io-rte + .io-rte-hint + .io-mail-preview { border-radius: 0 0 8px 8px; }
.io-rte-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 28px; padding: 0 6px; border: 0; border-radius: 6px; background: none; color: #3d3f42; font-size: 14px; cursor: pointer; }
.io-rte-btn:hover { background: var(--color-ghost-gray); }
.io-rte-btn.is-active { background: #e3ebfb; color: #1a56c4; }
.io-rte-a { font-weight: 700; border-bottom: 3px solid #d93025; line-height: 1; padding: 0 1px; }
.io-rte-size { height: 28px; padding: 0 6px; border: 1px solid var(--color-subtle-ash); border-radius: 6px; background: #fff; font-size: 12.5px; }
.io-rte-sep { width: 1px; height: 18px; margin: 0 4px; background: var(--color-subtle-ash); }
.io-rte-reset { margin-left: auto; font-size: 12.5px; }
.io-rte-pop { position: absolute; z-index: 5; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; max-width: 320px; padding: 8px; border: 1px solid var(--color-subtle-ash); border-radius: 8px; background: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, .12); }
.io-rte-pop[hidden] { display: none; }
.io-rte-pop .io-in { width: 220px; }
.io-rte-sw { width: 22px; height: 22px; padding: 0; border: 1px solid rgba(0, 0, 0, .15); border-radius: 4px; cursor: pointer; }
.io-rte-sw:hover { outline: 2px solid #1a56c4; outline-offset: 1px; }
.io-rte-sw.is-none { background: linear-gradient(to top right, #fff 45%, #d93025 45%, #d93025 55%, #fff 55%) !important; }
.io-rte-hint { margin: 0; padding: 4px 8px; border-left: 1px solid var(--color-subtle-ash); border-right: 1px solid var(--color-subtle-ash); background: #fafbfc; font-size: 12px; color: var(--color-midtone-gray); }
.io-mail-preview { width: 100%; height: 380px; border: 1px solid var(--color-subtle-ash); border-radius: 8px; background: #fff; }
.io-mail-connect { padding: 8px 2px 4px; font-size: 13.5px; line-height: 1.7; }
.io-mail-connect .erp-btn { margin-top: 6px; }
+152 -5
View File
@@ -750,6 +750,38 @@
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, edited = false;
// 발주 메일 본문 서식 막대(2026-10-27) — 안내문 발송 편집기와 같은 구성. 함수 안에 둔다(initMail 을 위에서 먼저 부른다 — TDZ)
const RTE_TEXT_COLORS = [["#1d1d1f", "기본(검정)"], ["#6b7280", "회색"], ["#d93025", "빨강"], ["#e8710a", "주황"], ["#b58100", "노랑"],
["#188038", "초록"], ["#1a73e8", "파랑"], ["#7b2fd0", "보라"]];
const RTE_BG_COLORS = [["transparent", "배경 없음"], ["#fff3bf", "노랑"], ["#ffd8a8", "주황"], ["#ffc9c9", "빨강"], ["#d3f9d8", "초록"],
["#d0ebff", "파랑"], ["#e5dbff", "보라"], ["#f1f3f5", "회색"]];
const ic = function (d) { return '<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' + d + "</svg>"; };
const tb = function (attr, title, inner) { return '<button type="button" class="io-rte-btn" ' + attr + ' title="' + title + '" aria-label="' + title + '">' + inner + "</button>"; };
const RTE_BAR = '<div class="io-rte" role="toolbar" aria-label="본문 서식">' +
'<select class="io-rte-size" data-rte-size title="글자 크기" aria-label="글자 크기"><option value="">크기</option>' +
["12px", "14px", "16px", "18px", "20px", "24px", "30px"].map(function (s) { return '<option value="' + s + '">' + s.replace("px", "") + (s === "14px" ? " (기본)" : "") + "</option>"; }).join("") +
"</select><span class=\"io-rte-sep\"></span>" +
tb('data-cmd="bold"', "굵게 (Ctrl+B)", "<b>B</b>") + tb('data-cmd="italic"', "기울임 (Ctrl+I)", "<i>I</i>") +
tb('data-cmd="underline"', "밑줄 (Ctrl+U)", "<u>U</u>") + tb('data-cmd="strikeThrough"', "취소선", "<s>S</s>") +
'<span class="io-rte-sep"></span>' +
tb('data-pop="foreColor"', "글자 색", '<span class="io-rte-a">A</span>') +
tb('data-pop="hiliteColor"', "배경 색", ic('<path d="M9 11l-4 4v3h3l4-4"/><path d="M14 6l4 4-6 6-4-4z"/><path d="M4 21h16" stroke="#f9ab00" stroke-width="3"/>')) +
'<span class="io-rte-sep"></span>' +
tb('data-cmd="justifyLeft"', "왼쪽 정렬", ic('<path d="M4 6h16M4 10h10M4 14h16M4 18h10"/>')) +
tb('data-cmd="justifyCenter"', "가운데 정렬", ic('<path d="M4 6h16M7 10h10M4 14h16M7 18h10"/>')) +
tb('data-cmd="justifyRight"', "오른쪽 정렬", ic('<path d="M4 6h16M10 10h10M4 14h16M10 18h10"/>')) +
'<span class="io-rte-sep"></span>' +
tb('data-cmd="insertOrderedList"', "번호 목록", ic('<path d="M10 6h10M10 12h10M10 18h10"/><path d="M4 5h1v4M4 15h2l-2 3h2" stroke-width="1.6"/>')) +
tb('data-cmd="insertUnorderedList"', "글머리 목록", ic('<path d="M10 6h10M10 12h10M10 18h10"/><circle cx="5" cy="6" r="1"/><circle cx="5" cy="12" r="1"/><circle cx="5" cy="18" r="1"/>')) +
'<span class="io-rte-sep"></span>' +
tb('data-pop="link"', "링크", ic('<path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/>')) +
tb('data-cmd="removeFormat"', "서식 지우기", ic('<path d="M6 5h12M12 5l-3 14M4 20l16-16" />')) +
'<span class="io-rte-sep"></span>' +
tb('data-cmd="undo"', "되돌리기 (Ctrl+Z)", ic('<path d="M9 14L4 9l5-5"/><path d="M4 9h11a5 5 0 0 1 0 10h-3"/>')) +
tb('data-cmd="redo"', "다시 하기 (Ctrl+Y)", ic('<path d="M15 14l5-5-5-5"/><path d="M20 9H9a5 5 0 0 0 0 10h3"/>')) +
'<button type="button" class="io-link-btn io-rte-reset" data-mail-reset hidden>원래 본문으로</button>' +
'<div class="io-rte-pop" hidden></div></div>' +
'<p class="io-rte-hint">본문을 눌러 바로 고칠 수 있습니다 — 글자를 고른 뒤 위 막대로 서식을 바꾸세요. 고친 내용 그대로 보냅니다.</p>';
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,8 +826,7 @@
(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>" : "") +
(cfg.editable ? '<div class="io-mail-edit-bar"><span>본문을 눌러 바로 고칠 수 있습니다 — 고친 내용 그대로 보냅니다.</span>' +
'<button type="button" class="io-link-btn" data-mail-reset hidden>원래 본문으로</button></div>' : "") +
(cfg.editable ? RTE_BAR : "") +
'<iframe class="io-mail-preview" title="메일 본문 미리보기"></iframe>';
edited = false;
setupPreview(body.querySelector(".io-mail-preview"), data.html);
@@ -803,21 +834,137 @@
}
// 발주 메일 본문 고치기(2026-10-27) — 미리보기 iframe 을 designMode 로. 스크립트는 막고(allow-scripts 없음) 부모만 문서에 손댈 수 있게
// allow-same-origin. 보낼 때 고쳤으면 body HTML 을 같이 보낸다(서버가 허용 태그·서식만 남김).
// 서식 막대(RTE_BAR) = execCommand — 표·인라인 서식을 그대로 두려고 Quill 대신(Quill 은 표를 못 담는다). 글자 서식은 span style 로.
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]");
const bar = body.querySelector(".io-rte"), reset = bar.querySelector("[data-mail-reset]");
const sizeSel = bar.querySelector("[data-rte-size]"), pop = bar.querySelector(".io-rte-pop");
let doc = null, saved = null;
function markEdited() { edited = true; reset.hidden = false; }
function saveRange() {
const sel = doc && doc.getSelection();
if (sel && sel.rangeCount) saved = sel.getRangeAt(0).cloneRange();
}
// 본문 문서는 포커스가 막대로 가도 자기 선택을 지닌다 — 그게 있으면 그대로, 없을 때만 기억한 선택
function restoreRange() {
const sel = doc.getSelection();
const keep = sel && sel.rangeCount ? sel.getRangeAt(0).cloneRange() : saved;
ifr.contentWindow.focus();
if (!keep) return;
sel.removeAllRanges();
sel.addRange(keep);
}
function exec(cmd, value) {
if (!doc) return;
restoreRange();
doc.execCommand("styleWithCSS", false, true);
doc.execCommand(cmd, false, value == null ? null : value);
saveRange();
markEdited();
refresh();
}
// 글자 크기 — execCommand 는 1~7 단계뿐이라 7 로 칠한 뒤 그 font 를 px 크기 span 으로 바꾼다
function setSize(px) {
if (!doc) return;
restoreRange();
doc.execCommand("styleWithCSS", false, false);
doc.execCommand("fontSize", false, "7");
const spans = [];
doc.querySelectorAll('font[size="7"]').forEach(function (f) {
const span = doc.createElement("span");
span.style.fontSize = px;
while (f.firstChild) span.appendChild(f.firstChild);
f.replaceWith(span);
span.querySelectorAll("span").forEach(function (s) { s.style.fontSize = ""; }); // 안쪽 예전 크기는 지운다
spans.push(span);
});
if (spans.length) { // font 를 바꿔 끼우면 선택이 풀린다 — 바꾼 글자를 다시 고른 채로
const r = doc.createRange();
r.setStartBefore(spans[0]);
r.setEndAfter(spans[spans.length - 1]);
doc.getSelection().removeAllRanges();
doc.getSelection().addRange(r);
}
saveRange();
markEdited();
refresh();
}
// 버튼 켜짐(굵게 등)·지금 글자 크기 표시
function refresh() {
if (!doc) return;
bar.querySelectorAll("[data-cmd]").forEach(function (b) {
let on = false;
try { on = doc.queryCommandState(b.dataset.cmd); } catch (_) { /* 상태 없는 명령 */ }
b.classList.toggle("is-active", !!on);
});
const sel = doc.getSelection();
let el = sel && sel.anchorNode;
if (el && el.nodeType === 1 && el.childNodes[sel.anchorOffset]) el = el.childNodes[sel.anchorOffset]; // 선택이 요소 경계에서 시작
if (el && el.nodeType === 3) el = el.parentNode;
const px = el && el.nodeType === 1 ? Math.round(parseFloat(doc.defaultView.getComputedStyle(el).fontSize)) + "px" : "";
sizeSel.value = [].some.call(sizeSel.options, function (o) { return o.value === px; }) ? px : "";
}
function closePop() { pop.hidden = true; pop.innerHTML = ""; }
function openPop(kind, anchor) {
if (!pop.hidden && pop.dataset.kind === kind) { closePop(); return; }
pop.dataset.kind = kind;
if (kind === "link") {
pop.innerHTML = '<input class="io-in" type="url" placeholder="https://… 또는 mailto:…" data-rte-url />' +
'<button type="button" class="erp-btn erp-btn-primary erp-btn-sm" data-rte-link-ok>넣기</button>' +
'<button type="button" class="erp-btn erp-btn-outline erp-btn-sm" data-rte-unlink>링크 빼기</button>';
} else {
const colors = kind === "foreColor" ? RTE_TEXT_COLORS : RTE_BG_COLORS;
pop.innerHTML = colors.map(function (c) {
return '<button type="button" class="io-rte-sw' + (c[0] === "transparent" ? " is-none" : "") + '" data-rte-color="' + c[0] +
'" style="background:' + c[0] + '" title="' + c[1] + '" aria-label="' + c[1] + '"></button>';
}).join("");
}
pop.style.left = anchor.offsetLeft + "px";
pop.style.top = anchor.offsetTop + anchor.offsetHeight + 4 + "px";
pop.hidden = false;
const url = pop.querySelector("[data-rte-url]");
if (url) url.focus();
}
ifr.addEventListener("load", function () {
const doc = ifr.contentDocument;
doc = ifr.contentDocument;
saved = null;
if (!doc) return;
doc.designMode = "on";
doc.body.style.outline = "none";
doc.addEventListener("input", function () { edited = true; reset.hidden = false; });
doc.addEventListener("input", markEdited);
doc.addEventListener("selectionchange", function () { saveRange(); refresh(); });
doc.addEventListener("mousedown", closePop);
});
// 막대를 누르는 순간의 본문 선택을 기억(크기 고르기·링크 칸으로 포커스가 옮겨 가도 그 글자에) — 색·링크 팝업 안은 이미 기억한 선택 그대로.
// 버튼은 기본 동작을 막아 본문 선택이 풀리지 않게
bar.addEventListener("mousedown", function (e) {
if (!e.target.closest(".io-rte-pop")) saveRange();
if (e.target.closest("button")) e.preventDefault();
});
bar.addEventListener("click", function (e) {
const b = e.target.closest("button");
if (!b) return;
if (b.dataset.cmd) { closePop(); exec(b.dataset.cmd); }
else if (b.dataset.pop) openPop(b.dataset.pop, b);
else if (b.dataset.rteColor) { exec(pop.dataset.kind, b.dataset.rteColor); closePop(); }
else if (b.hasAttribute("data-rte-link-ok")) {
const v = pop.querySelector("[data-rte-url]").value.trim();
if (!/^(https?:\/\/|mailto:)/i.test(v)) { pop.querySelector("[data-rte-url]").focus(); return; }
exec("createLink", v);
closePop();
} else if (b.hasAttribute("data-rte-unlink")) { exec("unlink"); closePop(); }
});
bar.addEventListener("keydown", function (e) {
if (e.key === "Enter" && e.target.matches("[data-rte-url]")) { e.preventDefault(); pop.querySelector("[data-rte-link-ok]").click(); }
if (e.key === "Escape" && !pop.hidden) { e.preventDefault(); e.stopPropagation(); closePop(); }
});
sizeSel.addEventListener("change", function () { if (sizeSel.value) setSize(sizeSel.value); else setSize("14px"); });
reset.onclick = async function () {
if (!(await confirmMsg("고친 내용을 버리고 원래 본문으로 되돌릴까요?"))) return;
edited = false;
reset.hidden = true;
closePop();
ifr.srcdoc = data.html;
};
ifr.srcdoc = html;
+13
View File
@@ -419,6 +419,19 @@ class OrderMailEditTests(OrderNoticeMailTests):
self.assertIn("MW-0320 | 5,500", factory.get_body(("plain",)).get_content()) # 글 버전도 고친 본문에서
self.assertIn("PO-261019-01", notice.get_body(("html",)).get_content()) # 알림은 서버가 만든 내용
def test_toolbar_formats_kept(self):
"""서식 막대(execCommand) 결과 — 크기·굵게·색·배경·밑줄(text-decoration-line → text-decoration)·링크·목록·정렬."""
h = s.clean_mail_html(
'<span style="font-size: 20px; text-decoration-line: underline;">이석준님</span>'
'<span style="font-weight: bold; color: rgb(217, 48, 37);">굵게</span>'
'<span style="background-color: rgb(255, 243, 191);">배경</span><a href="https://dbxcorp.co.kr">링크</a>'
'<a href="javascript:alert(1)">나쁜 링크</a><ol><li>하나</li></ol><div style="text-align: center;">가운데</div>')
for part in ('<span style="font-size:20px;text-decoration:underline">이석준님</span>',
'<span style="font-weight:bold;color:rgb(217, 48, 37)">굵게</span>',
'<span style="background-color:rgb(255, 243, 191)">배경</span>', '<a href="https://dbxcorp.co.kr">링크</a>',
"<a>나쁜 링크</a>", "<ol><li>하나</li></ol>", '<div style="text-align:center">가운데</div>'):
self.assertIn(part, h)
def test_empty_edited_body_rejected(self):
r = self._post({"html": "<p> <br></p>"})
self.assertEqual(r.status_code, 400)