chess/resources/views/content/others/user/action.blade.php
Ramadhon Ikhsan Prasetya 603e31b0f4 init
2024-08-29 10:56:32 +07:00

226 lines
8.4 KiB
PHP

<script>
var routeTable = '{{ $table }}';
var validator;
var colum = [
{data: 'member_name', name: 'member_name'},
{data: 'email', name: 'email'},
{data: 'role_name', name: 'role_name'},
{data: 'division_name', name: 'division_name'},
{data: 'is_active', name: 'is_active'},
{data: 'client_name', name: 'client_name'},
{data: 'action', name: 'action'},
];
var columStyle =
[
{ "orderable": false, "targets": [-1] },
];
var table = znGetTableScrolling(routeTable,colum,columStyle,'indexTable');
$(document).ready(function () {
validator = FormValidation.formValidation(
KTUtil.getById('formData'),
{
fields: {
foto_profil: {
validators: {
callback: {
callback: function(input) {
var get_id = $('#get_id').val();
if(get_id=='' && input.value=='') {
return {
valid: false,
message: 'Wajib diisi',
}
}
return true;
}
},
file: {
extension: 'jpg,jpeg,png',
type: 'image/jpg,image/jpeg,image/png',
maxSize: 0.25 * (1024*1024),
message: 'File Tidak Sesuai'
}
}
},
email: {
validators: {
notEmpty: {
message: 'Wajib diisi!'
},
emailAddress: {
message: 'Format Email Salah'
}
}
},
full_name: {
validators: {
notEmpty: {
message: 'Wajib diisi!'
}
}
},
user_code: {
validators: {
notEmpty: {
message: 'Wajib diisi!'
}
}
},
role_id: {
validators: {
notEmpty: {
message: 'Wajib diisi!'
}
}
},
client_id: {
validators: {
callback: {
message: 'Wajib diisi!',
callback: function(input) {
console.log(input.value)
if(($('#role_id').val()==4 || $('#role_id').val()==1) && input.value=='') {
return {
valid: false,
message: 'Wajib diisi!'
}
}
return true
}
}
}
}
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap: new FormValidation.plugins.Bootstrap()
}
}
);
$('#role_id').on('change', function(e) {
datarole = $(this).find('option:selected').data('isexternal');
console.log(datarole)
$('#is_external_v').val(datarole)
if(datarole) {
// $('#client_id').next(".select2-container").show()
$('#division_div').show()
$('#client_div').show()
} else {
// $('#client_id').next(".select2-container").hide()
$('#division_div').show()
$('#client_div').hide()
}
})
})
function clearForm() {
$('#get_id').val('');
$("#formData")[0].reset();
validator.resetForm();
$('#mForm_title').html(`Tambah Data`);
$('#mForm_subTitle').html(`Tambah Data User`);
$('#client_div').hide()
$('#division_div').hide()
$('#role_id').trigger('change')
reInitForm();
clearImage();
var avatar2 = new KTImageInput('kt_image_2');
}
function clearImage() {
let imageUrl = '{{asset('assets/media/logos/no_img.png')}}';
$('#ava1').css("background-image", "url(" + imageUrl + ")");
$('#produk_pic').val('');
$('#pic-cancel').hide();
}
function store() {
validator.validate().then(function(status) {
if(status=='Valid') {
popConfirm("Konfirmasi Proses",
`<div class="mt-2">Yakin Akan Menyimpan Data Ini ?</div>`, function () {
let myForm = document.getElementById('formData');
let formData = new FormData(myForm);
var isEdit = $('#get_id').val();
znLoadingModal('mForm');
doPost(base_url+'user/store', formData, function (msg, data) {
console.log(data);
znLoadingModalEnd('mForm');
if (data == null){
znNotif("danger", msg);
}else {
if(data.rc == 0){
znNotif('success','Berhasil Menyimpan Data');
$('#mForm').modal('hide');
table.ajax.url(routeTable).load();
}else{
znNotif("danger", data.rm);
}
}
})
});
}
});
}
function edit(id) {
clearForm();
znLoadingPage();
$('#mForm_title').html(`Edit Data`);
$('#mForm_subTitle').html(`Edit Data User`);
let formData = new FormData();
formData.append('id',id);
doPost(base_url+'user/get/'+id, formData, function (msg, res) {
znLoadingPageEnd()
let imageUrl = '{{asset('assets/media/logos/no_img.png')}}';
if(res.image_url){
imageUrl = res.image_url;
$('#ava1').css("background-image", "url('" + imageUrl + "')");
}
$('#get_id').val(res.id)
$('#full_name').val(res.full_name)
$('#email').val(res.email)
$('#user_code').val(res.user_code)
// $('#phone_number').val(res.phone_number)
// $('#unit_id').val(res.unit_id).trigger('change.select2')
$('#client_id').val(res.client_id).trigger('change.select2')
$('#role_id').val(res.role_id).trigger('change.select2')
var active = res.is_active?'true':'false';
$('#is_active').val(active).trigger('change.select2')
$('#mForm').modal('show');
});
}
function hapus(id) {
popConfirm("Konfirmasi Proses",
`<div class="mt-2">Yakin Akan Menghapus Data Ini ?</div>`, function () {
let formData = new FormData();
formData.append('id', id);
znLoadingPage()
doPost(base_url+'user/delete', formData, function (msg, data) {
console.log(data);
znLoadingPageEnd()
if (data == null){
znNotif("danger", msg);
}else {
if(data.rc == 0){
znNotif('success','Berhasil Menghapus Data');
$('#mForm').modal('hide');
table.ajax.url(routeTable).load();
}else{
znNotif("danger", data.rm);
}
}
})
});
}
</script>