Files
sam-manage/resources/views/departments/index.blade.php
kent aa9623c5bb fix(mng): HTMX SPA 네비게이션 오류 수정
## 수정 내용

### HTMX 응답 형식 수정
- DepartmentController: view 직접 반환 (JSON 래핑 제거)
- MenuController: ->render() 제거하여 SVG 이스케이프 문제 해결

### 사이드바 개선
- hx-boost 적용하여 SPA 스타일 네비게이션 구현
- 메뉴 클릭 시 활성화 상태 즉시 반영
- 스크롤 위치 저장/복원 기능 추가

### 불필요한 코드 제거
- departments/index.blade.php: JSON.parse 코드 제거

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 22:23:03 +09:00

118 lines
4.5 KiB
PHP

@extends('layouts.app')
@section('title', '부서 관리')
@section('content')
<!-- 페이지 헤더 -->
<div class="flex flex-col sm:flex-row sm:justify-between sm:items-center gap-4 mb-6">
<h1 class="text-2xl font-bold text-gray-800">부서 관리</h1>
<a href="{{ route('departments.create') }}" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition text-center w-full sm:w-auto">
+ 부서
</a>
</div>
<!-- 필터 영역 -->
<x-filter-collapsible id="filterForm">
<form id="filterForm" class="flex flex-wrap gap-2 sm:gap-4">
<!-- 검색 -->
<div class="flex-1 min-w-0 w-full sm:w-auto">
<input type="text"
name="search"
placeholder="부서명, 코드, 설명으로 검색..."
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<!-- 활성 상태 필터 -->
<div class="w-full sm:w-40">
<select name="is_active" 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>
<option value="1">활성</option>
<option value="0">비활성</option>
</select>
</div>
<!-- 삭제 상태 필터 -->
<div class="w-full sm:w-40">
<select name="trashed" 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>
<option value="with">전체 (삭제 포함)</option>
<option value="only">삭제된 항목만</option>
</select>
</div>
<!-- 검색 버튼 -->
<button type="submit" class="bg-gray-600 hover:bg-gray-700 text-white px-6 py-2 rounded-lg transition w-full sm:w-auto">
검색
</button>
</form>
</x-filter-collapsible>
<!-- 테이블 영역 (HTMX로 로드) -->
<div id="department-table"
hx-get="/api/admin/departments"
hx-trigger="load, filterSubmit from:body"
hx-include="#filterForm"
hx-headers='{"X-CSRF-TOKEN": "{{ csrf_token() }}"}'
class="bg-white rounded-lg shadow-sm overflow-hidden">
<!-- 로딩 스피너 -->
<div class="flex justify-center items-center p-12">
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
</div>
</div>
@endsection
@push('scripts')
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
<script>
// 폼 제출 시 HTMX 이벤트 트리거
document.getElementById('filterForm').addEventListener('submit', function(e) {
e.preventDefault();
htmx.trigger('#department-table', 'filterSubmit');
});
// 삭제 확인
window.confirmDelete = function(id, name) {
showDeleteConfirm(name, () => {
htmx.ajax('DELETE', `/api/admin/departments/${id}`, {
target: '#department-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#department-table', 'filterSubmit');
});
});
};
// 복원 확인
window.confirmRestore = function(id, name) {
showConfirm(`"${name}" 부서를 복원하시겠습니까?`, () => {
htmx.ajax('POST', `/api/admin/departments/${id}/restore`, {
target: '#department-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#department-table', 'filterSubmit');
});
}, { title: '복원 확인', icon: 'question' });
};
// 영구 삭제 확인
window.confirmForceDelete = function(id, name) {
showPermanentDeleteConfirm(name, () => {
htmx.ajax('DELETE', `/api/admin/departments/${id}/force`, {
target: '#department-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#department-table', 'filterSubmit');
});
});
};
</script>
@endpush