update form others
This commit is contained in:
@@ -65,50 +65,61 @@
|
||||
<label class="form-label">Tanggal <span class="font-italic font-weight-normal">(required)</span></label>
|
||||
<input type="date" class="form-control" name="tanggal" id="tanggal" required value="{{ old('tanggal') }}">
|
||||
</div>
|
||||
|
||||
<!-- Add field -->
|
||||
|
||||
<!-- <div class="mb-3">
|
||||
<label class="form-label">Nama Penerima <span class="font-italic font-weight-normal">(required)</span></label>
|
||||
<input type="text" class="form-control" name="name" required value="{{ old('name') }}">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">NPWP / NIK <span class="font-italic font-weight-normal">(required)</span></label>
|
||||
<input type="text" class="form-control" name="nik_or_npwp" id="nik_or_npwp" required value="{{ old('nik_or_npwp') }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Alamat <span class="font-italic font-weight-normal">(required)</span></label>
|
||||
<input type="text" class="form-control" name="alamat" id="alamat" required value="{{ old('alamat') }}">
|
||||
</div> -->
|
||||
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="col-lg-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Total <span class="font-italic font-weight-normal">(required)</span></label>
|
||||
<input type="string" class="form-control" name="total" id="total" required value="{{ old('total') }}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Bukti Total <span class="font-italic font-weight-normal">(required)</span></label>
|
||||
<input type="file" class="form-control" name="bukti_total" value="{{ old('bukti_total') }}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Keterangan <span class="font-italic font-weight-normal">(required)</span></label>
|
||||
<textarea class="form-control" name="keterangan" id="keterangan" required>{{ old('keterangan') }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<!-- </div> -->
|
||||
<button type="submit" class="btn btn-primary ml-2">Submit</button>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-12">
|
||||
<div class="mb-3">
|
||||
<div class="d-flex align-items-center justify-content-between">
|
||||
<label class="form-label mb-0">Lampiran</label>
|
||||
<button type="button" class="btn btn-outline-primary btn-sm" id="other-add-attachment-row">
|
||||
<i class="fas fa-plus mr-1"></i> Tambah Lampiran
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-muted small mt-1 mb-2">
|
||||
Maksimal 10 MB per file. Tidak diperbolehkan mengunggah file berformat <code>.exe</code>, <code>.dll</code>, <code>.sh</code>, <code>.bat</code>, <code>.cmd</code>, atau <code>.msi</code>.
|
||||
</p>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered align-middle" id="other-attachments-table">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th style="width: 30%">Kategori</th>
|
||||
<th style="width: 45%">Lampiran</th>
|
||||
<th style="width: 15%" class="text-center">Preview</th>
|
||||
<th style="width: 10%" class="text-center">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="other-attachments-empty text-center text-muted">
|
||||
<td colspan="4">Belum ada lampiran.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-primary ml-2">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@include('backend.components.attachment-preview-modal', [
|
||||
'modalId' => 'otherAttachmentPreviewModal',
|
||||
'title' => 'Preview Lampiran',
|
||||
])
|
||||
|
||||
<div id="loading-spinner-overlay" class="d-none">
|
||||
<div class="spinner-wrapper">
|
||||
<div class="spinner-border text-primary" role="status">
|
||||
@@ -123,19 +134,264 @@
|
||||
|
||||
<script>
|
||||
new AutoNumeric('#total', {
|
||||
digitGroupSeparator: '.', // Pemisah ribuan
|
||||
decimalCharacter: ',', // Karakter desimal (tidak digunakan karena tanpa desimal)
|
||||
currencySymbol: 'Rp.', // Simbol mata uang
|
||||
decimalPlaces: 0, // Tidak ada angka desimal
|
||||
unformatOnSubmit: true // Nilai asli tanpa format saat dikirimkan
|
||||
digitGroupSeparator: '.',
|
||||
decimalCharacter: ',',
|
||||
currencySymbol: 'Rp.',
|
||||
decimalPlaces: 0,
|
||||
unformatOnSubmit: true
|
||||
});
|
||||
|
||||
document.getElementById('expense-form').addEventListener('submit', function (e) {
|
||||
const spinnerOverlay = document.getElementById('loading-spinner-overlay');
|
||||
spinnerOverlay.classList.remove('d-none'); // Show overlay
|
||||
spinnerOverlay.classList.add('d-flex'); // Use flexbox for centering
|
||||
const spinnerOverlay = document.getElementById('loading-spinner-overlay');
|
||||
|
||||
document.getElementById('expense-form').addEventListener('submit', function () {
|
||||
spinnerOverlay.classList.remove('d-none');
|
||||
spinnerOverlay.classList.add('d-flex');
|
||||
});
|
||||
|
||||
const attachmentCategories = @json($attachmentCategories ?? ($otherAttachmentCategories ?? []));
|
||||
const blockedExtensions = ['exe', 'dll', 'sh', 'bat', 'cmd', 'msi'];
|
||||
const maxFileSizeBytes = 10 * 1024 * 1024;
|
||||
const otherAttachmentEmptyRow = '<tr class="other-attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran.</td></tr>';
|
||||
let otherAttachmentIndex = 0;
|
||||
|
||||
function escapeHtml(value) {
|
||||
return String(value || '')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function categoryToLabel(value) {
|
||||
if (!value) {
|
||||
return 'Pilih Kategori';
|
||||
}
|
||||
return value.replace(/_/g, ' ').replace(/\b\w/g, function (char) {
|
||||
return char.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
function detectPreviewType(extension) {
|
||||
const images = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
|
||||
if (images.indexOf(extension) !== -1) {
|
||||
return 'image';
|
||||
}
|
||||
if (extension === 'pdf') {
|
||||
return 'pdf';
|
||||
}
|
||||
return 'other';
|
||||
}
|
||||
|
||||
function buildCategoryOptions() {
|
||||
return attachmentCategories.map(function (category) {
|
||||
return '<option value="' + category + '">' + escapeHtml(categoryToLabel(category)) + '</option>';
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function setInlinePreview($row, type, source) {
|
||||
const $box = $row.find('.other-attachment-inline-preview');
|
||||
$box.removeClass('bg-light').html('<i class="fas fa-file-upload text-muted"></i>');
|
||||
|
||||
if (type === 'image' && source) {
|
||||
$box.addClass('bg-light').html(
|
||||
'<img src="' + source + '" class="img-thumbnail" style="width:100%;height:100%;object-fit:cover;" alt="Preview">'
|
||||
);
|
||||
} else if (type === 'pdf') {
|
||||
$box.addClass('bg-light').html('<i class="fas fa-file-pdf text-danger fa-lg"></i>');
|
||||
} else if (type === 'other') {
|
||||
$box.addClass('bg-light').html('<i class="fas fa-file-alt text-secondary fa-lg"></i>');
|
||||
}
|
||||
}
|
||||
|
||||
function resetAttachmentRowData($row, clearInput = true) {
|
||||
const existingUrl = $row.data('objectUrl');
|
||||
if (existingUrl) {
|
||||
URL.revokeObjectURL(existingUrl);
|
||||
}
|
||||
|
||||
$row.removeData('objectUrl')
|
||||
.removeData('previewType')
|
||||
.removeData('previewSource')
|
||||
.removeData('previewFileName');
|
||||
|
||||
setInlinePreview($row, null, null);
|
||||
$row.find('.other-preview-attachment').addClass('d-none');
|
||||
$row.find('.other-preview-filename').text('');
|
||||
|
||||
if (clearInput) {
|
||||
$row.find('.other-attachment-file').val('');
|
||||
}
|
||||
}
|
||||
|
||||
function openAttachmentModal(modalSelector, options) {
|
||||
const settings = Object.assign({
|
||||
title: 'Lampiran',
|
||||
type: 'other',
|
||||
source: 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');
|
||||
}
|
||||
|
||||
if (window.bootstrap && bootstrap.Modal && typeof bootstrap.Modal.getOrCreateInstance === 'function') {
|
||||
bootstrap.Modal.getOrCreateInstance($modal[0]).show();
|
||||
} else {
|
||||
$modal.modal('show');
|
||||
}
|
||||
}
|
||||
|
||||
function addOtherAttachmentRow() {
|
||||
const $tbody = $('#other-attachments-table tbody');
|
||||
|
||||
if ($tbody.find('.other-attachments-empty').length) {
|
||||
$tbody.empty();
|
||||
}
|
||||
|
||||
const index = otherAttachmentIndex++;
|
||||
const rowHtml = `
|
||||
<tr class="other-attachment-row" data-index="${index}">
|
||||
<td>
|
||||
<select class="form-control other-attachment-category" name="attachments[${index}][file_category]" required>
|
||||
<option value="">${escapeHtml(categoryToLabel(''))}</option>
|
||||
${buildCategoryOptions()}
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="other-attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white mr-2" style="width:56px;height:56px;">
|
||||
<i class="fas fa-file-upload text-muted"></i>
|
||||
</div>
|
||||
<input type="file" class="form-control other-attachment-file" name="attachments[${index}][file_path]">
|
||||
</div>
|
||||
<div class="small text-muted mt-1 other-preview-filename"></div>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary other-preview-attachment d-none">
|
||||
Preview
|
||||
</button>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<button type="button" class="btn btn-sm btn-outline-danger other-remove-attachment-row">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
|
||||
$tbody.append(rowHtml);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
$('#other-add-attachment-row').on('click', function () {
|
||||
addOtherAttachmentRow();
|
||||
});
|
||||
|
||||
$(document).on('click', '.other-remove-attachment-row', function () {
|
||||
const $row = $(this).closest('tr');
|
||||
const $tbody = $('#other-attachments-table tbody');
|
||||
resetAttachmentRowData($row, true);
|
||||
$row.remove();
|
||||
|
||||
if (!$tbody.find('.other-attachment-row').length) {
|
||||
$tbody.html(otherAttachmentEmptyRow);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('change', '.other-attachment-file', function () {
|
||||
const $input = $(this);
|
||||
const $row = $input.closest('tr');
|
||||
const previewButton = $row.find('.other-preview-attachment');
|
||||
const filenameHolder = $row.find('.other-preview-filename');
|
||||
|
||||
resetAttachmentRowData($row, false);
|
||||
filenameHolder.text('');
|
||||
|
||||
const file = this.files && this.files[0];
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.size > maxFileSizeBytes) {
|
||||
alert('Ukuran file melebihi 10 MB.');
|
||||
$input.val('');
|
||||
return;
|
||||
}
|
||||
|
||||
const extension = (file.name.split('.').pop() || '').toLowerCase();
|
||||
if (blockedExtensions.indexOf(extension) !== -1) {
|
||||
alert('Tipe file tidak diperbolehkan.');
|
||||
$input.val('');
|
||||
return;
|
||||
}
|
||||
|
||||
filenameHolder.text(escapeHtml(file.name));
|
||||
|
||||
const previewType = detectPreviewType(extension);
|
||||
$row.data('previewType', previewType);
|
||||
$row.data('previewFileName', file.name);
|
||||
$row.data('previewSource', null);
|
||||
$row.removeData('objectUrl');
|
||||
|
||||
if (previewType === 'image') {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function (event) {
|
||||
const source = event.target.result;
|
||||
$row.data('previewSource', source);
|
||||
setInlinePreview($row, previewType, source);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
} else if (previewType === 'pdf') {
|
||||
const objectUrl = URL.createObjectURL(file);
|
||||
$row.data('previewSource', objectUrl);
|
||||
$row.data('objectUrl', objectUrl);
|
||||
setInlinePreview($row, previewType, null);
|
||||
} else {
|
||||
const objectUrl = URL.createObjectURL(file);
|
||||
$row.data('previewSource', objectUrl);
|
||||
$row.data('objectUrl', objectUrl);
|
||||
setInlinePreview($row, 'other', null);
|
||||
}
|
||||
|
||||
previewButton.removeClass('d-none');
|
||||
});
|
||||
|
||||
$(document).on('click', '.other-preview-attachment', function () {
|
||||
const $row = $(this).closest('tr');
|
||||
const previewType = $row.data('previewType') || 'other';
|
||||
const previewSource = $row.data('previewSource') || null;
|
||||
const fileName = $row.data('previewFileName') || 'Lampiran';
|
||||
|
||||
if (previewType === 'image' || previewType === 'pdf') {
|
||||
openAttachmentModal('#otherAttachmentPreviewModal', {
|
||||
title: fileName,
|
||||
type: previewType,
|
||||
source: previewSource,
|
||||
fileName: fileName
|
||||
});
|
||||
} else if (previewSource) {
|
||||
window.open(previewSource, '_blank');
|
||||
}
|
||||
});
|
||||
|
||||
addOtherAttachmentRow();
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
Reference in New Issue
Block a user