Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QND7Co43B24zK2P937rdxt
98 lines
3.7 KiB
TypeScript
98 lines
3.7 KiB
TypeScript
/* =============================================================================
|
|
* M02_MasterTemplete_Labor_RefEdit.ts
|
|
* 일위대가 참조 줄 모달(51-14) — 서고 원본(50-3)을 그 자리에서 고침 · [저장] = 서고 저장 길(`saveTemplate`) ·
|
|
* 그 문서를 쓰는 모든 구조물에 따라감(머리 한 줄 알림) · 그 층을 못 고치면 읽기만.
|
|
* · 일위조합 [수정] = 사전조합 상세(서고 모드 표 · 안 줄 [옵션] · 수량 · 위로 · 아래로 · 삭제 · 추가)
|
|
* 닫으면(저장 · 취소 모두) `closed` — 부르는 쪽이 구조물 일위대가 표를 다시 셈.
|
|
* ========================================================================== */
|
|
|
|
import { createButton, el, showConfirmDialog, showToast } from "@ui/ui_template_elements";
|
|
import { openModal } from "@ui/ui_template_modal";
|
|
import { readTemplate, saveTemplate, type Layer } from "./M02_MasterTemplete_Api_Fetch";
|
|
import type { LaborRow } from "./M02_MasterTemplete_Labor_Api";
|
|
import type { LaborRef } from "./M02_MasterTemplete_Labor_Calc";
|
|
import { tc } from "./M02_MasterTemplete_Labor_Text";
|
|
|
|
export interface RefEditOptions {
|
|
ref: LaborRef;
|
|
/** 「SC-000001 돌붙임」 */
|
|
title: string;
|
|
readOnly: boolean;
|
|
closed: () => void;
|
|
}
|
|
|
|
const fail = (error: unknown, key: "Load_Failed" | "Lib_SaveFailed"): void =>
|
|
showToast(error instanceof Error ? error.message : tc(key), "error");
|
|
|
|
export async function openRefEdit(opt: RefEditOptions): Promise<void> {
|
|
const kind = "precombo";
|
|
const layer = opt.ref.층 as Layer;
|
|
let doc: { 담은로직?: LaborRow[] };
|
|
let 판: string;
|
|
try {
|
|
const got = await readTemplate(layer, kind, opt.ref.키, null, opt.ref.주인); // 134-3 — 참조 주인 그대로
|
|
doc = got.문서 as typeof doc;
|
|
판 = got.판 ?? "";
|
|
} catch (error) {
|
|
return fail(error, "Load_Failed");
|
|
}
|
|
const save = (body: unknown): Promise<unknown> =>
|
|
saveTemplate(layer, kind, opt.ref.키, null, 판, body, opt.ref.주인).then(() =>
|
|
showToast(tc("Saved"), "success"),
|
|
);
|
|
const notice = opt.readOnly ? `${tc("Ref_Shared")} · ${tc("Ref_ReadOnly")}` : tc("Ref_Shared");
|
|
|
|
// 사전조합 — 상세와 같은 부품(서로 부르므로 늦게 받음)
|
|
const { mountLaborDetail } = await import("./M02_MasterTemplete_Labor_Detail");
|
|
let dirty = false;
|
|
let handle: ReturnType<typeof mountLaborDetail> | null = null;
|
|
const finish = (): void => {
|
|
handle?.destroy();
|
|
opt.closed();
|
|
};
|
|
openModal({
|
|
title: opt.title,
|
|
closeLabel: tc("In_Close"),
|
|
dialogClass: "m02-modal m02-labref",
|
|
beforeClose: async () => {
|
|
if (dirty && !(await showConfirmDialog(tc("Ref_Discard")))) return false;
|
|
finish();
|
|
return true;
|
|
},
|
|
mount: (body, close, head) => {
|
|
const host = el("div", { attrs: { "data-labor-ref": opt.ref.키 } });
|
|
handle = mountLaborDetail(host, doc, {
|
|
layer,
|
|
column: opt.ref.키,
|
|
readOnly: opt.readOnly,
|
|
onChanged: (d) => (dirty = d && !opt.readOnly),
|
|
goArea: null,
|
|
mode: "precombo",
|
|
owner: opt.ref.주인,
|
|
});
|
|
const ok = createButton({
|
|
label: tc("Save"),
|
|
variant: "filled",
|
|
onClick: () =>
|
|
void save(handle?.getDoc()).then(
|
|
() => {
|
|
close();
|
|
finish();
|
|
},
|
|
(error) => fail(error, "Lib_SaveFailed"),
|
|
),
|
|
});
|
|
body.append(
|
|
el("p", {
|
|
className: "m02-labin__muted",
|
|
text: notice,
|
|
attrs: { "data-labor-notice": "" },
|
|
}),
|
|
host,
|
|
);
|
|
// [저장] = 머리 [닫기] 왼쪽 · 아래 단추 없음(머리 [닫기] = 취소 · 고친 것 있으면 물음 · 147-3)
|
|
if (!opt.readOnly) head.append(ok);
|
|
},
|
|
});
|
|
}
|