Files
sam-manage/resources/views/roles/create.blade.php
hskwon 5f50716d7f feat: Phase 4-2 역할 관리 시스템 구현 (HTMX + API 패턴)
- RoleService, RoleController (Blade/API) 생성
- 역할 CRUD 기능 완성 (목록/생성/수정/삭제)
- FormRequest 검증 (StoreRoleRequest, UpdateRoleRequest)
- HTMX 패턴 적용 (index, create, edit)
- 권한 선택 UI (체크박스, 전체 선택/해제)
- Tenant Selector 통합
- 레이아웃 패턴 문서화 (LAYOUT_PATTERN.md)
- Sidebar 메뉴에 역할 관리 추가
- Pagination partial 컴포넌트 추가
- Tenants 레이아웃 100% 폭으로 통일

주요 수정:
- UpdateRoleRequest 라우트 파라미터 수정 (role → id)
- RoleController permissions 조회 시 description 제거
- Conditional tenant filtering 적용
2025-11-24 16:36:02 +09:00

137 lines
6.0 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('roles.index') }}" class="text-gray-600 hover:text-gray-800">
목록으로
</a>
</div>
<!-- 영역 -->
<div class="bg-white rounded-lg shadow-sm p-6">
<form id="roleForm"
hx-post="/api/admin/roles"
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="space-y-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="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>
<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>
</div>
<!-- 권한 선택 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">권한 선택</h2>
@if($permissions->isEmpty())
<div class="text-center py-8 text-gray-500">
<p>선택 가능한 권한이 없습니다.</p>
<p class="text-sm mt-2">테넌트를 선택하거나 권한을 먼저 생성해주세요.</p>
</div>
@else
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
@foreach($permissions as $permission)
<label class="flex items-center p-3 border border-gray-200 rounded-lg hover:bg-gray-50 cursor-pointer">
<input type="checkbox" name="permissions[]" value="{{ $permission->id }}"
class="mr-2 h-4 w-4 text-blue-600 rounded focus:ring-2 focus:ring-blue-500">
<span class="font-medium text-gray-800">{{ $permission->name }}</span>
</label>
@endforeach
</div>
<div class="mt-4 flex gap-2">
<button type="button" onclick="selectAllPermissions()"
class="text-sm text-blue-600 hover:text-blue-700 underline">
전체 선택
</button>
<span class="text-gray-400">|</span>
<button type="button" onclick="deselectAllPermissions()"
class="text-sm text-blue-600 hover:text-blue-700 underline">
전체 해제
</button>
</div>
@endif
</div>
<!-- 버튼 영역 -->
<div class="flex justify-end gap-3">
<a href="{{ route('roles.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>
// 전체 선택
function selectAllPermissions() {
document.querySelectorAll('input[name="permissions[]"]').forEach(checkbox => {
checkbox.checked = true;
});
}
// 전체 해제
function deselectAllPermissions() {
document.querySelectorAll('input[name="permissions[]"]').forEach(checkbox => {
checkbox.checked = false;
});
}
// HTMX 응답 처리
document.body.addEventListener('htmx:afterRequest', function(event) {
if (event.detail.target.id === 'roleForm') {
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