Files
sam-manage/resources/views/document-templates/index.blade.php
권혁성 d1fad70395 refactor:문서템플릿 분류 동적 조회 및 회사정보 제거
- 분류: CommonCode → DocumentTemplate에서 group by 조회
- 분류 입력: select → input + datalist (자유입력 + 자동완성)
- 회사정보 입력 필드 제거 (tenant에서 자동 조회)
- 미리보기: tenant 회사명 자동 표시

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-28 17:47:14 +09:00

165 lines
6.9 KiB
PHP

@extends('layouts.app')
@section('title', '문서양식 관리')
@section('content')
<!-- 페이지 헤더 -->
<div class="flex flex-col lg:flex-row lg:justify-between lg:items-center gap-4 mb-6">
<div>
<h1 class="text-2xl font-bold text-gray-800">문서양식 관리</h1>
<p class="text-sm text-gray-500 mt-1 hidden sm:block">
검사 성적서, 작업지시서 문서 양식을 관리합니다.
</p>
</div>
<div class="flex flex-wrap items-center gap-2 sm:gap-3">
<a href="{{ route('document-templates.create') }}"
class="bg-blue-600 hover:bg-blue-700 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="M12 4v16m8-8H4" />
</svg>
양식
</a>
</div>
</div>
<!-- 필터 영역 -->
<x-filter-collapsible id="filterForm">
<form id="filterForm" class="flex flex-wrap gap-2 sm:gap-4">
<input type="hidden" name="per_page" id="perPageInput" value="10">
<input type="hidden" name="page" id="pageInput" value="1">
<!-- 검색 -->
<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>
<!-- 카테고리 필터 -->
<div class="w-full sm:w-40">
<select name="category" 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($categories as $category)
<option value="{{ $category }}">{{ $category }}</option>
@endforeach
</select>
</div>
<!-- 활성 상태 필터 -->
<div class="w-full sm:w-32">
<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 w-full sm:w-auto">
검색
</button>
</form>
</x-filter-collapsible>
<!-- 테이블 영역 (HTMX로 로드) -->
<div id="template-table"
hx-get="/api/admin/document-templates"
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>
// 폼 제출 시 HTMX 이벤트 트리거
(function() {
function initFilterForm() {
const filterForm = document.getElementById('filterForm');
if (filterForm && !filterForm._initialized) {
filterForm.addEventListener('submit', function(e) {
e.preventDefault();
htmx.trigger('#template-table', 'filterSubmit');
});
filterForm._initialized = true;
}
}
initFilterForm();
document.addEventListener('DOMContentLoaded', initFilterForm);
})();
// 삭제 확인
window.confirmDelete = function(id, name) {
showDeleteConfirm(name, () => {
fetch(`/api/admin/document-templates/${id}`, {
method: 'DELETE',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
showToast(data.message || '삭제되었습니다.', 'success');
htmx.trigger('#template-table', 'filterSubmit');
} else {
showToast(data.message || '삭제에 실패했습니다.', 'error');
}
})
.catch(error => {
showToast('삭제 중 오류가 발생했습니다.', 'error');
console.error('Delete error:', error);
});
});
};
// 활성 토글
window.toggleActive = function(id, buttonEl) {
const btn = buttonEl || document.querySelector(`tr[data-template-id="${id}"] button[onclick*="toggleActive"]`);
if (!btn) return;
const isCurrentlyActive = btn.classList.contains('bg-blue-500');
const thumb = btn.querySelector('span');
// 즉시 UI 토글
btn.classList.toggle('bg-blue-500', !isCurrentlyActive);
btn.classList.toggle('bg-gray-400', isCurrentlyActive);
thumb.classList.toggle('translate-x-3.5', !isCurrentlyActive);
thumb.classList.toggle('translate-x-0.5', isCurrentlyActive);
fetch(`/api/admin/document-templates/${id}/toggle-active`, {
method: 'POST',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (!data.success) {
// 실패 시 롤백
btn.classList.toggle('bg-blue-500', isCurrentlyActive);
btn.classList.toggle('bg-gray-400', !isCurrentlyActive);
thumb.classList.toggle('translate-x-3.5', isCurrentlyActive);
thumb.classList.toggle('translate-x-0.5', !isCurrentlyActive);
showToast(data.message || '상태 변경에 실패했습니다.', 'error');
}
})
.catch(error => {
btn.classList.toggle('bg-blue-500', isCurrentlyActive);
btn.classList.toggle('bg-gray-400', !isCurrentlyActive);
thumb.classList.toggle('translate-x-3.5', isCurrentlyActive);
thumb.classList.toggle('translate-x-0.5', !isCurrentlyActive);
showToast('상태 변경 중 오류가 발생했습니다.', 'error');
console.error('Toggle error:', error);
});
};
</script>
@endpush