176 lines
6.5 KiB
PHP
176 lines
6.5 KiB
PHP
<script>
|
|
var validator;
|
|
var routeTable = '{{ $table }}';
|
|
var colum = [
|
|
{data: 'member_name', name: 'member_name'},
|
|
{data: 'address', name: 'address'},
|
|
// {data: 'address', name: 'address'},
|
|
// {data: 'phone_no', name: 'phone_no'},
|
|
// {data: 'pic_name', name: 'pic_name'},
|
|
// {data: 'user_code', name: 'user_code'},
|
|
{data: 'action', name: 'action'},
|
|
];
|
|
|
|
var columStyle =
|
|
[
|
|
{ "orderable": false, "targets": [-1] },
|
|
];
|
|
|
|
var table = znGetTableScrolling(routeTable,colum,columStyle,'indexTable');
|
|
|
|
function clearForm() {
|
|
$('#get_id').val('');
|
|
$("#formData")[0].reset();
|
|
validator.resetForm();
|
|
$('#mForm_title').html(`Tambah Data`);
|
|
$('#mForm_subTitle').html(`Tambah Data Client`);
|
|
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 edit(id) {
|
|
clearForm();
|
|
znLoadingPage();
|
|
$('#mForm_title').html(`Edit Data`);
|
|
$('#mForm_subTitle').html(`Edit Data Client`);
|
|
let formData = new FormData();
|
|
formData.append('id',id);
|
|
doPost(base_url+'client/get/'+id, formData, function (msg, res) {
|
|
znLoadingPageEnd()
|
|
let imageUrl = '{{asset('assets/media/logos/no_img.png')}}';
|
|
if(res.data.logo_url){
|
|
imageUrl = res.data.logo_url;
|
|
$('#ava1').css("background-image", "url('" + imageUrl + "')");
|
|
}
|
|
$('#get_id').val(res.data.id)
|
|
$('#client_name').val(res.data.client_name)
|
|
$('#address').val(res.data.address)
|
|
var active = res.is_active?'true':'false';
|
|
$('#is_active').val(active).trigger('change.select2')
|
|
$('#mForm').modal('show');
|
|
});
|
|
}
|
|
|
|
function detail(id) {
|
|
znLoadingPage();
|
|
$('#mFormDet_title').html(`Detail Data`);
|
|
$('#mFormDet_subTitle').html(`Detail Data Perusahaan`);
|
|
let formData = new FormData();
|
|
formData.append('id',id);
|
|
doPost(base_url+'client/get/'+id, formData, function (msg, res) {
|
|
znLoadingPageEnd()
|
|
let imageUrl = '{{asset('assets/media/logos/no_img.png')}}';
|
|
if(res.data.logo_url){
|
|
imageUrl = res.data.logo_url;
|
|
$('#ava1_det').css("background-image", "url(" + imageUrl + ")");
|
|
}
|
|
$('#company_name_det').html(res.data.company_name)
|
|
$('#company_code_det').html(res.data.company_code)
|
|
$('#address_det').html(res.data.address)
|
|
$('#phone_no_det').html(res.data.phone_no)
|
|
$('#email_det').html(res.data.email)
|
|
$('#pic_name_det').html(res.data.pic_name)
|
|
$('#list_user_company').html(``)
|
|
$.each(res.list_user, function(k, v) {
|
|
$('#list_user_company').append(`
|
|
<div class="col-md-4">
|
|
<div class="form-group">
|
|
<div class="font-weight-bolder font-size-md">- ${v.full_name} (${v.user_code})</div>
|
|
</div>
|
|
</div>
|
|
`)
|
|
})
|
|
$('#mFormDet').modal('show');
|
|
});
|
|
}
|
|
|
|
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+'client/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);
|
|
}
|
|
}
|
|
})
|
|
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
$(document).ready(function () {
|
|
validator = FormValidation.formValidation(
|
|
KTUtil.getById('formData'),
|
|
{
|
|
fields: {
|
|
logo_url: {
|
|
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'
|
|
}
|
|
}
|
|
},
|
|
client_name: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Wajib diisi!'
|
|
}
|
|
}
|
|
},
|
|
address: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Wajib diisi!'
|
|
}
|
|
}
|
|
},
|
|
},
|
|
plugins: {
|
|
trigger: new FormValidation.plugins.Trigger(),
|
|
bootstrap: new FormValidation.plugins.Bootstrap()
|
|
}
|
|
}
|
|
);
|
|
})
|
|
</script> |