sim_rs/resources/views/pegawai/create.blade.php
Muhammad Thoriq 7966b1f95d Set Project
2025-04-27 20:58:13 +07:00

150 lines
6.3 KiB
PHP

@extends('template.template')
@section('title', 'Dashboard')
@section('content')
<div class="card shadow-sm">
<div class="card-header">
<h3 class="card-title">TAMBAH PEGAWAI</h3>
<div class="card-toolbar gap-2">
<a href="{{ url('/pegawai') }}" class="btn btn-danger">Back</a>
</div>
</div>
<div class="card-body">
<div class="row d-flex justify-content-center">
<div class="col-md-8">
<form action="" id="form">
<div class="fv-row mb-10">
<label for="name" class="required form-label">Nama Pegawai</label>
<input type="text" name="name" id="name" class="form-control"
placeholder="Nama Pegawai" />
</div>
<div class="fv-row mb-10">
<label for="ruang_pelayanan" class="required form-label">Ruang Pelayanan</label>
<select name="ruang_pelayanan" id="ruang_pelayanan" class="form-select" data-control="select2" data-placeholder="Select an option">
<option value="" selected disabled></option>
@foreach ($ruang_pelayanan as $item)
<option value="{{ $item->id }}">{{ $item->ruang_pelayanan_name }}</option>
@endforeach
</select>
</div>
<div class="d-flex justify-content-end">
<button id="submit" class="btn btn-success">
<span class="indicator-label">
Submit
</span>
<span class="indicator-progress">
Please wait... <span class="spinner-border spinner-border-sm align-middle ms-2"></span>
</span>
</button>
</div>
</form>
</div>
</div>
</div>
</div>
@endsection
@section('custom_js')
<script>
let validator = null;
$(document).ready(function() {
const form = document.getElementById('form');
validator = FormValidation.formValidation(
form, {
fields: {
'name': {
validators: {
notEmpty: {
message: 'Name is required'
}
}
},
'ruang_pelayanan': {
validators: {
notEmpty: {
message: 'Ruang Pelayanan is required'
}
}
},
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap: new FormValidation.plugins.Bootstrap5({
rowSelector: '.fv-row',
eleInvalidClass: '',
eleValidClass: ''
})
}
}
);
$('#submit').click(function(e) {
e.preventDefault();
submit();
});
});
function submit() {
if (validator) {
validator.validate().then(function(status) {
if (status == 'Valid') {
$('#submit').attr("data-kt-indicator", "on");
$('#submit').attr("disabled", "true");
const name = $('#name').val();
const ruang_pelayanan_id = $('#ruang_pelayanan').val();
const data = {
name : name,
ruang_pelayanan_id: ruang_pelayanan_id,
_token: "{{ csrf_token() }}"
}
$.ajax({
url: "{{ url('/pegawai/store') }}",
type: "POST",
data: data,
dataType: 'JSON',
success: function(response) {
if (response.status) {
Swal.fire({
icon: "success",
text: "Data Berhasil Disimpan",
buttonsStyling: false,
confirmButtonText: "close",
customClass: {
confirmButton: "btn btn-danger"
}
}).then(() => {
window.location.href = "{{ url('/pegawai') }}";
});
}
},
error: function(xhr) {
var errorMessage = xhr.responseJSON ? xhr.responseJSON.msg : "Terjadi kesalahan!";
Swal.fire({
icon: "error",
text: errorMessage,
buttonsStyling: false,
confirmButtonText: "Close",
customClass: {
confirmButton: "btn btn-danger"
}
});
},
complete: function() {
$('#submit').removeAttr("data-kt-indicator");
$('#submit').removeAttr("disabled");
}
});
}
});
}
}
</script>
@endsection