/******************************************************************* Module : /assets/js/fonia3.js Desc. : JS - Fonia Custom Class v3 Created By : Siau Pheng (siaupheng@3fonia.com). Created Date : June 19th, 2009. Last Modified : September 28th, 2026. (c) 3FONIA Software; WWW.3FONIA.COM. *******************************************************************/ 'use strict'; var FoniaJS = { version: "3.1.2", APP_ID: 0, APP_SID: "", WEB_HOST: "", WEB_FULLPATH: "", WEB_MOBILE: 0, AUTH_LEVEL: 9, User: {ID:null, UID:0, GID:0, Level:0}, phpversion: "", locales: [], deflocal: "", _debug: (jQuery.inArray(location.hostname, ["localhost","127.0.0.1"]) !== -1) ? true : false, setConfig: function(key, skey) { var _hasil, _adata = null; if (typeof(key) === 'string' && key !== '') { _hasil = $.base64.decode(key); _adata = _hasil.split(";"); this.APP_ID = _adata[0]; this.APP_SID = _adata[1]; this.WEB_HOST = _adata[2]; this.WEB_FULLPATH = _adata[3]; this.WEB_MOBILE = _adata[4]; this.AUTH_LEVEL = parseInt(_adata[5]); this.phpversion = ''; } if (typeof(skey) === 'string' && skey !== '') { _hasil = $.base64.decode(skey); _adata = _hasil.split(";"); this.User.ID = _adata[0]; this.User.UID = parseInt(_adata[1]); this.User.GID = parseInt(_adata[2]); this.User.Level = parseInt(_adata[3]); } }, user_level: function(l) { if (this.User.Level <= (l ?? 9)) return true; return false; }, user_level_not: function(l) { if (this.User.Level !== (l ?? 9)) return true; return false; }, callMenu: function(p, q) { var apar = ["p=" + p]; if (q !== null) apar.push("q=" + q); new Request({ url: "auth/menu", sendParam: apar, onSuccess: (apop) => { if (apop.login == false) { this.showErrorLocale("Fonia.sess_expire"); setTimeout(() => { self.location = self.location.href; }, 1600); return false; } if (apop.php === "" || !window[apop.func]) { this.showErrorLocale("Fonia.page404"); return false; } window[apop.func]['PHP'] = apop.php; window[apop.func]['KODE'] = apop.kode; if (apop.iswindow === true) { if (IndexJS.index) IndexJS.index(); new Request({ url: apop.php + '/index', onSuccess: (ajson) => { this.showWindow(apop.kode, apop.title, ajson.html, apop.width, apop.button, () => { if (typeof window[apop.func]['index'] === 'function') window[apop.func]['index'](q); }); } }).send(); } else { $("#pageToolbarBot").html(this.genToolButton(apop.button)); new Request({ url: apop.php + '/index', onSuccess: (ajson) => { $('#pageContent').html(ajson.html); if (typeof window[apop.func]['index'] === 'function') window[apop.func]['index'](q); } }).send(); } } }).send(); }, loadMenu: function() { $('.mlink').click((e) => { var sbar = $(e.currentTarget).closest('#sidebarMain'); var linkid = $(e.currentTarget).attr('id').replace('Link',''); FoniaJS.callMenu(linkid); if (sbar.length > 0) { sbar.modal('toggle'); } }); $('.slink').click((e) => { var ddown = $(e.currentTarget).closest('.dropdown-menu'); if (ddown.length > 0) { ddown.dropdown('toggle'); } }); if ($('#HomeLink').length){ $('#HomeLink').click(() => { this.closeAllWindows(); if (IndexJS.index) IndexJS.index(); }); } if ($('#ExitLink').length) { $('#ExitLink').click(() => { new Request({ url: "auth/logout", onFailure: () => { self.location = self.location.href; }, onSuccess: (respon) => { var _nurl = self.location.href; if (typeof respon !== 'undefined' && respon.nexthost !== '/') _nurl = respon.nexthost; self.location = _nurl; } }).send(); }); } }, showInfo: function(message, wtime) { var _tmpto = $('').appendTo('#div-toast'); _tmpto.on('hidden.bs.toast', (e) => { $(e.currentTarget).remove(); }); (new bootstrap.Toast(_tmpto)).show(); }, showError: function(message, wtime) { var _tmpto = $('').appendTo('#div-toast'); _tmpto.on('hidden.bs.toast', (e) => { $(e.currentTarget).remove(); }); (new bootstrap.Toast(_tmpto)).show(); }, showInfoLocale: function(tobj, wtime) { this.showInfo(this.locale(tobj), wtime); }, showErrorLocale: function(tobj, wtime) { this.showError(this.locale(tobj), wtime); }, showAuth: function(fungcall, ocall, tmsg, bnotsuper, buserover) { var _breq = (ocall == null) ? false : true; var _bsuper = (bnotsuper == null) ? true : !bnotsuper; var _buover = (buserover == null) ? false : buserover; var _tsid = parseInt(Math.random() * 99999999); var _ceksuper = null; var _isi = new String('
Username
Password

'+this.locale("Fonia.auth_wait_msg")+'


'); this.winSAuth = this.showWindow('SAuth', ((this.AUTH_LEVEL < 9 && _bsuper == true) ? this.locale("Fonia.auth_super") : this.locale("Fonia.auth_user")), _isi, 200, '', () => { $('#butSOK').click(() => { $('#butSOK').prop('disabled', true); new Request({ url: "auth/supervisi", sendParam: ["data=super-check", "UID", "PWD", "SUPER=" + _bsuper, "UOVER=" + _buover], onSuccess: (adata) => { if (adata.status == 1) { fungcall(); } else { this.showError(adata.pesan); } this.closeWindow(this.winSAuth); } }).send(); }); $('#butSBatal').click(() => { if (_ceksuper) { clearInterval(_ceksuper); new Request({ url: "auth/supervisi", sendParam: ["data=super-cancel", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid] }).send(); } }); $('#butSReq').click(() => { if (_breq == false) return false; $('#Auth_SP1').addClass('d-none'); $('#Auth_SP2').addClass('d-none'); $('#Auth_SP3').removeClass('d-none'); $('#butSOK').prop('disabled', true); new Request({ url: "auth/supervisi", sendParam: ["data=super-request", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid, "MSG=" + tmsg] }).send(); var _cobalagi = 5; _ceksuper = setInterval(() => { $('#butSBatal').html(this.locale("Fonia.cancel") + " (" + _cobalagi + ")"); if (_cobalagi === 0) { clearInterval(_ceksuper); new Request({ url: "auth/supervisi", sendParam: ["data=super-cancel", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid] }).send(); this.closeWindow(this.winSAuth); this.showErrorLocale("Fonia.auth_fail"); return false; } new Request({ url: "auth/supervisi", sendParam: ["data=request-check", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid], onSuccess: (adata) => { if (adata.status === 1) { clearInterval(_ceksuper); this.showInfoLocale("Fonia.auth_success"); fungcall(); this.closeWindow(this.winSAuth); } else { _cobalagi--; } } }).send(); }, 3000); }); $('#UID').keyup((e) => { if (-1!==$.inArray(e.which, [13,9])) { if (e.currentTarget.value !== '') $('#PWD').focus(); } }); $('#PWD').keyup((e) => { if (e.currentTarget.value === '') return false; if (13 == e.which) $('#butSOK').trigger('click'); }); if (_bsuper === false) { FoniaJS.setFocus("#PWD"); } else { FoniaJS.setFocus("#UID"); } }); }, genWinToolBut: function(menu) { if (!menu) return ''; var smenu = ''; if (typeof menu === 'object'){ var ma = ' me-sm-2'; smenu = '
'; $(menu).each((i, atom) => { if (Object.keys(atom).length === 0) { smenu += '
'; ma = ' ms-sm-2'; } else { if (atom.i == 'butTutup') { atom.v='Tutup', atom.c='danger', atom.d='' }; if (atom.i == 'butBatal') { atom.v='Batal', atom.c='danger', atom.d='' }; var _xt = (typeof atom?.d !== 'undefined') ? ' data-bs-dismiss="modal"' : ''; smenu += ''; } }); smenu += '
'; return smenu; } else { if (this._debug) console.log('menu not object'+menu); } return smenu; }, genToolButton: function(menu) { if (!menu) return ''; var smenu = ''; if (typeof menu === 'object'){ var ma = ' me-sm-2'; smenu = '
'; $(menu).each((i, atom) => { if (Object.keys(atom).length === 0) { smenu += '
'; ma = ' ms-sm-2'; } else { if (atom.i == 'butTutup') { atom.v='Tutup', atom.c='danger', atom.d='' }; if (atom.i == 'butBatal') { atom.v='Batal', atom.c='danger', atom.d='' }; smenu += ''; } }); smenu += '
'; return smenu; } else { if (this._debug) console.log('menu not object'+menu); } return smenu; }, FormDecorated: function() { $('input.form-control[class*=integer], input.form-control[class*=angka]').each((i, el) => { const elm = $(el); if ((elm.attr('o3') ?? '') !== '') return; elm.attr('o3', '1'); elm.on('keypress keyup paste', (e) => { elm.val(elm.val().replace(/[^\d].+/, "")); if ((e.which < 48 || e.which > 57)) e.preventDefault(); }); }); $('input.form-control[class*=double]').each((i, el) => { const elm = $(el); if ((elm.attr('o3') ?? '') !== '') return; elm.attr('o3', '1'); elm.on('keypress keyup input', (e) => { if (e.type === 'keypress') { if ((e.which != 45 || elm.val().indexOf('-') != -1) && (e.which != 46 || elm.val().indexOf('.') != -1) && (e.which < 48 || e.which > 57)) e.preventDefault(); } else { var _val = elm.val().replace(/[^0-9.-]/g, ''); if (_val.indexOf('-') > 0) _val = _val.charAt(0) + _val.slice(1).replace(/-/g, ''); var _parts = _val.split('.'); if (_parts.length > 2) _val = _parts[0] + '.' + _parts.slice(1).join(''); elm.val(_val); } }); elm.on('blur', () => elm.val( FoniaJS.FloatToStr(elm.val(), 2) )); elm.on('focus', (e) => { elm.val( FoniaJS.StrToFloat(elm.val()) ); elm.select(); e.preventDefault(); }); }); $('input.form-control[type=number]').each((i, el) => { const elm = $(el); if ((elm.attr('o3') ?? '') !== '') return; elm.attr('o3', '1'); elm.on('keypress keyup input', (e) => { if (e.type === 'keypress') { if ((e.which != 45 || elm.val().indexOf('-') != -1) && (e.which != 46 || elm.val().indexOf('.') != -1) && (e.which < 48 || e.which > 57)) e.preventDefault(); } else { var _val = elm.val().replace(/[^0-9.-]/g, ''); if (_val.indexOf('-') > 0) _val = _val.charAt(0) + _val.slice(1).replace(/-/g, ''); var _parts = _val.split('.'); if (_parts.length > 2) _val = _parts[0] + '.' + _parts.slice(1).join(''); elm.val(_val); } }); }); $('input.form-control, textarea.form-control, select.form-select').each((i, el) => { const elm = $(el); const okyup = elm.attr('okyup') ?? ''; const oblur = elm.attr('oblur') ?? ''; const ochan = elm.attr('ochan') ?? ''; if ((elm.attr('o3') ?? '') !== '') return; elm.attr('o3', '1'); elm.on('keyup blur change', (e) => { if (e.type === 'keyup' && okyup) { var fnc = okyup.split('.'); if (typeof window[fnc[0]][fnc[1]] === 'function'){ window[fnc[0]][fnc[1]](); } else console.warn('fungsi '+okyup+' tidak ada !'); } if (e.type === 'blur' && oblur) { var fnc = oblur.split('.'); if (typeof window[fnc[0]][fnc[1]] === 'function'){ window[fnc[0]][fnc[1]](); } else console.warn('fungsi '+oblur+' tidak ada !'); } if (e.type === 'change' && ochan) { var fnc = ochan.split('.'); if (typeof window[fnc[0]][fnc[1]] === 'function'){ window[fnc[0]][fnc[1]](); } else console.warn('fungsi '+ochan+' tidak ada !'); } e.preventDefault(); }); }); $('input.form-check-input[type=radio]').each((i, el) => { const elm = $(el); if ((elm.attr('o3') ?? '') !== '') return; elm.attr('o3', '1'); elm.on('click', () => { const oclic = elm.attr('ochan') ?? ''; const elp = $('#'+elm.attr('name')); if (elp && elm.is(':checked')) elp.val(elm.val()); if (oclic) { var fnc = oclic.split('.'); if (typeof window[fnc[0]][fnc[1]] === 'function'){ window[fnc[0]][fnc[1]](); } else console.warn('fungsi '+oclic+' tidak ada !'); } }); }); $('input.form-check-input[type=checkbox]').each((i, el) => { const elm = $(el); if ((elm.attr('o3') ?? '') !== '') return; elm.attr('o3', '1'); elm.on('change', () => { const odata = JSON.parse(elm.attr('odata') ?? '[]'); const ochan = elm.attr('ochan') ?? ''; if (odata.length > 0) elm.val(elm.is(':checked') ? odata[0] : odata[1]); if (ochan) { var fnc = ochan.split('.'); if (typeof window[fnc[0]][fnc[1]] === 'function'){ window[fnc[0]][fnc[1]](); } else console.warn('fungsi '+ochan+' tidak ada !'); } }); }); $('input[class*=error][type=hidden]').each((i, el) => { const elm = $(el); this.showError(elm.val()); }); $('.option-tags').each((i, el) => { const elm = $(el); if (typeof jQuery.fn.select2 !== 'function') return; var _opts = {tags: false, dropdownAutoWidth: true, width: 'auto', theme: 'bootstrap-5', language: 'id'}; var _dmodal = elm.closest('div.modal'); if (_dmodal.length) _opts.dropdownParent = _dmodal; var _sel2 = elm.select2(_opts); if (elm.prop('required')) elm.removeAttr('required'); //_sel2.on('select2:close', (e) =>{ $(e.target).valid(); }); }); $('[data-toggle="tooltip"]').tooltip(); if('function' == typeof jQuery.fn.datepicker){ $('.input-group.date').datepicker({ format: 'dd-mm-yyyy', weekStart: 1, language: 'id', autoclose: true, todayHighlight: true, enableOnReadonly: false }); } if ('function' == typeof autosize) autosize($('textarea')); }, RequestParam: function(aparam) { var _cblist = {}; var _ohasil = {}; $('tbody input[id*="cbox"][type="checkbox"]:checked').map((i, b) => { const arr = b.id.split('_'); if (!_cblist[arr[0]]) _cblist[arr[0]] = []; _cblist[arr[0]].push(arr[2]); }); $.each(_cblist, (i, b) => { _ohasil['List_CB_' + i] = b.join(); }); if (typeof aparam === 'object') { aparam.map(_par => { if (typeof _par !== "string") this.return; var _key = _par, _val = ""; const _ind = _par.indexOf('='); if (_ind !== -1) { _key = _par.slice(0, _ind); _val = _par.slice(_ind + 1); } else { if ($('#'+_par).length) { _val = $('#'+_par).val(); if (typeof _val === 'undefined') { _val = ($('#'+_par).is('.integer, .number, .double')) ? 0 : ''; } else { _val = ($('#'+_par).is('.integer, .number, .double')) ? this.StrToFloat(_val) : encodeURIComponent(_val); } } } _ohasil[_key] = _val; }); } _ohasil['SID'] = parseInt(Math.random() * 99999999); return _ohasil; }, StrToFloat: function(str_val) { var nstr = str_val + ""; var hasil = ""; var fkali = 1; if (nstr.slice(0, 4) == "Rp.") { nstr = nstr.slice(4); } for (var i = 0; i < nstr.length; i++) { if ((parseFloat(nstr.charAt(i))) || (nstr.charAt(i) == "0") || (nstr.charAt(i) == ".")) { hasil += nstr.charAt(i); } else { if ((nstr.charAt(i) == "(") || (nstr.charAt(i) == ")") || (nstr.charAt(i) == "-")) { fkali = -1; hasil += ""; } else { if (nstr.charAt(i) == ",") { hasil += ""; } } } } if (!hasil.indexOf(".") > 0) { hasil += ".00"; } return parseFloat(hasil) * fkali; }, FloatToStr: function(nangka, ndesi) { var nstr = nangka + ""; ndesi = (ndesi == null) ? 0 : ndesi; nstr = (Math.round(nstr.replace(/\,/g, "") * Math.pow(10, ndesi)) / Math.pow(10, ndesi)) + ""; var x = nstr.split("."); if (!x[0]) { x[0] = "0"; } if (!x[1]) { x[1] = ""; } var x1 = x[0]; if (x1.length > 3) { var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, "$1" + "," + "$2"); } } var x2 = x[1]; if (x2.length < ndesi) { var g = x2; for (var i = x2.length + 1; i <= ndesi; i++) { g += "0"; } x2 = g; } x2 = "." + x2; if (ndesi == 0) { x2 = ""; } return x1 + x2; }, formatBytes: function(bytes, deci) { if (bytes === 0) return '0 Bytes'; const dm = deci ?? 0; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const i = Math.floor(Math.log(bytes) / Math.log(1024)); return parseFloat((bytes / Math.pow(1024, i)).toFixed(dm)) + ' ' + sizes[i]; }, showConfirm: function(str_judul, str_isi, func_callback, conf_tipe) { var _cfunc = (typeof func_callback == "function") ? func_callback : () => {}; var _ctipe = (conf_tipe == null) ? 'modal-warning' : 'modal-'+conf_tipe; var _btipe = (conf_tipe == null) ? 'btn-warning' : 'btn-'+conf_tipe; var _wtxt = ''; if ($('#winAPPConf').length) $('#winAPPConf').modal('dispose').remove(); $(_wtxt).on('shown.bs.modal', (e) => { $('#winConfirmY').focus(); $('#winConfirmY').click((e) => { _cfunc(); $('#winAPPConf').modal('hide'); }); }).modal('show'); }, showWindow: function(id_wind, s_judul, s_isi, i_width, s_toolb, f_onload, f_offload, b_scroll) { var t_width = '', t_toolb = '', t_scroll = (typeof b_scroll == 'boolean' && b_scroll == false) ? '' : 'modal-dialog-scrollable'; var f_oncall = (typeof f_onload == "function") ? f_onload : function(){}; var f_offcall = (typeof f_offload == "function") ? f_offload : function(){}; if (typeof i_width == 'string') { t_width = 'modal-'+i_width; } else if (i_width <= 300) { t_width = 'modal-sm'; } else if (i_width <= 400) { t_width = 'modal-400'; } else if (i_width <= 500) { t_width = 'modal-500'; } else if (i_width <= 800) { t_width = 'modal-lg'; } else if (i_width <= 1200) { t_width = 'modal-xl'; } else if (i_width > 1200) { t_width = 'modal-fs'; } if (typeof s_toolb !== 'undefined' && s_toolb !== '' && s_toolb !== null) { t_toolb = ''; } var _wtxt = ''; if ($('#win'+id_wind).length) $('#win'+id_wind).modal('dispose').remove(); $(_wtxt).on('shown.bs.modal', (e) => { f_oncall(); FoniaJS.FormDecorated(); }).on('hidden.bs.modal', (e) => { f_offcall(); $(e.currentTarget).remove(); }).modal('show'); return '#win'+id_wind; }, closeWindow: function(elWin) { if ($(elWin).length) $(elWin).modal('hide'); }, closeAllWindows: function() { $(".modal").each((i, el) => { if ($(el).hasClass('show')) $(el).modal('toggle'); if ($(el).attr('id')!=='sidebarMain') $(el).modal('dispose').remove(); }); $(".fon-autotext", ".fon-autopos").each((i, el) => { $(el).remove(); }); if ($("#dataPrint").length) { $("#dataPrint").empty(); } }, setFocus: function(obj) { $(obj).select().focus(); }, lPad: function(n, width, z) { z = z || "0"; n = n + ""; return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; }, setCookie: function(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires="+d.toUTCString(); document.cookie = 'f' + this.APP_ID + '_' + cname + "=" + cvalue + ";" + expires + ";path=/"; }, getCookie: function(cname) { var name = 'f' + this.APP_ID + '_' + cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; }, locale: function(key, oset){ if (typeof oset === "object") { this.locales[key] = oset; if (this.deflocal == '') this.deflocal = key; } else { if (!this.locales[this.deflocal]) return ""; return key.split('.').reduce(function (cur, key) { return cur[key]; }, this.locales[this.deflocal]); } }, AutoComplete: function(elm, turl, aparam, func_comp, func_key){ var objComp = {}; objComp = { preventEnter: true, resolverSettings: { url: turl, param: (typeof aparam === 'object') ? aparam : [] } }; if ('object' === typeof func_comp){ objComp = $.extend(true, {}, objComp, func_comp); } else {//compatible if ('function' === typeof func_key) objComp.keyFunc = func_key; if ('function' === typeof func_comp) objComp.selectFunc = func_comp; } $(elm).nextAll('div.bootstrap-autocomplete').remove(); $(elm).off(); //fixed hidden on modal var _dbody = $(elm).closest('div.modal-body'); var _dcont = $(elm).closest('div.modal-content'); if (_dbody.length) $(_dbody).css('overflow', 'visible'); if (_dcont.length) $(_dcont).css('overflow', 'visible'); new AutoComplete(elm, objComp); }, getAppID: function() { return this.APP_ID; } }; class _Request { options = { url: '', sendParam: [], onSuccess: () => {}, onFailure: () => {}, data: null, dataType: 'json' } constructor(options) { $.extend(this.options, options); } send() { if (!this.options.url) { console.log(this.options.sendParam + ", cek url php!"); return false; } this.options.data = $.extend(this.options.data, FoniaJS.RequestParam(this.options.sendParam)); $.ajax({ type: 'POST', url: this.options.url, data: this.options.data, success: (typeof this.options.onSuccess === "function") ? this.options.onSuccess : () => {}, error: (typeof this.options.onFailure === "function") ? this.options.onFailure : () => {}, complete: FoniaJS.FormDecorated, dataType: this.options.dataType }); return this; } }; class _Request_JSONF extends _Request { constructor(options) { const _options = Object.assign({}, options); _options.onSuccess = (data) => { if (data.length > 0) { $(data).each((i, ini) => { if (ini.type == "table" && $(ini.id)) this.make_table(ini); if (ini.type == "form" && $(ini.id)) this.make_form(ini); if (ini.type == "option" && $(ini.id)) this.make_option(ini); if (ini.type == "html" && $(ini.id)) this.make_html(ini); if (ini.type == "msg") this.show_msg(ini); }); } if (typeof options.onSuccess === "function") options.onSuccess(data); }; super(_options); } show_msg (ini) { var wtime = parseInt(ini.wait); if (ini.mode == "error") { FoniaJS.showError(ini.value, wtime); } else { FoniaJS.showInfo(ini.value, wtime); } } make_html (ini) { $('#'+ini.id).html(ini.value); } make_form (ini) { var formIni = $('#'+ini.id); formIni.val(ini.value); if (ini.css) { formIni.prop('disabled', ini.css=='disabled'); } } make_option (ini) { var optIni = $('#'+ini.id); if (!optIni) return; if (ini.avalue) { optIni.empty(); var o_group = 0; $(ini.avalue).each((n, i) => { if (i.optgroup) { if (0 < o_group++) optIni.append(''); optIni.append(''); return; } optIni.append($(''); } if (ini.value) { optIni.val(ini.value); } optIni.trigger('change'); } make_table (ini) { var divData = $('#'+ini.id).empty(); var strHead = '', iCol = 0, sClass = '', aSortCol = [], aTombol = []; $(ini.header).each((key, val) => { if (val.o == ini.config.sort_col) iCol = key; strHead += ''+val.c+''; aSortCol.push((val.s ? { 'orderDataType': val.s } : null)); }); if (ini.option.length > 0) { var strAksi = 'Aksi', ChkField = ''; $(ini.option).each((key, val) => { if (val.type == 'checkbox'){ strAksi = ''; ChkField = val.field; } if ($.inArray(val.type,['button','button-dt'])!==-1) aTombol[val.icon] = [val.label, (val.type=='button'?0:1)]; }); strHead += ''+strAksi+''; } else { strHead += ' '; } aSortCol.push({'orderable': false}); strHead += ''; var strFoot = ''; if (ini.footer) { strFoot = ''; $(ini.footer).each((key, val) => { strFoot += ''+val.c+''; }); strFoot += ' '; } var sClass = ''; if (ini.config.css) sClass += ' '+ini.config.css; if (ini.config.func_select) sClass += ' table-select'; var strTab = ''; var strBody = ''; $(ini.content).each((key, val) => { strBody += ''; $(val).each((keyi, vali) => { if (keyi == 0) return; strBody += ''; }); var _tbtn1 = "", _tbtn2 = ""; if (val[0].rowcss) { _tbtn1 += ''; } if (ini.option.length > 0) { if (val[0].button.length > 0) { $(val[0].button).each((keyb, valb) => { var _link = (aTombol[valb[0]][1]==1) ? 'fon-tabel-dt' : valb[0]; var _cssa = (valb[1]=='') ? '' : ' text-'+valb[1]; var _cssb = (valb[1]=='') ? ' normal' : ' btn-'+valb[1]; if (ini.config.txtbutton === true) { _tbtn1 += ''; _tbtn2 += ''; } else { _tbtn2 += ''; } }) } if (val[0].checkbox) { _tbtn1 += '
'; } } strBody += ''; }); strBody += ''; $(divData).append(strTab + strHead + strBody + strFoot + '
' + vali + ''+_tbtn1+_tbtn2+'
'); var opsi = { responsive: true, columnDefs: [{responsivePriority:1,targets:0},{responsivePriority:2,targets:1},{responsivePriority:0,targets:-1}], lengthMenu: [], dom: '<"row"<"col-sm-12"tr>><"row"<"col-sm-12 col-lg-auto"<"toolbar">><"col-sm-3 col-lg-auto ms-lg-auto"l><"col-sm-9 col-lg-auto"p>>', autoWidth: false, processing: true, searching: false, columns: aSortCol, order: [[iCol, (ini.config.sort_dir=='A'?'asc':'desc')]], pageLength: ini.config.row_count, stateSave: true, stateSaveCallback: function(sett,data){localStorage.setItem(ini.id,JSON.stringify(data));}, stateLoadCallback: function(sett){try{var data=JSON.parse(localStorage.getItem(ini.id))??{};data.length=ini.config.row_count;return data;}catch(e){console.log(e)}} }; /** start live db **/ if (ini.config.live){ $(this.options.data).map((key, val) => { if (key === 'SID') val = parseInt(Math.random() * 99999999); // fixed bug for duplicate saving if (key === 'mode_detail') val = 'live-data'; //if ((''+val).indexOf('%') != -1) val = decodeURIComponent(val); }); opsi.serverSide = true; opsi.ajax = { url: this.options.url, type: 'POST', data: this.options.data, dataFilter: (data) => { var json = {}, jsono = {'draw':0,'recordsTotal':0,'recordsFiltered':0,'data':[]}; try { json = JSON.parse(data); if (!jQuery.isEmptyObject(json) && json.length > 0){ $(json).each((i, lini) => { if (lini.type == 'table-live' && lini.id == ini.id) { jsono.draw = lini.config.draw; jsono.recordsTotal = lini.config.recordsTotal; jsono.recordsFiltered = lini.config.recordsFiltered; jsono.data = lini.data; } }); } } catch (e){ console.log(e); } $(jsono.data).map((key, val) => { var optval = val[0]; jsono.data[key].shift(); var _tbtn1 = "", _tbtn2 = ""; if (optval.rowcss) { _tbtn1 += ''; } if (ini.option.length > 0) { if (optval.button.length > 0) { $(optval.button).map((keyb, valb) => { var _link = (aTombol[valb[0]][1]==1) ? 'fon-tabel-dt' : valb[0]; var _cssa = (valb[1]=='') ? '' : ' text-'+valb[1]; var _cssb = (valb[1]=='') ? ' normal' : ' btn-'+valb[1]; if (ini.config.txtbutton === true) { _tbtn1 += ''; _tbtn2 += ''; } else { _tbtn2 += ''; } }) } if (optval.checkbox) { _tbtn1 += '
'; } } jsono.data[key].push(_tbtn1+_tbtn2); }); return JSON.stringify(jsono); } }; } /** end live db **/ if (ini.option.length > 0) opsi.columnDefs.push({responsivePriority:3,targets:-1}, {orderable:false,targets:-1}); if (ini.navi.no_navi == true) opsi.paging = false; if (ini.config.scrollbar == true) { opsi.scrollY = ini.config.scroll_height; opsi.deferRender = true; opsi.scroller = { loadingIndicator: true }; } var _navibar = ''; if (ini.navi.button) { var _dis = '', _bcss = 'btn-info'; if (ini.config.nobutton === true){ _dis = ' disabled=true'; _bcss = 'btn-secondary'; } _navibar += '
'; $(ini.navi.button).map((key, val) => { _navibar += ''; }); _navibar += '
'; } opsi.initComplete = function(settings,json){ if (ini.navi.button) { $('#'+ini.id+'Tabel_wrapper div.toolbar').html(_navibar); // apply navi button if (ini.navi.button.length > 0){ $(ini.navi.button).map((key, val) => { $('#'+ini.id+'Tabel_wrapper div.toolbar button[class*=navi-btn-'+key+']').on('click', (e) => { e.preventDefault(); var fnc = val.func.split('.'); if (typeof window[fnc[0]][fnc[1]] === 'function'){ window[fnc[0]][fnc[1]](); } else console.warn('fungsi '+val.func+' tidak ada !'); }); }); } } } opsi.drawCallback = function(settings){ // apply rowcss to tr/row $('#'+ini.id+'Tabel tbody td:last-child:has(span.rowcss)').map((i, el) => { var span = $(el).find('span').attr('class').replace('rowcss ',''); $(el).parent().addClass(span); }); // create hover title for awr class td $('#'+ini.id+'Tabel tbody td[class*="awr"]').map((i, el) => { $(el).attr('title', $(el).html().replace(//gi,'\n').replace(/(<([^>]+)>)/gi,'')); }); // generate pagelength option var api = this.api(), menudiv = $('select[name="'+ini.id+'Tabel_length"]'); var record = api.page.info().recordsTotal ?? 0, _lmenu = []; $([10,25,50,100]).map((key, val) => { if (val > record && 10 < val) return false; _lmenu.push(val); }); if (10 < record && $.inArray(record, [25,50,100]) == -1){ _lmenu.push(record); } var _select = menudiv.val() ?? 10; menudiv.empty(); $(_lmenu).map((key, val) => { $('