248 lines
7.2 KiB
PHP
248 lines
7.2 KiB
PHP
<script>
|
|
// INIT FORM
|
|
function clearForm() {
|
|
$('#mForm_title').html(`Tambah Data`);
|
|
$('#mForm_subTitle').html(`Tambah Data `+title);
|
|
$('#get_id').val('');
|
|
$("#formData")[0].reset();
|
|
$('#formData').bootstrapValidator("resetForm",true);
|
|
reInitForm();
|
|
|
|
ref_merchant('mid')
|
|
$('#username').prop('readonly',false);
|
|
}
|
|
|
|
function edit(id) {
|
|
clearForm();
|
|
$('#mForm').modal('show');
|
|
znLoadingModal('mForm');
|
|
$('#mForm_title').html(`Edit Data`);
|
|
$('#mForm_subTitle').html(`Edit Data `+title);
|
|
|
|
let formData = new FormData();
|
|
formData.append('id',id);
|
|
doPost(routeEdit, formData, function (msg, res) {
|
|
console.log(res);
|
|
znLoadingModalEnd('mForm');
|
|
var data = res.data;
|
|
$('#username').prop('readonly',true);
|
|
$('#get_id').val(data.user_id);
|
|
$('#username').val(data.username);
|
|
$('#user_nm').val(data.user_nm);
|
|
$('#phone_no').val(data.phone_no);
|
|
$('#ktp').val(data.ktp);
|
|
$('#email').val(data.email);
|
|
|
|
$('#address').val(data.address);
|
|
// $('#mid').val(data.mid).trigger('change.select2');
|
|
|
|
ref_merchant('mid',data.mid,data.mid)
|
|
|
|
$('#formData').data('bootstrapValidator').validate();
|
|
})
|
|
}
|
|
|
|
|
|
|
|
function blockUser(id) {
|
|
popConfirm("Block User",
|
|
`Anda Yakin Akan Block User Ini ? `, function () {
|
|
znLoadingPage();
|
|
let formData = new FormData();
|
|
formData.append('id',id);
|
|
doPost(routeStoreCustom+'&act=blockUser', formData, function (msg, res) {
|
|
znLoadingPageEnd();
|
|
if (res == null){
|
|
znNotif("danger", msg);
|
|
}else {
|
|
if(res.rc == 0){
|
|
znNotif('success',res.rm);
|
|
table.ajax.url(routeTable).load();
|
|
}else{
|
|
znNotif("danger", res.rm);
|
|
}
|
|
}
|
|
})
|
|
});
|
|
}
|
|
|
|
|
|
function aktifUser(id) {
|
|
popConfirm("Aktifkan User",
|
|
`Anda Yakin Akan Aktifkan User Ini ? `, function () {
|
|
znLoadingPage();
|
|
let formData = new FormData();
|
|
formData.append('id',id);
|
|
doPost(routeStoreCustom+'&act=aktifkUser', formData, function (msg, res) {
|
|
znLoadingPageEnd();
|
|
if (res == null){
|
|
znNotif("danger", msg);
|
|
}else {
|
|
if(res.rc == 0){
|
|
znNotif('success',res.rm);
|
|
table.ajax.url(routeTable).load();
|
|
}else{
|
|
znNotif("danger", res.rm);
|
|
}
|
|
}
|
|
})
|
|
});
|
|
}
|
|
|
|
|
|
function resetPassword(id) {
|
|
popConfirm("Reset Password",
|
|
`Anda Yakin Akan Reset Password ? `, function () {
|
|
znLoadingPage();
|
|
let formData = new FormData();
|
|
formData.append('id',id);
|
|
doPost(routeStoreCustom+'&act=resetPassword', formData, function (msg, res) {
|
|
znLoadingPageEnd();
|
|
if (res == null){
|
|
znNotif("danger", msg);
|
|
}else {
|
|
if(res.rc == 0){
|
|
znNotif('success',res.rm);
|
|
filterTable();
|
|
}else{
|
|
znNotif("danger", res.rm);
|
|
}
|
|
}
|
|
})
|
|
});
|
|
}
|
|
|
|
function storeCustom() {
|
|
let myForm = document.getElementById('formData');
|
|
let formData = new FormData(myForm);
|
|
var isEdit = $('#get_id').val();
|
|
|
|
var $validator = $('#formData').data('bootstrapValidator').validate();
|
|
if ($validator.isValid()) {
|
|
znLoadingModal('mForm');
|
|
doPost(routeStoreCustom+'&act=storeUser', 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);
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
//VALIDASI
|
|
$(document).ready(function () {
|
|
|
|
$('#mid').on('select2:select', function (e) {
|
|
var data = e.params.data;
|
|
ref_type_user('user_type_uid',data.id);
|
|
});
|
|
|
|
$("#formData").bootstrapValidator({
|
|
excluded: [':disabled'],
|
|
feedbackIcons: {
|
|
valid: 'glyphicon glyphicon-ok',
|
|
invalid: 'glyphicon glyphicon-remove',
|
|
validating: 'glyphicon glyphicon-refresh'
|
|
},
|
|
fields: {
|
|
username: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
},
|
|
stringLength: {
|
|
max:30,
|
|
message: 'Maksimal 30 Karakter'
|
|
},
|
|
regexp: {
|
|
regexp: /^[a-z0-9_.]+$/,
|
|
message: 'Hanya Diperbolehkan huruf kecil dan angka'
|
|
}
|
|
|
|
}
|
|
},
|
|
email: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
},
|
|
emailAddress: {
|
|
message: 'format email salah'
|
|
},
|
|
stringLength: {
|
|
max:250,
|
|
message: 'Maksimal 250 Karakter'
|
|
},
|
|
}
|
|
},
|
|
user_nm: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
},
|
|
stringLength: {
|
|
max:250,
|
|
message: 'Maksimal 250 Karakter'
|
|
}
|
|
}
|
|
},
|
|
phone_no: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
}
|
|
}
|
|
},
|
|
ktp: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
}
|
|
}
|
|
},
|
|
address: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
}
|
|
}
|
|
},
|
|
user_type_uid: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
}
|
|
}
|
|
},
|
|
mid: {
|
|
validators: {
|
|
notEmpty: {
|
|
message: 'Tidak Boleh Kosong'
|
|
}
|
|
}
|
|
},
|
|
|
|
}
|
|
|
|
}).on('success.field.bv', function (e, data) {
|
|
var $parent = data.element.parents('.form-group');
|
|
$parent.removeClass('has-success');
|
|
$parent.find('.form-control-feedback[data-bv-icon-for="' + data.field + '"]').hide();
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
</script>
|