diff --git a/resources/views/produktivitas/petani/lahan/add.blade.php b/resources/views/produktivitas/petani/lahan/add.blade.php index f4e4ebb..2f0e8a5 100644 --- a/resources/views/produktivitas/petani/lahan/add.blade.php +++ b/resources/views/produktivitas/petani/lahan/add.blade.php @@ -815,7 +815,7 @@ let originalText = submitBtn.html(); submitBtn.prop('disabled', true).html(' Menyimpan...'); - $.ajax({ + $.ajax({ url: $(form).attr('action'), type: "POST", data: formData, @@ -826,8 +826,15 @@ 'Accept': 'application/json' }, success: function(res) { - alert('Data lahan berhasil ditambahkan!'); - window.location.href = "{{ route('petani.index') }}"; + Swal.fire({ + icon: 'success', + title: 'Berhasil!', + text: 'Data lahan berhasil ditambahkan.', + showConfirmButton: false, + timer: 1500 + }).then(() => { + window.location.href = "{{ route('petani.index') }}"; + }); }, error: function(xhr) { submitBtn.prop('disabled', false).html(originalText); @@ -838,15 +845,26 @@ $.each(errors, function(key, val) { errorMsg += val[0] + "\n"; }); - alert("Penyimpanan Gagal:\n\n" + errorMsg); + + Swal.fire({ + icon: 'warning', + title: 'Penyimpanan Gagal', + text: errorMsg, + confirmButtonColor: '#dc3545' + }); } else { let errorDetail = xhr.responseJSON && xhr.responseJSON.message ? xhr.responseJSON.message : xhr.statusText; - alert("Error " + xhr.status + ": " + errorDetail); + + Swal.fire({ + icon: 'error', + title: 'Terjadi Kesalahan', + text: "Error " + xhr.status + ": " + errorDetail, + confirmButtonColor: '#dc3545' + }); console.error(xhr.responseText); } } }); - return false; } }); diff --git a/resources/views/produktivitas/petani/lahan/edit.blade.php b/resources/views/produktivitas/petani/lahan/edit.blade.php index 3a79981..4e1d1e5 100644 --- a/resources/views/produktivitas/petani/lahan/edit.blade.php +++ b/resources/views/produktivitas/petani/lahan/edit.blade.php @@ -836,8 +836,6 @@ } }); - - // FORM VALIDATION & SUBMIT $('#petani-lahan-tanaman').validate({ rules: { luas_lahan: { required: true }, @@ -884,8 +882,8 @@ submitBtn.prop('disabled', true).html(' Menyimpan...'); $.ajax({ - url: $(form).attr('action'), - type: "POST", + url: $(form).attr('action'), + type: "POST", data: formData, processData: false, contentType: false, @@ -894,8 +892,15 @@ 'Accept': 'application/json' }, success: function(res) { - alert('Data lahan berhasil disimpan!'); - window.location.href = "{{ route('petani.index') }}"; + Swal.fire({ + icon: 'success', + title: 'Berhasil!', + text: 'Data lahan berhasil disimpan.', + showConfirmButton: false, + timer: 1500 + }).then(() => { + window.location.href = "{{ route('petani.index') }}"; + }); }, error: function(xhr) { submitBtn.prop('disabled', false).html(originalText); @@ -906,10 +911,22 @@ $.each(errors, function(key, val) { errorMsg += val[0] + "\n"; }); - alert("Penyimpanan Gagal:\n\n" + errorMsg); + + Swal.fire({ + icon: 'warning', + title: 'Penyimpanan Gagal', + text: errorMsg, + confirmButtonColor: '#dc3545' + }); } else { let errorDetail = xhr.responseJSON && xhr.responseJSON.message ? xhr.responseJSON.message : xhr.statusText; - alert("Error " + xhr.status + ": " + errorDetail); + + Swal.fire({ + icon: 'error', + title: 'Terjadi Kesalahan', + text: "Error " + xhr.status + ": " + errorDetail, + confirmButtonColor: '#dc3545' + }); console.error(xhr.responseText); } }