chess/resources/views/content/ref/ref_action_global.blade.php

123 lines
4.0 KiB
PHP
Raw Normal View History

2024-08-29 03:56:32 +00:00
<script>
var routeStore = "{{$store}}";
var routeEdit = "{{$edit}}";
var routeDelete = "{{$delete}}";
var routeTable = "{{$table}}";
var tableHead = "{{$head}}";
var tableHeadAlias = "{{$headAlias}}";
var title = "{{$title}}";
var routeStoreCustom = '{{ $storeCustom }}';
var validation;
var col = tableHead.split(',');
/* if (tableHeadAlias) {
var colAlias = tableHeadAlias.split(',');
} */
var colum = [];
col.forEach((c,k) => {
var v = {};
v['data'] = col[k];
/* if (tableHeadAlias) {
v['name'] = colAlias[k];
} */
colum.push(v);
});
var columStyle =
[
{ "orderable": false, "targets": [-1] },
];
var table = znGetTableScrolling(routeTable,colum,columStyle,'indexTable', 34);
function store() {
let myForm = document.getElementById('formData');
let formData = new FormData(myForm);
var isEdit = $('#get_id').val();
if(!isEdit){
formData.append('is_active','t');
}
validation.validate().then(function(status) {
if(status == 'Valid') {
popConfirm("Konfirmasi",
'<div class="mt-2">Yakin Akan Menyimpan Data Ini ?</div>',function() {
znLoadingModal('mForm');
doPost(routeStore, 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 setActive(id, isActive) {
console.log(isActive);
if (isActive == true) {
var titleSwal = `Non Aktif ${title}`;
var textSwal = `Anda yakin akan menonaktifkan ${title} ini?`;
} else {
var titleSwal = `Aktif ${title}`;
var textSwal = `Anda yakin akan mengaktifkan ${title} ini?`;
}
popConfirm(titleSwal,textSwal, function () {
znLoadingPage();
let formData = new FormData();
formData.append('id',id);
formData.append('active',isActive);
doPost(routeSetActive, 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 hapus(id) {
popConfirm("Konfirmasi",
'<div class="mt-2">Yakin Akan Menghapus Data Ini ?</div>',function() {
znLoadingPage();
let formData = new FormData();
formData.append('id',id);
doPost(routeDelete, 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>