feat(tkuser): 부서 관리 개선 — 상위부서 제거, hard delete, 휴가 부서별 그룹

- 상위부서(parent_id) 필드 UI/API 전체 제거
- 부서 비활성화(soft delete) → 진짜 삭제(hard delete) 전환 (트랜잭션)
- 소속 인원 있는 부서 삭제 시 department_id=NULL 처리
- 편집 모달에서 활성/비활성 필드 제거
- 휴가 발생 입력 작업자 select를 부서별 optgroup으로 표시

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-03-13 20:27:14 +09:00
parent 7e10a90a1a
commit e236883c64
5 changed files with 47 additions and 73 deletions

View File

@@ -465,12 +465,6 @@
<label class="block text-xs font-medium text-gray-600 mb-1">부서명 <span class="text-red-400">*</span></label>
<input type="text" id="newDeptName" class="input-field w-full px-3 py-1.5 rounded-lg text-sm" placeholder="부서 이름" required>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">상위부서</label>
<select id="newDeptParent" class="input-field w-full px-3 py-1.5 rounded-lg text-sm">
<option value="">없음 (최상위)</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">설명</label>
<input type="text" id="newDeptDescription" class="input-field w-full px-3 py-1.5 rounded-lg text-sm" placeholder="부서 설명">
@@ -1087,28 +1081,13 @@
<label class="block text-xs font-medium text-gray-600 mb-1">부서명</label>
<input type="text" id="editDeptName" class="input-field w-full px-3 py-1.5 rounded-lg text-sm" required>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">상위부서</label>
<select id="editDeptParent" class="input-field w-full px-3 py-1.5 rounded-lg text-sm">
<option value="">없음 (최상위)</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">설명</label>
<input type="text" id="editDeptDescription" class="input-field w-full px-3 py-1.5 rounded-lg text-sm">
</div>
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">표시순서</label>
<input type="number" id="editDeptOrder" class="input-field w-full px-3 py-1.5 rounded-lg text-sm" min="0">
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">활성</label>
<select id="editDeptActive" class="input-field w-full px-3 py-1.5 rounded-lg text-sm">
<option value="1">활성</option>
<option value="0">비활성</option>
</select>
</div>
<div>
<label class="block text-xs font-medium text-gray-600 mb-1">표시순서</label>
<input type="number" id="editDeptOrder" class="input-field w-full px-3 py-1.5 rounded-lg text-sm" min="0">
</div>
<div class="flex gap-3 pt-3">
<button type="button" onclick="closeDepartmentModal()" class="flex-1 px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-50 text-sm">취소</button>

View File

@@ -5,25 +5,12 @@ async function loadDepartments() {
try {
const r = await api('/departments'); departments = r.data || r;
departmentsLoaded = true;
populateParentDeptSelects();
displayDepartments();
} catch (err) {
document.getElementById('departmentList').innerHTML = `<div class="text-red-500 text-center py-6"><i class="fas fa-exclamation-triangle text-xl"></i><p class="text-sm mt-2">${err.message}</p></div>`;
}
}
function populateParentDeptSelects() {
['newDeptParent','editDeptParent'].forEach(id => {
const sel = document.getElementById(id); if (!sel) return;
const val = sel.value;
sel.innerHTML = '<option value="">없음 (최상위)</option>';
departments.filter(d => d.is_active !== 0 && d.is_active !== false).forEach(d => {
const o = document.createElement('option'); o.value = d.department_id; o.textContent = d.department_name; sel.appendChild(o);
});
sel.value = val;
});
}
let selectedDeptForMembers = null;
function displayDepartments() {
@@ -34,14 +21,12 @@ function displayDepartments() {
<div class="flex-1 min-w-0">
<div class="text-sm font-medium text-gray-800 truncate"><i class="fas fa-sitemap mr-1.5 text-gray-400 text-xs"></i>${d.department_name}</div>
<div class="text-xs text-gray-500 flex items-center gap-1.5 mt-0.5 flex-wrap">
${d.parent_name ? `<span class="px-1.5 py-0.5 rounded bg-slate-50 text-slate-500">상위: ${d.parent_name}</span>` : '<span class="px-1.5 py-0.5 rounded bg-indigo-50 text-indigo-500">최상위</span>'}
<span class="text-gray-400">순서: ${d.display_order || 0}</span>
${d.is_active === 0 || d.is_active === false ? '<span class="px-1.5 py-0.5 rounded bg-gray-100 text-gray-400">비활성</span>' : '<span class="px-1.5 py-0.5 rounded bg-emerald-50 text-emerald-600">활성</span>'}
</div>
</div>
<div class="flex gap-1 ml-2 flex-shrink-0" onclick="event.stopPropagation()">
<button onclick="editDepartment(${d.department_id})" class="p-1.5 text-slate-500 hover:text-slate-700 hover:bg-slate-200 rounded" title="편집"><i class="fas fa-pen-to-square text-xs"></i></button>
${d.is_active !== 0 && d.is_active !== false ? `<button onclick="deactivateDepartment(${d.department_id},'${(d.department_name||'').replace(/'/g,"\\'")}')" class="p-1.5 text-red-400 hover:text-red-600 hover:bg-red-100 rounded" title="비활성화"><i class="fas fa-ban text-xs"></i></button>` : ''}
<button onclick="deleteDepartment(${d.department_id},'${(d.department_name||'').replace(/'/g,"\\'")}')" class="p-1.5 text-red-400 hover:text-red-600 hover:bg-red-100 rounded" title="삭제"><i class="fas fa-trash text-xs"></i></button>
</div>
</div>`).join('');
}
@@ -96,7 +81,6 @@ document.getElementById('addDepartmentForm').addEventListener('submit', async e
try {
await api('/departments', { method: 'POST', body: JSON.stringify({
department_name: document.getElementById('newDeptName').value.trim(),
parent_id: document.getElementById('newDeptParent').value ? parseInt(document.getElementById('newDeptParent').value) : null,
description: document.getElementById('newDeptDescription').value.trim() || null,
display_order: parseInt(document.getElementById('newDeptOrder').value) || 0
})});
@@ -110,9 +94,6 @@ function editDepartment(id) {
document.getElementById('editDeptName').value = d.department_name;
document.getElementById('editDeptDescription').value = d.description || '';
document.getElementById('editDeptOrder').value = d.display_order || 0;
document.getElementById('editDeptActive').value = (d.is_active === 0 || d.is_active === false) ? '0' : '1';
populateParentDeptSelects();
document.getElementById('editDeptParent').value = d.parent_id || '';
document.getElementById('editDepartmentModal').classList.remove('hidden');
}
function closeDepartmentModal() { document.getElementById('editDepartmentModal').classList.add('hidden'); }
@@ -122,17 +103,15 @@ document.getElementById('editDepartmentForm').addEventListener('submit', async e
try {
await api(`/departments/${document.getElementById('editDeptId').value}`, { method: 'PUT', body: JSON.stringify({
department_name: document.getElementById('editDeptName').value.trim(),
parent_id: document.getElementById('editDeptParent').value ? parseInt(document.getElementById('editDeptParent').value) : null,
description: document.getElementById('editDeptDescription').value.trim() || null,
display_order: parseInt(document.getElementById('editDeptOrder').value) || 0,
is_active: document.getElementById('editDeptActive').value === '1'
display_order: parseInt(document.getElementById('editDeptOrder').value) || 0
})});
showToast('수정되었습니다.'); closeDepartmentModal(); await loadDepartments();
await loadDepartmentsForSelect();
} catch(e) { showToast(e.message, 'error'); }
});
async function deactivateDepartment(id, name) {
if (!confirm(`"${name}" 부서를 비활성화?`)) return;
try { await api(`/departments/${id}`, { method: 'DELETE' }); showToast('부서 비활성화 완료'); await loadDepartments(); } catch(e) { showToast(e.message, 'error'); }
async function deleteDepartment(id, name) {
if (!confirm(`"${name}" 부서를 삭제하시겠습니까? 소속 인원은 부서 미지정으로 변경됩니다.`)) return;
try { await api(`/departments/${id}`, { method: 'DELETE' }); showToast('부서가 삭제되었습니다'); await loadDepartments(); } catch(e) { showToast(e.message, 'error'); }
}