Files
sam-manage/resources/views/departments/create.blade.php
hskwon 6738505106 feat: Phase 4-3 부서 관리 시스템 구현
- DepartmentService, DepartmentController (Blade/API) 생성
- 부서 CRUD 기능 완성 (목록/생성/수정/삭제)
- FormRequest 검증 (StoreDepartmentRequest, UpdateDepartmentRequest)
- HTMX 패턴 적용 (index, create, edit, partials/table)
- 계층 구조 지원 (parent-child relationships)
- 활성/비활성 상태 관리
- 정렬 순서 관리
- Tenant Selector 통합
- Sidebar 메뉴에 부서 관리 추가

주요 기능:
- 자기 참조 방지 (parent_id validation)
- 하위 부서 존재 시 삭제 방지
- Conditional tenant filtering 적용
- Active/Inactive 필터링
- HTMX 페이지네이션 (target, includeForm 파라미터 포함)

정책:
- 모든 리스트 화면은 1페이지만 있어도 페이지네이션 표시
2025-11-24 16:52:23 +09:00

134 lines
6.4 KiB
PHP

@extends('layouts.app')
@section('title', '부서 생성')
@section('content')
<div class="container mx-auto max-w-4xl">
<!-- 페이지 헤더 -->
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold text-gray-800">🏢 부서 생성</h1>
<a href="{{ route('departments.index') }}" class="text-gray-600 hover:text-gray-800">
목록으로
</a>
</div>
<!-- 영역 -->
<div class="bg-white rounded-lg shadow-sm p-6">
<form id="departmentForm"
hx-post="/api/admin/departments"
hx-headers='{"X-CSRF-TOKEN": "{{ csrf_token() }}"}'
hx-swap="none">
<!-- 기본 정보 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">기본 정보</h2>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">
부서 코드 <span class="text-red-500">*</span>
</label>
<input type="text" name="code" required maxlength="50"
placeholder="예: DEV, SALES"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<p class="text-xs text-gray-500 mt-1">최대 50자까지 입력 가능합니다.</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">
부서명 <span class="text-red-500">*</span>
</label>
<input type="text" name="name" required maxlength="100"
placeholder="예: 개발팀, 영업팀"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<p class="text-xs text-gray-500 mt-1">최대 100자까지 입력 가능합니다.</p>
</div>
</div>
</div>
<!-- 부서 설정 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">부서 설정</h2>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">상위 부서</label>
<select name="parent_id" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="">없음 (최상위 부서)</option>
@foreach($departments as $dept)
<option value="{{ $dept->id }}">{{ $dept->name }} ({{ $dept->code }})</option>
@endforeach
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">정렬 순서</label>
<input type="number" name="sort_order" value="0" min="0"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<p class="text-xs text-gray-500 mt-1">숫자가 작을수록 먼저 표시됩니다.</p>
</div>
</div>
</div>
<!-- 설명 상태 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">추가 정보</h2>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">설명</label>
<textarea name="description" rows="3" maxlength="500"
placeholder="부서에 대한 설명을 입력하세요"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"></textarea>
<p class="text-xs text-gray-500 mt-1">최대 500자까지 입력 가능합니다.</p>
</div>
<div class="flex items-center">
<input type="checkbox" name="is_active" value="1" checked
class="h-4 w-4 text-blue-600 rounded focus:ring-2 focus:ring-blue-500">
<label class="ml-2 text-sm text-gray-700">활성 상태</label>
</div>
</div>
</div>
<!-- 버튼 영역 -->
<div class="flex justify-end gap-3">
<a href="{{ route('departments.index') }}"
class="px-6 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition">
취소
</a>
<button type="submit"
class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition">
생성
</button>
</div>
</form>
</div>
</div>
@endsection
@push('scripts')
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
<script>
// HTMX 응답 처리
document.body.addEventListener('htmx:afterRequest', function(event) {
if (event.detail.target.id === 'departmentForm') {
const response = JSON.parse(event.detail.xhr.response);
if (response.success) {
alert(response.message);
window.location.href = response.redirect;
} else {
alert('오류: ' + (response.message || '부서 생성에 실패했습니다.'));
}
}
});
// 에러 처리
document.body.addEventListener('htmx:responseError', function(event) {
if (event.detail.xhr.status === 422) {
const errors = JSON.parse(event.detail.xhr.response).errors;
let errorMsg = '입력 오류:\n';
for (let field in errors) {
errorMsg += '- ' + errors[field].join('\n') + '\n';
}
alert(errorMsg);
} else {
alert('서버 오류가 발생했습니다.');
}
});
</script>
@endpush