feat: add compressed photo upload for LV, unit support, and employees

This commit is contained in:
Ray1111-aa
2026-10-20 16:00:29 +07:00
parent cb284a7432
commit 7126648c1c
10 changed files with 929 additions and 15 deletions
+114 -3
View File
@@ -130,7 +130,18 @@
</td>
<td class="py-3.5 px-4 whitespace-nowrap">
<span class="font-bold text-slate-900 block text-xs">{{ $v->unit_category ?? 'Alat Berat' }}</span>
<div class="flex items-center space-x-3">
@if($v->photo_path)
<img src="{{ $v->photo_url }}" alt="{{ $v->code }}" class="w-9 h-9 rounded-lg object-cover border border-slate-200 shadow-2xs flex-shrink-0 cursor-pointer" onclick='openDetailModal(@json($v))'>
@else
<div class="w-9 h-9 rounded-lg bg-slate-100 border border-slate-200 flex items-center justify-center text-slate-400 flex-shrink-0">
<i class="fa-solid fa-truck-monster text-xs"></i>
</div>
@endif
<div>
<span class="font-bold text-slate-900 block text-xs">{{ $v->unit_category ?? 'Alat Berat' }}</span>
</div>
</div>
</td>
<td class="py-3.5 px-4 text-center whitespace-nowrap">
@@ -240,10 +251,29 @@
</button>
</div>
<form id="addVehicleForm" action="{{ route('qma.vehicles.store') }}" method="POST" class="space-y-3.5">
<form id="addVehicleForm" action="{{ route('qma.vehicles.store') }}" method="POST" enctype="multipart/form-data" class="space-y-3.5">
@csrf
<input type="hidden" name="category" value="unit_support">
<div>
<label class="block text-xs font-bold text-slate-800 mb-1">Foto Kategori Unit Support (Opsional)</label>
<div class="flex items-center space-x-3.5 p-3 rounded-2xl border border-slate-200 bg-slate-50/50">
<div id="addPhotoPreviewContainer" class="w-14 h-14 rounded-xl border-2 border-dashed border-slate-300 bg-white flex items-center justify-center overflow-hidden flex-shrink-0 shadow-2xs">
<img id="addPhotoPreview" src="" alt="Pratinjau" class="w-full h-full object-cover hidden">
<i id="addPhotoPlaceholder" class="fa-solid fa-camera text-slate-400 text-base"></i>
</div>
<div class="flex-1 min-w-0">
<input type="file"
name="photo"
id="addPhotoInput"
accept="image/jpeg,image/png,image/jpg,image/webp"
onchange="previewVehicleImage(this, 'addPhotoPreview', 'addPhotoPlaceholder')"
class="block w-full text-xs text-slate-500 file:mr-3 file:py-1.5 file:px-3 file:rounded-xl file:border-0 file:text-xs file:font-bold file:bg-emerald-50 file:text-[#1b5e20] hover:file:bg-emerald-100 cursor-pointer">
<p class="text-[10px] text-slate-400 mt-1">Format: JPG, PNG, WebP (Maks. 10MB). Resolusi & file dikompresi otomatis.</p>
</div>
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label class="block text-xs font-bold text-slate-800 mb-1">Kode Kategori <span class="text-rose-500">*</span></label>
@@ -343,10 +373,29 @@
</button>
</div>
<form id="editVehicleForm" action="" method="POST" class="space-y-3.5">
<form id="editVehicleForm" action="" method="POST" enctype="multipart/form-data" class="space-y-3.5">
@csrf
<input type="hidden" name="category" value="unit_support">
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Foto Kategori Unit Support</label>
<div class="flex items-center space-x-3.5 p-3 rounded-2xl border border-slate-200 bg-slate-50/50">
<div id="editPhotoPreviewContainer" class="w-14 h-14 rounded-xl border border-slate-200 bg-white flex items-center justify-center overflow-hidden flex-shrink-0 shadow-2xs">
<img id="editPhotoPreview" src="" alt="Foto Kategori" class="w-full h-full object-cover hidden">
<i id="editPhotoPlaceholder" class="fa-solid fa-truck-monster text-slate-400 text-base"></i>
</div>
<div class="flex-1 min-w-0">
<input type="file"
name="photo"
id="editPhotoInput"
accept="image/jpeg,image/png,image/jpg,image/webp"
onchange="previewVehicleImage(this, 'editPhotoPreview', 'editPhotoPlaceholder')"
class="block w-full text-xs text-slate-500 file:mr-3 file:py-1.5 file:px-3 file:rounded-xl file:border-0 file:text-xs file:font-bold file:bg-emerald-50 file:text-[#1b5e20] hover:file:bg-emerald-100 cursor-pointer">
<p class="text-[10px] text-slate-400 mt-1">Pilih foto baru jika ingin mengganti. Otomatis dikompresi hemat storage.</p>
</div>
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3.5">
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Kode Kategori <span class="text-rose-500">*</span></label>
@@ -443,6 +492,11 @@
</div>
<div class="space-y-4">
<!-- Foto Kategori di Detail Modal -->
<div id="detailPhotoContainer" class="w-full h-48 rounded-2xl bg-slate-100 border border-slate-200 flex items-center justify-center overflow-hidden relative hidden">
<img id="detailPhoto" src="" alt="Foto Kategori Unit Support" class="w-full h-full object-cover">
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3.5">
<div>
<label class="block text-xs font-bold text-slate-800 mb-1.5">Kode Kategori</label>
@@ -794,8 +848,37 @@
});
}
function previewVehicleImage(input, imgId, placeholderId) {
if (input.files && input.files[0]) {
const reader = new FileReader();
reader.onload = function(e) {
const img = document.getElementById(imgId);
const placeholder = document.getElementById(placeholderId);
if (img) {
img.src = e.target.result;
img.classList.remove('hidden');
}
if (placeholder) {
placeholder.classList.add('hidden');
}
};
reader.readAsDataURL(input.files[0]);
}
}
function openAddModal() {
document.getElementById('addVehicleModal').classList.remove('hidden');
const addPhotoPreview = document.getElementById('addPhotoPreview');
const addPhotoPlaceholder = document.getElementById('addPhotoPlaceholder');
const addPhotoInput = document.getElementById('addPhotoInput');
if (addPhotoInput) addPhotoInput.value = '';
if (addPhotoPreview) {
addPhotoPreview.src = '';
addPhotoPreview.classList.add('hidden');
}
if (addPhotoPlaceholder) {
addPhotoPlaceholder.classList.remove('hidden');
}
if (addCodeInput) addCodeInput.focus();
}
function closeAddModal() {
@@ -836,6 +919,24 @@
}
document.getElementById('editOwnership').value = v.ownership || '';
document.getElementById('editFuelConsumption').value = v.fuel_consumption || '';
const editPhotoPreview = document.getElementById('editPhotoPreview');
const editPhotoPlaceholder = document.getElementById('editPhotoPlaceholder');
const editPhotoInput = document.getElementById('editPhotoInput');
if (editPhotoInput) editPhotoInput.value = '';
if (v.photo_url) {
if (editPhotoPreview) {
editPhotoPreview.src = v.photo_url;
editPhotoPreview.classList.remove('hidden');
}
if (editPhotoPlaceholder) editPhotoPlaceholder.classList.add('hidden');
} else {
if (editPhotoPreview) {
editPhotoPreview.src = '';
editPhotoPreview.classList.add('hidden');
}
if (editPhotoPlaceholder) editPhotoPlaceholder.classList.remove('hidden');
}
}
function closeEditModal() {
document.getElementById('editVehicleModal').classList.add('hidden');
@@ -853,6 +954,16 @@
document.getElementById('detailDivision').innerText = v.division || '-';
document.getElementById('detailOwnership').innerText = v.ownership || 'PT Kerinci Merangin Hidro';
const detailPhotoContainer = document.getElementById('detailPhotoContainer');
const detailPhoto = document.getElementById('detailPhoto');
if (v.photo_url) {
if (detailPhoto) detailPhoto.src = v.photo_url;
if (detailPhotoContainer) detailPhotoContainer.classList.remove('hidden');
} else {
if (detailPhoto) detailPhoto.src = '';
if (detailPhotoContainer) detailPhotoContainer.classList.add('hidden');
}
const count = v.units_count !== undefined ? v.units_count : 0;
document.getElementById('detailUnitCountText').innerText = count + ' Unit Fisik';
const manageBtn = document.getElementById('detailManageUnitsBtn');