/* -*- coding: utf-8 -*- */ /** * 그림 코드 화면 (scr_img.js) — TwM_Boxa 그림 넣기(SpeedButton2Click) · 보기(ds_CostIDataChange) · 그림저장 * 근거: img_code.py 머리 — 그림 = COSTN I 코드 행 IFORM · 꼴 = SIZE(TJPEGIMAGE · TBITMAP · TICON · TMETAFILE) * 서버: api_img.py — 넣기는 work_dbf/<이름>/ 에 COSTN.DBF · COSTN.SMT 만 바꿔 씀 → 다시 불러옴 */ (function (global) { "use strict"; const P = (global.STMATE_PLUGINS = global.STMATE_PLUGINS || { screens: {}, actions: {}, menus: [], }); const esc = (s) => String(s == null ? "" : s).replace( /[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c], ); async function post(url, body, raw) { const res = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); if (!res.ok) throw new Error(await res.text()); return raw ? res : res.json(); } function pickImage() { return new Promise((resolve, reject) => { const inp = document.createElement("input"); inp.type = "file"; inp.accept = ".bmp,.jpg,.jpeg,.ico,.emf,.wmf"; inp.onchange = () => { const f = inp.files && inp.files[0]; if (!f) return reject(new Error("파일을 고르지 않음")); const rd = new FileReader(); rd.onload = () => resolve({ b64: String(rd.result), name: f.name }); rd.onerror = () => reject(rd.error); rd.readAsDataURL(f); }; inp.click(); }); } function load(ctx, app) { const u = ctx.uiState; if (u.imgRows || u.imgLoading || !ctx.currentSourcePath) return; u.imgLoading = true; post("/api/img/list", { source_path: ctx.currentSourcePath }) .then((r) => ((u.imgRows = r.rows), (u.imgLoading = false), app.renderWorkspace())) .catch((e) => ((u.imgRows = []), (u.imgLoading = false), (u.imgErr = e.message))); } async function show(ctx, app, code) { const u = ctx.uiState; if (u.imgUrl) URL.revokeObjectURL(u.imgUrl); u.imgUrl = ""; u.imgSel = code; u.imgKind = ""; try { const res = await post("/api/img/get", { source_path: ctx.currentSourcePath, code }, true); u.imgKind = res.headers.get("X-Img-Kind") || ""; u.imgUrl = URL.createObjectURL(await res.blob()); } catch (e) { u.imgKind = "그림 없음"; } app.renderWorkspace(); } function render(ctx, app) { load(ctx, app); const u = ctx.uiState; const rows = u.imgRows || []; const meta = u.imgKind === "TMETAFILE"; const view = !u.imgSel ? "
| 코드 | 명칭 | 꼴(SIZE) | 크기 |
|---|---|---|---|
| ${esc(r.CODE)} | ${esc(r.NAME)} | ${esc(r.SIZE)} | ${r.bytes ? r.bytes.toLocaleString() : ""} |