stage Form Vehicle Running Cost
This commit is contained in:
@@ -47,10 +47,6 @@
|
||||
<label class="form-label">Total</label>
|
||||
<input type="string" class="form-control" name="total" id="total" readonly value="{{ $form->total }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Bukti Total</label><br>
|
||||
<a href="{{ $form->bukti_total }}" target="_blank">Lihat Bukti</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-6">
|
||||
@@ -82,6 +78,54 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<div class="mb-4">
|
||||
<label class="form-label mb-0">Lampiran</label>
|
||||
<p class="text-muted small mt-1 mb-2">Gunakan tombol preview untuk melihat lampiran.</p>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered align-middle" id="vehicle-view-attachments-table">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width: 30%">Kategori</th>
|
||||
<th style="width: 40%">Nama File</th>
|
||||
<th style="width: 15%" class="text-center">Preview</th>
|
||||
<th style="width: 15%" class="text-center">Download</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse ($attachments as $attachment)
|
||||
<tr class="vehicle-view-attachment-row">
|
||||
<td>{{ $attachment['file_category'] ? ucwords(str_replace('_', ' ', $attachment['file_category'])) : '-' }}</td>
|
||||
<td>{{ $attachment['filename'] ?? basename($attachment['file_path']) }}</td>
|
||||
<td class="text-center">
|
||||
<button type="button"
|
||||
class="btn btn-sm btn-outline-secondary vehicle-preview-attachment"
|
||||
data-preview-url="{{ $attachment['preview_url'] }}"
|
||||
data-download-url="{{ $attachment['download_url'] }}"
|
||||
data-preview-type="{{ $attachment['preview_type'] }}"
|
||||
data-file-name="{{ $attachment['filename'] ?? basename($attachment['file_path']) }}">
|
||||
Preview
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<a href="{{ $attachment['download_url'] }}"
|
||||
target="_blank"
|
||||
class="btn btn-sm btn-outline-primary">
|
||||
Download
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr class="vehicle-view-attachments-empty text-center text-muted">
|
||||
<td colspan="4">Tidak ada lampiran.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-12">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Status</label>
|
||||
@@ -117,6 +161,12 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@include('backend.components.attachment-preview-modal', [
|
||||
'modalId' => 'vehicleViewAttachmentPreviewModal',
|
||||
'title' => 'Preview Lampiran',
|
||||
])
|
||||
|
||||
<section>
|
||||
<div class="modal fade" id="approveModal" tabindex="-1" role="dialog" aria-labelledby="approveModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg" role="document">
|
||||
@@ -304,6 +354,93 @@
|
||||
</script>
|
||||
|
||||
<script>
|
||||
function escapeHtml(value) {
|
||||
return String(value || '')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function openAttachmentModal(modalSelector, options) {
|
||||
const settings = Object.assign({
|
||||
title: 'Lampiran',
|
||||
type: 'other',
|
||||
source: null,
|
||||
downloadUrl: null,
|
||||
fileName: 'Lampiran'
|
||||
}, options || {});
|
||||
|
||||
const $modal = $(modalSelector);
|
||||
const $image = $modal.find('.attachment-preview-image');
|
||||
const $object = $modal.find('.attachment-preview-object');
|
||||
const $placeholder = $modal.find('.attachment-preview-placeholder');
|
||||
|
||||
$modal.find('.attachment-preview-modal-title').text(settings.title || 'Lampiran');
|
||||
|
||||
$image.addClass('d-none').attr('src', '');
|
||||
$object.addClass('d-none').attr('data', '').attr('src', '');
|
||||
$placeholder.removeClass('d-none').html('Tidak ada file untuk ditampilkan.');
|
||||
|
||||
if (settings.type === 'image' && settings.source) {
|
||||
$image.attr('src', settings.source).removeClass('d-none');
|
||||
$placeholder.addClass('d-none');
|
||||
} else if (settings.type === 'pdf' && settings.source) {
|
||||
$object.attr('data', settings.source).attr('src', settings.source).removeClass('d-none');
|
||||
$placeholder.addClass('d-none');
|
||||
} else {
|
||||
const safeName = escapeHtml(settings.fileName || 'Lampiran');
|
||||
let message = '<p class="mb-2">' + safeName + '</p><p class="text-muted mb-0">Preview tidak tersedia. Silakan unduh file untuk melihat konten.</p>';
|
||||
if (settings.downloadUrl) {
|
||||
message += '<div class="mt-3"><a href="' + settings.downloadUrl + '" target="_blank" class="btn btn-sm btn-outline-primary">Download</a></div>';
|
||||
}
|
||||
$placeholder.html(message);
|
||||
}
|
||||
|
||||
if (window.bootstrap && bootstrap.Modal && typeof bootstrap.Modal.getOrCreateInstance === 'function') {
|
||||
bootstrap.Modal.getOrCreateInstance($modal[0]).show();
|
||||
} else {
|
||||
$modal.modal('show');
|
||||
}
|
||||
}
|
||||
|
||||
function buildAttachmentLinks(attachments) {
|
||||
if (!attachments || !attachments.length) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
return attachments.map(function (item, index) {
|
||||
const label = escapeHtml(item.filename || item.file_category || ('Lampiran ' + (index + 1)));
|
||||
const downloadUrl = item.download_url || '#';
|
||||
return '<div><a href="' + downloadUrl + '" target="_blank">' + label + '</a></div>';
|
||||
}).join('');
|
||||
}
|
||||
|
||||
$(document).on('click', '.vehicle-preview-attachment', function () {
|
||||
const $button = $(this);
|
||||
const previewType = $button.data('preview-type') || 'other';
|
||||
const previewUrl = $button.data('preview-url') || null;
|
||||
const downloadUrl = $button.data('download-url') || null;
|
||||
const fileName = $button.data('file-name') || 'Lampiran';
|
||||
|
||||
let type = previewType;
|
||||
let source = previewUrl;
|
||||
|
||||
if (!previewUrl || (previewType !== 'image' && previewType !== 'pdf')) {
|
||||
type = 'other';
|
||||
source = null;
|
||||
}
|
||||
|
||||
openAttachmentModal('#vehicleViewAttachmentPreviewModal', {
|
||||
title: fileName,
|
||||
type: type,
|
||||
source: source,
|
||||
downloadUrl: downloadUrl,
|
||||
fileName: fileName
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.open-reject-modal', function () {
|
||||
const rejectUrl = $(this).data('action');
|
||||
$('#rejectForm').attr('action', rejectUrl);
|
||||
@@ -357,7 +494,7 @@
|
||||
$('#tipe_bensin').text(data.tipe_bensin);
|
||||
$('#nopol').text(data.nopol);
|
||||
|
||||
$('#bukti_total').html(data.total ? '<a href="' + data.total + '" target="_blank">Download</a>' : '-');
|
||||
$('#bukti_total').html(buildAttachmentLinks(data.attachments));
|
||||
|
||||
// Hide spinner and show content
|
||||
$('#loadingSpinner').hide();
|
||||
@@ -412,7 +549,7 @@
|
||||
$('#final_tipe_bensin').text(data.tipe_bensin);
|
||||
$('#final_nopol').text(data.nopol);
|
||||
|
||||
$('#final_bukti_total').html(data.bukti_total ? '<a href="' + data.bukti_total + '" target="_blank">Download</a>' : '-');
|
||||
$('#final_bukti_total').html(buildAttachmentLinks(data.attachments));
|
||||
|
||||
// Hide spinner and show content
|
||||
$('#finalLoadingSpinner').hide();
|
||||
|
||||
Reference in New Issue
Block a user