feat: add compressed photo upload for LV, unit support, and employees
This commit is contained in:
@@ -145,7 +145,21 @@
|
||||
</td>
|
||||
|
||||
<td class="py-3.5 px-4 font-bold text-slate-900">
|
||||
{{ $v->brand_type }}
|
||||
<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-car text-xs"></i>
|
||||
</div>
|
||||
@endif
|
||||
<div class="min-w-0">
|
||||
<div class="truncate">{{ $v->brand_type }}</div>
|
||||
@if($v->serial_number)
|
||||
<div class="text-[10px] text-slate-400 font-mono font-normal truncate">SN: {{ $v->serial_number }}</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="py-3.5 px-4 text-center whitespace-nowrap">
|
||||
@@ -267,10 +281,29 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form id="addVehicleForm" action="{{ route('qma.vehicles.store') }}" method="POST" class="space-y-4">
|
||||
<form id="addVehicleForm" action="{{ route('qma.vehicles.store') }}" method="POST" enctype="multipart/form-data" class="space-y-4">
|
||||
@csrf
|
||||
<input type="hidden" name="category" value="light_vehicle">
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-800 mb-1.5">Foto Unit Kendaraan (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). Otomatis dikompresi agar hemat storage.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-800 mb-1.5">Kode LV <span class="text-rose-500">*</span></label>
|
||||
@@ -364,10 +397,29 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form id="editVehicleForm" action="" method="POST" class="space-y-4">
|
||||
<form id="editVehicleForm" action="" method="POST" enctype="multipart/form-data" class="space-y-4">
|
||||
@csrf
|
||||
<input type="hidden" name="category" value="light_vehicle">
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-800 mb-1.5">Foto Unit Kendaraan</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 Unit" class="w-full h-full object-cover hidden">
|
||||
<i id="editPhotoPlaceholder" class="fa-solid fa-car 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 server.</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 LV <span class="text-rose-500">*</span></label>
|
||||
@@ -456,6 +508,11 @@
|
||||
</div>
|
||||
|
||||
<div class="space-y-4">
|
||||
<!-- Foto Kendaraan 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 Unit LV" class="w-full h-full object-cover">
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-800 mb-1.5">Kode LV</label>
|
||||
@@ -828,8 +885,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() {
|
||||
@@ -849,6 +935,24 @@
|
||||
document.getElementById('editOwnership').value = v.ownership || '';
|
||||
document.getElementById('editStatus').value = v.status || 'Operation';
|
||||
document.getElementById('editCurrentKm').value = v.current_km || 0;
|
||||
|
||||
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');
|
||||
@@ -865,6 +969,16 @@
|
||||
document.getElementById('detailDivision').innerText = v.division || '-';
|
||||
document.getElementById('detailOwnership').innerText = v.ownership || '-';
|
||||
|
||||
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 badge = document.getElementById('detailStatusBadge');
|
||||
if (badge) {
|
||||
badge.className = 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold border ';
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -154,9 +154,18 @@
|
||||
</td>
|
||||
|
||||
<td class="py-3.5 px-4 font-bold text-slate-900 font-mono text-xs whitespace-nowrap">
|
||||
<span class="bg-blue-50 text-blue-800 px-2.5 py-1 rounded-lg border border-blue-200 font-bold">
|
||||
{{ $u->code }}
|
||||
</span>
|
||||
<div class="flex items-center space-x-2.5">
|
||||
@if($u->photo_path)
|
||||
<img src="{{ $u->photo_url }}" alt="{{ $u->code }}" class="w-8 h-8 rounded-lg object-cover border border-slate-200 shadow-2xs flex-shrink-0 cursor-pointer" onclick='openDetailModal(@json($u))'>
|
||||
@else
|
||||
<div class="w-8 h-8 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-pickup text-[10px]"></i>
|
||||
</div>
|
||||
@endif
|
||||
<span class="bg-blue-50 text-blue-800 px-2.5 py-1 rounded-lg border border-blue-200 font-bold">
|
||||
{{ $u->code }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="py-3.5 px-4 font-mono text-xs text-slate-700 whitespace-nowrap">
|
||||
@@ -331,9 +340,28 @@
|
||||
Tambah Unit Baru
|
||||
</h3>
|
||||
|
||||
<form method="POST" action="{{ route('qma.vehicles.support.units.store', $category->id) }}" id="addUnitForm" class="space-y-4">
|
||||
<form method="POST" action="{{ route('qma.vehicles.support.units.store', $category->id) }}" id="addUnitForm" enctype="multipart/form-data" class="space-y-4">
|
||||
@csrf
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1.5">Foto Unit Fisik (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="previewUnitImage(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 otomatis dikompresi hemat storage.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Aset Induk (Readonly) Sesuai Mockup -->
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1.5">
|
||||
@@ -495,11 +523,30 @@
|
||||
<h3 class="text-xl font-extrabold text-slate-900 tracking-tight mb-5">
|
||||
Edit Data Unit Fisik
|
||||
</h3>
|
||||
<form id="editUnitForm" method="POST" action="" class="space-y-4">
|
||||
<form id="editUnitForm" method="POST" action="" enctype="multipart/form-data" class="space-y-4">
|
||||
@csrf
|
||||
<input type="hidden" name="category" value="unit_support">
|
||||
<input type="hidden" name="brand_type" id="edit_brand_type">
|
||||
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1.5">Foto Unit Fisik</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 Unit" class="w-full h-full object-cover hidden">
|
||||
<i id="editPhotoPlaceholder" class="fa-solid fa-truck-pickup 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="previewUnitImage(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>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1.5">Kode Unit <span class="text-rose-500">*</span></label>
|
||||
<input type="text" name="code" id="edit_code" required class="w-full text-xs px-3.5 py-2 rounded-xl border border-slate-200 bg-slate-100 text-slate-700 font-mono font-bold focus:outline-none" readonly>
|
||||
@@ -589,6 +636,11 @@
|
||||
</div>
|
||||
|
||||
<div class="py-4 space-y-3 text-xs">
|
||||
<!-- Foto Unit Fisik di Detail Modal -->
|
||||
<div id="detail_photo_container" class="w-full h-44 rounded-2xl bg-slate-100 border border-slate-200 flex items-center justify-center overflow-hidden relative hidden mb-3">
|
||||
<img id="detail_photo" src="" alt="Foto Unit Fisik" class="w-full h-full object-cover">
|
||||
</div>
|
||||
|
||||
<div class="flex justify-between py-1.5 border-b border-slate-50">
|
||||
<span class="text-slate-400">Kategori Induk:</span>
|
||||
<span class="font-bold text-slate-800">{{ $category->code }} - {{ $category->unit_category }}</span>
|
||||
@@ -675,8 +727,37 @@
|
||||
<script>
|
||||
const categoryCode = "{{ $category->code }}";
|
||||
|
||||
function previewUnitImage(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 openAddUnitModal() {
|
||||
document.getElementById('addUnitModal').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');
|
||||
}
|
||||
document.getElementById('unitNumberInput').focus();
|
||||
}
|
||||
|
||||
@@ -722,6 +803,24 @@
|
||||
document.getElementById('edit_silo').value = unit.silo_document || '';
|
||||
document.getElementById('edit_kir').value = unit.kir_document || '';
|
||||
|
||||
const editPhotoPreview = document.getElementById('editPhotoPreview');
|
||||
const editPhotoPlaceholder = document.getElementById('editPhotoPlaceholder');
|
||||
const editPhotoInput = document.getElementById('editPhotoInput');
|
||||
if (editPhotoInput) editPhotoInput.value = '';
|
||||
if (unit.photo_url) {
|
||||
if (editPhotoPreview) {
|
||||
editPhotoPreview.src = unit.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');
|
||||
}
|
||||
|
||||
document.getElementById('editModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
@@ -740,6 +839,16 @@
|
||||
document.getElementById('detail_silo').textContent = unit.silo_document || 'Tidak ada';
|
||||
document.getElementById('detail_kir').textContent = unit.kir_document || 'Tidak ada';
|
||||
|
||||
const detailPhotoContainer = document.getElementById('detail_photo_container');
|
||||
const detailPhoto = document.getElementById('detail_photo');
|
||||
if (unit.photo_url) {
|
||||
if (detailPhoto) detailPhoto.src = unit.photo_url;
|
||||
if (detailPhotoContainer) detailPhotoContainer.classList.remove('hidden');
|
||||
} else {
|
||||
if (detailPhoto) detailPhoto.src = '';
|
||||
if (detailPhotoContainer) detailPhotoContainer.classList.add('hidden');
|
||||
}
|
||||
|
||||
document.getElementById('detailModal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user