add share.js, upgrade validate and reform fonia3

This commit is contained in:
2026-01-19 15:56:49 +07:00
parent 7c7d4d8f59
commit eefff2b65c
6 changed files with 322 additions and 266 deletions
+3
View File
@@ -329,6 +329,9 @@ ul.dtr-details li.hidden { visibility: hidden !important; display: none !importa
font-weight: bolder !important; font-weight: bolder !important;
font-size: 1.1rem; font-size: 1.1rem;
} }
.select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__option--highlighted {
background-color: var(--bs-yellow);
}
/******************************** Autocomplete ********************************/ /******************************** Autocomplete ********************************/
+35 -16
View File
@@ -4,40 +4,59 @@
Desc. : Fungsi-fungsi export data & laporan Desc. : Fungsi-fungsi export data & laporan
Created By : Siau Pheng ([email protected]). Created By : Siau Pheng ([email protected]).
Created Date : April 1st, 2011. Created Date : April 1st, 2011.
Last Modified : January 7th, 2016. Last Modified : January 19th, 2026.
(c) 2011 - 2016, 3FONIA Software; WWW.3FONIA.COM. (c) 2011 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/ *******************************************************************/
var cEXPORT = function(url, options){ var cEXPORT = function(url, options){
var vars = { var _options = {
'url': '', 'url': '',
'param': [] 'filename': ''
}; };
var _params = [];
this.construct = function(url, options){ this.construct = function(url, options){
$.extend(vars, options); if (typeof url == 'object') {
vars.url = url; $.extend(_options, url);
} else {
$.extend(_options, options);
_options.url = url;
}
}; };
this.set_url = function (url){ this.set_url = function (url){
vars.url = url; _options.url = url;
}; };
this.add_param = function (par_id, par_val){ this.add_param = function (par_id, par_val){
var _getvalue = (par_val) ? par_id + "=" + escape(par_val) : par_id; var _getvalue = (par_val) ? par_id + "=" + escape(par_val) : par_id;
vars.param.push(_getvalue); _params.push(_getvalue);
}, },
this.download = function(){ this.download = async function(){
if (!vars.url) { if (!_options.url) {
console.warn(vars.param + ", cek url php!"); console.warn('cek url !');
return false; return false;
} }
var _pro = (window.location.protocol=='https:') ? 'https://' : 'http://'; var _pro = (window.location.protocol=='https:') ? 'https://' : 'http://';
var _src = _pro+FoniaJS.WEB_HOST + vars.url + '?' + (FoniaJS.RequestParam(vars.param)).join('&'); var _src = _pro+FoniaJS.WEB_HOST + _options.url + '?' + (FoniaJS.RequestParam(_params)).join('&');
var $exportData = $('#IFrame_Export');
if (!$exportData.length) { try {
var $exportData = $('<iframe>', {id:'IFrame_Export','class':'d-none'}).appendTo('body'); const response = await fetch(_src)
.then(response => {
const cDispo = response.headers.get('Content-Disposition');
if (cDispo && cDispo.indexOf('filename=') !== -1) {
_options.filename = cDispo.split('filename=')[1].split(';')[0].replace(/"/g, '');
}
return response;
})
const blob = await response.blob();
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = _options.filename;
link.click();
} catch (error) {
console.error('Download gagal:', error);
} }
$exportData.prop('src', _src);
return this; return this;
}; };
this.construct(url, options); this.construct(url, options);
+200 -239
View File
@@ -13,7 +13,7 @@
'use strict'; 'use strict';
var FoniaJS = { var FoniaJS = {
version: "3.0.1", version: "3.1.1",
APP_ID: 0, APP_ID: 0,
APP_SID: "", APP_SID: "",
WEB_HOST: "", WEB_HOST: "",
@@ -64,7 +64,7 @@ var FoniaJS = {
new Request.JSON({ new Request.JSON({
url: this.WEB_PATH + "auth.php", url: this.WEB_PATH + "auth.php",
sendParam: apar, sendParam: apar,
onSuccess: function(apop) { onSuccess: (apop) => {
if (apop.login == false) { if (apop.login == false) {
this.showErrorLocale("Fonia.sess_expire"); this.showErrorLocale("Fonia.sess_expire");
setTimeout(function(){self.location = FoniaJS.WEB_PATH;}, 1600); setTimeout(function(){self.location = FoniaJS.WEB_PATH;}, 1600);
@@ -81,72 +81,72 @@ var FoniaJS = {
new Request({ new Request({
url: this.WEB_PATH + "apps/php/" + apop.php, url: this.WEB_PATH + "apps/php/" + apop.php,
sendParam: ["data=default"], sendParam: ["data=default"],
onSuccess: function(txt) { onSuccess: (txt) => {
this.showWindow(apop.kode, apop.title, txt, apop.width, apop.button, function(){ this.showWindow(apop.kode, apop.title, txt, apop.width, apop.button, function(){
if (typeof window[apop.func]['loading'] === 'function') window[apop.func]['loading'](q); if (typeof window[apop.func]['loading'] === 'function') window[apop.func]['loading'](q);
}); });
}.bind(this) }
}).send(); }).send();
} else { } else {
$("#pageToolbarBot").html(this.genToolButton(apop.button)); $("#pageToolbarBot").html(this.genToolButton(apop.button));
new Request({ new Request({
url: this.WEB_PATH + "apps/php/" + apop.php, url: this.WEB_PATH + "apps/php/" + apop.php,
sendParam: ["data=default"], sendParam: ["data=default"],
onSuccess: function(txt) { onSuccess: (txt) => {
$('#pageContent').html(txt); $('#pageContent').html(txt);
if (typeof window[apop.func]['loading'] === 'function') window[apop.func]['loading'](q); if (typeof window[apop.func]['loading'] === 'function') window[apop.func]['loading'](q);
} }
}).send(); }).send();
} }
}.bind(this) }
}).send(); }).send();
}, },
loadMenu: function() { loadMenu: function() {
$(".mlink").click(function(e){ $('.mlink').click((e) => {
var sbar = $(this).closest('#sidebarMain'); var sbar = $(e.currentTarget).closest('#sidebarMain');
var linkid = $(this).attr('id').replace("Link", ""); var linkid = $(e.currentTarget).attr('id').replace('Link','');
FoniaJS.callMenu(linkid); FoniaJS.callMenu(linkid);
if (sbar.length > 0) { sbar.modal('toggle'); } if (sbar.length > 0) { sbar.modal('toggle'); }
}); });
$(".slink").click(function(e){ $('.slink').click((e) => {
var ddown = $(this).closest('.dropdown-menu'); var ddown = $(e.currentTarget).closest('.dropdown-menu');
if (ddown.length > 0) { ddown.dropdown('toggle'); } if (ddown.length > 0) { ddown.dropdown('toggle'); }
}); });
if ($("#HomeLink").length){ if ($('#HomeLink').length){
$("#HomeLink").click(function(){ $('#HomeLink').click(() => {
this.closeAllWindows(); this.closeAllWindows();
if (IndexJS.loading) IndexJS.loading(); if (IndexJS.loading) IndexJS.loading();
}.bind(this)); });
} }
if ($("#ExitLink").length) { if ($('#ExitLink').length) {
$("#ExitLink").click(function() { $('#ExitLink').click(() => {
new Request.JSON({ new Request.JSON({
url: this.WEB_PATH + "apps/php/login.php", url: this.WEB_PATH + "apps/php/login.php",
sendParam: ["mode=logout"], sendParam: ["mode=logout"],
onFailure: function(){ onFailure: () => {
self.location = (['localhost','127.0.0.1'].indexOf(location.hostname) >= 0) ? this.WEB_PATH : "/"; self.location = (['localhost','127.0.0.1'].indexOf(location.hostname) >= 0) ? this.WEB_PATH : "/";
}.bind(this), },
onSuccess: function(respon){ onSuccess: (respon) => {
var _nurl = (['localhost','127.0.0.1'].indexOf(location.hostname) >= 0) ? this.WEB_PATH : "/"; var _nurl = (['localhost','127.0.0.1'].indexOf(location.hostname) >= 0) ? this.WEB_PATH : "/";
if (typeof respon !== 'undefined' && respon.nexthost !== '/') _nurl = respon.nexthost; if (typeof respon !== 'undefined' && respon.nexthost !== '/') _nurl = respon.nexthost;
self.location = _nurl; self.location = _nurl;
}.bind(this) }
}).send(); }).send();
}.bind(this)); });
} }
}, },
showInfo: function(message, wtime) { showInfo: function(message, wtime) {
var _tmpto = $('<div class="toast align-items-center text-white bg-info border-0" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="'+(wtime?wtime:3000)+'"><div class="d-flex"><div class="toast-body me-2">'+message+'</div><button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button></div></div>').appendTo('#div-toast'); var _tmpto = $('<div class="toast align-items-center text-white bg-info border-0" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="'+(wtime?wtime:3000)+'"><div class="d-flex"><div class="toast-body me-2">'+message+'</div><button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button></div></div>').appendTo('#div-toast');
_tmpto.on('hidden.bs.toast', function(e){ _tmpto.on('hidden.bs.toast', (e) => {
$(this).remove(); $(e.currentTarget).remove();
}); });
(new bootstrap.Toast(_tmpto)).show(); (new bootstrap.Toast(_tmpto)).show();
}, },
showError: function(message, wtime) { showError: function(message, wtime) {
var _tmpto = $('<div class="toast align-items-center text-white bg-danger border-0" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="'+(wtime?wtime:3000)+'"><div class="d-flex"><div class="toast-body me-2">'+message+'</div><button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button></div></div>').appendTo('#div-toast'); var _tmpto = $('<div class="toast align-items-center text-white bg-danger border-0" role="alert" aria-live="assertive" aria-atomic="true" data-bs-delay="'+(wtime?wtime:3000)+'"><div class="d-flex"><div class="toast-body me-2">'+message+'</div><button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button></div></div>').appendTo('#div-toast');
_tmpto.on('hidden.bs.toast', function(e){ _tmpto.on('hidden.bs.toast', (e) => {
$(this).remove(); $(e.currentTarget).remove();
}); });
(new bootstrap.Toast(_tmpto)).show(); (new bootstrap.Toast(_tmpto)).show();
}, },
@@ -163,23 +163,23 @@ var FoniaJS = {
var _tsid = parseInt(Math.random() * 99999999); var _tsid = parseInt(Math.random() * 99999999);
var _ceksuper = null; var _ceksuper = null;
var _isi = new String('<div class="row mb-1" id="Auth_SP1"><div class="col-sm-6 col-lg-5">Username</div><div class="col-sm-6 col-lg-7"><input type="text" class="form-control" id="UID" name="UID" value="'+((_bsuper==false)?this.User.ID:'')+'" required="true"></div></div><div class="row mb-1" id="Auth_SP2"><div class="col-sm-6 col-lg-5">Password</div><div class="col-sm-6 col-lg-7"><input type="password" class="form-control" id="PWD" name="PWD" value="" required="true"></div></div><div class="row mb-1 d-none" id="Auth_SP3"><div class="col-12 text-center"><p>'+this.locale("Fonia.auth_wait_msg")+'</p></div></div><hr class="my-2"><div class="row mt-1"><div class="col-4"><button type="button" class="btn btn-outline-primary shadow-none" id="butSReq">Request</button></div><div class="col-8 text-end"><button type="button" class="btn btn-danger me-2" id="butSBatal" data-bs-dismiss="modal">Batal</button><button type="button" class="btn btn-success" id="butSOK">OK</button></div></div>'); var _isi = new String('<div class="row mb-1" id="Auth_SP1"><div class="col-sm-6 col-lg-5">Username</div><div class="col-sm-6 col-lg-7"><input type="text" class="form-control" id="UID" name="UID" value="'+((_bsuper==false)?this.User.ID:'')+'" required="true"></div></div><div class="row mb-1" id="Auth_SP2"><div class="col-sm-6 col-lg-5">Password</div><div class="col-sm-6 col-lg-7"><input type="password" class="form-control" id="PWD" name="PWD" value="" required="true"></div></div><div class="row mb-1 d-none" id="Auth_SP3"><div class="col-12 text-center"><p>'+this.locale("Fonia.auth_wait_msg")+'</p></div></div><hr class="my-2"><div class="row mt-1"><div class="col-4"><button type="button" class="btn btn-outline-primary shadow-none" id="butSReq">Request</button></div><div class="col-8 text-end"><button type="button" class="btn btn-danger me-2" id="butSBatal" data-bs-dismiss="modal">Batal</button><button type="button" class="btn btn-success" id="butSOK">OK</button></div></div>');
this.winSAuth = this.showWindow('SAuth', ((this.AUTH_LEVEL < 9 && _bsuper == true) ? this.locale("Fonia.auth_super") : this.locale("Fonia.auth_user")), _isi, 200, '', function(){ 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(function() { $('#butSOK').click(() => {
$('#butSOK').prop('disabled', true); $('#butSOK').prop('disabled', true);
new Request.JSON({ new Request.JSON({
url: this.WEB_PATH + "auth.php", url: this.WEB_PATH + "auth.php",
sendParam: ["mode=auth", "data=super-check", "UID", "PWD", "SUPER=" + _bsuper, "UOVER=" + _buover], sendParam: ["mode=auth", "data=super-check", "UID", "PWD", "SUPER=" + _bsuper, "UOVER=" + _buover],
onSuccess: function(adata) { onSuccess: (adata) => {
if (adata.status == 1) { if (adata.status == 1) {
fungcall(); fungcall();
} else { } else {
this.showError(adata.pesan); this.showError(adata.pesan);
} }
this.closeWindow(this.winSAuth); this.closeWindow(this.winSAuth);
}.bind(this) }
}).send(); }).send();
}.bind(this)); });
$('#butSBatal').click(function() { $('#butSBatal').click(() => {
if (_ceksuper) { if (_ceksuper) {
clearInterval(_ceksuper); clearInterval(_ceksuper);
new Request({ new Request({
@@ -187,8 +187,8 @@ var FoniaJS = {
sendParam: ["mode=auth", "data=super-cancel", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid] sendParam: ["mode=auth", "data=super-cancel", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid]
}).send(); }).send();
} }
}.bind(this)); });
$('#butSReq').click(function() { $('#butSReq').click(() => {
if (_breq == false) return false; if (_breq == false) return false;
$('#Auth_SP1').addClass('d-none'); $('#Auth_SP1').addClass('d-none');
$('#Auth_SP2').addClass('d-none'); $('#Auth_SP2').addClass('d-none');
@@ -199,7 +199,7 @@ var FoniaJS = {
sendParam: ["mode=auth", "data=super-request", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid, "MSG=" + tmsg] sendParam: ["mode=auth", "data=super-request", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid, "MSG=" + tmsg]
}).send(); }).send();
var _cobalagi = 5; var _cobalagi = 5;
_ceksuper = setInterval(function() { _ceksuper = setInterval(() => {
$('#butSBatal').html(this.locale("Fonia.cancel") + " (" + _cobalagi + ")"); $('#butSBatal').html(this.locale("Fonia.cancel") + " (" + _cobalagi + ")");
if (_cobalagi == 0) { if (_cobalagi == 0) {
clearInterval(_ceksuper); clearInterval(_ceksuper);
@@ -214,7 +214,7 @@ var FoniaJS = {
new Request.JSON({ new Request.JSON({
url: this.WEB_PATH + "auth.php", url: this.WEB_PATH + "auth.php",
sendParam: ["mode=auth", "data=request-check", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid], sendParam: ["mode=auth", "data=request-check", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid],
onSuccess: function(adata) { onSuccess: (adata) => {
if (adata.status == 1) { if (adata.status == 1) {
clearInterval(_ceksuper); clearInterval(_ceksuper);
this.showInfoLocale("Fonia.auth_success"); this.showInfoLocale("Fonia.auth_success");
@@ -223,17 +223,17 @@ var FoniaJS = {
} else { } else {
_cobalagi--; _cobalagi--;
} }
}.bind(this) }
}).send(); }).send();
}.bind(this), 3000); }, 3000);
}.bind(this)); });
$('#UID').keyup(function(e) { $('#UID').keyup((e) => {
if (-1!==$.inArray(e.which, [13,9])) { if (-1!==$.inArray(e.which, [13,9])) {
if (e.target.value != '') $('#PWD').focus(); if (e.currentTarget.value != '') $('#PWD').focus();
} }
}); });
$('#PWD').keyup(function(e) { $('#PWD').keyup((e) => {
if (e.target.value == '') return false; if (e.currentTarget.value == '') return false;
if (13 == e.which) $('#butSOK').trigger('click'); if (13 == e.which) $('#butSOK').trigger('click');
}); });
if (_bsuper == false) { if (_bsuper == false) {
@@ -241,14 +241,14 @@ var FoniaJS = {
} else { } else {
FoniaJS.setFocus("#UID"); FoniaJS.setFocus("#UID");
} }
}.bind(this)); });
}, },
genWinToolBut: function(menu) { genWinToolBut: function(menu) {
if (!menu) return ''; if (!menu) return '';
var smenu = ''; var smenu = '';
if (typeof menu === 'object'){ if (typeof menu === 'object'){
var ma = ' me-sm-2'; smenu = '<div class="col-12 col-sm-6 my-0 mx-sm-0 text-center text-sm-start">'; var ma = ' me-sm-2'; smenu = '<div class="col-12 col-sm-6 my-0 mx-sm-0 text-center text-sm-start">';
$.each(menu, function(i, atom) { $(menu).each((i, atom) => {
if (Object.keys(atom).length === 0) { if (Object.keys(atom).length === 0) {
smenu += '</div><div class="col-12 col-sm-6 my-0 mx-sm-0 text-center text-sm-end">'; smenu += '</div><div class="col-12 col-sm-6 my-0 mx-sm-0 text-center text-sm-end">';
ma = ' ms-sm-2'; ma = ' ms-sm-2';
@@ -271,7 +271,7 @@ var FoniaJS = {
var smenu = ''; var smenu = '';
if (typeof menu === 'object'){ if (typeof menu === 'object'){
var ma = ' me-sm-2'; smenu = '<div class="row mt-2 my-sm-2 justify-content-sm-between"><div class="col-sm-6 text-center text-sm-start">'; var ma = ' me-sm-2'; smenu = '<div class="row mt-2 my-sm-2 justify-content-sm-between"><div class="col-sm-6 text-center text-sm-start">';
$.each(menu, function(i, atom) { $(menu).each((i, atom) => {
if (Object.keys(atom).length === 0) { if (Object.keys(atom).length === 0) {
smenu += '</div><div class="col-sm-6 text-center text-sm-end">'; smenu += '</div><div class="col-sm-6 text-center text-sm-end">';
ma = ' ms-sm-2'; ma = ' ms-sm-2';
@@ -290,60 +290,63 @@ var FoniaJS = {
return smenu; return smenu;
}, },
FormDecorated: function() { FormDecorated: function() {
$('input').each(function() { $('input').each((i, el) => {
const elm = $(el);
// 16:shift 17:ctrl 18:alt 35:end 36:home 37:left 38:up 39:right 40:down 9:tab 13:enter 27:esc // 16:shift 17:ctrl 18:alt 35:end 36:home 37:left 38:up 39:right 40:down 9:tab 13:enter 27:esc
// 8:backspace 46:delete 45:delete 48-57/96-105:num 110/190:dot 109/189/173:minus 107/187/61:plus // 8:backspace 46:delete 45:delete 48-57/96-105:num 110/190:dot 109/189/173:minus 107/187/61:plus
if ($(this).hasClass('integer') || $(this).hasClass('angka')) { if (elm.hasClass('integer') || elm.hasClass('angka')) {
$(this).keydown(function(e) { elm.keydown((e) => {
var key = e.keyCode ?? e.which; var key = e.keyCode ?? e.which;
return (jQuery.inArray(key,[8,9,13,46,110,190])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105)); return (jQuery.inArray(key,[8,9,13,46,110,190])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105));
}); });
} else if ($(this).hasClass('number')) { } else if (elm.hasClass('number')) {
$(this).keydown(function(e) { elm.keydown((e) => {
var key = e.keyCode ?? e.which; var key = e.keyCode ?? e.which;
return (jQuery.inArray(key,[8,9,13,46,110,190,109,189,173])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105)); return (jQuery.inArray(key,[8,9,13,46,110,190,109,189,173])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105));
}); });
$(this).focus(function() { elm.focus((e) => {
$(this).val( FoniaJS.StrToFloat($(this).val()) ); $(e.currentTarget).val( FoniaJS.StrToFloat($(e.currentTarget).val()) );
}); });
$(this).blur(function() { elm.blur((e) => {
$(this).val( FoniaJS.FloatToStr($(this).val(), 0) ); $(e.currentTarget).val( FoniaJS.FloatToStr($(e.currentTarget).val(), 0) );
}); });
} else if ($(this).hasClass('double')) { } else if (elm.hasClass('double')) {
$(this).keydown(function(e) { elm.keydown((e) => {
var key = e.keyCode ?? e.which; var key = e.keyCode ?? e.which;
return (jQuery.inArray(key,[8,9,13,46,110,190,109,189,173])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105)); return (jQuery.inArray(key,[8,9,13,46,110,190,109,189,173])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105));
}); });
$(this).focus(function() { elm.focus((e) => {
$(this).val( FoniaJS.StrToFloat($(this).val()) ); $(e.currentTarget).val( FoniaJS.StrToFloat($(e.currentTarget).val()) );
$(this).select(); $(e.currentTarget).select();
}); });
$(this).blur(function() { elm.blur((e) => {
$(this).val( FoniaJS.FloatToStr($(this).val(), 2) ); $(e.currentTarget).val( FoniaJS.FloatToStr($(e.currentTarget).val(), 2) );
}); });
} else if ($(this).hasClass('phone')) { } else if (elm.hasClass('phone')) {
$(this).keyup(function() { elm.keyup((e) => {
var key = e.keyCode ?? e.which; var key = e.keyCode ?? e.which;
return (jQuery.inArray(key,[8,9,13,46,110,190,109,189,173,107,187,61])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105)); return (jQuery.inArray(key,[8,9,13,46,110,190,109,189,173,107,187,61])!==-1 || (key>=16 && key<=18) || (key>=35 && key<=40) || (key>=48 && key<=57) || (key>=96 && key<=105));
}); });
} else if ($(this).hasClass('error') && $(this).val()) { } else if (elm.hasClass('error') && elm.val()) {
var tmp_str = $(this).val(); var tmp_str = elm.val();
$(this).val(''); elm.val('');
FoniaJS.showError(tmp_str); FoniaJS.showError(tmp_str);
} }
}); });
$('.option-tags').each(function() { $('.option-tags').each((i, el) => {
const elm = $(el);
if (!jQuery.isFunction(jQuery.fn.select2)) return; if (!jQuery.isFunction(jQuery.fn.select2)) return;
var _opts = {tags: false, dropdownAutoWidth: true, width: 'auto', theme: 'bootstrap-5'}; var _opts = {tags: false, dropdownAutoWidth: true, width: 'auto', theme: 'bootstrap-5'};
var _dmodal = $(this).closest('div.modal'); var _dmodal = elm.closest('div.modal');
if ($(_dmodal).hasClass('modal')) _opts.dropdownParent = _dmodal; if ($(_dmodal).hasClass('modal')) _opts.dropdownParent = _dmodal;
var _sel2 = $(this).select2(_opts); var _sel2 = elm.select2(_opts);
if ($(this).prop('required')) _sel2.on('select2:close', function(e){ $(this).valid(); }); if (elm.prop('required')) elm.removeAttr('required');
//_sel2.on('select2:close', (e) =>{ $(e.target).valid(); });
}); });
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
$('.colorpic').each(function() { /*$('.colorpic').each((i, el) => {
$(this).prop('background-color', $(this).val()); $(el).prop('background-color', $(el).val());
}); });*/
if('function' == typeof jQuery.fn.datepicker){ if('function' == typeof jQuery.fn.datepicker){
$('.pickdate').datepicker({ $('.pickdate').datepicker({
@@ -361,16 +364,15 @@ var FoniaJS = {
RequestParam: function(aparam) { RequestParam: function(aparam) {
var tmp_hasil = []; var tmp_hasil = [];
var tmp_array = aparam; var tmp_array = aparam;
tmp_array.push('SID=' + parseInt(Math.random() * 99999999)); $('input').each((i, el) => {
$('input').each(function() { /*if (el.id.indexOf('_db')!==-1){
if (this.id.indexOf('_db')!==-1){ tmp_array.push(el.id);
tmp_array.push(this.id); }*/
} if (el.id.indexOf('_cbox')!==-1){
if (this.id.indexOf('_cbox')!==-1){ tmp_array.push(el.id + '=' + el.value);
tmp_array.push(this.id + '=' + this.value);
} }
}); });
$.each(tmp_array, function(i, nilai) { tmp_array.map(nilai => {
if (typeof nilai === "string") { if (typeof nilai === "string") {
var tmp_value = ""; var tmp_value = "";
if (nilai.indexOf("=") == -1) { if (nilai.indexOf("=") == -1) {
@@ -381,15 +383,15 @@ var FoniaJS = {
} else { } else {
tmp_value = ($('#'+nilai).is('.integer, .number, .double')) ? this.StrToFloat(tmp_value) : encodeURIComponent(tmp_value); tmp_value = ($('#'+nilai).is('.integer, .number, .double')) ? this.StrToFloat(tmp_value) : encodeURIComponent(tmp_value);
} }
if ($('#'+nilai).hasClass("cgrpbox")) { /*if ($('#'+nilai).hasClass("cgrpbox")) {//not used !
var _tmp_value = ""; var _tmp_value = "";
$('input').each(function() { $('input').each((i, el) => {
if (this.id.indexOf(nilai + "_cgrpbox")!==-1 && this.checked) { if (el.id.indexOf(nilai + "_cgrpbox")!==-1 && el.checked) {
_tmp_value += "," + this.value; _tmp_value += "," + el.value;
} }
}); });
tmp_value = _tmp_value.substr(1); tmp_value = _tmp_value.substr(1);
} }*/
} }
tmp_value = nilai + "=" + tmp_value; tmp_value = nilai + "=" + tmp_value;
} else { } else {
@@ -397,7 +399,8 @@ var FoniaJS = {
} }
tmp_hasil.push(tmp_value); tmp_hasil.push(tmp_value);
} }
}.bind(this)); });
tmp_hasil.push('SID=' + parseInt(Math.random() * 99999999));
return tmp_hasil; return tmp_hasil;
}, },
StrToFloat: function(str_val) { StrToFloat: function(str_val) {
@@ -466,7 +469,7 @@ var FoniaJS = {
return parseFloat((bytes / Math.pow(1024, i)).toFixed(dm)) + ' ' + sizes[i]; return parseFloat((bytes / Math.pow(1024, i)).toFixed(dm)) + ' ' + sizes[i];
}, },
showConfirm: function(str_judul, str_isi, func_callback, conf_tipe) { showConfirm: function(str_judul, str_isi, func_callback, conf_tipe) {
var _cfunc = (typeof func_callback == "function") ? func_callback : function() {}; var _cfunc = (typeof func_callback == "function") ? func_callback : () => {};
var _ctipe = (conf_tipe == null) ? 'modal-warning' : 'modal-'+conf_tipe; var _ctipe = (conf_tipe == null) ? 'modal-warning' : 'modal-'+conf_tipe;
var _btipe = (conf_tipe == null) ? 'btn-warning' : 'btn-'+conf_tipe; var _btipe = (conf_tipe == null) ? 'btn-warning' : 'btn-'+conf_tipe;
var _wtxt = var _wtxt =
@@ -478,9 +481,9 @@ var FoniaJS = {
'<div class="modal-footer"><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tidak</button><button type="button" class="btn '+_btipe+' ms-2" id="winConfirmY">Ya</button></div>'+ '<div class="modal-footer"><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tidak</button><button type="button" class="btn '+_btipe+' ms-2" id="winConfirmY">Ya</button></div>'+
'</div></div></div>'; '</div></div></div>';
if ($('#winAPPConf').length) $('#winAPPConf').modal('dispose').remove(); if ($('#winAPPConf').length) $('#winAPPConf').modal('dispose').remove();
$(_wtxt).on('shown.bs.modal', function(e){ $(_wtxt).on('shown.bs.modal', (e) => {
$('#winConfirmY').focus(); $('#winConfirmY').focus();
$('#winConfirmY').click(function(e){ $('#winConfirmY').click((e) => {
_cfunc(); _cfunc();
$('#winAPPConf').modal('hide'); $('#winAPPConf').modal('hide');
}); });
@@ -510,12 +513,12 @@ var FoniaJS = {
'<div class="modal-body">'+s_isi+'</div>'+ t_toolb + '<div class="modal-body">'+s_isi+'</div>'+ t_toolb +
'</div></div></div>'; '</div></div></div>';
if ($('#win'+id_wind).length) $('#win'+id_wind).modal('dispose').remove(); if ($('#win'+id_wind).length) $('#win'+id_wind).modal('dispose').remove();
$(_wtxt).on('shown.bs.modal', function(e){ $(_wtxt).on('shown.bs.modal', (e) => {
f_oncall(); f_oncall();
FoniaJS.FormDecorated(); FoniaJS.FormDecorated();
}).on('hidden.bs.modal', function(e){ }).on('hidden.bs.modal', (e) => {
f_offcall(); f_offcall();
$(this).remove(); $(e.currentTarget).remove();
}).modal('show'); }).modal('show');
return '#win'+id_wind; return '#win'+id_wind;
}, },
@@ -523,12 +526,12 @@ var FoniaJS = {
if ($(elWin).length) $(elWin).modal('hide'); if ($(elWin).length) $(elWin).modal('hide');
}, },
closeAllWindows: function() { closeAllWindows: function() {
$(".modal").each(function() { $(".modal").each((i, el) => {
if ($(this).hasClass('show')) $(this).modal('toggle'); if ($(el).hasClass('show')) $(el).modal('toggle');
if ($(this).attr('id')!=='sidebarMain') $(this).modal('dispose').remove(); if ($(el).attr('id')!=='sidebarMain') $(el).modal('dispose').remove();
}); });
$(".fon-autotext", ".fon-autopos").each(function() { $(".fon-autotext", ".fon-autopos").each((i, el) => {
$(this).remove(); $(el).remove();
}); });
if ($("#dataPrint").length) { if ($("#dataPrint").length) {
$("#dataPrint").empty(); $("#dataPrint").empty();
@@ -598,136 +601,82 @@ var FoniaJS = {
} }
}; };
var Request = function(options){ class _Request {
var vars = { options = {
url: "", url: '',
sendParam: [], sendParam: [],
onSuccess: null, onSuccess: () => {},
onFailure: null, onFailure: () => {},
data: null data: null,
}; dataType: 'text'
this.construct = function(options){ }
$.extend(vars, options);
}; constructor(options) {
this.send = function(){ $.extend(this.options, options);
if (!vars.url) { }
//if (this._debug)
console.log(vars.sendParam + ", cek url php!"); send() {
if (!this.options.url) {
console.log(this.options.sendParam + ", cek url php!");
return false; return false;
} }
vars.data = FoniaJS.RequestParam(vars.sendParam); this.options.data = FoniaJS.RequestParam(this.options.sendParam);
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: vars.url, url: this.options.url,
data: (vars.data).join('&'), data: (this.options.data).join('&'),
success: (typeof vars.onSuccess === "function") ? vars.onSuccess : null, success: (typeof this.options.onSuccess === "function") ? this.options.onSuccess : () => {},
error: (typeof vars.onFailure === "function") ? vars.onFailure : null, error: (typeof this.options.onFailure === "function") ? this.options.onFailure : () => {},
complete: FoniaJS.FormDecorated, complete: FoniaJS.FormDecorated,
dataType: this.options.dataType
}); });
return this; return this;
}; }
this.construct(options);
}; };
Request.JSON = function(options){ class _Request_JSONF extends _Request {
var vars = { constructor(options) {
url: "", const _options = Object.assign({}, options, {'dataType':'json'});
sendParam: [], _options.onSuccess = (data) => {
onSuccess: null,
onFailure: null,
data: []
};
this.construct = function(options){
$.extend(vars, options);
};
this.send = function(){
if (!vars.url) {
//if (this._debug)
console.log(vars.sendParam + ", cek url php!");
return false;
}
vars.data = FoniaJS.RequestParam(vars.sendParam);
$.ajax({
type: 'POST',
url: vars.url,
data: (vars.data).join('&'),
success: (typeof vars.onSuccess === "function") ? vars.onSuccess : null,
error: (typeof vars.onFailure === "function") ? vars.onFailure : null,
complete: FoniaJS.FormDecorated,
dataType: 'json'
});
return this;
};
this.construct(options);
};
Request.JSONF = function(options){
var vars = {
url: "",
sendParam: [],
onSuccess: null,
onFailure: null,
data: null
};
this.construct = function(options){
$.extend(vars, options);
};
this.send = function(){
if (!vars.url) {
//if (this._debug)
console.log(vars.sendParam + ", cek url php!");
return false;
}
vars.data = FoniaJS.RequestParam(vars.sendParam);
$.ajax({
type: 'POST',
url: vars.url,
data: (vars.data).join('&'),
success: function(data){
if (data.length > 0) { if (data.length > 0) {
for (var no = 0; no < data.length; no++) { $(data).each((i, ini) => {
var ini = data[no]; if (ini.type == "table" && $(ini.id)) this.make_table(ini);
if (ini.type == "table" && $(ini.id)) make_table(ini); if (ini.type == "form" && $(ini.id)) this.make_form(ini);
if (ini.type == "form" && $(ini.id)) make_form(ini); if (ini.type == "option" && $(ini.id)) this.make_option(ini);
if (ini.type == "option" && $(ini.id)) make_option(ini); if (ini.type == "html" && $(ini.id)) this.make_html(ini);
if (ini.type == "html" && $(ini.id)) make_html(ini); if (ini.type == "msg") this.show_msg(ini);
if (ini.type == "msg") show_msg(ini);
}
}
if (typeof vars.onSuccess === "function") vars.onSuccess(data);
},
error: (typeof vars.onFailure === "function") ? vars.onFailure : null,
complete: FoniaJS.FormDecorated,
dataType: 'json'
}); });
return this; }
if (typeof options.onSuccess === "function") options.onSuccess(data);
}; };
super(_options);
}
var show_msg = function(ini){ show_msg (ini) {
var wtime = parseInt(ini.wait); var wtime = parseInt(ini.wait);
if (ini.mode == "error") { if (ini.mode == "error") {
FoniaJS.showError(ini.value, wtime); FoniaJS.showError(ini.value, wtime);
} else { } else {
FoniaJS.showInfo(ini.value, wtime); FoniaJS.showInfo(ini.value, wtime);
} }
}; }
var make_html = function(ini){ make_html (ini) {
$('#'+ini.id).html(ini.value); $('#'+ini.id).html(ini.value);
}; }
var make_form = function(ini){ make_form (ini) {
var formIni = $('#'+ini.id); var formIni = $('#'+ini.id);
formIni.val(ini.value); formIni.val(ini.value);
if (ini.css) { if (ini.css) {
formIni.prop('disabled', ini.css=='disabled'); formIni.prop('disabled', ini.css=='disabled');
} }
}; }
var make_option = function(ini){ make_option (ini) {
var optIni = $('#'+ini.id); var optIni = $('#'+ini.id);
if (!optIni) return; if (!optIni) return;
if (ini.avalue) { if (ini.avalue) {
optIni.empty(); optIni.empty();
var o_group = 0; var o_group = 0;
$(ini.avalue).each(function(n, i) { $(ini.avalue).each((n, i) => {
if (i.optgroup) { if (i.optgroup) {
if (0 < o_group++) optIni.append('</optgroup>'); if (0 < o_group++) optIni.append('</optgroup>');
optIni.append('<optgroup label="'+i.optgroup+'">'); optIni.append('<optgroup label="'+i.optgroup+'">');
@@ -743,18 +692,18 @@ Request.JSONF = function(options){
optIni.val(ini.value); optIni.val(ini.value);
} }
optIni.trigger('change'); optIni.trigger('change');
}; }
var make_table = function(ini){ make_table (ini) {
var divData = $('#'+ini.id).empty(); var divData = $('#'+ini.id).empty();
var strHead = '<thead><tr>', iCol = 0, sClass = '', aSortCol = [], aTombol = []; var strHead = '<thead><tr>', iCol = 0, sClass = '', aSortCol = [], aTombol = [];
$.each(ini.header, function(key, val){ $(ini.header).each((key, val) => {
if (val.o == ini.config.sort_col) iCol = key; if (val.o == ini.config.sort_col) iCol = key;
strHead += '<th data-class-name="'+val.f+'">'+val.c+'</th>'; strHead += '<th data-class-name="'+val.f+'">'+val.c+'</th>';
aSortCol.push((val.s ? { 'orderDataType': val.s } : null)); aSortCol.push((val.s ? { 'orderDataType': val.s } : null));
}); });
if (ini.option.length > 0) { if (ini.option.length > 0) {
var strAksi = 'Aksi', ChkField = ''; var strAksi = 'Aksi', ChkField = '';
$.each(ini.option, function(key, val){ $(ini.option).each((key, val) => {
if (val.type == 'checkbox'){ if (val.type == 'checkbox'){
strAksi = '<input class="form-check-input" type="checkbox" id="'+ini.id+'_cbhead_'+val.field+'" value="'+val.avalue[1]+'">'; strAksi = '<input class="form-check-input" type="checkbox" id="'+ini.id+'_cbhead_'+val.field+'" value="'+val.avalue[1]+'">';
ChkField = val.field; ChkField = val.field;
@@ -771,7 +720,7 @@ Request.JSONF = function(options){
var strFoot = ''; var strFoot = '';
if (ini.footer) { if (ini.footer) {
strFoot = '<tfoot><tr>'; strFoot = '<tfoot><tr>';
$.each(ini.footer, function(key, val){ $(ini.footer).each((key, val) => {
strFoot += '<th class="'+ini.header[key].f+'">'+val.c+'</th>'; strFoot += '<th class="'+ini.header[key].f+'">'+val.c+'</th>';
}); });
strFoot += '<th>&nbsp;</th></tr></tfoot>'; strFoot += '<th>&nbsp;</th></tr></tfoot>';
@@ -783,9 +732,9 @@ Request.JSONF = function(options){
var strTab = '<table id="'+ini.id+'Tabel" class="table table-striped table-bordered table-hover'+sClass+'">'; var strTab = '<table id="'+ini.id+'Tabel" class="table table-striped table-bordered table-hover'+sClass+'">';
var strBody = '<tbody>'; var strBody = '<tbody>';
$.each(ini.content, function(key, val){ $(ini.content).each((key, val) => {
strBody += '<tr>'; strBody += '<tr>';
$.each(val, function(keyi, vali){ $(val).each((keyi, vali) => {
if (keyi == 0) return; if (keyi == 0) return;
strBody += '<td>' + vali + '</td>'; strBody += '<td>' + vali + '</td>';
}); });
@@ -795,7 +744,7 @@ Request.JSONF = function(options){
} }
if (ini.option.length > 0) { if (ini.option.length > 0) {
if (val[0].button.length > 0) { if (val[0].button.length > 0) {
$.each(val[0].button, function(keyb, valb){ $(val[0].button).each((keyb, valb) => {
var _link = (aTombol[valb[0]][1]==1) ? 'fon-tabel-dt' : valb[0]; var _link = (aTombol[valb[0]][1]==1) ? 'fon-tabel-dt' : valb[0];
var _cssa = (valb[1]=='') ? '' : ' text-'+valb[1]; var _cssa = (valb[1]=='') ? '' : ' text-'+valb[1];
var _cssb = (valb[1]=='') ? ' normal' : ' btn-'+valb[1]; var _cssb = (valb[1]=='') ? ' normal' : ' btn-'+valb[1];
@@ -820,7 +769,7 @@ Request.JSONF = function(options){
/** start live db **/ /** start live db **/
if (ini.config.live){ if (ini.config.live){
var post_data = {}; var post_data = {};
$(vars.data).map(function(key, item){ $(this.options.data).map((key, item) => {
var keyval = item.split("="); var keyval = item.split("=");
if (keyval[0] == 'SID') keyval[1] = parseInt(Math.random() * 99999999); if (keyval[0] == 'SID') keyval[1] = parseInt(Math.random() * 99999999);
if ((''+keyval[1]).indexOf('%') != -1) keyval[1] = decodeURIComponent(keyval[1]); if ((''+keyval[1]).indexOf('%') != -1) keyval[1] = decodeURIComponent(keyval[1]);
@@ -828,10 +777,10 @@ Request.JSONF = function(options){
}); });
opsi.serverSide = true; opsi.serverSide = true;
opsi.ajax = { opsi.ajax = {
url: vars.url, url: this.options.url,
type: 'POST', type: 'POST',
data: post_data, data: post_data,
dataFilter: function(data){ dataFilter: (data) => {
var json = {}, jsono = {'draw':0,'recordsTotal':0,'recordsFiltered':0,'data':[]}; var json = {}, jsono = {'draw':0,'recordsTotal':0,'recordsFiltered':0,'data':[]};
try { try {
json = jQuery.parseJSON(data); json = jQuery.parseJSON(data);
@@ -845,7 +794,7 @@ Request.JSONF = function(options){
console.log(e); console.log(e);
} }
$.each(jsono.data, function(key, val){ $(jsono.data).map((key, val) => {
var optval = val[0]; jsono.data[key].shift(); var optval = val[0]; jsono.data[key].shift();
var _tbtn1 = "", _tbtn2 = ""; var _tbtn1 = "", _tbtn2 = "";
if (optval.rowcss) { if (optval.rowcss) {
@@ -853,7 +802,7 @@ Request.JSONF = function(options){
} }
if (ini.option.length > 0) { if (ini.option.length > 0) {
if (optval.button.length > 0) { if (optval.button.length > 0) {
$.each(optval.button, function(keyb, valb){ $(optval.button).map((keyb, valb) => {
var _link = (aTombol[valb[0]][1]==1) ? 'fon-tabel-dt' : valb[0]; var _link = (aTombol[valb[0]][1]==1) ? 'fon-tabel-dt' : valb[0];
var _cssa = (valb[1]=='') ? '' : ' text-'+valb[1]; var _cssa = (valb[1]=='') ? '' : ' text-'+valb[1];
var _cssb = (valb[1]=='') ? ' normal' : ' btn-'+valb[1]; var _cssb = (valb[1]=='') ? ' normal' : ' btn-'+valb[1];
@@ -893,7 +842,7 @@ Request.JSONF = function(options){
_bcss = 'btn-secondary'; _bcss = 'btn-secondary';
} }
_navibar += '<div class="row"><div class="col">'; _navibar += '<div class="row"><div class="col">';
$.each(ini.navi.button, function(key, val){ $(ini.navi.button).map((key, val) => {
_navibar += '<button type="button" class="btn rounded-pill '+_bcss+' me-2"'+_dis+' onclick="'+val.func+'();">'+val.label+'</button>'; _navibar += '<button type="button" class="btn rounded-pill '+_bcss+' me-2"'+_dis+' onclick="'+val.func+'();">'+val.label+'</button>';
}); });
_navibar += '</div></div>'; _navibar += '</div></div>';
@@ -903,18 +852,18 @@ Request.JSONF = function(options){
} }
opsi.drawCallback = function(settings){ opsi.drawCallback = function(settings){
// apply rowcss to tr/row // apply rowcss to tr/row
$('#'+ini.id+'Tabel tbody td:last-child:has(span.rowcss)').each(function(){ $('#'+ini.id+'Tabel tbody td:last-child:has(span.rowcss)').map((i, el) => {
var span = $(this).find('span').attr('class').replace('rowcss ',''); var span = $(el).find('span').attr('class').replace('rowcss ','');
$(this).parent().addClass(span); $(el).parent().addClass(span);
}); });
// create hover title for awr class td // create hover title for awr class td
$('#'+ini.id+'Tabel tbody td[class*="awr"]').each(function(){ $('#'+ini.id+'Tabel tbody td[class*="awr"]').map((i, el) => {
$(this).attr('title', $(this).html().replace(/<br\s*[\/]?>/gi,'\n').replace(/(<([^>]+)>)/gi,'')); $(el).attr('title', $(el).html().replace(/<br\s*[\/]?>/gi,'\n').replace(/(<([^>]+)>)/gi,''));
}); });
// generate pagelength option // generate pagelength option
var api = this.api(), menudiv = $('select[name="'+ini.id+'Tabel_length"]'); var api = this.api(), menudiv = $('select[name="'+ini.id+'Tabel_length"]');
var record = api.page.info().recordsTotal ?? 0, _lmenu = []; var record = api.page.info().recordsTotal ?? 0, _lmenu = [];
$.each([10,25,50,100], function(key, val){ $([10,25,50,100]).map((key, val) => {
if (val > record && 10 < val) return false; if (val > record && 10 < val) return false;
_lmenu.push(val); _lmenu.push(val);
}); });
@@ -923,14 +872,14 @@ Request.JSONF = function(options){
} }
var _select = menudiv.val() ?? 10; var _select = menudiv.val() ?? 10;
menudiv.empty(); menudiv.empty();
$.each(_lmenu, function(key, val){ $(_lmenu).map((key, val) => {
$('<option/>', {'value':val, 'text':val}).appendTo(menudiv); $('<option/>', {'value':val, 'text':val}).appendTo(menudiv);
}); });
menudiv.val(_select); menudiv.val(_select);
// apply select function // apply select function
if (ini.config.func_select){ if (ini.config.func_select){
$('#'+ini.id+'Tabel tbody').on('click', 'tr', function(){ $('#'+ini.id+'Tabel tbody').on('click', 'tr', (e) => {
var dta = otabel.row(this).data(); var dta = otabel.row(e.currentTarget).data();
var fnc = ini.config.func_select.split('.'); var fnc = ini.config.func_select.split('.');
if (typeof window[fnc[0]][fnc[1]] === 'function') { window[fnc[0]][fnc[1]](dta); } if (typeof window[fnc[0]][fnc[1]] === 'function') { window[fnc[0]][fnc[1]](dta); }
else console.warn('fungsi '+ini.config.func_select+' tidak ada !'); else console.warn('fungsi '+ini.config.func_select+' tidak ada !');
@@ -941,31 +890,31 @@ Request.JSONF = function(options){
$('#'+ini.id+'Tabel thead input[type=checkbox][id*=_cbhead_]').off('change'); $('#'+ini.id+'Tabel thead input[type=checkbox][id*=_cbhead_]').off('change');
$('#'+ini.id+'Tabel tbody input[type=checkbox][id*=_cbox_]').off('change'); $('#'+ini.id+'Tabel tbody input[type=checkbox][id*=_cbox_]').off('change');
$('#'+ini.id+'Tabel tbody').off('click'); $('#'+ini.id+'Tabel tbody').off('click');
$.each(ini.option, function(key, val){ $(ini.option).map((key, val) => {
if (val.type == 'checkbox'){ if (val.type == 'checkbox'){
$('#'+ini.id+'Tabel thead input[type=checkbox][id*=_cbhead_]').on('change', function(){ $('#'+ini.id+'Tabel thead input[type=checkbox][id*=_cbhead_]').on('change', (e) => {
var _chek = this.checked; var _chek = e.currentTarget.checked;
this.value = (this.checked ? val.avalue[0] : val.avalue[1]); e.currentTarget.value = (e.currentTarget.checked ? val.avalue[0] : val.avalue[1]);
$('#'+ini.id+'Tabel tbody input[type=checkbox][id*='+val.field+'_cbox_]').each(function(){ $('#'+ini.id+'Tabel tbody input[type=checkbox][id*='+val.field+'_cbox_]').each((i, el) => {
this.checked = _chek; el.checked = _chek;
this.value = (this.checked ? val.avalue[0] : val.avalue[1]); el.value = (el.checked ? val.avalue[0] : val.avalue[1]);
}); });
}); });
$('#'+ini.id+'Tabel tbody input[type=checkbox][id*=_cbox_]').on('change', function(){ $('#'+ini.id+'Tabel tbody input[type=checkbox][id*=_cbox_]').on('change', (e) => {
this.value = (this.value == val.avalue[1] ? val.avalue[0] : val.avalue[1]); e.currentTarget.value = (e.currentTarget.value == val.avalue[1] ? val.avalue[0] : val.avalue[1]);
this.checked = this.value == val.avalue[0]; e.currentTarget.checked = e.currentTarget.value == val.avalue[0];
}); });
} else if (val.type == 'button'){ } else if (val.type == 'button'){
$('#'+ini.id+'Tabel tbody').on('click', '.'+val.icon, function(){ $('#'+ini.id+'Tabel tbody').on('click', '.'+val.icon, (e) => {
var dta = otabel.row($(this.closest('tr'))).data(); var dta = otabel.row($(e.currentTarget.closest('tr'))).data();
var fnc = val.func.split('.'); var fnc = val.func.split('.');
if (typeof window[fnc[0]][fnc[1]] === 'function') { window[fnc[0]][fnc[1]](dta, this); } if (typeof window[fnc[0]][fnc[1]] === 'function') { window[fnc[0]][fnc[1]](dta, e.currentTarget); }
else if (typeof window[fnc[0]] === 'function') { window[fnc[0]](dta, this); } else if (typeof window[fnc[0]] === 'function') { window[fnc[0]](dta, e.currentTarget); }
else console.warn('fungsi '+val.func+' tidak ada !'); else console.warn('fungsi '+val.func+' tidak ada !');
}); });
} else if (val.type == 'button-dt'){ } else if (val.type == 'button-dt'){
$('#'+ini.id+'Tabel tbody').on('click', '.fon-tabel-dt', function(){ $('#'+ini.id+'Tabel tbody').on('click', '.fon-tabel-dt', (e) => {
var tr = $(this).closest('tr'); var tr = $(e.currentTarget).closest('tr');
var row = otabel.row(tr); var row = otabel.row(tr);
if (row.child.isShown()){ if (row.child.isShown()){
row.child.hide(); row.child.hide();
@@ -986,8 +935,8 @@ Request.JSONF = function(options){
} }
}); });
} }
$('#'+ini.id+'Tabel tbody').on('click', 'td.dtr-control', function(){ $('#'+ini.id+'Tabel tbody').on('click', 'td.dtr-control', (e) => {
var tr = $(this).closest('tr'); var tr = $(e.currentTarget).closest('tr');
var row = otabel.row(tr); var row = otabel.row(tr);
if (row.child.isShown()){ if (row.child.isShown()){
row.child.hide(); row.child.hide();
@@ -1009,10 +958,22 @@ Request.JSONF = function(options){
}); });
} }
var otabel = $('#'+ini.id+'Tabel').DataTable(opsi); var otabel = $('#'+ini.id+'Tabel').DataTable(opsi);
}
}; };
this.construct(options);
var Request = function (options) {
return new _Request(options);
}; };
Request.JSON = function (options) {
const _options = Object.assign({}, options, {'dataType':'json'});
return new _Request(_options);
};
Request.JSONF = function(options){
return new _Request_JSONF(options);
}
if (jQuery.validator) { if (jQuery.validator) {
jQuery.validator.setDefaults({ jQuery.validator.setDefaults({
ignore: ':hidden, [readonly=readonly]', ignore: ':hidden, [readonly=readonly]',
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -21,7 +21,7 @@ var cPOLEDISPLAY = function(port, options){
flowControl: 'NONE' flowControl: 'NONE'
}; };
this.construct = function (port, options){//oke this.construct = function (port, options){
$.extend(_options, options); $.extend(_options, options);
_cd_port = port; _cd_port = port;
}; };
@@ -85,7 +85,7 @@ var cPOLEDISPLAY = function(port, options){
return " ".repeat(lPadding) + text + " ".repeat(rPadding); return " ".repeat(lPadding) + text + " ".repeat(rPadding);
}; };
this.cd_Error = function (err){//oke this.cd_Error = function (err){
console.error(err); console.error(err);
}; };
+73
View File
@@ -0,0 +1,73 @@
/*******************************************************************
Module : /assets/js/share.js
Desc. : JS Class Share File Cross Browser
Created By : Siau Pheng ([email protected]).
Created Date : May 27th, 2007.
Last Modified : January 19th, 2026.
(c) 2007 - 2026, 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
var cSHARE = function(url, options) {
var _options = {
'url': '',
'filename': '',
'title': '',
'text': 'share dari aplikasi'
};
var _params = [];
this.construct = function(url, options){
if (typeof url == 'object') {
$.extend(_options, url);
} else {
$.extend(_options, options);
_options.url = url;
}
};
this.set_url = function (url){
_options.url = url;
};
this.add_param = function(par_id, par_val) {
var _getvalue = (par_val) ? par_id + '=' + escape(par_val) : par_id;
_params.push(_getvalue);
};
this.share = async function() {
if (!_options.url) {
console.warn('cek url !');
return false;
}
var _pro = (window.location.protocol=='https:') ? 'https://' : 'http://';
var _src = _pro+FoniaJS.WEB_HOST + _options.url + '?' + (FoniaJS.RequestParam(_params)).join('&');
try {
const response = await fetch(_src)
.then(response => {
const cDispo = response.headers.get('Content-Disposition');
if (cDispo && cDispo.indexOf('filename=') !== -1) {
_options.filename = cDispo.split('filename=')[1].split(';')[0].replace(/"/g, '');
}
return response;
});
const blob = await response.blob();
const file = new File([blob], _options.filename, { type: blob.type });
if (navigator.canShare && navigator.canShare({ files: [file] })) {
await navigator.share({
files: [file],
title: _options.title ?? _options.filename,
text: _options.text
});
} else {
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = _options.filename;
link.click();
}
} catch (error) {
console.error('Sharing gagal:', error);
}
};
this.construct(url, options);
};