pos-gis/resources/views/content/user/action.blade.php

326 lines
9.0 KiB
PHP
Raw Permalink Normal View History

2024-10-07 06:13:42 +00:00
<script type="text/javascript">
// INIT
var routeTable = "{{$table}}";
var tableHead = "{{$head}}";
var col = tableHead.split(',');
var colum = [];
col.forEach((c,k) => { var v = {};v['data'] = col[k]; colum.push(v); });
var columStyle =
[
{ "orderable": false, "targets": [-1] }
];
var table = znGetTable(routeTable,colum,columStyle,'indexTable');
// INIT
function generate() {
$('#key').val(znRandomString(128));
$('#formData').data('bootstrapValidator').validate();
$('#formData').bootstrapValidator('revalidateField', 'key');
}
function isMerchant(id) {
if (id == 2) {
$('#viewMerchant').show()
$('#mid').prop('disabled',false);
}else{
$('#viewMerchant').hide()
$('#mid').prop('disabled',true);
}
}
function isPemda(id) {
if (id == 3) {
$('#viewKota').show()
$('#id_kota').prop('disabled',false);
}else{
$('#viewKota').hide()
$('#id_kota').prop('disabled',true);
}
}
$(document).ready(function () {
$('#role').on('select2:select', function (e) {
var data = e.params.data;
isMerchant(data.id)
isPemda(data.id)
});
$('#formData').on('keyup keypress', function (e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) {
e.preventDefault();
return false;
}
});
$("#formData").bootstrapValidator({
excluded: [':disabled'],
fields: {
role: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
id_kota: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
mid: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
email: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
},
emailAddress: {
message: 'format email salah'
}
}
},
address: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
},
stringLength: {
min:10,
max:250,
message: 'Minimal 10 Karakter Maksimal 250 Karakter'
}
}
},
full_name: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
},
stringLength: {
min:2,
max:20,
message: 'Minimal 2 Karakter Maksimal 20 Karakter'
}
}
},
phone: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
}
}
},
username: {
validators: {
notEmpty: {
message: 'Tidak Boleh Kosong'
},
stringLength: {
min:2,
max:20,
message: 'Minimal 2 Karakter Maksimal 20 Karakter'
}
}
}
}
}).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();
});
})
function clearForm() {
$('#get_id').val('');
$("#formData")[0].reset();
$('#formData').bootstrapValidator("resetForm",true);
reInitForm();
$('#viewMerchant').hide()
$('#key').attr('readonly',true)
$('#username').prop('readonly',false);
}
function store() {
let myForm = document.getElementById('formData');
let formData = new FormData(myForm);
var isEdit = $('#get_id').val();
var $validator_budget = $('#formData').data('bootstrapValidator').validate();
if ($validator_budget.isValid()) {
znLoadingModal('mForm');
doPost('/user/act_any/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();
$('#mForm').modal('show');
znLoadingModal('mForm');
$('#mForm_title').html(`Edit Data`);
$('#mForm_subTitle').html(`Edit Data User`);
console.log(id);
let formData = new FormData();
formData.append('id',id);
doPost('/user/act_any/get_user_detail', formData, function (msg, res) {
znLoadingModalEnd('mForm');
console.log(res.data);
var data = res.data;
$('#username').prop('readonly',true);
$('#get_id').val(data.id);
$('#email').val(data.email);
$('#full_name').val(data.full_name);
$('#username').val(data.username);
$('#phone').val(data.phone);
$('#address').val(data.address);
$('#role').val(data.role).trigger('change.select2');
$('#mid').val(data.mid).trigger('change.select2');
$('#id_kota').val(data.id_kota).trigger('change.select2');
isMerchant(data.role)
isPemda(data.role)
$('#formData').data('bootstrapValidator').validate();
})
}
function refreshTable() {
table.ajax.url(routeTable).load();
}
function del(id) {
popConfirm("Hapus Data",
`Anda Yakin Akan Menghapus Data ? `, function () {
znLoadingPage();
let formData = new FormData();
formData.append('id',id);
doPost('/user/act_any/user_delete', 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 blockUser(id) {
popConfirm("Block User",
`Anda Yakin Akan Block User Ini ? `, function () {
znLoadingPage();
let formData = new FormData();
formData.append('id',id);
doPost('/user/act_any/user_block', 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('/user/act_any/user_aktif', 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('/user/act_any/user_reset_password', 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);
}
}
})
});
}
</script>