88 lines
3.9 KiB
PHP
88 lines
3.9 KiB
PHP
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasEditProgram" aria-labelledby="offcanvasEditProgramLabel">
|
|
<div class="offcanvas-header border-bottom">
|
|
<h5 id="offcanvasEditProgramLabel" class="offcanvas-title">Edit Program</h5>
|
|
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Tutup"></button>
|
|
</div>
|
|
|
|
<div class="offcanvas-body mx-0 flex-grow-0 p-6 h-100">
|
|
<form id="editProgramForm" class="pt-0" method="POST" action="{{ route('program.update', ':id') }}">
|
|
@csrf
|
|
@method('PUT')
|
|
|
|
<input type="hidden" id="edit-program-id" name="id" />
|
|
|
|
<div class="mb-6 form-control-validation">
|
|
<label class="form-label" for="edit-program-name">Nama Program<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="edit-program-name" name="nama" />
|
|
</div>
|
|
|
|
<div class="mb-6 form-control-validation">
|
|
<label class="form-label" for="edit-program-subdomain">Sub Domain</label>
|
|
<textarea class="form-control" id="edit-program-subdomain" name="sub_domain" rows="3"></textarea>
|
|
</div>
|
|
|
|
<div class="mb-6 form-control-validation">
|
|
<label class="form-label" for="edit-program-tahun">Tahun<span class="text-danger">*</span></label>
|
|
<input type="number" id="edit-program-tahun" class="form-control" name="tahun" />
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary me-3">Update Data</button>
|
|
<button type="reset" class="btn btn-label-danger" data-bs-dismiss="offcanvas">Tutup</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
@push('scripts')
|
|
<script>
|
|
'use strict';
|
|
|
|
$(document).ready(function () {
|
|
const offcanvasEdit = new bootstrap.Offcanvas(document.getElementById('offcanvasEditProgram'));
|
|
|
|
$('.edit-record').click(function (e) {
|
|
e.preventDefault();
|
|
const id = $(this).data('id');
|
|
|
|
$.get("{{ route('program.show', ':id') }}".replace(':id', id), function (res) {
|
|
$('#edit-program-id').val(res.data.id);
|
|
$('#edit-program-name').val(res.data.nama);
|
|
$('#edit-program-subdomain').val(res.data.sub_domain);
|
|
$('#edit-program-tahun').val(res.data.tahun);
|
|
offcanvasEdit.show();
|
|
}).fail(function (xhr) {
|
|
Swal.fire({ icon: 'error', title: 'Gagal!', text: xhr.responseJSON?.message || 'Error' });
|
|
});
|
|
});
|
|
|
|
$('#editProgramForm').validate({
|
|
rules: {
|
|
nama: { required: true },
|
|
sub_domain: { required: true },
|
|
tahun: { required: true, number: true }
|
|
},
|
|
messages: {
|
|
nama: { required: "Nama provinsi wajib diisi" },
|
|
sub_domain: { required: "Sub domain wajib diisi" },
|
|
tahun: { required: "Tahun wajib diisi", number: "Harus berupa angka" }
|
|
},
|
|
submitHandler: function (form) {
|
|
const id = $('#edit-program-id').val();
|
|
$.ajax({
|
|
url: $(form).attr('action').replace(':id', id),
|
|
type: 'POST',
|
|
data: $(form).serialize(),
|
|
success: function () {
|
|
offcanvasEdit.hide();
|
|
form.reset();
|
|
Swal.fire({ icon: 'success', title: 'Berhasil!', showConfirmButton: false, timer: 1500 })
|
|
.then(() => window.location.reload());
|
|
},
|
|
error: function (xhr) {
|
|
Swal.fire({ icon: 'error', title: 'Gagal!', text: xhr.responseJSON?.message || 'Error' });
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
@endpush |