30b0366818
- 옵션 창의 프로젝트 화면·보드 분류를 수퍼관리자에게만 렌더(관리자 분류와 같은 조건). - 수퍼관리자가 아니면 project.js 가 브라우저에 남은 pj_default_view·pj_board_cover 를 무시하고 기본값(보드·표지 켬)으로 동작. 일반 사용자 저장은 pj_font 만 씀. - 테스트: 수퍼관리자 렌더(project_super_render.html) 추가, 일반 사용자 경우 테스트. 도움말·문서 갱신. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
5.5 KiB
JavaScript
101 lines
5.5 KiB
JavaScript
(function () {
|
|
"use strict";
|
|
const button = document.getElementById("pj-options-btn"), dialog = document.getElementById("pj-options-dialog");
|
|
if (!button || !dialog || button.dataset.bound) return;
|
|
button.dataset.bound = "1";
|
|
const names = { system: null, pretendard: "Pretendard Variable", "nanum-square": "NanumSquare",
|
|
"nanum-square-neo": "NanumSquareNeo", "nanum-square-round": "NanumSquareRound" };
|
|
const VIEWS = ["board", "list", "calendar", "timeline", "dashboard"];
|
|
const DEFAULTS = { font: "system", default_view: "board", board_cover: true };
|
|
const form = document.getElementById("pj-options-form");
|
|
const select = document.getElementById("pj-options-font"), preview = document.getElementById("pj-options-preview");
|
|
const cover = document.getElementById("pj-options-cover");
|
|
const error = document.getElementById("pj-options-error"), save = document.getElementById("pj-options-save");
|
|
const cancel = document.getElementById("pj-options-cancel"), closeX = document.getElementById("pj-options-x");
|
|
const reset = document.getElementById("pj-options-reset");
|
|
const tabs = Array.from(dialog.querySelectorAll(".pj-options-nav [role=tab]"));
|
|
const panes = Array.from(dialog.querySelectorAll(".pj-options-pane"));
|
|
// 처음 여는 탭·표지는 수퍼관리자 창에만 있다(_options.html) — 없으면 폰트만 다룬다.
|
|
const views = form.elements.default_view || null;
|
|
const controls = [select, cover, cancel, closeX, reset].concat(Array.from(views || [])).filter(Boolean);
|
|
|
|
function ls(key) { try { return localStorage.getItem(key); } catch (_) { return null; } }
|
|
function current() {
|
|
const f = document.documentElement.dataset.pjFont, v = ls("pj_default_view");
|
|
return {
|
|
font: Object.hasOwn(names, f) ? f : DEFAULTS.font,
|
|
default_view: VIEWS.indexOf(v) >= 0 ? v : DEFAULTS.default_view,
|
|
board_cover: ls("pj_board_cover") !== "0",
|
|
};
|
|
}
|
|
function fill(o) {
|
|
select.value = o.font;
|
|
if (views) views.value = o.default_view;
|
|
if (cover) cover.checked = o.board_cover;
|
|
paint();
|
|
}
|
|
function paint() {
|
|
const font = names[select.value];
|
|
preview.style.fontFamily = font ? '"' + font + '", sans-serif' : "var(--pj-system-font)";
|
|
}
|
|
function showPane(name, focus) {
|
|
tabs.forEach(function (t) {
|
|
const on = t.dataset.pane === name;
|
|
t.classList.toggle("is-active", on);
|
|
t.setAttribute("aria-selected", on ? "true" : "false");
|
|
t.tabIndex = on ? 0 : -1;
|
|
if (on && focus) t.focus();
|
|
});
|
|
panes.forEach(function (p) { p.hidden = p.dataset.pane !== name; });
|
|
}
|
|
function busy(on) { save.disabled = on; controls.forEach(function (c) { c.disabled = on; }); }
|
|
function close() { if (!save.disabled) dialog.close(); }
|
|
|
|
button.addEventListener("click", function () {
|
|
fill(current()); error.hidden = true; showPane(tabs[0].dataset.pane); dialog.showModal(); tabs[0].focus();
|
|
});
|
|
dialog.querySelector(".pj-options-nav").addEventListener("click", function (e) {
|
|
const t = e.target.closest("[role=tab]");
|
|
if (t) showPane(t.dataset.pane);
|
|
});
|
|
// 분류 목록 — 위/아래 화살표로 이동(데스크톱 프로그램 설정 창처럼)
|
|
dialog.querySelector(".pj-options-nav").addEventListener("keydown", function (e) {
|
|
const i = tabs.indexOf(document.activeElement);
|
|
if (i < 0 || (e.key !== "ArrowDown" && e.key !== "ArrowUp")) return;
|
|
e.preventDefault();
|
|
showPane(tabs[(i + (e.key === "ArrowDown" ? 1 : tabs.length - 1)) % tabs.length].dataset.pane, true);
|
|
});
|
|
select.addEventListener("change", paint);
|
|
reset.addEventListener("click", function () { fill(DEFAULTS); error.hidden = true; });
|
|
cancel.addEventListener("click", close);
|
|
closeX.addEventListener("click", close);
|
|
dialog.addEventListener("cancel", function (e) { if (save.disabled) e.preventDefault(); });
|
|
dialog.addEventListener("close", function () { button.focus(); });
|
|
form.addEventListener("submit", async function (e) {
|
|
e.preventDefault(); if (save.disabled) return;
|
|
const before = current();
|
|
const next = { font: select.value };
|
|
if (views) next.default_view = views.value;
|
|
if (cover) next.board_cover = cover.checked;
|
|
if (!Object.hasOwn(names, next.font) || (views && VIEWS.indexOf(next.default_view) < 0)) return;
|
|
const font = names[next.font];
|
|
busy(true); error.hidden = true;
|
|
try {
|
|
if (font && document.fonts) {
|
|
const loaded = await Promise.all([document.fonts.load('400 14px "' + font + '"', "가나다 Project"), document.fonts.load('700 14px "' + font + '"', "가나다 Project")]);
|
|
if (loaded.some(function (list) { return !list.length; })) throw new Error("폰트를 불러오지 못했습니다. 다시 시도해 주세요.");
|
|
}
|
|
localStorage.setItem("pj_font", next.font);
|
|
if (views) localStorage.setItem("pj_default_view", next.default_view);
|
|
if (cover) localStorage.setItem("pj_board_cover", next.board_cover ? "1" : "0");
|
|
document.documentElement.dataset.pjFont = next.font;
|
|
const changed = Object.keys(next).filter(function (k) { return next[k] !== before[k]; });
|
|
// project.js 가 듣는다 — 보드 표지가 바뀌면 지금 보드를 다시 그린다(첫 탭은 다음에 프로젝트를 열 때부터).
|
|
if (changed.length) window.dispatchEvent(new CustomEvent("pj-options-change", { detail: { options: next, changed: changed } }));
|
|
window.dispatchEvent(new Event("resize"));
|
|
dialog.close();
|
|
} catch (err) { error.textContent = "설정을 저장하지 못했습니다. " + err.message; error.hidden = false; }
|
|
finally { busy(false); }
|
|
});
|
|
})();
|