update kelompok belajar
This commit is contained in:
@@ -0,0 +1,266 @@
|
||||
@extends('layout.main')
|
||||
|
||||
@section('content')
|
||||
<div class="container-xxl flex-grow-1 container-p-y">
|
||||
|
||||
<div class="card mb-4">
|
||||
|
||||
{{-- HEADER --}}
|
||||
<div class="card-header border-bottom d-flex justify-content-between align-items-center pt-4 pb-3">
|
||||
<h5 class="mb-0">Tambah Kelompok Belajar Petani</h5>
|
||||
|
||||
<span class="badge bg-label-primary">
|
||||
Data Baru
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{{-- FORM --}}
|
||||
<form action="{{ route('kelompok-belajar-tani.store') }}"
|
||||
method="POST"
|
||||
id="formAddKelompok">
|
||||
|
||||
@csrf
|
||||
|
||||
<div class="card-body pt-4">
|
||||
|
||||
{{-- INFORMASI DASAR --}}
|
||||
<div class="mb-4">
|
||||
|
||||
<div class="d-flex align-items-center mb-3">
|
||||
<i class="ti tabler-users-group me-2 text-primary"></i>
|
||||
|
||||
<h6 class="fw-medium mb-0 text-uppercase">
|
||||
Informasi Kelompok
|
||||
</h6>
|
||||
</div>
|
||||
|
||||
<div class="row g-4">
|
||||
|
||||
{{-- NAMA KELOMPOK --}}
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" for="nama_kelompok">
|
||||
Nama Kelompok <span class="text-danger">*</span>
|
||||
</label>
|
||||
|
||||
<input type="text"
|
||||
class="form-control"
|
||||
id="nama_kelompok"
|
||||
name="nama_kelompok"
|
||||
placeholder="Masukkan nama kelompok..."
|
||||
value="{{ old('nama_kelompok') }}"
|
||||
required>
|
||||
</div>
|
||||
|
||||
{{-- STATUS --}}
|
||||
<div class="col-md-6">
|
||||
<label class="form-label" for="status">
|
||||
Status <span class="text-danger">*</span>
|
||||
</label>
|
||||
|
||||
<select class="form-select"
|
||||
id="status"
|
||||
name="status"
|
||||
required>
|
||||
|
||||
<option value="" disabled selected>
|
||||
-- Pilih Status --
|
||||
</option>
|
||||
|
||||
<option value="aktif">
|
||||
Aktif
|
||||
</option>
|
||||
|
||||
<option value="nonaktif">
|
||||
Nonaktif
|
||||
</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{{-- DESKRIPSI --}}
|
||||
<div class="col-12">
|
||||
<label class="form-label" for="deskripsi">
|
||||
Deskripsi
|
||||
</label>
|
||||
|
||||
<textarea class="form-control"
|
||||
id="deskripsi"
|
||||
name="deskripsi"
|
||||
rows="4"
|
||||
placeholder="Masukkan deskripsi kelompok...">{{ old('deskripsi') }}</textarea>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{{-- ALERT --}}
|
||||
<div class="col-12 mt-4">
|
||||
|
||||
<div class="alert alert-label-info d-flex align-items-center border-0 mb-0"
|
||||
role="alert">
|
||||
|
||||
<span class="alert-icon me-2">
|
||||
<i class="ti ti-info-circle ti-xs"></i>
|
||||
</span>
|
||||
|
||||
<div>
|
||||
Pastikan data kelompok belajar tani yang dimasukkan sudah benar sebelum disimpan.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{{-- FOOTER --}}
|
||||
<div class="card-footer border-top pt-4 pb-4 d-flex justify-content-end gap-3 bg-lighter">
|
||||
|
||||
<a href="{{ route('kelompok-belajar-tani.index') }}"
|
||||
class="btn btn-label-secondary">
|
||||
|
||||
Kembali
|
||||
</a>
|
||||
|
||||
<button type="submit"
|
||||
class="btn btn-primary px-4">
|
||||
|
||||
<i class="ti tabler-device-floppy me-1"></i>
|
||||
Simpan Kelompok
|
||||
</button>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
const formAddKelompok = document.getElementById('formAddKelompok');
|
||||
|
||||
if(formAddKelompok) {
|
||||
|
||||
formAddKelompok.addEventListener('submit', function(e) {
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
let form = this;
|
||||
let formData = new FormData(form);
|
||||
|
||||
let submitBtn = form.querySelector('button[type="submit"]');
|
||||
let originalBtnText = submitBtn.innerHTML;
|
||||
|
||||
// Disable tombol
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.innerHTML =
|
||||
'<span class="spinner-border spinner-border-sm me-2"></span> Menyimpan...';
|
||||
|
||||
fetch(form.action, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(async response => {
|
||||
|
||||
const isJson = response.headers.get('content-type')
|
||||
?.includes('application/json');
|
||||
|
||||
const data = isJson ? await response.json() : null;
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
const error =
|
||||
(data && data.message)
|
||||
|| response.statusText;
|
||||
|
||||
return Promise.reject({
|
||||
status: response.status,
|
||||
data: data,
|
||||
message: error
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
})
|
||||
.then(data => {
|
||||
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.innerHTML = originalBtnText;
|
||||
|
||||
if (data.status === 'success') {
|
||||
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Berhasil!',
|
||||
text: data.message,
|
||||
showConfirmButton: false,
|
||||
timer: 2000,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-primary'
|
||||
},
|
||||
buttonsStyling: false
|
||||
}).then(() => {
|
||||
|
||||
window.location.href =
|
||||
"{{ route('kelompok-belajar-tani.index') }}";
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.innerHTML = originalBtnText;
|
||||
|
||||
let errorMsg =
|
||||
'Terjadi kesalahan saat menyimpan data.';
|
||||
|
||||
if (
|
||||
error.status === 422
|
||||
&& error.data
|
||||
&& error.data.errors
|
||||
) {
|
||||
|
||||
errorMsg = Object.values(error.data.errors)
|
||||
.map(err => err.join(', '))
|
||||
.join('<br>');
|
||||
|
||||
} else if (
|
||||
error.data
|
||||
&& error.data.message
|
||||
) {
|
||||
|
||||
errorMsg = error.data.message;
|
||||
}
|
||||
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Data Tidak Valid',
|
||||
html: errorMsg,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-primary'
|
||||
},
|
||||
buttonsStyling: false
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
Reference in New Issue
Block a user