253 lines
8.5 KiB
PHP
253 lines
8.5 KiB
PHP
@extends('layout.main')
|
|
|
|
@section('content')
|
|
<div class="container-xxl flex-grow-1 container-p-y">
|
|
|
|
<div class="card mb-4">
|
|
<div class="card-header border-bottom d-flex justify-content-between align-items-center pt-4 pb-3">
|
|
<h5 class="mb-0">Edit Kelompok Belajar Tani</h5>
|
|
|
|
@php
|
|
$badgeColor = $kelompok->status == 'aktif'
|
|
? 'bg-label-success'
|
|
: 'bg-label-danger';
|
|
@endphp
|
|
|
|
<span class="badge {{ $badgeColor }}">
|
|
Status: {{ ucfirst($kelompok->status) }}
|
|
</span>
|
|
</div>
|
|
|
|
<form action="{{ route('kelompok-belajar-tani.update', $kelompok->id) }}"
|
|
method="POST"
|
|
id="formEditKelompok">
|
|
|
|
@csrf
|
|
@method('PUT')
|
|
|
|
<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-8">
|
|
<label class="form-label" for="nama_kelompok">
|
|
Nama Kelompok <span class="text-danger">*</span>
|
|
</label>
|
|
|
|
<input type="text"
|
|
class="form-control @error('nama_kelompok') is-invalid @enderror"
|
|
id="nama_kelompok"
|
|
name="nama_kelompok"
|
|
placeholder="Masukkan nama kelompok..."
|
|
value="{{ old('nama_kelompok', $kelompok->nama_kelompok) }}"
|
|
required>
|
|
|
|
@error('nama_kelompok')
|
|
<div class="invalid-feedback">
|
|
{{ $message }}
|
|
</div>
|
|
@enderror
|
|
</div>
|
|
|
|
{{-- STATUS --}}
|
|
<div class="col-md-4">
|
|
<label class="form-label" for="status">
|
|
Status <span class="text-danger">*</span>
|
|
</label>
|
|
|
|
<select class="form-select @error('status') is-invalid @enderror"
|
|
id="status"
|
|
name="status"
|
|
required>
|
|
|
|
<option value="aktif"
|
|
{{ old('status', $kelompok->status) == 'aktif' ? 'selected' : '' }}>
|
|
Aktif
|
|
</option>
|
|
|
|
<option value="nonaktif"
|
|
{{ old('status', $kelompok->status) == 'nonaktif' ? 'selected' : '' }}>
|
|
Nonaktif
|
|
</option>
|
|
|
|
</select>
|
|
|
|
@error('status')
|
|
<div class="invalid-feedback">
|
|
{{ $message }}
|
|
</div>
|
|
@enderror
|
|
</div>
|
|
|
|
{{-- DESKRIPSI --}}
|
|
<div class="col-12">
|
|
<label class="form-label" for="deskripsi">
|
|
Deskripsi
|
|
</label>
|
|
|
|
<textarea class="form-control @error('deskripsi') is-invalid @enderror"
|
|
id="deskripsi"
|
|
name="deskripsi"
|
|
rows="4"
|
|
placeholder="Masukkan deskripsi kelompok...">{{ old('deskripsi', $kelompok->deskripsi) }}</textarea>
|
|
|
|
@error('deskripsi')
|
|
<div class="invalid-feedback">
|
|
{{ $message }}
|
|
</div>
|
|
@enderror
|
|
</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">
|
|
|
|
Batal
|
|
</a>
|
|
|
|
<button type="submit"
|
|
class="btn btn-primary px-4">
|
|
|
|
<i class="ti tabler-device-floppy me-1"></i>
|
|
Simpan Perubahan
|
|
</button>
|
|
</div>
|
|
|
|
</form>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script>
|
|
'use strict';
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
const formEditKelompok = document.getElementById('formEditKelompok');
|
|
|
|
if(formEditKelompok) {
|
|
|
|
formEditKelompok.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 |