feat(dokumen): tambahkan fitur hapus detail dokumen
- Menambahkan metode `clearDetail` pada `DokumenJaminanController` untuk menghapus detail dokumen. - Menghapus file terkait saat detail dihapus. - Menambahkan tombol untuk menghapus detail pada tampilan dokumen. - Mengimplementasikan konfirmasi penghapusan menggunakan SweetAlert. - Menambahkan rute baru untuk mengakses metode `clearDetail`.
This commit is contained in:
@@ -262,7 +262,16 @@
|
||||
<label class="form-label max-w-56 font-bold">
|
||||
{{ $n + 1 }}. {{ $detail->jenisLegalitasJaminan->name }}
|
||||
</label>
|
||||
<input type="hidden" name="jenis_legalitas_jaminan_id[]" value=" {{ $detail->jenis_legalitas_jaminan_id }}">
|
||||
<input type="hidden" name="jenis_legalitas_jaminan_id[]" value="{{ $detail->jenis_legalitas_jaminan_id }}">
|
||||
<button type="button" class="btn btn-danger btn-sm" onclick="clearDetail({{ $detail->id }})">
|
||||
<i class="ki-duotone ki-trash-square fs-2">
|
||||
<span class="path1"></span>
|
||||
<span class="path2"></span>
|
||||
<span class="path3"></span>
|
||||
<span class="path4"></span>
|
||||
</i>
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
@@ -713,5 +722,75 @@
|
||||
return `<input class="input" type="text" name="custom_field[${itemId}][${fieldName}]" value="${value}">`;
|
||||
}
|
||||
}
|
||||
|
||||
function clearDetail(detailId) {
|
||||
Swal.fire({
|
||||
title: 'Apakah Anda yakin?',
|
||||
text: "Anda akan menghapus detail ini!",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Ya, yakin!',
|
||||
cancelButtonText: 'Batal'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
Swal.fire({
|
||||
title: 'Apakah Anda yakin?',
|
||||
text: "Data yang telah di hapus tidak dapat di kembalikan",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: 'Ya, hapus!',
|
||||
cancelButtonText: 'Batal'
|
||||
}).then((result2) => {
|
||||
if (result2.isConfirmed) {
|
||||
// Hapus input fields
|
||||
$(`input[name="detail_dokumen_jaminan_id[]"][value="${detailId}"]`).closest('.grid.gap-5').remove();
|
||||
|
||||
// Kirim request AJAX untuk menghapus data dari database
|
||||
$.ajax({
|
||||
url: '{{ route("debitur.jaminan.clearDetail", $debitur->id ) }}',
|
||||
type: 'POST',
|
||||
data: {
|
||||
_token: '{{ csrf_token() }}',
|
||||
detail_id: detailId
|
||||
},
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
Swal.fire({
|
||||
title: 'Berhasil!',
|
||||
text: 'Detail berhasil dihapus',
|
||||
icon: 'success',
|
||||
confirmButtonText: 'OK'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: 'Gagal!',
|
||||
text: 'Detail gagal dihapus',
|
||||
icon: 'error',
|
||||
confirmButtonText: 'OK'
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
Swal.fire({
|
||||
title: 'Gagal!',
|
||||
text: 'Terjadi kesalahan saat menghapus detail',
|
||||
icon: 'error',
|
||||
confirmButtonText: 'OK'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
Reference in New Issue
Block a user