188 lines
6.0 KiB
PHP
188 lines
6.0 KiB
PHP
|
<script>
|
||
|
var routeStore = "{{$store}}";
|
||
|
var routeEdit = "{{$edit}}";
|
||
|
var routeSetActive = "{{$setActive}}";
|
||
|
var routeDelete = "{{$delete}}";
|
||
|
var routeStoreCustom = "{{$storeCustom}}";
|
||
|
var routeImportXls = "{{$import_xls}}"
|
||
|
|
||
|
var routeTable = "{{$table}}";
|
||
|
var tableHead = "{{$head}}";
|
||
|
var title = "{{$title}}";
|
||
|
var userRole = "{{Auth::guard('admin')->user()->role}}"
|
||
|
var userMID = "{{Auth::guard('admin')->user()->mid}}"
|
||
|
|
||
|
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');
|
||
|
|
||
|
// STORE ADD AND EDIT
|
||
|
function store() {
|
||
|
|
||
|
let myForm = document.getElementById('formData');
|
||
|
let formData = new FormData(myForm);
|
||
|
var isEdit = $('#get_id').val();
|
||
|
|
||
|
if(!isEdit){
|
||
|
formData.append('is_active','t');
|
||
|
}
|
||
|
|
||
|
var $validator = $('#formData').data('bootstrapValidator').validate();
|
||
|
if ($validator.isValid()) {
|
||
|
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 refreshTable() {
|
||
|
table.ajax.url(routeTable).load();
|
||
|
}
|
||
|
|
||
|
function actImportExcel() {
|
||
|
let myForm = document.getElementById('formDataExcel');
|
||
|
let formData = new FormData(myForm);
|
||
|
|
||
|
var $validator = $('#formDataExcel').data('bootstrapValidator').validate();
|
||
|
if ($validator.isValid()) {
|
||
|
$('#viewValidate').hide();
|
||
|
znLoadingModal('mImport');
|
||
|
doPost(routeImportXls, formData, function (msg, data) {
|
||
|
console.log(data);
|
||
|
znLoadingModalEnd('mImport');
|
||
|
if (data == null){
|
||
|
znNotif("danger", msg);
|
||
|
}else {
|
||
|
if(data.rc == 0){
|
||
|
znNotif('success','Berhasil Menyimpan Data');
|
||
|
$('#mImport').modal('hide');
|
||
|
table.ajax.url(routeTable).load();
|
||
|
}else{
|
||
|
$("#formDataExcel")[0].reset();
|
||
|
$('#formDataExcel').bootstrapValidator("resetForm",true);
|
||
|
$('#viewValidate').show();
|
||
|
$('#resultValidate').html(data.msg);
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function importExcel() {
|
||
|
$('#mImport').modal('show');
|
||
|
$('#viewValidate').hide();
|
||
|
$("#formDataExcel")[0].reset();
|
||
|
$('#formDataExcel').bootstrapValidator("resetForm",true);
|
||
|
}
|
||
|
|
||
|
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) {
|
||
|
var titleSwal = `Hapus Data`;
|
||
|
var textSwal = `Anda yakin akan Hapus ini?`;
|
||
|
|
||
|
popConfirm(titleSwal,textSwal, 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);
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
});
|
||
|
}
|
||
|
|
||
|
$(document).ready(function () {
|
||
|
|
||
|
$('#berkala_startDate').datepicker({
|
||
|
rtl: KTUtil.isRTL(),
|
||
|
orientation: "bottom left",
|
||
|
todayHighlight: false,
|
||
|
format: 'dd-mm-yyyy',
|
||
|
autoclose: true,
|
||
|
}).on('changeDate', function (selected) {
|
||
|
var minDate = new Date(selected.date.valueOf());
|
||
|
$('#berkala_endDate').datepicker('setStartDate', minDate);
|
||
|
$("#berkala_endDate").datepicker().datepicker("setDate", minDate);
|
||
|
});
|
||
|
|
||
|
$('#berkala_endDate').datepicker({
|
||
|
rtl: KTUtil.isRTL(),
|
||
|
orientation: "bottom left",
|
||
|
todayHighlight: false,
|
||
|
format: 'dd-mm-yyyy',
|
||
|
autoclose: true,
|
||
|
});
|
||
|
|
||
|
$('#formData').on('keypress', function (e) {
|
||
|
var keyCode = e.keyCode || e.which;
|
||
|
if (keyCode === 13) {
|
||
|
e.preventDefault();
|
||
|
document.getElementById("znBtnLoader").click();
|
||
|
}
|
||
|
});
|
||
|
})
|
||
|
|
||
|
|
||
|
|
||
|
</script>
|