191 lines
6.8 KiB
PHP
191 lines
6.8 KiB
PHP
<script>
|
|
var validator;
|
|
var routeTable = '{{ $table }}';
|
|
var colum = [
|
|
{data: 'member_name', name: 'member_name'},
|
|
{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 Perusahaan`);
|
|
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 Perusahaan`);
|
|
let formData = new FormData();
|
|
formData.append('id',id);
|
|
doPost(base_url+'company/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)
|
|
$('#company_name').val(res.data.company_name)
|
|
$('#company_code').val(res.data.company_code)
|
|
$('#address').val(res.data.address)
|
|
$('#phone_no').val(res.data.phone_no)
|
|
$('#email').val(res.data.email)
|
|
$('#pic_name').val(res.data.pic_name)
|
|
$('#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+'company/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+'company/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'
|
|
}
|
|
}
|
|
},
|
|
company_name: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Wajib diisi!'
|
|
}
|
|
}
|
|
},
|
|
company_code: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Wajib diisi!'
|
|
}
|
|
}
|
|
},
|
|
address: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Wajib diisi!'
|
|
}
|
|
}
|
|
},
|
|
pic_name: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Wajib diisi!'
|
|
}
|
|
}
|
|
},
|
|
},
|
|
plugins: {
|
|
trigger: new FormValidation.plugins.Trigger(),
|
|
bootstrap: new FormValidation.plugins.Bootstrap()
|
|
}
|
|
}
|
|
);
|
|
})
|
|
</script> |