Files
sam-manage/resources/views/departments/edit.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

166 lines
8.3 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('departments.index') }}" class="text-gray-600 hover:text-gray-800">
목록으로
</a>
</div>
<!-- 영역 -->
<div class="bg-white rounded-lg shadow-sm p-6">
<form id="departmentForm"
hx-post="/api/admin/departments/{{ $department->id }}"
hx-headers='{"X-CSRF-TOKEN": "{{ csrf_token() }}"}'
hx-swap="none">
<input type="hidden" name="_method" value="PUT">
<!-- 기본 정보 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">기본 정보</h2>
<div class="grid grid-cols-2 gap-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="code" required maxlength="50"
value="{{ old('code', $department->code) }}"
placeholder="예: DEV, SALES"
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">최대 50자까지 입력 가능합니다.</p>
</div>
<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"
value="{{ old('name', $department->name) }}"
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>
</div>
<!-- 부서 설정 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">부서 설정</h2>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">상위 부서</label>
<select name="parent_id" 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>
@foreach($departments as $dept)
@if($dept->id !== $department->id)
<option value="{{ $dept->id }}" {{ old('parent_id', $department->parent_id) == $dept->id ? 'selected' : '' }}>
{{ $dept->name }} ({{ $dept->code }})
</option>
@endif
@endforeach
</select>
<p class="text-xs text-gray-500 mt-1">자기 자신은 선택할 없습니다.</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">정렬 순서</label>
<input type="number" name="sort_order" min="0"
value="{{ old('sort_order', $department->sort_order) }}"
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">숫자가 작을수록 먼저 표시됩니다.</p>
</div>
</div>
</div>
<!-- 설명 상태 -->
<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">설명</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">{{ old('description', $department->description) }}</textarea>
<p class="text-xs text-gray-500 mt-1">최대 500자까지 입력 가능합니다.</p>
</div>
<div class="flex items-center">
<input type="checkbox" name="is_active" value="1" {{ old('is_active', $department->is_active) ? 'checked' : '' }}
class="h-4 w-4 text-blue-600 rounded focus:ring-2 focus:ring-blue-500">
<label class="ml-2 text-sm text-gray-700">활성 상태</label>
</div>
</div>
</div>
<!-- 부서 정보 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">부서 정보</h2>
<div class="grid grid-cols-2 gap-4 text-sm">
<div>
<span class="text-gray-600">생성일:</span>
<span class="font-medium">{{ $department->created_at->format('Y-m-d H:i') }}</span>
</div>
<div>
<span class="text-gray-600">수정일:</span>
<span class="font-medium">{{ $department->updated_at->format('Y-m-d H:i') }}</span>
</div>
<div>
<span class="text-gray-600">하위 부서 :</span>
<span class="font-medium">{{ $department->children->count() }}</span>
</div>
<div>
<span class="text-gray-600">부서 ID:</span>
<span class="font-medium">#{{ $department->id }}</span>
</div>
</div>
</div>
<!-- 버튼 영역 -->
<div class="flex justify-end gap-3">
<a href="{{ route('departments.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>
// HTMX 응답 처리
document.body.addEventListener('htmx:afterRequest', function(event) {
if (event.detail.target.id === 'departmentForm') {
const response = JSON.parse(event.detail.xhr.response);
if (response.success) {
showToast(response.message, 'success');
window.location.href = response.redirect;
} else {
showToast(response.message || '부서 수정에 실패했습니다.', 'error');
}
}
});
// 에러 처리
document.body.addEventListener('htmx:responseError', function(event) {
if (event.detail.xhr.status === 422) {
const errors = JSON.parse(event.detail.xhr.response).errors;
let errorMsg = '입력 오류: ';
for (let field in errors) {
errorMsg += errors[field].join(', ') + ' ';
}
showToast(errorMsg, 'error');
} else {
showToast('서버 오류가 발생했습니다.', 'error');
}
});
</script>
@endpush