Files
sam-manage/resources/views/menus/index.blade.php
hskwon 604aa256f6 refactor: 메뉴 트리 스크립트 공통화 및 디자인 통일
- public/js/menu-tree.js 공통 스크립트 생성
  - 테이블(tr.menu-row) / div(.menu-item) 둘 다 지원
  - toggleChildren, hideChildren, showChildren 함수 통합

- 권한 관리 페이지들 메뉴 트리 디자인 통일
  - role-permissions, department-permissions, user-permissions
  - 폴더/파일 아이콘, 접기/펼치기 버튼, chevron 아이콘
  - menu-row 클래스 및 data 속성 추가

- permission-analyze 접기/펼치기 기능 추가
  - data-parent-id, data-depth 속성 추가
  - 폴더 버튼 클릭으로 하위 메뉴 토글

- menus 페이지 스크립트 공통화

- 각 페이지 중복 코드 제거 및 공통 menu-tree.js 로드
2025-11-27 10:25:02 +09:00

148 lines
5.1 KiB
PHP

@extends('layouts.app')
@section('title', '메뉴 관리')
@section('content')
<!-- 페이지 헤더 -->
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold text-gray-800">메뉴 관리</h1>
<a href="{{ route('menus.create') }}" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition">
+ 메뉴
</a>
</div>
<!-- 필터 영역 -->
<div class="bg-white rounded-lg shadow-sm p-4 mb-6">
<form id="filterForm" class="flex gap-4">
<!-- 검색 -->
<div class="flex-1">
<input type="text"
name="search"
placeholder="메뉴명, URL로 검색..."
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-48">
<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>
<!-- 검색 버튼 -->
<button type="submit" class="bg-gray-600 hover:bg-gray-700 text-white px-6 py-2 rounded-lg transition">
검색
</button>
</form>
</div>
<!-- 테이블 영역 (HTMX로 로드) -->
<div id="menu-table"
hx-get="/api/admin/menus"
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('#menu-table', 'filterSubmit');
});
// HTMX 응답 처리
document.body.addEventListener('htmx:afterSwap', function(event) {
if (event.detail.target.id === 'menu-table') {
const response = JSON.parse(event.detail.xhr.response);
if (response.html) {
event.detail.target.innerHTML = response.html;
}
}
});
// 삭제 확인
window.confirmDelete = function(id, name) {
if (confirm(`"${name}" 메뉴를 삭제하시겠습니까?`)) {
htmx.ajax('DELETE', `/api/admin/menus/${id}`, {
target: '#menu-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#menu-table', 'filterSubmit');
});
}
};
// 복원 확인
window.confirmRestore = function(id, name) {
if (confirm(`"${name}" 메뉴를 복원하시겠습니까?`)) {
htmx.ajax('POST', `/api/admin/menus/${id}/restore`, {
target: '#menu-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#menu-table', 'filterSubmit');
});
}
};
// 영구삭제 확인
window.confirmForceDelete = function(id, name) {
if (confirm(`⚠️ 경고: "${name}" 메뉴를 영구 삭제하시겠습니까?\n\n이 작업은 되돌릴 수 없습니다!`)) {
htmx.ajax('DELETE', `/api/admin/menus/${id}/force`, {
target: '#menu-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#menu-table', 'filterSubmit');
});
}
};
// 활성 토글
window.toggleActive = function(id) {
htmx.ajax('POST', `/api/admin/menus/${id}/toggle-active`, {
target: '#menu-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#menu-table', 'filterSubmit');
});
};
// 숨김 토글
window.toggleHidden = function(id) {
htmx.ajax('POST', `/api/admin/menus/${id}/toggle-hidden`, {
target: '#menu-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#menu-table', 'filterSubmit');
});
};
</script>
<script src="{{ asset('js/menu-tree.js') }}"></script>
@endpush