119 lines
4.9 KiB
PHP
119 lines
4.9 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>
|
|
<div class="flex flex-wrap items-center gap-2 sm:gap-3">
|
|
<!-- 일괄 삭제 -->
|
|
<button onclick="bulkDelete()" id="bulkDeleteBtn"
|
|
class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg transition flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
disabled>
|
|
선택 삭제 (<span id="deleteCount">0</span>)
|
|
</button>
|
|
<a href="{{ route('roles.create') }}" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition text-center">
|
|
+ 새 역할
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 필터 영역 -->
|
|
<x-filter-collapsible id="filterForm">
|
|
<form id="filterForm" class="flex flex-wrap gap-2 sm:gap-4">
|
|
<!-- Guard 선택 -->
|
|
<div class="w-full sm:w-32">
|
|
<select name="guard_name"
|
|
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="">전체 Guard</option>
|
|
<option value="api">API</option>
|
|
<option value="web">Web</option>
|
|
</select>
|
|
</div>
|
|
|
|
<!-- 검색 -->
|
|
<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>
|
|
|
|
<!-- 검색 버튼 -->
|
|
<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="role-table"
|
|
hx-get="/api/admin/roles"
|
|
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('#role-table', 'filterSubmit');
|
|
});
|
|
|
|
// 삭제 확인
|
|
window.confirmDelete = function(id, name) {
|
|
showDeleteConfirm(name, () => {
|
|
htmx.ajax('DELETE', `/api/admin/roles/${id}`, {
|
|
target: '#role-table',
|
|
swap: 'none',
|
|
headers: {
|
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
|
}
|
|
}).then(() => {
|
|
htmx.trigger('#role-table', 'filterSubmit');
|
|
});
|
|
});
|
|
};
|
|
|
|
// ===== 일괄 작업 =====
|
|
window.toggleSelectAll = function(headerCheckbox) {
|
|
document.querySelectorAll('.bulk-checkbox').forEach(cb => cb.checked = headerCheckbox.checked);
|
|
updateBulkButtonState();
|
|
};
|
|
|
|
window.updateBulkButtonState = function() {
|
|
const checked = document.querySelectorAll('.bulk-checkbox:checked');
|
|
const deleteBtn = document.getElementById('bulkDeleteBtn');
|
|
if (deleteBtn) {
|
|
document.getElementById('deleteCount').textContent = checked.length;
|
|
deleteBtn.disabled = checked.length === 0;
|
|
}
|
|
};
|
|
|
|
window.bulkDelete = function() {
|
|
const ids = Array.from(document.querySelectorAll('.bulk-checkbox:checked')).map(cb => parseInt(cb.value));
|
|
if (ids.length === 0) { showToast('삭제할 역할을 선택해주세요.', 'warning'); return; }
|
|
|
|
showDeleteConfirm(`${ids.length}개 역할`, () => {
|
|
fetch('/api/admin/roles/bulk-delete', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '{{ csrf_token() }}', 'Accept': 'application/json' },
|
|
body: JSON.stringify({ ids })
|
|
}).then(r => r.json()).then(data => {
|
|
showToast(data.message || '삭제 완료', data.success ? 'success' : 'error');
|
|
htmx.trigger('#role-table', 'filterSubmit');
|
|
}).catch(() => showToast('삭제 중 오류 발생', 'error'));
|
|
});
|
|
};
|
|
</script>
|
|
@endpush |