Files
sam-manage/resources/views/menus/global-index.blade.php
hskwon 5c892c1ed9 브라우저 alert/confirm을 SweetAlert2로 전환
- layouts/app.blade.php에 SweetAlert2 CDN 및 전역 헬퍼 함수 추가
  - showToast(): 토스트 알림 (success, error, warning, info)
  - showConfirm(): 확인 대화상자
  - showDeleteConfirm(): 삭제 확인 (경고 아이콘)
  - showPermanentDeleteConfirm(): 영구 삭제 확인 (빨간색 경고)
  - showSuccess(), showError(): 성공/에러 알림

- 변환된 파일 목록 (48개 Blade 파일):
  - menus/* (6개), boards/* (2개), posts/* (3개)
  - daily-logs/* (3개), project-management/* (6개)
  - dev-tools/flow-tester/* (6개)
  - quote-formulas/* (4개), permission-analyze/* (1개)
  - archived-records/* (1개), profile/* (1개)
  - roles/* (3개), permissions/* (3개)
  - departments/* (3개), tenants/* (3개), users/* (3개)

- 주요 개선사항:
  - Tailwind CSS 테마와 일관된 디자인
  - 비동기 콜백 패턴으로 리팩토링
  - 삭제/복원/영구삭제 각각 다른 스타일 적용
2025-12-05 09:49:56 +09:00

252 lines
8.6 KiB
PHP

@extends('layouts.app')
@section('title', '기본 메뉴 관리')
@section('content')
<!-- 페이지 헤더 -->
<div class="flex justify-between items-center mb-6">
<div>
<h1 class="text-2xl font-bold text-gray-800">기본 메뉴 관리</h1>
<p class="text-sm text-gray-500 mt-1">
시스템 전체에서 사용되는 기본 메뉴를 관리합니다. 테넌트는 메뉴를 복사하여 사용합니다.
</p>
</div>
<div class="flex items-center gap-3">
<a href="{{ route('menus.index') }}" class="bg-gray-500 hover:bg-gray-600 text-white px-4 py-2 rounded-lg transition flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18" />
</svg>
메뉴 관리로 돌아가기
</a>
<a href="{{ route('menus.global.create') }}" class="bg-purple-600 hover:bg-purple-700 text-white px-4 py-2 rounded-lg transition">
+ 기본 메뉴
</a>
</div>
</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-purple-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-purple-500">
<option value="">전체 상태</option>
<option value="1">활성</option>
<option value="0">비활성</option>
</select>
</div>
<!-- 검색 버튼 -->
<button type="submit" class="bg-purple-600 hover:bg-purple-700 text-white px-6 py-2 rounded-lg transition">
검색
</button>
</form>
</div>
<!-- 테이블 영역 (HTMX로 로드) -->
<div id="menu-table"
hx-get="/api/admin/global-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-purple-600"></div>
</div>
</div>
@endsection
@push('styles')
<style>
/* 드래그 인디케이터 스타일 */
.drag-indicator {
position: fixed;
pointer-events: none;
z-index: 9999;
padding: 6px 12px;
border-radius: 6px;
font-size: 12px;
font-weight: 600;
white-space: nowrap;
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.drag-indicator.reorder {
background: linear-gradient(135deg, #9333ea, #7c3aed);
color: white;
}
.sortable-fallback {
opacity: 0.9;
background: white !important;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
border-radius: 4px;
z-index: 9998 !important;
}
.drag-handle {
user-select: none;
-webkit-user-select: none;
}
</style>
@endpush
@push('scripts')
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.2/Sortable.min.js"></script>
<script>
// 폼 제출 시 HTMX 이벤트 트리거
document.getElementById('filterForm').addEventListener('submit', function(e) {
e.preventDefault();
htmx.trigger('#menu-table', 'filterSubmit');
});
// HTMX 응답 처리 + SortableJS 초기화
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;
initGlobalMenuSortable();
}
}
});
// SortableJS 초기화 함수
function initGlobalMenuSortable() {
const tbody = document.getElementById('menu-sortable');
if (!tbody) return;
if (tbody.sortableInstance) {
tbody.sortableInstance.destroy();
}
tbody.sortableInstance = new Sortable(tbody, {
handle: '.drag-handle',
animation: 150,
forceFallback: true,
fallbackClass: 'sortable-fallback',
fallbackOnBody: true,
ghostClass: 'bg-purple-50',
chosenClass: 'bg-purple-100',
onEnd: function(evt) {
const rows = Array.from(tbody.querySelectorAll('tr.menu-row'));
const items = rows.map((row, index) => ({
id: parseInt(row.dataset.menuId),
sort_order: index + 1
}));
saveGlobalMenuOrder(items);
}
});
}
// 메뉴 순서 저장 API 호출
function saveGlobalMenuOrder(items) {
fetch('/api/admin/global-menus/reorder', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json'
},
body: JSON.stringify({ items: items })
})
.then(response => response.json())
.then(data => {
if (data.success) {
htmx.trigger('#menu-table', 'filterSubmit');
} else {
showToast('순서 변경 실패: ' + (data.message || ''), 'error');
htmx.trigger('#menu-table', 'filterSubmit');
}
})
.catch(error => {
console.error('Error:', error);
showToast('순서 변경 중 오류 발생', 'error');
htmx.trigger('#menu-table', 'filterSubmit');
});
}
// 삭제 확인
window.confirmDelete = function(id, name) {
showDeleteConfirm(name, () => {
htmx.ajax('DELETE', `/api/admin/global-menus/${id}`, {
target: '#menu-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#menu-table', 'filterSubmit');
});
});
};
// 복원 확인
window.confirmRestore = function(id, name) {
showConfirm(`"${name}" 기본 메뉴를 복원하시겠습니까?`, () => {
htmx.ajax('POST', `/api/admin/global-menus/${id}/restore`, {
target: '#menu-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#menu-table', 'filterSubmit');
});
}, { title: '복원 확인', icon: 'question' });
};
// 영구삭제 확인
window.confirmForceDelete = function(id, name) {
showPermanentDeleteConfirm(name, () => {
htmx.ajax('DELETE', `/api/admin/global-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/global-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/global-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