feat(vacation): 휴가 신청 날짜 칸 — 프로젝트와 같은 아사나식 날짜 팝업
- 공용 erp-datepop.js/css(project.js openDatePopover·enhanceDateInput·.pj-datepop CSS 를 떼어 낸 같은 모양·동작) - 시작일·종료일 = 숨긴 input + 날짜 버튼 둘(enhanceRange), 어느 쪽을 눌러도 같은 기간 팝업(누른 칸 먼저, 시작 → 종료 → 닫힘), 반차는 하루짜리, 직접 입력(Enter), Esc·바깥 클릭 닫힘 - 공휴일 = 휴가 설정 공휴일(빨강, 작년~내년) — 팝업 빨강·이름, 예상 일수에서도 제외(서버 compute_days 와 같게) - 테스트: vacation_datepop.browser.test.js(render_vacation.py), 휴가 신청 화면 공휴일·스크립트 렌더 확인 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
- 용어는 **"업무"**(2026-10-13 "작업"에서 다시 통일 — 화면·메시지·알림 제목, 코드·DB 는 그대로)·"세부 업무"·"메인 업무 추가". ERP 메뉴 이름은 "Project"(`app/main.py` 모듈 목록 title).
|
||||
- 화면 기능을 바꾸면 도움말(`/project/help`)도 같이 고친다.
|
||||
- UI 버그는 로컬 헤드리스 크롬/엣지로 렌더·좌표 덤프해 재현 후 고칠 것.
|
||||
- 날짜 팝업(`openDatePopover`·`enhanceDateInput`·`.pj-datepop` CSS)은 다른 모듈용 공용 복사본이 있다 — `app/static/erp-datepop.js`·`.css`
|
||||
(2026-10-27, 휴가 신청 날짜 칸). 모양·동작을 바꾸면 그쪽도 같이 고칠 것(나중에 프로젝트도 공용 파일로 옮기면 하나가 됨).
|
||||
|
||||
## 권한 — 관리자 등급 4단계 (2026-10-12, 6-14)
|
||||
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
|
||||
- 월간 달력(구글식 bar) / 연차·반차 신청 / 승인 워크플로 / 공휴일·연차 설정.
|
||||
- 권한키 `vacation`(사용)·`vacation_approver`(승인).
|
||||
- **신청 화면 날짜 칸 = 프로젝트와 같은 아사나식 날짜 팝업**(2026-10-27, 공용 `app/static/erp-datepop.js`·`.css` — project.js `openDatePopover`·
|
||||
`enhanceDateInput` 을 떼어 낸 것). 시작일·종료일 input 은 숨긴 값 저장소, 옆 날짜 버튼 둘(`ErpDatePop.enhanceRange`) — 어느 쪽을 눌러도 같은
|
||||
기간 팝업(누른 칸이 먼저, 시작일 고르면 종료일 칸으로, 종료일 고르면 닫힘, 지우기 없음), 반차는 하루짜리 팝업(시작=종료). 직접 입력(10/27·1027 Enter).
|
||||
공휴일 = 휴가 설정 공휴일 중 빨강(`router._red_holidays`, 작년~내년, `#vac-holidays`) — 팝업 빨강·이름 + 예상 일수에서도 뺀다(서버 compute_days 와 같은 표).
|
||||
테스트 `tests/js/vacation_datepop.browser.test.js`(`render_vacation.py`).
|
||||
|
||||
## 휴가 옵션 · 휴가 메일 (2026-10-27, 마이그레이션 `vacation_db_001_options_mail.sql`)
|
||||
|
||||
|
||||
@@ -343,9 +343,27 @@ def _form_context(request: Request, user: dict[str, Any]) -> dict[str, Any]:
|
||||
"vacation_types": list(VACATION_TYPES),
|
||||
"halves": list(HALVES),
|
||||
"half_labels": HALF_LABELS,
|
||||
"holidays": _red_holidays(request),
|
||||
}
|
||||
|
||||
|
||||
def _red_holidays(request: Request) -> dict[str, str]:
|
||||
"""날짜 팝업 공휴일(빨강·이름) — 휴가 설정의 공휴일(is_red) 작년~내년. 일수 계산과 같은 표."""
|
||||
st = _store(request)
|
||||
if st is None:
|
||||
return {}
|
||||
year = today_kst().year
|
||||
out: dict[str, str] = {}
|
||||
try:
|
||||
for y in (year - 1, year, year + 1):
|
||||
for h in st.list_holidays(year=y):
|
||||
if h.get("is_red", True):
|
||||
out[h["holiday_date"]] = h.get("name") or ""
|
||||
except Exception: # noqa: BLE001 — 공휴일 표시가 신청 화면을 막지 않게
|
||||
return {}
|
||||
return out
|
||||
|
||||
|
||||
@router.get("/new", response_class=HTMLResponse)
|
||||
def new_form(request: Request) -> HTMLResponse:
|
||||
from app.main import render_template # noqa: WPS433
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
{% extends "erp_base.html" %}
|
||||
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/vacation.css?v=20261027a" />{% endblock %}
|
||||
{% block head_extra %}<link rel="stylesheet" href="/static/vacation.css?v=20261027a" />
|
||||
{#- 날짜 칸 = 프로젝트와 같은 아사나식 날짜 팝업(2026-10-27, erp-datepop) -#}
|
||||
<link rel="stylesheet" href="/static/vendor/material-symbols/material-symbols.css" />
|
||||
<link rel="stylesheet" href="/static/erp-datepop.css?v=20261027a" />{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="vac">
|
||||
@@ -51,7 +54,7 @@
|
||||
|
||||
<div class="vac-days-preview">
|
||||
예상 사용 일수: <strong id="vac-days-out">—</strong>
|
||||
<span class="erp-muted">(주말 제외 · 공휴일은 저장 시 반영)</span>
|
||||
<span class="erp-muted">(주말 · 공휴일 제외)</span>
|
||||
</div>
|
||||
|
||||
<div class="erp-page-actions vac-form-actions">
|
||||
@@ -68,4 +71,6 @@
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}<script src="/static/vacation.js?v=20260530i" defer></script>{% endblock %}
|
||||
{% block scripts %}<script type="application/json" id="vac-holidays">{{ holidays | tojson }}</script>
|
||||
<script src="/static/erp-datepop.js?v=20261027a" defer></script>
|
||||
<script src="/static/vacation.js?v=20261027a" defer></script>{% endblock %}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/* 아사나식 날짜 팝업 · 날짜 버튼 — 공용(2026-10-27, erp-datepop.js).
|
||||
프로젝트 모듈 project.css 의 .pj-date-btn · .pj-datepop · .pj-dp-* 규칙을 그대로 옮긴 것(같은 모양) — 프로젝트 화면은 아직
|
||||
project.css 쪽을 쓴다(둘을 한 화면에 같이 싣지 않음). 모양을 바꾸면 두 곳 모두 고칠 것.
|
||||
아이콘은 Material Symbols(/static/vendor/material-symbols/material-symbols.css)를 화면에서 함께 싣는다. */
|
||||
.pj-date-btn {
|
||||
display: inline-flex; align-items: center; gap: 6px; margin-top: 5px; height: 36px; padding: 0 12px;
|
||||
border: 1px solid #d8dce2; border-radius: 8px; background: #fff; cursor: pointer;
|
||||
font-size: var(--pj-text-size, 14px); font-family: inherit; font-weight: 500; color: var(--pj-ink, #050505); white-space: nowrap; line-height: var(--pj-text-leading, 1.4);
|
||||
}
|
||||
.pj-date-btn .material-symbols-outlined { font-size: 19px; color: #6d6e6f; }
|
||||
.pj-date-btn:hover { background: #f6f7f8; border-color: #c4c9d0; }
|
||||
.pj-date-btn.is-empty { color: #9aa1a9; }
|
||||
.pj-date-btn.is-overdue { color: #c22b10; }
|
||||
/* 날짜가 없을 때 — 테두리 없이 점선 원 달력 아이콘만(아사나) */
|
||||
.pj-date-btn.is-icon-only {
|
||||
width: 32px; height: 32px; padding: 0; justify-content: center; border: none; border-radius: 50%;
|
||||
background: transparent; color: #6d6e6f;
|
||||
}
|
||||
.pj-date-btn.is-icon-only:hover { background: #eceef0; color: #1e1f21; }
|
||||
|
||||
/* ── 아사나식 날짜 팝업(openDatePopover) — 시작일/마감일 칸 + 월 달력 + 지우기.
|
||||
앵커 아래(자리 없으면 위)에 뜨고 꼬리가 앵커를 가리킨다(--pj-dp-tail). ── */
|
||||
.pj-datepop {
|
||||
position: fixed; z-index: 2300; width: 300px; box-sizing: border-box;
|
||||
background: #fff; border: 1px solid #e3e5e8; border-radius: 12px;
|
||||
box-shadow: 0 8px 28px rgba(15,23,42,.16), 0 1px 3px rgba(15,23,42,.08);
|
||||
padding: 14px 14px 8px; font-size: 13px; color: var(--pj-ink, #050505);
|
||||
animation: pj-dp-in .12s ease-out;
|
||||
}
|
||||
@keyframes pj-dp-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
|
||||
.pj-datepop::before, .pj-datepop::after {
|
||||
content: ""; position: absolute; left: var(--pj-dp-tail, 50%); transform: translateX(-50%);
|
||||
border: 8px solid transparent;
|
||||
}
|
||||
/* 아래에 뜸 → 위쪽 꼬리 */
|
||||
.pj-datepop::before { bottom: 100%; border-bottom-color: #e3e5e8; }
|
||||
.pj-datepop::after { bottom: calc(100% - 1px); border-bottom-color: #fff; }
|
||||
/* 위에 뜸 → 아래쪽 꼬리 */
|
||||
.pj-datepop.is-above::before { bottom: auto; top: 100%; border-bottom-color: transparent; border-top-color: #e3e5e8; }
|
||||
.pj-datepop.is-above::after { bottom: auto; top: calc(100% - 1px); border-bottom-color: transparent; border-top-color: #fff; }
|
||||
|
||||
.pj-dp-fields { display: flex; gap: 8px; margin-bottom: 10px; }
|
||||
.pj-dp-field, .pj-dp-addstart {
|
||||
flex: 1 1 0; min-width: 0; height: 36px; box-sizing: border-box;
|
||||
border: 1px solid #d8dce2; border-radius: 8px; padding: 0 10px;
|
||||
font: inherit; font-size: 13.5px; color: var(--pj-ink, #050505); background: #fff;
|
||||
}
|
||||
.pj-dp-field:focus, .pj-dp-field.is-active { outline: none; border: 2px solid #4573d2; padding: 0 9px; }
|
||||
.pj-dp-field::placeholder { color: #9aa1a9; }
|
||||
.pj-dp-addstart {
|
||||
border-color: transparent; background: transparent; cursor: pointer; font-weight: 600; color: #525860; text-align: left;
|
||||
}
|
||||
.pj-dp-addstart:hover { background: #f1f2f4; }
|
||||
|
||||
.pj-dp-nav { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 6px; }
|
||||
.pj-dp-title { font-size: 14px; font-weight: 500; color: var(--pj-ink, #050505); }
|
||||
.pj-dp-navbtn {
|
||||
width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
|
||||
border: 0; background: transparent; border-radius: 6px; color: #525860; cursor: pointer;
|
||||
}
|
||||
.pj-dp-navbtn:hover { background: #f1f2f4; color: var(--pj-ink, #050505); }
|
||||
.pj-dp-navbtn .material-symbols-outlined { font-size: 22px; }
|
||||
|
||||
.pj-dp-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); row-gap: 2px; }
|
||||
.pj-dp-wd { text-align: center; font-size: 12px; font-weight: 600; color: #6d6e6f; padding: 4px 0 6px; }
|
||||
.pj-dp-day {
|
||||
position: relative; height: 34px; border: 0; padding: 0; background: transparent; cursor: pointer;
|
||||
font: inherit; font-size: 13.5px; color: var(--pj-ink, #050505);
|
||||
display: flex; flex-direction: column; align-items: center; justify-content: flex-start; min-width: 0;
|
||||
}
|
||||
/* 원(오늘·선택·마우스)은 숫자 자리(위 34px)의 가운데 — 공휴일 이름 줄이 붙어도 그대로 */
|
||||
.pj-dp-day::before {
|
||||
content: ""; position: absolute; width: 30px; height: 30px; border-radius: 50%; z-index: 0;
|
||||
left: 50%; top: 17px; transform: translate(-50%, -50%);
|
||||
}
|
||||
.pj-dp-num { height: 34px; display: flex; align-items: center; justify-content: center; flex: none; }
|
||||
/* 공휴일 이름 — 숫자 밑 작은 글씨. 이 칸이 있는 주만 줄이 높아진다(다른 칸은 34px 그대로 위에 붙음). */
|
||||
.pj-dp-day.has-hol { height: 46px; }
|
||||
.pj-dp-hol {
|
||||
max-width: 100%; margin-top: -3px; padding: 0 1px; box-sizing: border-box;
|
||||
font-size: 9px; line-height: 1.1; letter-spacing: -.5px; font-weight: 500;
|
||||
white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #d93025;
|
||||
}
|
||||
.pj-dp-day.is-out .pj-dp-hol { color: #efaaa3; }
|
||||
.pj-dp-day { z-index: 0; }
|
||||
.pj-dp-day > * { position: relative; }
|
||||
.pj-dp-day:hover::before { background: #f1f2f4; }
|
||||
.pj-dp-day.is-out { color: #b3b8bf; }
|
||||
/* 일요일·공휴일(국경일·대체공휴일) 빨강, 토요일 파랑 — 다른 달 날짜는 옅게 */
|
||||
.pj-dp-day.is-sun, .pj-dp-wd.is-sun { color: #d93025; }
|
||||
.pj-dp-day.is-sat, .pj-dp-wd.is-sat { color: #1a73e8; }
|
||||
.pj-dp-day.is-out.is-sun { color: #efaaa3; }
|
||||
.pj-dp-day.is-out.is-sat { color: #a8c6f3; }
|
||||
/* 오늘 = 파란 테두리 원 + 굵게 */
|
||||
.pj-dp-day.is-today { font-weight: 800; }
|
||||
.pj-dp-day.is-today::before { border: 1.5px solid #4573d2; }
|
||||
/* 선택 = 파란 원 + 흰 글자 (숫자가 원 위에 보이도록 글자는 z 위로) */
|
||||
.pj-dp-day.is-selected, .pj-dp-day.is-selected.is-sun, .pj-dp-day.is-selected.is-sat { color: #fff; font-weight: 600; }
|
||||
.pj-dp-day.is-selected::before { background: #4573d2; border: 0; }
|
||||
.pj-dp-day.is-inrange { background: #e8effb; }
|
||||
.pj-dp-day.is-selected .pj-dp-hol { color: #d93025; font-weight: 600; }
|
||||
.pj-dp-day { isolation: isolate; }
|
||||
.pj-dp-day::before { z-index: -1; }
|
||||
|
||||
.pj-dp-foot {
|
||||
display: flex; justify-content: space-between; align-items: center;
|
||||
margin-top: 8px; padding-top: 8px; border-top: 1px solid #eef0f2;
|
||||
}
|
||||
.pj-dp-link {
|
||||
border: 0; background: transparent; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600;
|
||||
color: #525860; padding: 6px 8px; border-radius: 6px;
|
||||
}
|
||||
.pj-dp-link:hover { background: #f1f2f4; color: var(--pj-ink, #050505); }
|
||||
@@ -0,0 +1,294 @@
|
||||
/* 아사나식 날짜 팝업 · 날짜 버튼 — 공용(2026-10-27).
|
||||
프로젝트 모듈 project.js 의 openDatePopover · enhanceDateInput 과 같은 모양·같은 동작을 다른 모듈에서 쓰려고 떼어 낸 것
|
||||
(프로젝트 화면은 아직 project.js 안의 것을 쓴다 — 동작을 바꾸면 두 곳 모두 고칠 것). 스타일 = erp-datepop.css.
|
||||
· 브라우저 기본 달력(input[type=date])은 숨기고 그 옆에 날짜 버튼을 둔다 — input 은 값 저장소(.value 읽기/쓰기·change 이벤트 그대로).
|
||||
· 팝업: 위 칸(시작일·종료일 — 직접 입력 2026-10-27 / 10.27 / 10월 27일 / 1027, Enter), 월 달력(일·공휴일 빨강, 토 파랑,
|
||||
공휴일 이름은 숫자 밑, 오늘 테두리, 기간 옅은 파랑), 오늘 · 지우기. 바깥 클릭·Esc 로 닫힘, 앵커 아래(자리 없으면 위).
|
||||
window.ErpDatePop = { open(anchor, opts), close(), enhanceRange(startInput, endInput, opts), fmt(iso) } */
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function esc(s) {
|
||||
return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
|
||||
return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c];
|
||||
});
|
||||
}
|
||||
function isoOf(d) {
|
||||
return d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
|
||||
}
|
||||
// 오늘 = 한국시간 날짜(브라우저 시간대와 무관 — 프로젝트 isoToday 와 같음)
|
||||
function isoToday() { return new Date(Date.now() + 9 * 3600000).toISOString().slice(0, 10); }
|
||||
// 'YYYY-MM-DD' → 'mm/dd(요일)' — 오늘·내일·어제는 글자로(프로젝트 날짜 버튼과 같음), 다른 해면 앞에 연도
|
||||
function fmt(iso) {
|
||||
if (!iso) return "";
|
||||
const d = new Date(String(iso).slice(0, 10) + "T00:00:00");
|
||||
if (isNaN(d.getTime())) return iso;
|
||||
const today = isoToday();
|
||||
const diff = Math.round((d - new Date(today + "T00:00:00")) / 86400000);
|
||||
if (diff === 0) return "오늘";
|
||||
if (diff === 1) return "내일";
|
||||
if (diff === -1) return "어제";
|
||||
const wd = ["일", "월", "화", "수", "목", "금", "토"][d.getDay()];
|
||||
const md = String(d.getMonth() + 1).padStart(2, "0") + "/" + String(d.getDate()).padStart(2, "0") + "(" + wd + ")";
|
||||
return (String(d.getFullYear()) === today.slice(0, 4) ? "" : d.getFullYear() + "/") + md;
|
||||
}
|
||||
function fmtField(iso) {
|
||||
if (!iso) return "";
|
||||
const d = new Date(iso + "T00:00:00");
|
||||
const same = d.getFullYear() === new Date().getFullYear();
|
||||
return (same ? "" : d.getFullYear() + "년 ") + (d.getMonth() + 1) + "월 " + d.getDate() + "일";
|
||||
}
|
||||
// 직접 입력 해석 — 2026-09-30 / 2026.9.30 / 9/30 / 9월 30일 / 0930. 빈 값 = "", 해석 불가 = null.
|
||||
function parseTyped(text, baseIso) {
|
||||
const v = String(text || "").trim().replace(/\s+/g, "");
|
||||
if (!v) return "";
|
||||
let m = v.match(/^(\d{4})[-./년](\d{1,2})[-./월](\d{1,2})[.일]?$/);
|
||||
let y, mo, d;
|
||||
if (m) { y = +m[1]; mo = +m[2]; d = +m[3]; }
|
||||
else if ((m = v.match(/^(\d{1,2})[-./월](\d{1,2})[.일]?$/))) { y = +baseIso.slice(0, 4); mo = +m[1]; d = +m[2]; }
|
||||
else if ((m = v.match(/^(\d{2})(\d{2})$/))) { y = +baseIso.slice(0, 4); mo = +m[1]; d = +m[2]; }
|
||||
else return null;
|
||||
const dt = new Date(y, mo - 1, d);
|
||||
if (dt.getFullYear() !== y || dt.getMonth() !== mo - 1 || dt.getDate() !== d) return null;
|
||||
return isoOf(dt);
|
||||
}
|
||||
const HOLIDAY_SHORT = { "부처님오신날": "석가탄신일", "추석·개천절": "추석" };
|
||||
|
||||
let popEl = null, cleanup = null;
|
||||
function close() {
|
||||
if (cleanup) cleanup();
|
||||
cleanup = null;
|
||||
if (popEl) { popEl.remove(); popEl = null; }
|
||||
}
|
||||
|
||||
// opts: { start, due, allowStart, active("start"|"due"), labels {start, due}, holidays {iso: 이름}, clear(bool, 기본 true),
|
||||
// onChange(patch {due_date, start_date?}) } — 날짜를 누를 때마다 onChange, 마감(종료)일을 고르면 닫힘.
|
||||
function open(anchor, opts) {
|
||||
close();
|
||||
opts = opts || {};
|
||||
const labels = Object.assign({ start: "시작일", due: "마감일" }, opts.labels || {});
|
||||
const holidays = opts.holidays || {};
|
||||
const today = isoToday();
|
||||
let start = opts.start ? String(opts.start).slice(0, 10) : "";
|
||||
let due = opts.due ? String(opts.due).slice(0, 10) : "";
|
||||
let showStart = !!(opts.allowStart && (start || opts.active === "start"));
|
||||
let active = opts.allowStart && opts.active === "start" ? "start" : "due";
|
||||
const base = new Date(((active === "start" ? start : due) || start || due || today) + "T00:00:00");
|
||||
let viewY = base.getFullYear(), viewM = base.getMonth();
|
||||
|
||||
const pop = document.createElement("div");
|
||||
pop.className = "pj-datepop";
|
||||
document.body.appendChild(pop);
|
||||
popEl = pop;
|
||||
|
||||
function emit() {
|
||||
const patch = { due_date: due || null };
|
||||
if (opts.allowStart) patch.start_date = start || null;
|
||||
if (opts.onChange) opts.onChange(patch);
|
||||
}
|
||||
function field(kind, val) {
|
||||
return '<input type="text" class="pj-dp-field' + (active === kind ? " is-active" : "") +
|
||||
'" data-kind="' + kind + '" placeholder="' + esc(labels[kind]) + '" value="' + esc(fmtField(val)) + '" autocomplete="off" />';
|
||||
}
|
||||
function render() {
|
||||
const first = new Date(viewY, viewM, 1);
|
||||
const gridStart = new Date(viewY, viewM, 1 - first.getDay());
|
||||
let days = "";
|
||||
for (let i = 0; i < 42; i++) {
|
||||
const d = new Date(gridStart.getFullYear(), gridStart.getMonth(), gridStart.getDate() + i);
|
||||
const iso = isoOf(d);
|
||||
const cls = ["pj-dp-day"];
|
||||
if (d.getMonth() !== viewM) cls.push("is-out");
|
||||
const holName = holidays[iso] || "";
|
||||
if (d.getDay() === 0 || holName) cls.push("is-sun");
|
||||
else if (d.getDay() === 6) cls.push("is-sat");
|
||||
if (iso === today) cls.push("is-today");
|
||||
if (iso === due || (showStart && iso === start)) cls.push("is-selected");
|
||||
if (showStart && start && due && iso > start && iso < due) cls.push("is-inrange");
|
||||
if (holName) cls.push("has-hol");
|
||||
const holShort = /\s대체$/.test(holName) ? "대체휴일" : (HOLIDAY_SHORT[holName] || holName);
|
||||
days += '<button type="button" class="' + cls.join(" ") + '" data-iso="' + iso + '"' +
|
||||
(holName ? ' title="' + esc(holName) + '"' : "") + ">" +
|
||||
'<span class="pj-dp-num">' + d.getDate() + "</span>" +
|
||||
(holName ? '<span class="pj-dp-hol">' + esc(holShort) + "</span>" : "") + "</button>";
|
||||
}
|
||||
pop.innerHTML =
|
||||
'<div class="pj-dp-fields">' +
|
||||
(opts.allowStart ? (showStart ? field("start", start) : '<button type="button" class="pj-dp-addstart">+ ' + esc(labels.start) + "</button>") : "") +
|
||||
field("due", due) +
|
||||
"</div>" +
|
||||
'<div class="pj-dp-nav">' +
|
||||
'<button type="button" class="pj-dp-navbtn" data-nav="-1" title="이전 달"><span class="material-symbols-outlined">chevron_left</span></button>' +
|
||||
'<span class="pj-dp-title">' + viewY + "년 " + (viewM + 1) + "월</span>" +
|
||||
'<button type="button" class="pj-dp-navbtn" data-nav="1" title="다음 달"><span class="material-symbols-outlined">chevron_right</span></button>' +
|
||||
"</div>" +
|
||||
'<div class="pj-dp-grid">' +
|
||||
["일", "월", "화", "수", "목", "금", "토"].map(function (w, i) {
|
||||
return '<span class="pj-dp-wd' + (i === 0 ? " is-sun" : i === 6 ? " is-sat" : "") + '">' + w + "</span>";
|
||||
}).join("") + days +
|
||||
"</div>" +
|
||||
'<div class="pj-dp-foot">' +
|
||||
'<button type="button" class="pj-dp-link pj-dp-today">오늘</button>' +
|
||||
(opts.clear === false ? "" : '<button type="button" class="pj-dp-link pj-dp-clear">지우기</button>') +
|
||||
"</div>";
|
||||
wire();
|
||||
}
|
||||
// 시작일 칸이 활성이면 시작일(그 뒤 마감일로), 아니면 마감일(저장하고 닫음). 시작일 > 마감일이 되지 않게 맞춘다.
|
||||
function pick(iso) {
|
||||
if (active === "start") {
|
||||
start = iso;
|
||||
if (due && due < iso) due = iso;
|
||||
active = "due";
|
||||
render(); emit(); focusActive();
|
||||
return;
|
||||
}
|
||||
due = iso;
|
||||
if (start && start > iso) start = iso;
|
||||
emit();
|
||||
close();
|
||||
}
|
||||
function wire() {
|
||||
pop.querySelectorAll(".pj-dp-day").forEach(function (b) {
|
||||
b.addEventListener("click", function () { pick(b.dataset.iso); });
|
||||
});
|
||||
pop.querySelectorAll(".pj-dp-navbtn").forEach(function (b) {
|
||||
b.addEventListener("click", function () {
|
||||
viewM += +b.dataset.nav;
|
||||
if (viewM < 0) { viewM = 11; viewY--; } else if (viewM > 11) { viewM = 0; viewY++; }
|
||||
render();
|
||||
});
|
||||
});
|
||||
const add = pop.querySelector(".pj-dp-addstart");
|
||||
if (add) add.addEventListener("click", function () { showStart = true; active = "start"; render(); focusActive(); });
|
||||
pop.querySelectorAll(".pj-dp-field").forEach(function (inp) {
|
||||
inp.addEventListener("focus", function () {
|
||||
active = inp.dataset.kind;
|
||||
pop.querySelectorAll(".pj-dp-field").forEach(function (x) { x.classList.toggle("is-active", x === inp); });
|
||||
});
|
||||
function commit() {
|
||||
const kind = inp.dataset.kind;
|
||||
const cur = kind === "start" ? start : due;
|
||||
const parsed = parseTyped(inp.value, today);
|
||||
if (parsed === null || parsed === cur) { inp.value = fmtField(cur); return; }
|
||||
if (!parsed) {
|
||||
if (opts.clear === false) { inp.value = fmtField(cur); return; }
|
||||
if (kind === "start") { start = ""; showStart = false; } else due = "";
|
||||
render(); emit(); return;
|
||||
}
|
||||
active = kind;
|
||||
const d = new Date(parsed + "T00:00:00");
|
||||
viewY = d.getFullYear(); viewM = d.getMonth();
|
||||
pick(parsed);
|
||||
}
|
||||
inp.addEventListener("keydown", function (e) {
|
||||
if (e.isComposing) return;
|
||||
if (e.key === "Enter") { e.preventDefault(); commit(); }
|
||||
});
|
||||
inp.addEventListener("change", commit);
|
||||
});
|
||||
pop.querySelector(".pj-dp-today").addEventListener("click", function () {
|
||||
const d = new Date(); viewY = d.getFullYear(); viewM = d.getMonth();
|
||||
pick(today);
|
||||
});
|
||||
const clr = pop.querySelector(".pj-dp-clear");
|
||||
if (clr) clr.addEventListener("click", function () { start = ""; due = ""; emit(); close(); });
|
||||
}
|
||||
function focusActive() {
|
||||
const f = pop.querySelector('.pj-dp-field[data-kind="' + active + '"]');
|
||||
if (f) f.focus();
|
||||
}
|
||||
function place() {
|
||||
const r = anchor.getBoundingClientRect();
|
||||
const vw = document.documentElement.clientWidth, vh = document.documentElement.clientHeight;
|
||||
const w = pop.offsetWidth, h = pop.offsetHeight;
|
||||
const ax = r.left + r.width / 2;
|
||||
const left = Math.min(Math.max(8, ax - w / 2), vw - w - 8);
|
||||
const below = r.bottom + 10 + h <= vh - 8 || r.top - 10 - h < 8;
|
||||
pop.classList.toggle("is-above", !below);
|
||||
pop.style.left = left + "px";
|
||||
pop.style.top = (below ? r.bottom + 10 : r.top - 10 - h) + "px";
|
||||
pop.style.setProperty("--pj-dp-tail", Math.min(Math.max(ax - left, 16), w - 16) + "px");
|
||||
}
|
||||
function onDown(e) {
|
||||
if (pop.contains(e.target) || anchor.contains(e.target)) return;
|
||||
close();
|
||||
}
|
||||
function onKey(e) { if (e.key === "Escape") { e.stopPropagation(); close(); } }
|
||||
render();
|
||||
place();
|
||||
setTimeout(function () {
|
||||
if (popEl !== pop) return; // 그 사이 닫혔으면 걸지 않는다(남은 Esc 처리가 이후 Esc 를 삼키지 않게)
|
||||
document.addEventListener("mousedown", onDown, true);
|
||||
document.addEventListener("keydown", onKey, true);
|
||||
}, 0);
|
||||
window.addEventListener("resize", close);
|
||||
cleanup = function () {
|
||||
document.removeEventListener("mousedown", onDown, true);
|
||||
document.removeEventListener("keydown", onKey, true);
|
||||
window.removeEventListener("resize", close);
|
||||
};
|
||||
focusActive();
|
||||
}
|
||||
|
||||
// 시작·끝 날짜 input 두 개 → 날짜 버튼 두 개(각 input 자리), 어느 쪽을 눌러도 같은 기간 팝업(누른 쪽 칸이 먼저).
|
||||
// endInput 이 숨겨져 있으면(opts.single() 이 true — 예: 반차) 하루짜리 팝업으로 시작=끝을 같이 맞춘다.
|
||||
// input 은 숨겨 값 저장소로 둔다 — value 쓰기를 가로채 버튼 글자도 따라 바뀌고, 고르면 input·change 이벤트를 낸다.
|
||||
function enhanceRange(startInput, endInput, opts) {
|
||||
opts = opts || {};
|
||||
const labels = Object.assign({ start: "시작일", due: "종료일" }, opts.labels || {});
|
||||
const desc = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value");
|
||||
const pairs = [[startInput, "start"], [endInput, "due"]].filter(function (p) { return p[0] && !p[0].dataset.erpDate; });
|
||||
const btns = {};
|
||||
pairs.forEach(function (p) {
|
||||
const inp = p[0], kind = p[1];
|
||||
inp.dataset.erpDate = "1";
|
||||
inp.style.display = "none";
|
||||
const btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.className = "pj-date-btn erp-date-btn";
|
||||
btn.dataset.kind = kind;
|
||||
inp.after(btn);
|
||||
btns[kind] = btn;
|
||||
Object.defineProperty(inp, "value", {
|
||||
configurable: true,
|
||||
get: function () { return desc.get.call(this); },
|
||||
set: function (v) { desc.set.call(this, v); sync(); },
|
||||
});
|
||||
btn.addEventListener("click", function (e) {
|
||||
e.preventDefault(); e.stopPropagation();
|
||||
const single = !!(opts.single && opts.single());
|
||||
open(btn, {
|
||||
start: single ? "" : startInput.value, due: single ? startInput.value : endInput.value,
|
||||
allowStart: !single, active: single ? "due" : kind, clear: false, holidays: opts.holidays || {},
|
||||
labels: single ? { due: opts.singleLabel || "날짜" } : labels,
|
||||
onChange: function (patch) {
|
||||
if (single) { set(startInput, patch.due_date); set(endInput, patch.due_date); return; }
|
||||
set(startInput, patch.start_date);
|
||||
set(endInput, patch.due_date);
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
function set(inp, v) {
|
||||
if (!v || (inp.value || "") === v) return; // 필수 칸 — 비우지 않는다
|
||||
inp.value = v;
|
||||
inp.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
inp.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
}
|
||||
function sync() {
|
||||
[["start", startInput], ["due", endInput]].forEach(function (p) {
|
||||
const btn = btns[p[0]];
|
||||
if (!btn) return;
|
||||
const text = fmt(p[1].value);
|
||||
btn.innerHTML = '<span class="material-symbols-outlined">calendar_month</span><span class="pj-date-btn-text"></span>';
|
||||
btn.querySelector(".pj-date-btn-text").textContent = text || labels[p[0]] + " 선택";
|
||||
btn.classList.toggle("is-empty", !text);
|
||||
btn.title = text ? labels[p[0]] + " 변경" : labels[p[0]] + " 지정";
|
||||
});
|
||||
}
|
||||
sync();
|
||||
return { sync: sync, buttons: btns };
|
||||
}
|
||||
|
||||
window.ErpDatePop = { open: open, close: close, enhanceRange: enhanceRange, fmt: fmt, parse: parseTyped };
|
||||
})();
|
||||
+23
-7
@@ -1,5 +1,7 @@
|
||||
/* 휴가 신청 폼 — 종류에 따른 필드 토글 + 예상 일수 미리보기.
|
||||
서버(store.compute_days)가 공휴일 포함 정확히 재계산한다. 여기선 주말만 제외한 근사치. */
|
||||
서버(store.compute_days)가 공휴일 포함 정확히 재계산한다. 여기선 주말만 제외한 근사치.
|
||||
시작일·종료일 = 프로젝트와 같은 아사나식 날짜 팝업(2026-10-27, erp-datepop.js — 숨긴 input 옆 날짜 버튼, 둘 중 어느 쪽을 눌러도
|
||||
같은 기간 팝업, 반차는 하루짜리 팝업). 공휴일 = 휴가 설정의 공휴일(#vac-holidays). */
|
||||
(function () {
|
||||
"use strict";
|
||||
var form = document.getElementById("vac-form");
|
||||
@@ -17,6 +19,20 @@
|
||||
|
||||
function isHalfType(t) { return t === "오전반차" || t === "오후반차"; }
|
||||
|
||||
// 휴가 설정의 공휴일(빨강) {날짜: 이름} — 날짜 팝업 표시 + 예상 일수에서 제외(서버 compute_days 와 같은 표)
|
||||
var holidays = {};
|
||||
try { holidays = JSON.parse((document.getElementById("vac-holidays") || {}).textContent || "{}"); } catch (_) { holidays = {}; }
|
||||
function isoOf(d) {
|
||||
return d.getFullYear() + "-" + String(d.getMonth() + 1).padStart(2, "0") + "-" + String(d.getDate()).padStart(2, "0");
|
||||
}
|
||||
|
||||
if (window.ErpDatePop) {
|
||||
window.ErpDatePop.enhanceRange(start, end, {
|
||||
labels: { start: "시작일", due: "종료일" }, holidays: holidays, singleLabel: "날짜",
|
||||
single: function () { return isHalfType(type.value); },
|
||||
});
|
||||
}
|
||||
|
||||
function parseDate(s) {
|
||||
if (!s) return null;
|
||||
var p = s.split("-");
|
||||
@@ -28,16 +44,15 @@
|
||||
var n = 0;
|
||||
var d = new Date(sd.getTime());
|
||||
while (d <= ed) {
|
||||
var wd = d.getDay(); // 0=일, 6=토
|
||||
if (wd !== 0 && wd !== 6) n++;
|
||||
if (isWorking(d)) n++;
|
||||
d.setDate(d.getDate() + 1);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
function isWorking(d) {
|
||||
var wd = d.getDay();
|
||||
return wd !== 0 && wd !== 6;
|
||||
var wd = d.getDay(); // 0=일, 6=토
|
||||
return wd !== 0 && wd !== 6 && !holidays[isoOf(d)];
|
||||
}
|
||||
|
||||
function recalc() {
|
||||
@@ -50,7 +65,8 @@
|
||||
startHalfField.style.display = half ? "none" : "";
|
||||
|
||||
if (half) {
|
||||
out.textContent = "0.5";
|
||||
var hd = parseDate(start.value);
|
||||
out.textContent = hd && !isWorking(hd) ? "0" : "0.5";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,7 +75,7 @@
|
||||
if (!sd || !ed || ed < sd) { out.textContent = "—"; return; }
|
||||
|
||||
if (sd.getTime() === ed.getTime()) {
|
||||
out.textContent = (startHalf.value === "am" || startHalf.value === "pm") ? "0.5" : "1";
|
||||
out.textContent = !isWorking(sd) ? "0" : (startHalf.value === "am" || startHalf.value === "pm") ? "0.5" : "1";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user