perbaikan denah bisa banyak
This commit is contained in:
@@ -226,60 +226,72 @@ class SurveyorController extends Controller
|
|||||||
|
|
||||||
public function storeDenah(Request $request)
|
public function storeDenah(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
$validator = $request->validate([
|
||||||
$maxSize = getMaxFileSize('Foto');
|
'foto_denah.*' => 'nullable|file|mimes:jpg,jpeg,png,bmp,gif,webp,pdf',
|
||||||
$validationRules = [
|
'nama_denah.*' => 'nullable|string|max:255',
|
||||||
'luas' => 'required|numeric',
|
'luas_denah.*' => 'nullable|numeric',
|
||||||
'permohonan_id' => 'required',
|
'permohonan_id' => 'required|exists:permohonan,id',
|
||||||
'dokument_id' => 'required'
|
'dokument_id' => 'required'
|
||||||
];
|
]);
|
||||||
|
if ($validator) {
|
||||||
|
try {
|
||||||
|
|
||||||
if ($request->hasFile('foto_denah')) {
|
$denahs = [];
|
||||||
$maxSize = getMaxFileSize('Foto');
|
|
||||||
$validationRules['foto_denah'] = 'file|mimes:jpeg,jpg,png,pdf,svg|max:'. $maxSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
$validatedData = $request->validate($validationRules);
|
$inspeksi = Inspeksi::where('permohonan_id', $request->permohonan_id)
|
||||||
|
->where('dokument_id', $request->dokument_id)
|
||||||
$formatJsonDenah = [
|
|
||||||
'luas' => $validatedData['luas'],
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($request->hasFile('foto_denah')) {
|
|
||||||
$formatJsonDenah['foto_denah'] = $this->uploadFile($request->file('foto_denah'), 'foto_denah');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))
|
|
||||||
->where('dokument_id', $request->input('dokument_id'))
|
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($inspeksi) {
|
$existingDenah = $inspeksi ? json_decode($inspeksi->denah_form ?? '[]', true) : [];
|
||||||
$existingDenah = json_decode($inspeksi->denah_form, true) ?? [];
|
$existingDenahs = $existingDenah['denahs'] ?? [];
|
||||||
|
|
||||||
$updatedDenah = array_merge($existingDenah, $formatJsonDenah);
|
if ($request->has('nama_denah')) {
|
||||||
|
foreach ($request->nama_denah as $index => $namaDenah) {
|
||||||
|
$denahItem = [
|
||||||
|
'nama_denah' => $namaDenah,
|
||||||
|
'luas_denah' => $request->luas_denah[$index] ?? null
|
||||||
|
];
|
||||||
|
|
||||||
$inspeksi->update([
|
if ($request->hasFile('foto_denah') && isset($request->file('foto_denah')[$index])) {
|
||||||
'denah_form' => json_encode($updatedDenah)
|
$file = $request->file('foto_denah')[$index];
|
||||||
]);
|
$denahItem['foto_denah'] = $this->uploadFile($file, 'foto_denah');
|
||||||
} else {
|
} elseif (isset($existingDenahs[$index]['foto_denah'])) {
|
||||||
Inspeksi::create([
|
$denahItem['foto_denah'] = $existingDenahs[$index]['foto_denah'];
|
||||||
'permohonan_id' => $request->input('permohonan_id'),
|
|
||||||
'dokument_id' => $request->input('dokument_id'),
|
|
||||||
'denah_form' => json_encode($formatJsonDenah)
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$denahs[] = $denahItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($denahs) && !empty($existingDenahs)) {
|
||||||
|
$denahs = $existingDenahs;
|
||||||
|
}
|
||||||
|
|
||||||
|
$inspeksi = Inspeksi::firstOrNew([
|
||||||
|
'permohonan_id' => $request->permohonan_id,
|
||||||
|
'dokument_id' => $request->dokument_id
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Update denah_form
|
||||||
|
$updatedDenah = ['denahs' => $denahs];
|
||||||
|
$inspeksi->denah_form = json_encode($updatedDenah);
|
||||||
|
$inspeksi->save();
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'message' => 'Data berhasil disimpan',
|
'message' => 'Data berhasil disimpan',
|
||||||
'data' => $formatJsonDenah
|
'data' => $updatedDenah
|
||||||
], 200);
|
], 200);
|
||||||
} catch (Exception $e) {
|
|
||||||
return response()->json(['success' => false, 'message' => 'Data gagal disimpan: ' . $e->getMessage()], 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
\Log::error('Denah Store Error: ' . $e->getMessage());
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Gagal menyimpan data: ' . $e->getMessage()
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function storeFoto(Request $request)
|
public function storeFoto(Request $request)
|
||||||
{
|
{
|
||||||
@@ -291,7 +303,7 @@ class SurveyorController extends Controller
|
|||||||
'foto_lingkungan',
|
'foto_lingkungan',
|
||||||
];
|
];
|
||||||
|
|
||||||
$lainnya =[
|
$lainnya = [
|
||||||
'foto_rute_lainnya' => ['foto_rute_lainnya', 'name_rute_lainnya'],
|
'foto_rute_lainnya' => ['foto_rute_lainnya', 'name_rute_lainnya'],
|
||||||
'foto_lantai_lainnya' => ['foto_lantai_lainnya', 'name_lantai_lainnya']
|
'foto_lantai_lainnya' => ['foto_lantai_lainnya', 'name_lantai_lainnya']
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -16,15 +16,11 @@
|
|||||||
|
|
||||||
@include('lpj::assetsku.includenya')
|
@include('lpj::assetsku.includenya')
|
||||||
<div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
|
<div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
|
||||||
<div class="card border border-agi-100 min-w-full">
|
|
||||||
<div class="card border border-agi-100 min-w-full">
|
<div class="card border border-agi-100 min-w-full">
|
||||||
<div class="card-header bg-agi-50">
|
<div class="card-header bg-agi-50">
|
||||||
<h3 class="card-title">
|
<h3 class="card-title">Denah</h3>
|
||||||
Denah
|
|
||||||
</h3>
|
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<a href="{{ route('surveyor.show', ['id' => request('denah')]) }}?form=denah"
|
<a href="{{ route('surveyor.show', ['id' => request('denah')]) }}?form=denah" class="btn btn-xs btn-info">
|
||||||
class="btn btn-xs btn-info">
|
|
||||||
<i class="ki-filled ki-exit-left"></i> Back
|
<i class="ki-filled ki-exit-left"></i> Back
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -33,157 +29,277 @@
|
|||||||
@include('lpj::component.detail-jaminan', ['status' => true])
|
@include('lpj::component.detail-jaminan', ['status' => true])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
<form id="formDenah" method="POST" enctype="multipart/form-data" class="w-full">
|
||||||
<form id="formDenah" method="POST" class="grid gap-5" enctype="multipart/form-data">
|
|
||||||
@if (isset($debitur->id))
|
|
||||||
<input type="hidden" name="id" value="{{ $debitur->id }}">
|
|
||||||
@method('PUT')
|
|
||||||
@endif
|
|
||||||
@csrf
|
@csrf
|
||||||
|
|
||||||
<input type="hidden" value="{{ $permohonan->id }}" name="permohonan_id">
|
<input type="hidden" value="{{ $permohonan->id }}" name="permohonan_id">
|
||||||
<input type="hidden" name="dokument_id" value="{{ request('dokument') }}">
|
<input type="hidden" name="dokument_id" value="{{ request('dokument') }}">
|
||||||
<div class="mt-2">
|
|
||||||
<div class=" mx-auto overflow-hidden">
|
<!-- Container untuk daftar denah -->
|
||||||
<div class="flex flex-wrap gap-4" style="margin-top: 20px">
|
<!-- Container untuk daftar denah -->
|
||||||
<div class="flex w-full items-center justify-center gap-4">
|
<div id="denah-container">
|
||||||
|
@if (isset($formDenah['denahs']) && is_array($formDenah['denahs']) && count($formDenah['denahs']) > 0)
|
||||||
|
@foreach ($formDenah['denahs'] as $index => $denah)
|
||||||
|
<div class="denah-item grid gap-5 mb-5 border p-4 rounded">
|
||||||
|
<div class="flex flex-wrap gap-4">
|
||||||
|
<div class="flex w-full items-baseline flex-wrap lg:flex-nowrap gap-4">
|
||||||
<label class="form-label max-w-56">
|
<label class="form-label max-w-56">
|
||||||
<span class="form-label">Upload Denah (Foto/PDF)</span>
|
<span class="form-label">Upload Denah (Foto/PDF)</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="w-full grid gap-5">
|
<div class="w-full grid gap-5">
|
||||||
<!-- Preview Container -->
|
<!-- Preview Container -->
|
||||||
<div id="preview-container">
|
<div class="preview-container-{{ $index }}">
|
||||||
<!-- Image preview -->
|
@if (isset($denah['foto_denah']))
|
||||||
<img id="foto_denah-preview"
|
@php
|
||||||
src="{{ isset($formDenah['foto_denah']) ? asset('storage/' . old('foto_denah', $formDenah['foto_denah'])) : '' }}"
|
$fileExtension = pathinfo(
|
||||||
alt="Gambar foto_denah"
|
$denah['foto_denah'],
|
||||||
style="{{ isset($formDenah['foto_denah']) && strpos($formDenah['foto_denah'], '.pdf') === false ? 'width: 30rem;' : 'display: none;' }}">
|
PATHINFO_EXTENSION,
|
||||||
|
);
|
||||||
|
@endphp
|
||||||
|
|
||||||
<!-- PDF preview -->
|
@if (in_array($fileExtension, ['jpg', 'jpeg', 'png']))
|
||||||
@if (isset($formDenah['foto_denah']) && strpos($formDenah['foto_denah'], '.pdf') !== false)
|
<img src="{{ asset('storage/' . $denah['foto_denah']) }}"
|
||||||
<div id="pdf-preview" class="pdf-preview">
|
style="max-width: 30rem;">
|
||||||
<embed src="{{ asset('storage/' . $formDenah['foto_denah']) }}"
|
@elseif($fileExtension === 'pdf')
|
||||||
|
<embed src="{{ asset('storage/' . $denah['foto_denah']) }}"
|
||||||
type="application/pdf" width="100%" height="500px">
|
type="application/pdf" width="100%" height="500px">
|
||||||
</div>
|
@endif
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input-group w-full flex gap-2">
|
<div class="input-group w-full flex gap-2">
|
||||||
<input type="file"
|
<input type="file" name="foto_denah[]"
|
||||||
name="foto_denah" class="file-input file-input-bordered w-full"
|
class="file-input file-input-bordered w-full"
|
||||||
|
data-index="{{ $index }}" accept=".jpg,.jpeg,.png,.pdf"
|
||||||
|
onchange="previewFile(this)">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap lg:flex-nowrap w-full gap-4">
|
||||||
|
<div class="w-full">
|
||||||
|
<div class="flex flex-wrap gap-4">
|
||||||
|
<div class="flex w-full items-center justify-center gap-4">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
<span class="form-label">Nama Denah</span>
|
||||||
|
</label>
|
||||||
|
<input type="text" name="nama_denah[]" class="input w-full"
|
||||||
|
value="{{ $denah['nama_denah'] ?? '' }}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="w-full">
|
||||||
|
<div class="flex flex-wrap gap-4">
|
||||||
|
<div class="flex w-full items-center justify-center gap-4">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
<span class="form-label">Total Luas</span>
|
||||||
|
</label>
|
||||||
|
<input type="text" name="luas_denah[]"
|
||||||
|
class="input w-full number-format"
|
||||||
|
value="{{ $denah['luas_denah'] ?? '' }}"
|
||||||
|
onkeyup="formatNumber(this)">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@if ($index > 0)
|
||||||
|
<div class="flex items-center">
|
||||||
|
<button type="button" class="btn btn-danger remove-denah">
|
||||||
|
<i class="ki-filled ki-minus"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
@else
|
||||||
|
<!-- Tambahkan satu elemen default jika tidak ada data -->
|
||||||
|
<div class="denah-item grid gap-5 mb-5 border p-4 rounded">
|
||||||
|
<!-- Isi dengan elemen default seperti sebelumnya -->
|
||||||
|
<div class="flex flex-wrap gap-4">
|
||||||
|
<div class="flex w-full items-baseline flex-wrap lg:flex-nowrap gap-4">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
<span class="form-label">Upload Denah (Foto/PDF)</span>
|
||||||
|
</label>
|
||||||
|
<div class="w-full grid gap-5">
|
||||||
|
<div class="preview-container-0">
|
||||||
|
<!-- Preview akan ditampilkan di sini -->
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-group w-full flex gap-2">
|
||||||
|
<input type="file" name="foto_denah[]"
|
||||||
|
class="file-input file-input-bordered w-full" data-index="0"
|
||||||
accept=".jpg,.jpeg,.png,.pdf" onchange="previewFile(this)">
|
accept=".jpg,.jpeg,.png,.pdf" onchange="previewFile(this)">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<em id="error-foto_denah" class="alert text-danger text-sm"></em>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-2">
|
|
||||||
<div class=""max-w-4xl mx-auto bg-white rounded-lg shadow-md overflow-hidden">
|
|
||||||
|
|
||||||
|
<div class="flex flex-wrap lg:flex-nowrap w-full gap-4">
|
||||||
|
<div class="w-full">
|
||||||
<div class="flex flex-wrap gap-4">
|
<div class="flex flex-wrap gap-4">
|
||||||
<div class="flex w-full items-center justify-center gap-4">
|
<div class="flex w-full items-center justify-center gap-4">
|
||||||
|
|
||||||
<label class="form-label max-w-56">
|
<label class="form-label max-w-56">
|
||||||
<span class="form-label">Masukkan total luas tanah</span>
|
<span class="form-label">Nama Denah</span>
|
||||||
</label>
|
</label>
|
||||||
<input type="text" name="luas" class="input w-full number-format"
|
<input type="text" name="nama_denah[]" class="input w-full">
|
||||||
value="{{ old('luas', isset($formDenah['luas']) ? $formDenah['luas'] : '') }}">
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="w-full">
|
||||||
|
<div class="flex flex-wrap gap-4">
|
||||||
|
<div class="flex w-full items-center justify-center gap-4">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
<span class="form-label">Total Luas</span>
|
||||||
|
</label>
|
||||||
|
<input type="text" name="luas_denah[]" class="input w-full number-format"
|
||||||
|
onkeyup="formatNumber(this)">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<em id="error-luas" class="alert text-danger text-sm"></em>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="flex justify-end gap-2" style="margin-right: 20px; margin-top: 20px">
|
<div class="flex justify-end gap-2" style="margin-right: 20px; margin-top: 20px">
|
||||||
<button type="button" class="btn btn-success" id="saveButton" onclick="submitDenah()">
|
<button type="button" class="btn btn-success" id="saveButton" onclick="submitDenah()">
|
||||||
<span id="saveButtonText">Save</span>
|
<span id="saveButtonText">Save</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button class="btn btn-primary" type="button" id="tambahDenah">
|
||||||
|
Tambah Denah
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="loadingOverlay" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
|
|
||||||
<div class="bg-white p-4 rounded-lg">
|
|
||||||
<div class="loader"></div>
|
|
||||||
<p class="mt-2 text-center">Sedang memproses...</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@endsection
|
@endsection
|
||||||
|
|
||||||
|
|
||||||
@push('scripts')
|
@push('scripts')
|
||||||
@include('lpj::surveyor.js.utils')
|
@include('lpj::surveyor.js.utils')
|
||||||
<script>
|
<script>
|
||||||
|
const datas = @json($denah);
|
||||||
|
|
||||||
|
let denahIndex = 1; // Mulai dari 1 karena sudah ada satu elemen default
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// Format number input
|
||||||
document.querySelectorAll('.number-format').forEach(input => {
|
document.querySelectorAll('.number-format').forEach(input => {
|
||||||
input.addEventListener('input', function() {
|
input.addEventListener('input', function() {
|
||||||
formatNumber(this);
|
formatNumber(this);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Tambah Denah
|
||||||
|
document.getElementById('tambahDenah').addEventListener('click', function() {
|
||||||
|
const denahContainer = document.getElementById('denah-container');
|
||||||
|
const newDenah = createDenahElement(denahIndex);
|
||||||
|
denahContainer.appendChild(newDenah);
|
||||||
|
denahIndex++;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Event delegation untuk tombol hapus denah
|
||||||
|
document.getElementById('denah-container').addEventListener('click', function(e) {
|
||||||
|
if (e.target.closest('.remove-denah')) {
|
||||||
|
e.target.closest('.denah-item').remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function createDenahElement(index) {
|
||||||
|
const denahItem = document.createElement('div');
|
||||||
|
denahItem.className = 'denah-item grid gap-5 mb-5 border p-4 rounded';
|
||||||
|
denahItem.innerHTML = `
|
||||||
|
<div class="flex flex-wrap gap-4">
|
||||||
|
<div class="flex w-full items-baseline flex-wrap lg:flex-nowrap gap-4">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
<span class="form-label">Upload Denah (Foto/PDF)</span>
|
||||||
|
</label>
|
||||||
|
<div class="w-full grid gap-5">
|
||||||
|
<div class="preview-container-${index}">
|
||||||
|
<!-- Preview akan ditampilkan di sini -->
|
||||||
|
</div>
|
||||||
|
<div class="input-group w-full flex gap-2">
|
||||||
|
<input type="file" name="foto_denah[]"
|
||||||
|
class="file-input file-input-bordered w-full"
|
||||||
|
data-index="${index}"
|
||||||
|
accept=".jpg,.jpeg,.png,.pdf"
|
||||||
|
onchange="previewFile(this)">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-wrap lg:flex-nowrap w-full gap-4">
|
||||||
|
<div class="w-full">
|
||||||
|
<div class="flex flex-wrap gap-4">
|
||||||
|
<div class="flex w-full items-center justify-center gap-4">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
<span class="form-label">Nama Denah</span>
|
||||||
|
</label>
|
||||||
|
<input type="text" name="nama_denah[]" class="input w-full">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="w-full">
|
||||||
|
<div class="flex flex-wrap gap-4">
|
||||||
|
<div class="flex w-full items-center justify-center gap-4">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
<span class="form-label">Total Luas</span>
|
||||||
|
</label>
|
||||||
|
<input type="text" name="luas_denah[]"
|
||||||
|
class="input w-full number-format"
|
||||||
|
onkeyup="formatNumber(this)">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center">
|
||||||
|
<button type="button" class="btn btn-danger remove-denah">
|
||||||
|
<i class="ki-filled ki-minus"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
return denahItem;
|
||||||
|
}
|
||||||
|
|
||||||
function previewFile(input) {
|
function previewFile(input) {
|
||||||
const previewContainer = document.getElementById('preview-container');
|
const index = input.getAttribute('data-index');
|
||||||
const imagePreview = document.getElementById('foto_denah-preview');
|
const previewContainer = document.querySelector(`.preview-container-${index}`);
|
||||||
const file = input.files[0];
|
const file = input.files[0];
|
||||||
|
|
||||||
// Hapus preview PDF yang ada (jika ada)
|
// Hapus preview sebelumnya
|
||||||
const existingPdfPreview = document.getElementById('pdf-preview');
|
previewContainer.innerHTML = '';
|
||||||
if (existingPdfPreview) {
|
|
||||||
existingPdfPreview.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
// Cek tipe file
|
|
||||||
if (file.type.startsWith('image/')) {
|
if (file.type.startsWith('image/')) {
|
||||||
// Jika file adalah gambar
|
// Jika file adalah gambar
|
||||||
imagePreview.style.display = 'block';
|
const img = document.createElement('img');
|
||||||
|
img.style.maxWidth = '30rem';
|
||||||
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
|
|
||||||
reader.onload = function(e) {
|
reader.onload = function(e) {
|
||||||
imagePreview.src = e.target.result;
|
img.src = e.target.result;
|
||||||
imagePreview.style.width = '30rem';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.readAsDataURL(file);
|
reader.readAsDataURL(file);
|
||||||
|
|
||||||
|
previewContainer.appendChild(img);
|
||||||
} else if (file.type === 'application/pdf') {
|
} else if (file.type === 'application/pdf') {
|
||||||
// Jika file adalah PDF
|
// Jika file adalah PDF
|
||||||
imagePreview.style.display = 'none';
|
|
||||||
|
|
||||||
// Buat preview PDF
|
|
||||||
const pdfPreview = document.createElement('div');
|
|
||||||
pdfPreview.id = 'pdf-preview';
|
|
||||||
pdfPreview.className = 'pdf-preview';
|
|
||||||
|
|
||||||
const pdfEmbed = document.createElement('embed');
|
const pdfEmbed = document.createElement('embed');
|
||||||
pdfEmbed.src = URL.createObjectURL(file);
|
pdfEmbed.src = URL.createObjectURL(file);
|
||||||
pdfEmbed.type = 'application/pdf';
|
pdfEmbed.type = 'application/pdf';
|
||||||
pdfEmbed.width = '100%';
|
pdfEmbed.width = '100%';
|
||||||
pdfEmbed.height = '500px';
|
pdfEmbed.height = '500px';
|
||||||
|
pdfEmbed.className = 'pdf-preview';
|
||||||
|
|
||||||
pdfPreview.appendChild(pdfEmbed);
|
previewContainer.appendChild(pdfEmbed);
|
||||||
previewContainer.appendChild(pdfPreview);
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Jika tidak ada file yang dipilih
|
|
||||||
imagePreview.style.display = 'none';
|
|
||||||
imagePreview.src = '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function submitDenah() {
|
function submitDenah() {
|
||||||
showLoadingSwal('Mengirim data ke server...');
|
showLoadingSwal('Mengirim data ke server...');
|
||||||
@@ -222,7 +338,6 @@
|
|||||||
confirmButtonText: 'OK'
|
confirmButtonText: 'OK'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(response);
|
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
let errors = xhr.responseJSON?.errors;
|
let errors = xhr.responseJSON?.errors;
|
||||||
@@ -232,18 +347,10 @@
|
|||||||
$(`#error-${key}`).text(value[0]);
|
$(`#error-${key}`).text(value[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.error('Terjadi error:', error); // Menampilkan pesan error di konsol
|
|
||||||
console.log('Status:', status);
|
|
||||||
console.log('Response:', xhr.responseText);
|
|
||||||
console.log(errors);
|
|
||||||
hideLoadingSwal();
|
hideLoadingSwal();
|
||||||
toastrErrorBuild(error);
|
toastrErrorBuild(error);
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@include('lpj::surveyor.js.utils')
|
|
||||||
@endpush
|
@endpush
|
||||||
|
|||||||
@@ -63,17 +63,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function previewImage(input, previewId) {
|
|
||||||
if (input.files && input.files[0]) {
|
|
||||||
var reader = new FileReader();
|
|
||||||
reader.onload = function(e) {
|
|
||||||
$('#' + previewId).attr('src', e.target.result).show();
|
|
||||||
}
|
|
||||||
reader.readAsDataURL(input.files[0]);
|
|
||||||
} else {
|
|
||||||
$('#' + previewId).hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addClonableItem(containerId, itemClass) {
|
function addClonableItem(containerId, itemClass) {
|
||||||
const container = document.getElementById(containerId);
|
const container = document.getElementById(containerId);
|
||||||
|
|||||||
Reference in New Issue
Block a user