${groupEnd}
`;
}
}
}).join(" ")
this.data.htmlForm = formP;
return this;
},newData: function(){
var t = this.data.id;
var htmlForm = this.data.htmlForm;
var title = this.data.title;
var cari = "cari-"+t;
var idN = "tambah-"+t;
var simpan = "simpan"+t;
var close = "close"+t;
var hapus = "hapus"+t;
var idM = "#modal"+t;
var idm = "m"+t;
var update = "[data-update"+t+"]";
var dataUpdate = "data-update"+t;
var loadForm = this;
var pagination = this.data.pagination;
var tbl = this.data.table;
var startPage = this.data.pagination[this.data.table];
var totPage = this.data.totData[tbl];
var bataspagin = this.data.bataspagin;
if (document.getElementById(cari) != undefined) {
document.getElementById(cari).addEventListener('keypress', function(e){
if (e.key === 'Enter') {
loadForm.data.pagination[loadForm.data.table] = 0;
loadForm.data.search = this.value;
loadForm.load();
}
}, false)
}
document.getElementById(close).addEventListener('click', function(){
if (loadForm.data.backFunc != undefined) {
document.getElementById('load-'+tableName).innerHTML = `
Loading...
please wait...>
`;
loadForm.data.backFunc(loadForm);
}else{
loadForm.load();
}
},false)
document.getElementById("prev-"+t).addEventListener('click', function(){
if ((Number(startPage) - bataspagin) < 0) {
Swal.fire('anda berada di halaman awal', '', 'info')
}else{
pagination[loadForm.data.table] = startPage - bataspagin;
loadForm.load();
}
},false)
document.getElementById("next-"+t).addEventListener('click', function(){
if ((Number(startPage) + bataspagin) >= Number(totPage)) {
Swal.fire('anda berada di halaman akhir', '', 'info')
}else{
pagination[loadForm.data.table] = startPage + bataspagin;
loadForm.load();
}
},false)
Array.from(document.querySelectorAll(update)).forEach(function(elupdate, i){
elupdate.addEventListener('click', function(){
document.getElementById(hapus).style.display = 'inline-block';
var tF = 'form-get-app'+t;
var getData = binary2text(this.getAttribute(dataUpdate));
for(const elpsd of Object.keys(getData)){
if (getData[elpsd] == null) {
delete getData[elpsd];
}
}
loadForm.data.loadDataEdit = getData;
loadForm.data.idUpdate = true;
document.getElementById(idm).innerText = 'Ubah '+title;
document.querySelector('.form-e').style.display = 'none';
document.querySelector('.form-d').style.display = 'block';
var htmlForm = loadForm.data.htmlForm
document.getElementById(tF).innerHTML = htmlForm;
setTimeout(function(){
Object.keys(loadForm.data.objform).forEach(function(e){
if(loadForm.data.objform[e].type == 'number'){
document.getElementById(e).addEventListener('keyup', function(){
var eva = this.value;
eva = eva.replace(/\./g, '');
this.value = formatRupiah(eva);
}, false)
}
if(loadForm.data.objform[e].change != undefined){
document.getElementById(e).addEventListener('change', loadForm.data.objform[e].change, false);
}
})
function decodeHtml(text) {
return text
.replace(/&/g, '&')
.replace(/</g , '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g,"'");
}
loadForm.data.idData.forEach(function(pol){
if (getData[pol] != null) {
if(loadForm.data.objform[pol].type == "number"){
var numx = Number(getData[pol]).toFixed(0).toString();
document.getElementById(pol).value = formatRupiah(numx);
}else if(loadForm.data.objform[pol].type == "select"){
var table = dataMaster[loadForm.data.objform[pol].table];
var val = loadForm.data.objform[pol].value;
var vw = loadForm.data.objform[pol].view;
table = table.filter(function(es){
if (es[val] == getData[pol]) {
return es;
}
})
var tab = null;
var ops = "";
var names = " pilih data ";
if (table.length > 0) {
tab = table[0];
ops = tab[val];
names = vw.map(function(elop){
return tab[elop];
}).join(' ');
}
document.getElementById(pol).innerHTML = ``;
}else if(loadForm.data.objform[pol].type == "note"){
var tp = JSON.parse(decodeHtml(getData[pol]));
tp = binary2text(tp.kontent);
document.getElementById(pol).value = tp;
}else{
document.getElementById(pol).value = decodeHtml(getData[pol]);
}
}
})
if (loadForm.data.onupdate != undefined) {
loadForm.data.onupdate(loadForm, getData, new db);
}
setTimeout(function(){
document.getElementById(loadForm.data.idData[0]).focus();
},500)
setTimeout(function(){
if (loadForm.data.equals != undefined) {
for(const eq of loadForm.data.equals){
document.getElementById(eq).addEventListener('keyup', loadForm.data.delay(function(){
var getVals = []
var n = 0;
for(const es of loadForm.data.equals){
var vals = document.getElementById(es).value.replace(/\"/g, "\\\"");
if (n == 0) {
getVals.push({
opsi: "", data : [es, '=', `"${vals}"`]
})
}else{
getVals.push({
opsi: "AND", data : [es, '=', `"${vals}"`]
})
}
n++;
}
db()
.table(loadForm.data.table)
.condition(getVals)
.get(function(a, b){
if (Number(b) > 0 ) {
var keysRow = Object.keys(loadForm.data.objform);
var objUpdt = {}
for(const lpp of keysRow){
if (loadForm.data.objform[lpp].type == "select") {
document.getElementById(lpp).value = a[0][lpp];
$('#'+lpp).val(a[0][lpp]).trigger('change');
}else if(loadForm.data.objform[lpp].type == "number"){
document.getElementById(lpp).value = formatRupiah(a[0][lpp]);
}else{
document.getElementById(lpp).value = a[0][lpp];
}
objUpdt[lpp] = a[0][lpp];
}
if (loadForm.data.onupdate != undefined) {
loadForm.data.onupdate(loadForm, a, new db);
}
document.getElementById(idm).innerText = 'Ubah '+title;
loadForm.data.loadDataEdit = objUpdt;
loadForm.data.idUpdate = true;
document.getElementById(hapus).style.display = 'inline-block';
}else{
document.getElementById(idm).innerText = 'Tambah '+title;
loadForm.data.loadDataEdit = {};
loadForm.data.idUpdate = null;
document.getElementById(hapus).style.display = 'none';
var keysRow = Object.keys(loadForm.data.objform);
for(const lpp of keysRow){
if (loadForm.data.equals.indexOf(lpp) == -1) {
document.getElementById(lpp).value = '';
if (loadForm.data.oncreate != undefined) {
loadForm.data.oncreate(loadForm, new db);
}
if (loadForm.data.objform[lpp].type == "select") {
$('#'+lpp).val(null).trigger('change');
}
}
}
}
})
},500), false)
}
}
document.getElementById(loadForm.data.idData[0]).focus()
for(const dataid of loadForm.data.idData){
if(loadForm.data.objform[dataid].type == 'note' || loadForm.data.objform[dataid].type == 'textarea'){
$('#'+dataid).summernote();
var s = Array.from(document.querySelectorAll('.note-editable'))
for (const yi of s) {
yi.addEventListener('focus', function(){
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}, false)
}
}
if(loadForm.data.objform[dataid].type == 'select'){
document.getElementById(dataid).addEventListener('focus', function(){
if(loadForm.data.objform[dataid].relation != undefined){
document.getElementById('choice-'+dataid).innerHTML = globalThis.listdata[dataid](null, loadForm.data.objform[dataid].relation);
globalThis.actionListUpdate[dataid]();
}
if (loadForm.data.objform[dataid].relationChange == undefined) {
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
document.getElementById('choice-'+dataid).style.display = 'grid';
document.getElementById('search-choice-'+dataid).style.display = 'block';
document.getElementById('search-choice-'+dataid).style.width = document.getElementById('choice-'+dataid).offsetWidth+'px';
document.getElementById('search-choice-'+dataid).focus();
document.getElementById('search-choice-'+dataid).addEventListener('blur', function(){
setTimeout(function(){
document.querySelector('#choice-'+dataid).style.display = 'none';
document.querySelector('#search-choice-'+dataid).style.display = 'none';
},200)
}, false)
function posx(){
var clientX = document.getElementById(dataid);
clientX = Array.from(clientX.getClientRects())[0].x / window.innerWidth * 100;
var positionProsent = Math.round(clientX);
if(positionProsent >= 50){
document.getElementById('search-choice-'+dataid).style.right = '10px';
document.getElementById('search-choice-'+dataid).style.left = 'auto';
document.getElementById('choice-'+dataid).style.right = '10px';
document.getElementById('choice-'+dataid).style.left = 'auto';
document.getElementById('search-choice-'+dataid).addEventListener('blur', function(){
setTimeout(function(){
document.querySelector('#choice-'+dataid).style.display = 'none';
document.querySelector('#search-choice-'+dataid).style.display = 'none';
},200)
}, false)
}
}
posx()
window.onresize = function(){
posx()
}
}else{
var idRelation = loadForm.data.objform[dataid].relationChange;
var dataParent = dataMaster[dataid];
var parenCode = loadForm.data.objform[dataid].value;
var parenView = loadForm.data.objform[dataid].view;
var mainid = loadForm.data.objform[dataid].relationId;
var kodemain = loadForm.data.objform[dataid].value;
var main = loadForm.data.objform[idRelation].table;
var kode = loadForm.data.objform[idRelation].value;
var getVal = document.getElementById(idRelation).value;
var dataMain = dataMaster[main].filter(function(lop){
if (lop[kode] == getVal) {
return lop
}
});
if (dataMain.length > 0) {
var mdata = dataMain[0];
var pId = mdata[mainid];
var getPdata = dataParent.filter(function(e){
if (e[parenCode] == pId) {
return e
}
})[0];
var vW = parenView.map(function(sa){
return getPdata[sa];
}).join(' ')
document.getElementById(dataid).innerHTML = ``
}
if (loadForm.data.idData.indexOf(document.getElementById(dataid).id) != (loadForm.data.idData.length - 1)) {
var mop = loadForm.data.idData.indexOf(document.getElementById(dataid).id) + 1;
document.getElementById(loadForm.data.idData[mop]).focus();
}else{
document.getElementById(simpan).addEventListener('focus', function(){
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}, false)
setTimeout(function(){
document.getElementById(simpan).focus();
},100)
}
}
}, false)
}else{
document.getElementById(dataid).addEventListener('focus', function(){
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}, false)
}
if (globalThis.actionListUpdate == undefined) {
globalThis.actionListUpdate = {}
}
globalThis.actionListUpdate[dataid] = function(){
Array.from(document.querySelectorAll('div[data-select-v'+dataid+']')).forEach(function(elm){
elm.addEventListener('click', function(){
var sp = binary2text(this.dataset['selectV'+dataid])
var obj = loadForm.data.objform[dataid];
var name = obj.view.map(function(sl){
return sp['data'][sl];
}).join(' ')
var op = "";
if(loadForm.data.selectAction != undefined){
loadForm.data.selectAction(sp, dataid, obj);
}
document.getElementById(dataid).innerHTML = op;
if (loadForm.data.idData.indexOf(document.getElementById(dataid).id) != (loadForm.data.idData.length - 1)) {
var mop = loadForm.data.idData.indexOf(document.getElementById(dataid).id) + 1;
var nextr = loadForm.data.idData[mop];
if(loadForm.data.objform[nextr].type == 'note'){
$('#'+nextr).summernote('focus')
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}else{
document.getElementById(loadForm.data.idData[mop]).focus();
}
}else{
document.getElementById(simpan).addEventListener('focus', function(){
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}, false)
setTimeout(function(){
document.getElementById(simpan).focus();
},100)
}
},false)
})
}
globalThis.actionListUpdate[dataid]()
// action form
var getredirect = dataid;
if (loadForm.data.objform[dataid].type == 'slug') {
document.getElementById(dataid).addEventListener('focus', function(){
var getValFrom = document.getElementById(loadForm.data.objform[dataid].from).value;
this.value = getValFrom.toLowerCase().replace(/ /g,'-')
.replace(/\#/g,'')
.replace(/\'/g,'')
.replace(/\"/g,'')
.replace(/\&/g,'')
.replace(/\^/g,'')
.replace(/\@/g,'')
.replace(/\!/g,'')
.replace(/\~/g,'')
.replace(/\*/g,'')
.replace(/\;/g,'')
.replace(/\:/g,'')
.replace(/\{/g,'')
.replace(/\}/g,'')
.replace(/\,/g,'')
.replace(/\./g,'')
.replace(/\)/g,'')
.replace(/\(/g,'')
.replace(/\%/g,'')
.replace(/\%/g,'')
.replace(/\?/g,'')
.replace(/\//g,'')
}, false)
}
if (loadForm.data.objform[dataid].type == 'select') {
getredirect = 'search-choice-'+dataid;
document.getElementById('search-choice-'+dataid).addEventListener('keyup', function(){
var relations = null;
if(loadForm.data.objform[dataid].relation != undefined){
relations = loadForm.data.objform[dataid].relation;
}
document.getElementById('choice-'+dataid).innerHTML = globalThis.listdata[dataid](this.value, relations);
globalThis.actionListUpdate[dataid]()
},false)
}
document.getElementById(getredirect).addEventListener('keypress', function(e){
if (e.key === 'Enter') {
if (loadForm.data.idData.indexOf(document.getElementById(dataid).id) != (loadForm.data.idData.length - 1)) {
var mop = loadForm.data.idData.indexOf(document.getElementById(dataid).id) + 1;
var nextr = loadForm.data.idData[mop];
if(loadForm.data.objform[nextr].type == 'note'){
$('#'+nextr).summernote('focus')
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}else{
document.getElementById(loadForm.data.idData[mop]).focus();
}
}else{
document.getElementById(simpan).addEventListener('focus', function(){
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}, false)
setTimeout(function(){
document.getElementById(simpan).focus();
},100)
}
}
}, false)
}
},100)
},100)
},false)
})
document.getElementById(hapus).addEventListener('click',function(){
Swal.fire({
title: 'Apa anda yakin untuk menghapus data ini?',
showDenyButton: true,
showCancelButton: true,
confirmButtonText: `hapus`,
denyButtonText: `batalkan`,
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
var sopd = db().table(loadForm.data.table)
var epso = [];
var edt = loadForm.data.loadDataEdit;
if (loadForm.data.equals != undefined) {
var dataList = {};
loadForm.data.equals.forEach(function(a){
dataList[a] = loadForm.data.loadDataEdit[a];
})
edt = dataList;
}
Object.keys(edt).forEach(function(elps, i){
var lop = edt[elps];
if (lop == "null") {
lop = null
}else{
lop = `"${lop.replace(/\"/g, "\\\"")}"`;
}
if (lop != null) {
if (i == 0) {
epso.push({opsi:"", data: [elps, '=',`${lop}`]});
}else{
epso.push({opsi:"AND", data: [elps, '=',`${lop}`]});
}
}
})
sopd.condition(epso);
sopd.delete();
sopd.get(function(res){
if(loadForm.data.onsave != undefined){
loadForm.data.onsave(loadForm, loadForm.data.loadDataEdit, 1)
}else{
loadForm.load();
}
if (res == 'disimpan') {
Swal.fire(
'Success!',
'Data berhasil di hapus!',
'success'
)
}
})
} else if (result.isDenied) {
Swal.fire('Perintah dibatalkan', '', 'info')
}
})
},false)
document.getElementById(simpan).addEventListener('click', function(){
function escapeHtml(text) {
return text
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
var dataA = {}
loadForm.data.idData.map(function(pol){
if (loadForm.data.objform[pol].type == 'number') {
var num = document.getElementById(pol).value.replace(/\./g, '').replace(/\,/g, '.');
num = Number(num).toFixed(0).toString();
dataA[pol] = num;
}else if(loadForm.data.objform[pol].type == 'date'){
var evf = escapeHtml(document.getElementById(pol).value.replace(/\"/g, '\\\"'));
if (evf == '') {
evf = "null";
}
dataA[pol] = evf;
}else if(loadForm.data.objform[pol].type == 'note'){
dataA[pol] = escapeHtml(JSON.stringify({
kontent: text2Binary(document.getElementById(pol).value)}
));
}else{
dataA[pol] = escapeHtml(document.getElementById(pol).value.replace(/\"/g, '\\\"'));
}
})
var validEr = null;
if(loadForm.data.validate != undefined){
var validate = loadForm.data.validate;
Object.keys(loadForm.data.validate).forEach(function(key){
if(dataA[key] == validate[key]){
if(validEr == null){
validEr = key
}
}
if(validEr != null){
document.getElementById(validEr).focus();
document.getElementById(validEr).scrollIntoView();
alert(validEr + 'tidak boleh kosong')
return false;
}
})
}
if(validEr == null){
document.getElementById('load-'+tableName).innerHTML = `
Loading...
please wait...>
`;
var sopd = db().table(loadForm.data.table)
console.log(loadForm.data.idUpdate);
if(loadForm.data.idUpdate != null){
var epso = [];
if (loadForm.data.equals != undefined) {
var dataList = {};
loadForm.data.equals.forEach(function(a){
dataList[a] = dataA[a];
})
loadForm.data.loadDataEdit = dataList;
}
Object.keys(loadForm.data.loadDataEdit).forEach(function(elps, i){
var lop = loadForm.data.loadDataEdit[elps].toString().replace(/\"/g, '\\\"');
if (lop == "null") {
lop = null
}else{
lop = `"${lop}"`;
}
if (lop != null) {
if (i == 0) {
epso.push({opsi:"", data: [elps, '=',`${lop}`]});
}else{
epso.push({opsi:"AND", data: [elps, '=',`${lop}`]});
}
}
})
console.log(epso);
sopd.condition(epso);
sopd.update(dataA);
}else{
sopd.save(dataA)
}
sopd.get(function(res){
if (res == 'disimpan') {
if(loadForm.data.idUpdate != null){
Swal.fire(
'Success!',
'Data berhasil di ubah!',
'success'
)
}else{
Swal.fire(
'Success!',
'Data berhasil di tambahkan!',
'success'
)
}
// document.querySelector('.form-e').style.display = 'block';
// document.querySelector('.form-d').style.display = 'none';
setTimeout(function(){
// setting for custome proses save
if(loadForm.data.onsave != undefined){
loadForm.data.onsave(loadForm, dataA)
}else{
loadForm.load();
}
},100)
}
})
}
},false)
document.getElementById(idN).addEventListener('click',function(){
var tF = 'form-get-app'+t;
document.querySelector('.form-e').style.display = 'none';
document.querySelector('.form-d').style.display = 'block';
loadForm.data.idUpdate = null;
document.getElementById(hapus).style.display = 'none';
setTimeout(function(){
document.getElementById(idm).innerText = 'Tambah '+title;
var htmlForm = loadForm.data.htmlForm
document.getElementById(tF).innerHTML = htmlForm;
if (loadForm.data.oncreate != undefined) {
loadForm.data.oncreate(loadForm, new db);
}
setTimeout(function(){
document.getElementById(loadForm.data.idData[0]).focus();
},500)
setTimeout(function(){
Object.keys(loadForm.data.objform).forEach(function(e){
if(loadForm.data.objform[e].type == 'note'){
$('#'+e).summernote();
var s = Array.from(document.querySelectorAll('.note-editable'))
for (const yi of s) {
yi.addEventListener('focus', function(){
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}, false)
}
}
if(loadForm.data.objform[e].type == 'number'){
document.getElementById(e).addEventListener('keyup', function(){
var eva = this.value;
eva = eva.replace(/\./g, '');
this.value = formatRupiah(eva);
}, false)
}
if(loadForm.data.objform[e].type == 'select'){
document.getElementById(e).addEventListener('focus', function(){
if(loadForm.data.objform[e].relation != undefined){
document.getElementById('choice-'+e).innerHTML = globalThis.listdata[e](null, loadForm.data.objform[e].relation);
globalThis.actionListNew[e]();
}
if (loadForm.data.objform[e].relationChange == undefined) {
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
document.getElementById('choice-'+e).style.display = 'grid';
document.getElementById('search-choice-'+e).style.display = 'block';
document.getElementById('search-choice-'+e).style.width = document.getElementById('choice-'+e).offsetWidth+'px';
document.getElementById('search-choice-'+e).focus();
document.getElementById('search-choice-'+e).addEventListener('blur', function(){
setTimeout(function(){
document.querySelector('#choice-'+e).style.display = 'none';
document.querySelector('#search-choice-'+e).style.display = 'none';
},200)
}, false)
function posx(){
var clientX = document.getElementById(e);
clientX = Array.from(clientX.getClientRects())[0].x / window.innerWidth * 100;
var positionProsent = Math.round(clientX);
if(positionProsent >= 50){
document.getElementById('search-choice-'+e).style.right = '10px';
document.getElementById('search-choice-'+e).style.left = 'auto';
document.getElementById('choice-'+e).style.right = '10px';
document.getElementById('choice-'+e).style.left = 'auto';
document.getElementById('search-choice-'+dataid).addEventListener('blur', function(){
setTimeout(function(){
document.querySelector('#choice-'+e).style.display = 'none';
document.querySelector('#search-choice-'+e).style.display = 'none';
},200)
}, false)
}
}
posx()
window.onresize = function(){
posx()
}
}else{
var idRelation = loadForm.data.objform[e].relationChange;
var dataParent = dataMaster[e];
var parenCode = loadForm.data.objform[e].value;
var parenView = loadForm.data.objform[e].view;
var mainid = loadForm.data.objform[e].relationId;
var kodemain = loadForm.data.objform[e].value;
var main = loadForm.data.objform[idRelation].table;
var kode = loadForm.data.objform[idRelation].value;
var getVal = document.getElementById(idRelation).value;
var dataMain = dataMaster[main].filter(function(lop){
if (lop[kode] == getVal) {
return lop
}
});
if (dataMain.length > 0) {
var mdata = dataMain[0];
var pId = mdata[mainid];
var getPdata = dataParent.filter(function(e){
if (e[parenCode] == pId) {
return e
}
})[0];
var vW = parenView.map(function(sa){
return getPdata[sa];
}).join(' ')
document.getElementById(e).innerHTML = ``
}
if (loadForm.data.idData.indexOf(document.getElementById(e).id) != (loadForm.data.idData.length - 1)) {
var mop = loadForm.data.idData.indexOf(document.getElementById(e).id) + 1;
document.getElementById(loadForm.data.idData[mop]).focus();
}else{
document.getElementById(simpan).addEventListener('focus', function(){
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}, false)
setTimeout(function(){
document.getElementById(simpan).focus();
},100)
}
}
}, false)
}else{
document.getElementById(e).addEventListener('focus', function(){
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}, false)
}
if (globalThis.actionListNew == undefined) {
globalThis.actionListNew = {}
}
globalThis.actionListNew[e] = function(){
Array.from(document.querySelectorAll('div[data-select-v'+e+']')).forEach(function(elm){
elm.addEventListener('click', function(){
var sp = binary2text(this.dataset['selectV'+e])
var obj = loadForm.data.objform[e];
var name = obj.view.map(function(sl){
return sp['data'][sl];
}).join(' ')
var op = "";
if(loadForm.data.selectAction != undefined){
loadForm.data.selectAction(sp, e, obj);
}
document.getElementById(e).innerHTML = op;
var dataid = e;
if (loadForm.data.idData.indexOf(document.getElementById(dataid).id) != (loadForm.data.idData.length - 1)) {
var mop = loadForm.data.idData.indexOf(document.getElementById(dataid).id) + 1;
var nextr = loadForm.data.idData[mop];
if(loadForm.data.objform[nextr].type == 'note'){
$('#'+nextr).summernote('focus')
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}else{
document.getElementById(loadForm.data.idData[mop]).focus();
}
}else{
document.getElementById(simpan).addEventListener('focus', function(){
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}, false)
setTimeout(function(){
document.getElementById(simpan).focus();
},100)
}
},false)
})
}
globalThis.actionListNew[e]();
})
if (loadForm.data.equals != undefined) {
for(const eq of loadForm.data.equals){
document.getElementById(eq).addEventListener('keyup', loadForm.data.delay(function(){
var getVals = []
var n = 0;
for(const es of loadForm.data.equals){
var vals = document.getElementById(es).value.replace(/\"/g, "\\\"");
if (n == 0) {
getVals.push({
opsi: "", data : [es, '=', `"${vals}"`]
})
}else{
getVals.push({
opsi: "AND", data : [es, '=', `"${vals}"`]
})
}
n++;
}
db()
.table(loadForm.data.table)
.condition(getVals)
.get(function(a, b){
if (Number(b) > 0 ) {
var keysRow = Object.keys(loadForm.data.objform);
var objUpdt = {}
for(const lpp of keysRow){
if (loadForm.data.objform[lpp].type == "select") {
document.getElementById(lpp).value = a[0][lpp];
$('#'+lpp).val(a[0][lpp]).trigger('change');
}else if(loadForm.data.objform[lpp].type == "number"){
document.getElementById(lpp).value = formatRupiah(a[0][lpp]);
}else{
document.getElementById(lpp).value = a[0][lpp];
}
objUpdt[lpp] = a[0][lpp];
}
if (loadForm.data.onupdate != undefined) {
loadForm.data.onupdate(loadForm, a, new db);
}
document.getElementById(idm).innerText = 'Ubah '+title;
loadForm.data.loadDataEdit = objUpdt;
loadForm.data.idUpdate = true;
document.getElementById(hapus).style.display = 'inline-block';
}else{
document.getElementById(idm).innerText = 'Tambah '+title;
loadForm.data.loadDataEdit = {};
loadForm.data.idUpdate = null;
document.getElementById(hapus).style.display = 'none';
var keysRow = Object.keys(loadForm.data.objform);
for(const lpp of keysRow){
if (loadForm.data.equals.indexOf(lpp) == -1) {
document.getElementById(lpp).value = '';
if (loadForm.data.oncreate != undefined) {
loadForm.data.oncreate(loadForm, new db);
}
if (loadForm.data.objform[lpp].type == "select") {
$('#'+lpp).val(null).trigger('change');
}
}
}
}
})
},500), false)
}
}
document.getElementById(loadForm.data.idData[0]).focus()
for(const dataid of loadForm.data.idData){
// if define equals cek data
// action form
var getredirect = dataid;
if (loadForm.data.objform[dataid].type == 'select') {
getredirect = 'search-choice-'+dataid;
document.getElementById('search-choice-'+dataid).addEventListener('keyup', function(){
var relations = null;
if(loadForm.data.objform[dataid].relation != undefined){
relations = loadForm.data.objform[dataid].relation;
}
document.getElementById('choice-'+dataid).innerHTML = globalThis.listdata[dataid](this.value, relations);
globalThis.actionListNew[dataid]();
},false)
}
if (loadForm.data.objform[dataid].type == 'slug') {
document.getElementById(dataid).addEventListener('focus', function(){
var getValFrom = document.getElementById(loadForm.data.objform[dataid].from).value;
this.value = getValFrom.replace(/ /g,'-')
.replace(/\#/g,'')
.replace(/\'/g,'')
.replace(/\"/g,'')
.replace(/\&/g,'')
.replace(/\^/g,'')
.replace(/\@/g,'')
.replace(/\!/g,'')
.replace(/\~/g,'')
.replace(/\*/g,'')
.replace(/\;/g,'')
.replace(/\:/g,'')
.replace(/\{/g,'')
.replace(/\}/g,'')
.replace(/\,/g,'')
.replace(/\./g,'')
.replace(/\)/g,'')
.replace(/\(/g,'')
.replace(/\%/g,'')
.replace(/\%/g,'')
}, false)
}
// --------- //
document.getElementById(getredirect).addEventListener('keypress', function(e){
if (e.key === 'Enter') {
if (loadForm.data.idData.indexOf(document.getElementById(dataid).id) != (loadForm.data.idData.length - 1)) {
var mop = loadForm.data.idData.indexOf(document.getElementById(dataid).id) + 1;
var nextr = loadForm.data.idData[mop];
if(loadForm.data.objform[nextr].type == 'note'){
$('#'+nextr).summernote('focus')
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}else{
document.getElementById(loadForm.data.idData[mop]).focus();
}
}else{
document.getElementById(simpan).addEventListener('focus', function(){
Array.from(document.querySelectorAll('.select-choice')).forEach(function(elm, i){
elm.style.display = 'none';
})
Array.from(document.querySelectorAll('.select-search')).forEach(function(elm, i){
elm.style.display = 'none';
})
}, false)
setTimeout(function(){
document.getElementById(simpan).focus();
},100)
}
}
}, false)
}
},100)
})
}, false);
return this;
},
loadData: function(dat){
var disableNew = false;
if(this.data.disableCreateR == true){
disableNew = true;
}
var pagination = this.data.pagination;
var bataspagin = this.data.bataspagin;
var totData = this.data.totData;
var objform = this.data.objform;
var t = this.data.id;
var m = this.data.row;
var k = Object.keys(this.data.row);
globalThis.act = this;
if(act.data.addRow != undefined) {
setTimeout(function(){
globalThis.actAddRow = function(){
var dataLoad = dat.map(function(resData){
for (let l = 0; l < k.length; l++) {
if (l == (k.length - 1)) {
if (act.data.addRow != undefined) {
var objAddRow = Object.keys(act.data.addRow);
objAddRow.map(function(er){
var id = act.data.addRow[er].id;
var key = act.data.addRow[er].key;
for(const placeEf of key){
var ty = '{{'+placeEf+'}}';
id = id.replaceAll(ty, resData[placeEf]);
}
if (act.data.addRow[er].click != undefined) {
document.getElementById(id).addEventListener('click', act.data.addRow[er].click, false)
}
if (act.data.addRow[er].load != undefined) {
act.data.addRow[er].load(resData, act, text2Binary(resData));
}
})
}
}
}
})
}
})
}
console.log(dat);
var dataLoad = dat.map(function(resData, r){
var lop = '';
for (let l = 0; l < k.length; l++) {
var lopin = resData[k[l]];
var align = "left";
if (objform[k[l]] != undefined) {
if (objform[k[l]].type != undefined) {
if (objform[k[l]].type == 'date') {
lopin = tanggal(resData[k[l]]).sekarang;
align = "center";
}else if(objform[k[l]].type == 'number'){
lopin = formatRupiah(resData[k[l]]);
align = "right";
}else{
lopin = resData[k[l]];
}
}else{
lopin = resData[k[l]];
}
}else{
lopin = resData[k[l]];
}
if (act.data.none != undefined) {
if (act.data.none.indexOf(l) != -1) {
lop += `
${lopin}
`;
}else{
lop += `
${lopin}
`;
}
}else{
lop += `
${lopin}
`;
}
if (l == (k.length - 1)) {
if (act.data.addRow != undefined) {
var objAddRow = Object.keys(act.data.addRow);
lop += objAddRow.map(function(er){
var key = act.data.addRow[er].key;
var ef = act.data.addRow[er].template;
for(const placeEf of key){
var ty = '{{'+placeEf+'}}';
ef = ef.replaceAll(ty, resData[placeEf]);
var uptd = "{{updateid}}";
ef = ef.replaceAll(uptd, `data-update${t}="${text2Binary(resData)}"`);
ef = ef.replaceAll("{{times}}", Date.now());
}
var style = '';
if (act.data.addRow[er].position != undefined) {
style += 'text-align: '+act.data.addRow[er].position+';';
}
return `
${ef}
`;
}).join("")
}
}
}
return lop;
}).join("")
var setGrid = k.map(function(lp, r){
if (act.data.none != undefined) {
if (act.data.none.indexOf(r) != -1) {
}else{
return "auto";
}
}else{
return "auto";
}
}).join(" ")
var setGridName = k.map(function(lp, r){
var lopin = m[lp];
if (act.data.none != undefined) {
if (act.data.none.indexOf(r) != -1) {
return '
'+lopin+'
';
}else{
return '
'+lopin+'
';
}
}else{
return '
'+lopin+'
';
}
}).join(" ")
if (act.data.addRow != undefined) {
var objAddRow = Object.keys(act.data.addRow);
setGrid += ' '+objAddRow.map(function(er){
return 'auto';
}).join(" ")
setGridName += objAddRow.map(function(er){
var ef = act.data.addRow[er].title;
return `
${ef}
`;
}).join("")
}
var wrap = 'white-space: nowrap;';
if (act.data.wrap != undefined) {
wrap = act.data.wrap;
}
var loadTable = `
`;
var newCreateBtn = '';
if (disableNew == false) {
newCreateBtn = `
`;
if (act.data.search != undefined) {
newCreateBtn += `
`;
}else{
newCreateBtn += `
`;
}
}
var back = '';
if (act.data.back != undefined) {
back = `
`;
}
loadTable += `
${newCreateBtn}