uncomment fungsi submit inspeksi

This commit is contained in:
majid
2024-12-04 13:35:33 +07:00
parent ab0b402884
commit 405dc82ac6
2 changed files with 57 additions and 62 deletions

View File

@@ -417,11 +417,11 @@ class SurveyorController extends Controller
} }
// If validation passes, update permohonan status // If validation passes, update permohonan status
// $permohonan = Permohonan::findOrFail($id); $permohonan = Permohonan::findOrFail($id);
// $permohonan->update([ $permohonan->update([
// 'status' => 'done', 'status' => 'done',
// 'submitted_at' => now() 'submitted_at' => now()
// ]); ]);
return response()->json([ return response()->json([
'success' => true, 'success' => true,

View File

@@ -145,70 +145,65 @@
function submitData() { function submitData() {
const loadingOverlay = document.getElementById('loadingOverlay'); const loadingOverlay = document.getElementById('loadingOverlay');
loadingOverlay.classList.remove('hidden'); loadingOverlay.classList.remove('hidden');
loadingOverlay.classList.add('flex'); loadingOverlay.classList.add('flex');
const formElement = $('#formInspeksi')[0]; const formElement = $('#formInspeksi')[0];
const formData = new FormData(formElement); const formData = new FormData(formElement);
formData.forEach((value, key) => {
console.log(key, value); $.ajax({
url: '{{ route('surveyor.store') }}',
type: 'POST',
data: formData,
processData: false,
contentType: false,
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
success: function(response) {
if (response.success) {
Swal.fire({
title: 'Berhasil!',
text: response.message,
icon: 'success',
confirmButtonText: 'OK'
}).then((response) => {
if (response.isConfirmed) {
window.location.href =
'{{ route('surveyor.show', ['id' => $permohonan->id]) }}';
}
});
} else {
Swal.fire({
title: 'Error!',
text: response.message || 'Terjadi kesalahan',
icon: 'error',
confirmButtonText: 'OK'
});
}
console.log(response);
},
error: function(xhr, status, error) {
let errors = xhr.responseJSON?.errors;
$('.alert').text('');
if (errors) {
$.each(errors, function(key, value) {
$(`#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);
toastrErrorBuild(error);
},
complete: function() {
// Re-enable the button and hide the spinner
loadingOverlay.classList.add('hidden');
loadingOverlay.classList.remove('flex');
}
}); });
// $.ajax({
// url: '{{ route('surveyor.store') }}',
// type: 'POST',
// data: formData,
// processData: false,
// contentType: false,
// headers: {
// 'X-CSRF-TOKEN': '{{ csrf_token() }}'
// },
// success: function(response) {
// if (response.success) {
// Swal.fire({
// title: 'Berhasil!',
// text: response.message,
// icon: 'success',
// confirmButtonText: 'OK'
// }).then((response) => {
// if (response.isConfirmed) {
// window.location.href =
// '{{ route('surveyor.show', ['id' => $permohonan->id]) }}';
// }
// });
// } else {
// Swal.fire({
// title: 'Error!',
// text: response.message || 'Terjadi kesalahan',
// icon: 'error',
// confirmButtonText: 'OK'
// });
// }
// console.log(response);
// },
// error: function(xhr, status, error) {
// let errors = xhr.responseJSON?.errors;
// $('.alert').text('');
// if (errors) {
// $.each(errors, function(key, value) {
// $(`#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);
// toastrErrorBuild(error);
// },
// complete: function() {
// // Re-enable the button and hide the spinner
// loadingOverlay.classList.add('hidden');
// loadingOverlay.classList.remove('flex');
// }
// });
} }
function previewImage(input, previewId) { function previewImage(input, previewId) {