130 lines
6.0 KiB
PHP
130 lines
6.0 KiB
PHP
<div
|
|
class="offcanvas offcanvas-end"
|
|
tabindex="-1"
|
|
id="offcanvasUpdateKolom"
|
|
aria-labelledby="offcanvasUpdateKolomLabel">
|
|
<div class="offcanvas-header border-bottom">
|
|
<h5 id="offcanvasUpdateKolomLabel" class="offcanvas-title">Update Kolom</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 class="add-new-kolom pt-0" id="updateKolomForm" action="{{ route('tabel.kolom.update', [$tabel->id, ':id']) }}" method="POST">
|
|
@csrf
|
|
@method('PUT')
|
|
|
|
<input type="hidden" id="update-kolom-id" name="id" />
|
|
|
|
<div class="mb-6 form-control-validation">
|
|
<label class="form-label" for="update-kolom-nama">Nama Kolom<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="update-kolom-nama" name="kolom" placeholder="Cth: Nama Petani" />
|
|
</div>
|
|
<div class="mb-6 form-control-validation">
|
|
<label class="form-label" for="update-kolom-label">Label<span class="text-danger">*</span></label>
|
|
<input type="text" class="form-control" id="update-kolom-label" name="label" placeholder="Cth: Nama Petani" />
|
|
</div>
|
|
<div class="mb-6 form-control-validation">
|
|
<label class="form-label" for="update-kolom-jenis_data">Jenis Data<span class="text-danger">*</span></label>
|
|
<select class="form-select" id="update-kolom-jenis_data" name="tipe">
|
|
<option value="">Pilih Jenis Data</option>
|
|
<option value="varchar">Varchar</option>
|
|
<option value="integer">Integer</option>
|
|
<option value="float">Float</option>
|
|
<option value="boolean">Boolean</option>
|
|
<option value="date">Date</option>
|
|
<option value="datetime">Datetime</option>
|
|
<option value="text">Text</option>
|
|
</select>
|
|
</div>
|
|
<div class="mb-6 form-control-validation">
|
|
<label class="form-label" for="update-kolom-validasi">Validasi<span class="text-danger">*</span></label>
|
|
<textarea class="form-control" id="update-kolom-validasi" name="validasi" value="1" placeholder="Cth: required"></textarea>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-success me-3 data-submit">Simpan</button>
|
|
<button type="reset" class="btn btn-label-danger" data-bs-dismiss="offcanvas">Batal</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
@push('scripts')
|
|
<script>
|
|
$(document).ready(function() {
|
|
|
|
|
|
$('#update-kolom-jenis_data').select2({
|
|
dropdownParent: $('#offcanvasUpdateKolom'),
|
|
width: '100%',
|
|
});
|
|
|
|
$.validator.addMethod("snakecase", function(value, element) {
|
|
return this.optional(element) || /^[a-z0-9]+(_[a-z0-9]+)*$/.test(value);
|
|
}, "Gunakan format snake_case (huruf kecil dan underscore)");
|
|
|
|
const offcanvasUpdate = new bootstrap.Offcanvas(document.getElementById('offcanvasUpdateKolom'));
|
|
$(".edit-record").click(function () {
|
|
const id = $(this).data('id');
|
|
console.log("Edit record with ID:", id);
|
|
|
|
const editForm = $('#updateKolomForm');
|
|
editForm.validate().resetForm();
|
|
editForm.find('.is-invalid').removeClass('is-invalid');
|
|
|
|
$.get("{{ route('tabel.kolom.show', [$tabel->id, ':id']) }}".replace(':id', id), function (res) {
|
|
if (res.status === 'success') {
|
|
console.log("Data kolom:", res.data);
|
|
$('#update-kolom-id').val(res.data.id);
|
|
$('#update-kolom-nama').val(res.data.kolom);
|
|
$('#update-kolom-label').val(res.data.label);
|
|
$('#update-kolom-jenis_data').val(res.data.tipe).trigger('change');
|
|
$('#update-kolom-validasi').val(res.data.required ? 'required' : '');
|
|
offcanvasUpdate.show();
|
|
}
|
|
});
|
|
});
|
|
|
|
$('#updateKolomForm').validate({
|
|
rules: {
|
|
kolom: { required: true, snakecase: true },
|
|
label: { required: true },
|
|
tipe: { required: true }
|
|
},
|
|
messages: {
|
|
kolom: { required: "Kolom wajib diisi", snakecase: "Gunakan format snake_case (huruf kecil dan underscore)" },
|
|
label: { required: "Label wajib diisi" },
|
|
tipe: { required: "Jenis data wajib diisi" }
|
|
},
|
|
submitHandler: function (form) {
|
|
$.ajax({
|
|
url: $(form).attr('action').replace(':id', $('#update-kolom-id').val()),
|
|
type: 'PUT',
|
|
data: $(form).serialize(),
|
|
success: function () {
|
|
offcanvasUpdate.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' });
|
|
}
|
|
});
|
|
},
|
|
errorElement: 'div',
|
|
errorPlacement: function (error, element) {
|
|
error.addClass('invalid-feedback');
|
|
element.closest('.mb-6, .form-control-validation').append(error);
|
|
},
|
|
highlight: function (element) {
|
|
$(element).addClass('is-invalid');
|
|
},
|
|
unhighlight: function (element) {
|
|
$(element).removeClass('is-invalid');
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
@endpush |