diff --git a/app/modules/inout/CLAUDE.md b/app/modules/inout/CLAUDE.md index 50edc56..1344ab7 100644 --- a/app/modules/inout/CLAUDE.md +++ b/app/modules/inout/CLAUDE.md @@ -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 필요). diff --git a/app/modules/inout/store.py b/app/modules/inout/store.py index 0f3b7f0..14989da 100644 --- a/app/modules/inout/store.py +++ b/app/modules/inout/store.py @@ -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) diff --git a/app/modules/inout/templates/inout/index.html b/app/modules/inout/templates/inout/index.html index f99a64d..002f538 100644 --- a/app/modules/inout/templates/inout/index.html +++ b/app/modules/inout/templates/inout/index.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} {% from "inout/_macros.html" import order_badge, progress, due, n, ymd %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %}
{# 2열 — 왼쪽 화면 | 오른쪽 달력(2026-10-21) #} @@ -71,4 +71,4 @@ {% include "inout/_calendar.html" %}
{% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/inout/templates/inout/order_detail.html b/app/modules/inout/templates/inout/order_detail.html index 464a1fa..9f3ad06 100644 --- a/app/modules/inout/templates/inout/order_detail.html +++ b/app/modules/inout/templates/inout/order_detail.html @@ -20,7 +20,7 @@ {%- endmacro -%} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %} {% set active = order.status in ('open', 'partial') %} @@ -258,4 +258,4 @@ {% include "inout/_calendar.html" %} {% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/inout/templates/inout/order_form.html b/app/modules/inout/templates/inout/order_form.html index 9848629..7439499 100644 --- a/app/modules/inout/templates/inout/order_form.html +++ b/app/modules/inout/templates/inout/order_form.html @@ -1,5 +1,5 @@ {% extends "erp_base.html" %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %}
{# 2열 — 왼쪽 화면 | 오른쪽 달력(2026-10-21) #} @@ -95,4 +95,4 @@ {% include "inout/_calendar.html" %}
{% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/modules/inout/templates/inout/pending.html b/app/modules/inout/templates/inout/pending.html index 8713854..e3d7eeb 100644 --- a/app/modules/inout/templates/inout/pending.html +++ b/app/modules/inout/templates/inout/pending.html @@ -1,6 +1,6 @@ {% extends "erp_base.html" %} {% from "inout/_macros.html" import due, n, ymd %} -{% block head_extra %}{% endblock %} +{% block head_extra %}{% endblock %} {% block content %}
{# 2열 — 왼쪽 화면 | 오른쪽 달력(2026-10-21) #} @@ -91,4 +91,4 @@ {% include "inout/_calendar.html" %}
{% endblock %} -{% block scripts %}{% endblock %} +{% block scripts %}{% endblock %} diff --git a/app/static/inout.css b/app/static/inout.css index c7240a8..c2d6318 100644 --- a/app/static/inout.css +++ b/app/static/inout.css @@ -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; } diff --git a/app/static/inout.js b/app/static/inout.js index 8d3aaa8..975d7ea 100644 --- a/app/static/inout.js +++ b/app/static/inout.js @@ -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 '"; }; + const tb = function (attr, title, inner) { return '"; }; + const RTE_BAR = '' + + '

본문을 눌러 바로 고칠 수 있습니다 — 글자를 고른 뒤 위 막대로 서식을 바꾸세요. 고친 내용 그대로 보냅니다.

'; 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 ? '

' + esc(notice) + "

" : "") + (receipt && data.photos_skipped ? '

HEIC 등 본문에 넣지 못하는 입고증 사진 ' + esc(data.photos_skipped) + "장은 빠집니다(입고 기록에는 그대로).

" : "") + (sentList ? '
보낸 기록
" : "") + - (cfg.editable ? '
본문을 눌러 바로 고칠 수 있습니다 — 고친 내용 그대로 보냅니다.' + - '
' : "") + + (cfg.editable ? RTE_BAR : "") + ''; 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 = '' + + '' + + ''; + } else { + const colors = kind === "foreColor" ? RTE_TEXT_COLORS : RTE_BG_COLORS; + pop.innerHTML = colors.map(function (c) { + return ''; + }).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; diff --git a/tests/test_inout_receipt_mail.py b/tests/test_inout_receipt_mail.py index 985214b..f69a6de 100644 --- a/tests/test_inout_receipt_mail.py +++ b/tests/test_inout_receipt_mail.py @@ -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( + '이석준님' + '굵게' + '배경링크' + '나쁜 링크
  1. 하나
가운데
') + for part in ('이석준님', + '굵게', + '배경', '링크', + "나쁜 링크", "
  1. 하나
", '
가운데
'): + self.assertIn(part, h) + def test_empty_edited_body_rejected(self): r = self._post({"html": "


"}) self.assertEqual(r.status_code, 400)