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-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 ********************************/
+35 -16
View File
@@ -4,40 +4,59 @@
Desc. : Fungsi-fungsi export data & laporan
Created By : Siau Pheng ([email protected]).
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 vars = {
var _options = {
'url': '',
'param': []
'filename': ''
};
var _params = [];
this.construct = function(url, options){
$.extend(vars, options);
vars.url = url;
if (typeof url == 'object') {
$.extend(_options, url);
} else {
$.extend(_options, options);
_options.url = url;
}
};
this.set_url = function (url){
vars.url = url;
_options.url = url;
};
this.add_param = function (par_id, par_val){
var _getvalue = (par_val) ? par_id + "=" + escape(par_val) : par_id;
vars.param.push(_getvalue);
_params.push(_getvalue);
},
this.download = function(){
if (!vars.url) {
console.warn(vars.param + ", cek url php!");
this.download = 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 + vars.url + '?' + (FoniaJS.RequestParam(vars.param)).join('&');
var $exportData = $('#IFrame_Export');
if (!$exportData.length) {
var $exportData = $('<iframe>', {id:'IFrame_Export','class':'d-none'}).appendTo('body');
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 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;
};
this.construct(url, options);
+206 -245
View File
@@ -13,7 +13,7 @@
'use strict';
var FoniaJS = {
version: "3.0.1",
version: "3.1.1",
APP_ID: 0,
APP_SID: "",
WEB_HOST: "",
@@ -64,7 +64,7 @@ var FoniaJS = {
new Request.JSON({
url: this.WEB_PATH + "auth.php",
sendParam: apar,
onSuccess: function(apop) {
onSuccess: (apop) => {
if (apop.login == false) {
this.showErrorLocale("Fonia.sess_expire");
setTimeout(function(){self.location = FoniaJS.WEB_PATH;}, 1600);
@@ -81,72 +81,72 @@ var FoniaJS = {
new Request({
url: this.WEB_PATH + "apps/php/" + apop.php,
sendParam: ["data=default"],
onSuccess: function(txt) {
onSuccess: (txt) => {
this.showWindow(apop.kode, apop.title, txt, apop.width, apop.button, function(){
if (typeof window[apop.func]['loading'] === 'function') window[apop.func]['loading'](q);
});
}.bind(this)
}
}).send();
} else {
$("#pageToolbarBot").html(this.genToolButton(apop.button));
new Request({
url: this.WEB_PATH + "apps/php/" + apop.php,
sendParam: ["data=default"],
onSuccess: function(txt) {
onSuccess: (txt) => {
$('#pageContent').html(txt);
if (typeof window[apop.func]['loading'] === 'function') window[apop.func]['loading'](q);
}
}).send();
}
}.bind(this)
}
}).send();
},
loadMenu: function() {
$(".mlink").click(function(e){
var sbar = $(this).closest('#sidebarMain');
var linkid = $(this).attr('id').replace("Link", "");
$('.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(function(e){
var ddown = $(this).closest('.dropdown-menu');
$('.slink').click((e) => {
var ddown = $(e.currentTarget).closest('.dropdown-menu');
if (ddown.length > 0) { ddown.dropdown('toggle'); }
});
if ($("#HomeLink").length){
$("#HomeLink").click(function(){
if ($('#HomeLink').length){
$('#HomeLink').click(() => {
this.closeAllWindows();
if (IndexJS.loading) IndexJS.loading();
}.bind(this));
});
}
if ($("#ExitLink").length) {
$("#ExitLink").click(function() {
if ($('#ExitLink').length) {
$('#ExitLink').click(() => {
new Request.JSON({
url: this.WEB_PATH + "apps/php/login.php",
sendParam: ["mode=logout"],
onFailure: function(){
onFailure: () => {
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 : "/";
if (typeof respon !== 'undefined' && respon.nexthost !== '/') _nurl = respon.nexthost;
self.location = _nurl;
}.bind(this)
}
}).send();
}.bind(this));
});
}
},
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');
_tmpto.on('hidden.bs.toast', function(e){
$(this).remove();
_tmpto.on('hidden.bs.toast', (e) => {
$(e.currentTarget).remove();
});
(new bootstrap.Toast(_tmpto)).show();
},
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');
_tmpto.on('hidden.bs.toast', function(e){
$(this).remove();
_tmpto.on('hidden.bs.toast', (e) => {
$(e.currentTarget).remove();
});
(new bootstrap.Toast(_tmpto)).show();
},
@@ -163,23 +163,23 @@ var FoniaJS = {
var _tsid = parseInt(Math.random() * 99999999);
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>');
this.winSAuth = this.showWindow('SAuth', ((this.AUTH_LEVEL < 9 && _bsuper == true) ? this.locale("Fonia.auth_super") : this.locale("Fonia.auth_user")), _isi, 200, '', function(){
$('#butSOK').click(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(() => {
$('#butSOK').prop('disabled', true);
new Request.JSON({
url: this.WEB_PATH + "auth.php",
sendParam: ["mode=auth", "data=super-check", "UID", "PWD", "SUPER=" + _bsuper, "UOVER=" + _buover],
onSuccess: function(adata) {
onSuccess: (adata) => {
if (adata.status == 1) {
fungcall();
} else {
this.showError(adata.pesan);
}
this.closeWindow(this.winSAuth);
}.bind(this)
}
}).send();
}.bind(this));
$('#butSBatal').click(function() {
});
$('#butSBatal').click(() => {
if (_ceksuper) {
clearInterval(_ceksuper);
new Request({
@@ -187,8 +187,8 @@ var FoniaJS = {
sendParam: ["mode=auth", "data=super-cancel", "KODE=" + ocall.KODE, "REQ_SID=" + this.APP_SID, "REQ=" + _tsid]
}).send();
}
}.bind(this));
$('#butSReq').click(function() {
});
$('#butSReq').click(() => {
if (_breq == false) return false;
$('#Auth_SP1').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]
}).send();
var _cobalagi = 5;
_ceksuper = setInterval(function() {
_ceksuper = setInterval(() => {
$('#butSBatal').html(this.locale("Fonia.cancel") + " (" + _cobalagi + ")");
if (_cobalagi == 0) {
clearInterval(_ceksuper);
@@ -214,7 +214,7 @@ var FoniaJS = {
new Request.JSON({
url: this.WEB_PATH + "auth.php",
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) {
clearInterval(_ceksuper);
this.showInfoLocale("Fonia.auth_success");
@@ -223,17 +223,17 @@ var FoniaJS = {
} else {
_cobalagi--;
}
}.bind(this)
}
}).send();
}.bind(this), 3000);
}.bind(this));
$('#UID').keyup(function(e) {
}, 3000);
});
$('#UID').keyup((e) => {
if (-1!==$.inArray(e.which, [13,9])) {
if (e.target.value != '') $('#PWD').focus();
if (e.currentTarget.value != '') $('#PWD').focus();
}
});
$('#PWD').keyup(function(e) {
if (e.target.value == '') return false;
$('#PWD').keyup((e) => {
if (e.currentTarget.value == '') return false;
if (13 == e.which) $('#butSOK').trigger('click');
});
if (_bsuper == false) {
@@ -241,14 +241,14 @@ var FoniaJS = {
} else {
FoniaJS.setFocus("#UID");
}
}.bind(this));
});
},
genWinToolBut: function(menu) {
if (!menu) return '';
var smenu = '';
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">';
$.each(menu, function(i, atom) {
$(menu).each((i, atom) => {
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">';
ma = ' ms-sm-2';
@@ -271,7 +271,7 @@ var FoniaJS = {
var smenu = '';
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">';
$.each(menu, function(i, atom) {
$(menu).each((i, atom) => {
if (Object.keys(atom).length === 0) {
smenu += '</div><div class="col-sm-6 text-center text-sm-end">';
ma = ' ms-sm-2';
@@ -290,61 +290,64 @@ var FoniaJS = {
return smenu;
},
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
// 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')) {
$(this).keydown(function(e) {
if (elm.hasClass('integer') || elm.hasClass('angka')) {
elm.keydown((e) => {
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));
});
} else if ($(this).hasClass('number')) {
$(this).keydown(function(e) {
} else if (elm.hasClass('number')) {
elm.keydown((e) => {
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));
});
$(this).focus(function() {
$(this).val( FoniaJS.StrToFloat($(this).val()) );
elm.focus((e) => {
$(e.currentTarget).val( FoniaJS.StrToFloat($(e.currentTarget).val()) );
});
$(this).blur(function() {
$(this).val( FoniaJS.FloatToStr($(this).val(), 0) );
elm.blur((e) => {
$(e.currentTarget).val( FoniaJS.FloatToStr($(e.currentTarget).val(), 0) );
});
} else if ($(this).hasClass('double')) {
$(this).keydown(function(e) {
} else if (elm.hasClass('double')) {
elm.keydown((e) => {
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));
});
$(this).focus(function() {
$(this).val( FoniaJS.StrToFloat($(this).val()) );
$(this).select();
elm.focus((e) => {
$(e.currentTarget).val( FoniaJS.StrToFloat($(e.currentTarget).val()) );
$(e.currentTarget).select();
});
$(this).blur(function() {
$(this).val( FoniaJS.FloatToStr($(this).val(), 2) );
elm.blur((e) => {
$(e.currentTarget).val( FoniaJS.FloatToStr($(e.currentTarget).val(), 2) );
});
} else if ($(this).hasClass('phone')) {
$(this).keyup(function() {
} else if (elm.hasClass('phone')) {
elm.keyup((e) => {
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));
});
} else if ($(this).hasClass('error') && $(this).val()) {
var tmp_str = $(this).val();
$(this).val('');
} else if (elm.hasClass('error') && elm.val()) {
var tmp_str = elm.val();
elm.val('');
FoniaJS.showError(tmp_str);
}
});
$('.option-tags').each(function() {
$('.option-tags').each((i, el) => {
const elm = $(el);
if (!jQuery.isFunction(jQuery.fn.select2)) return;
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;
var _sel2 = $(this).select2(_opts);
if ($(this).prop('required')) _sel2.on('select2:close', function(e){ $(this).valid(); });
var _sel2 = elm.select2(_opts);
if (elm.prop('required')) elm.removeAttr('required');
//_sel2.on('select2:close', (e) =>{ $(e.target).valid(); });
});
$('[data-toggle="tooltip"]').tooltip();
$('.colorpic').each(function() {
$(this).prop('background-color', $(this).val());
});
/*$('.colorpic').each((i, el) => {
$(el).prop('background-color', $(el).val());
});*/
if('function' == typeof jQuery.fn.datepicker){
$('.pickdate').datepicker({
format: 'dd-mm-yyyy',
@@ -361,16 +364,15 @@ var FoniaJS = {
RequestParam: function(aparam) {
var tmp_hasil = [];
var tmp_array = aparam;
tmp_array.push('SID=' + parseInt(Math.random() * 99999999));
$('input').each(function() {
if (this.id.indexOf('_db')!==-1){
tmp_array.push(this.id);
}
if (this.id.indexOf('_cbox')!==-1){
tmp_array.push(this.id + '=' + this.value);
$('input').each((i, el) => {
/*if (el.id.indexOf('_db')!==-1){
tmp_array.push(el.id);
}*/
if (el.id.indexOf('_cbox')!==-1){
tmp_array.push(el.id + '=' + el.value);
}
});
$.each(tmp_array, function(i, nilai) {
tmp_array.map(nilai => {
if (typeof nilai === "string") {
var tmp_value = "";
if (nilai.indexOf("=") == -1) {
@@ -381,15 +383,15 @@ var FoniaJS = {
} else {
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 = "";
$('input').each(function() {
if (this.id.indexOf(nilai + "_cgrpbox")!==-1 && this.checked) {
_tmp_value += "," + this.value;
$('input').each((i, el) => {
if (el.id.indexOf(nilai + "_cgrpbox")!==-1 && el.checked) {
_tmp_value += "," + el.value;
}
});
tmp_value = _tmp_value.substr(1);
}
}*/
}
tmp_value = nilai + "=" + tmp_value;
} else {
@@ -397,7 +399,8 @@ var FoniaJS = {
}
tmp_hasil.push(tmp_value);
}
}.bind(this));
});
tmp_hasil.push('SID=' + parseInt(Math.random() * 99999999));
return tmp_hasil;
},
StrToFloat: function(str_val) {
@@ -466,7 +469,7 @@ var FoniaJS = {
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 : function() {};
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 =
@@ -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></div></div>';
if ($('#winAPPConf').length) $('#winAPPConf').modal('dispose').remove();
$(_wtxt).on('shown.bs.modal', function(e){
$(_wtxt).on('shown.bs.modal', (e) => {
$('#winConfirmY').focus();
$('#winConfirmY').click(function(e){
$('#winConfirmY').click((e) => {
_cfunc();
$('#winAPPConf').modal('hide');
});
@@ -510,12 +513,12 @@ var FoniaJS = {
'<div class="modal-body">'+s_isi+'</div>'+ t_toolb +
'</div></div></div>';
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();
FoniaJS.FormDecorated();
}).on('hidden.bs.modal', function(e){
}).on('hidden.bs.modal', (e) => {
f_offcall();
$(this).remove();
$(e.currentTarget).remove();
}).modal('show');
return '#win'+id_wind;
},
@@ -523,12 +526,12 @@ var FoniaJS = {
if ($(elWin).length) $(elWin).modal('hide');
},
closeAllWindows: function() {
$(".modal").each(function() {
if ($(this).hasClass('show')) $(this).modal('toggle');
if ($(this).attr('id')!=='sidebarMain') $(this).modal('dispose').remove();
$(".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(function() {
$(this).remove();
$(".fon-autotext", ".fon-autopos").each((i, el) => {
$(el).remove();
});
if ($("#dataPrint").length) {
$("#dataPrint").empty();
@@ -598,136 +601,82 @@ var FoniaJS = {
}
};
var Request = function(options){
var vars = {
url: "",
class _Request {
options = {
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!");
onSuccess: () => {},
onFailure: () => {},
data: null,
dataType: 'text'
}
constructor(options) {
$.extend(this.options, options);
}
send() {
if (!this.options.url) {
console.log(this.options.sendParam + ", cek url php!");
return false;
}
vars.data = FoniaJS.RequestParam(vars.sendParam);
this.options.data = FoniaJS.RequestParam(this.options.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,
url: this.options.url,
data: (this.options.data).join('&'),
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;
};
this.construct(options);
}
};
Request.JSON = function(options){
var vars = {
url: "",
sendParam: [],
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);
};
class _Request_JSONF extends _Request {
constructor(options) {
const _options = Object.assign({}, options, {'dataType':'json'});
_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);
}
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) {
for (var no = 0; no < data.length; no++) {
var ini = data[no];
if (ini.type == "table" && $(ini.id)) make_table(ini);
if (ini.type == "form" && $(ini.id)) make_form(ini);
if (ini.type == "option" && $(ini.id)) make_option(ini);
if (ini.type == "html" && $(ini.id)) make_html(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;
};
var show_msg = function(ini){
show_msg (ini) {
var wtime = parseInt(ini.wait);
if (ini.mode == "error") {
FoniaJS.showError(ini.value, wtime);
} else {
FoniaJS.showInfo(ini.value, wtime);
}
};
var make_html = function(ini){
}
make_html (ini) {
$('#'+ini.id).html(ini.value);
};
var make_form = function(ini){
}
make_form (ini) {
var formIni = $('#'+ini.id);
formIni.val(ini.value);
if (ini.css) {
formIni.prop('disabled', ini.css=='disabled');
}
};
var make_option = function(ini){
}
make_option (ini) {
var optIni = $('#'+ini.id);
if (!optIni) return;
if (ini.avalue) {
optIni.empty();
var o_group = 0;
$(ini.avalue).each(function(n, i) {
$(ini.avalue).each((n, i) => {
if (i.optgroup) {
if (0 < o_group++) optIni.append('</optgroup>');
optIni.append('<optgroup label="'+i.optgroup+'">');
@@ -743,18 +692,18 @@ Request.JSONF = function(options){
optIni.val(ini.value);
}
optIni.trigger('change');
};
var make_table = function(ini){
}
make_table (ini) {
var divData = $('#'+ini.id).empty();
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;
strHead += '<th data-class-name="'+val.f+'">'+val.c+'</th>';
aSortCol.push((val.s ? { 'orderDataType': val.s } : null));
});
if (ini.option.length > 0) {
var strAksi = 'Aksi', ChkField = '';
$.each(ini.option, function(key, val){
$(ini.option).each((key, val) => {
if (val.type == 'checkbox'){
strAksi = '<input class="form-check-input" type="checkbox" id="'+ini.id+'_cbhead_'+val.field+'" value="'+val.avalue[1]+'">';
ChkField = val.field;
@@ -771,7 +720,7 @@ Request.JSONF = function(options){
var strFoot = '';
if (ini.footer) {
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>&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 strBody = '<tbody>';
$.each(ini.content, function(key, val){
$(ini.content).each((key, val) => {
strBody += '<tr>';
$.each(val, function(keyi, vali){
$(val).each((keyi, vali) => {
if (keyi == 0) return;
strBody += '<td>' + vali + '</td>';
});
@@ -795,7 +744,7 @@ Request.JSONF = function(options){
}
if (ini.option.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 _cssa = (valb[1]=='') ? '' : ' text-'+valb[1];
var _cssb = (valb[1]=='') ? ' normal' : ' btn-'+valb[1];
@@ -820,7 +769,7 @@ Request.JSONF = function(options){
/** start live db **/
if (ini.config.live){
var post_data = {};
$(vars.data).map(function(key, item){
$(this.options.data).map((key, item) => {
var keyval = item.split("=");
if (keyval[0] == 'SID') keyval[1] = parseInt(Math.random() * 99999999);
if ((''+keyval[1]).indexOf('%') != -1) keyval[1] = decodeURIComponent(keyval[1]);
@@ -828,10 +777,10 @@ Request.JSONF = function(options){
});
opsi.serverSide = true;
opsi.ajax = {
url: vars.url,
url: this.options.url,
type: 'POST',
data: post_data,
dataFilter: function(data){
dataFilter: (data) => {
var json = {}, jsono = {'draw':0,'recordsTotal':0,'recordsFiltered':0,'data':[]};
try {
json = jQuery.parseJSON(data);
@@ -845,7 +794,7 @@ Request.JSONF = function(options){
console.log(e);
}
$.each(jsono.data, function(key, val){
$(jsono.data).map((key, val) => {
var optval = val[0]; jsono.data[key].shift();
var _tbtn1 = "", _tbtn2 = "";
if (optval.rowcss) {
@@ -853,7 +802,7 @@ Request.JSONF = function(options){
}
if (ini.option.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 _cssa = (valb[1]=='') ? '' : ' text-'+valb[1];
var _cssb = (valb[1]=='') ? ' normal' : ' btn-'+valb[1];
@@ -893,7 +842,7 @@ Request.JSONF = function(options){
_bcss = 'btn-secondary';
}
_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 += '</div></div>';
@@ -903,18 +852,18 @@ Request.JSONF = function(options){
}
opsi.drawCallback = function(settings){
// apply rowcss to tr/row
$('#'+ini.id+'Tabel tbody td:last-child:has(span.rowcss)').each(function(){
var span = $(this).find('span').attr('class').replace('rowcss ','');
$(this).parent().addClass(span);
$('#'+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"]').each(function(){
$(this).attr('title', $(this).html().replace(/<br\s*[\/]?>/gi,'\n').replace(/(<([^>]+)>)/gi,''));
$('#'+ini.id+'Tabel tbody td[class*="awr"]').map((i, el) => {
$(el).attr('title', $(el).html().replace(/<br\s*[\/]?>/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 = [];
$.each([10,25,50,100], function(key, val){
$([10,25,50,100]).map((key, val) => {
if (val > record && 10 < val) return false;
_lmenu.push(val);
});
@@ -923,14 +872,14 @@ Request.JSONF = function(options){
}
var _select = menudiv.val() ?? 10;
menudiv.empty();
$.each(_lmenu, function(key, val){
$(_lmenu).map((key, val) => {
$('<option/>', {'value':val, 'text':val}).appendTo(menudiv);
});
menudiv.val(_select);
// apply select function
if (ini.config.func_select){
$('#'+ini.id+'Tabel tbody').on('click', 'tr', function(){
var dta = otabel.row(this).data();
$('#'+ini.id+'Tabel tbody').on('click', 'tr', (e) => {
var dta = otabel.row(e.currentTarget).data();
var fnc = ini.config.func_select.split('.');
if (typeof window[fnc[0]][fnc[1]] === 'function') { window[fnc[0]][fnc[1]](dta); }
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 tbody input[type=checkbox][id*=_cbox_]').off('change');
$('#'+ini.id+'Tabel tbody').off('click');
$.each(ini.option, function(key, val){
$(ini.option).map((key, val) => {
if (val.type == 'checkbox'){
$('#'+ini.id+'Tabel thead input[type=checkbox][id*=_cbhead_]').on('change', function(){
var _chek = this.checked;
this.value = (this.checked ? val.avalue[0] : val.avalue[1]);
$('#'+ini.id+'Tabel tbody input[type=checkbox][id*='+val.field+'_cbox_]').each(function(){
this.checked = _chek;
this.value = (this.checked ? val.avalue[0] : val.avalue[1]);
$('#'+ini.id+'Tabel thead input[type=checkbox][id*=_cbhead_]').on('change', (e) => {
var _chek = e.currentTarget.checked;
e.currentTarget.value = (e.currentTarget.checked ? val.avalue[0] : val.avalue[1]);
$('#'+ini.id+'Tabel tbody input[type=checkbox][id*='+val.field+'_cbox_]').each((i, el) => {
el.checked = _chek;
el.value = (el.checked ? val.avalue[0] : val.avalue[1]);
});
});
$('#'+ini.id+'Tabel tbody input[type=checkbox][id*=_cbox_]').on('change', function(){
this.value = (this.value == val.avalue[1] ? val.avalue[0] : val.avalue[1]);
this.checked = this.value == val.avalue[0];
$('#'+ini.id+'Tabel tbody input[type=checkbox][id*=_cbox_]').on('change', (e) => {
e.currentTarget.value = (e.currentTarget.value == val.avalue[1] ? val.avalue[0] : val.avalue[1]);
e.currentTarget.checked = e.currentTarget.value == val.avalue[0];
});
} else if (val.type == 'button'){
$('#'+ini.id+'Tabel tbody').on('click', '.'+val.icon, function(){
var dta = otabel.row($(this.closest('tr'))).data();
$('#'+ini.id+'Tabel tbody').on('click', '.'+val.icon, (e) => {
var dta = otabel.row($(e.currentTarget.closest('tr'))).data();
var fnc = val.func.split('.');
if (typeof window[fnc[0]][fnc[1]] === 'function') { window[fnc[0]][fnc[1]](dta, this); }
else if (typeof window[fnc[0]] === 'function') { window[fnc[0]](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, e.currentTarget); }
else console.warn('fungsi '+val.func+' tidak ada !');
});
} else if (val.type == 'button-dt'){
$('#'+ini.id+'Tabel tbody').on('click', '.fon-tabel-dt', function(){
var tr = $(this).closest('tr');
$('#'+ini.id+'Tabel tbody').on('click', '.fon-tabel-dt', (e) => {
var tr = $(e.currentTarget).closest('tr');
var row = otabel.row(tr);
if (row.child.isShown()){
row.child.hide();
@@ -986,8 +935,8 @@ Request.JSONF = function(options){
}
});
}
$('#'+ini.id+'Tabel tbody').on('click', 'td.dtr-control', function(){
var tr = $(this).closest('tr');
$('#'+ini.id+'Tabel tbody').on('click', 'td.dtr-control', (e) => {
var tr = $(e.currentTarget).closest('tr');
var row = otabel.row(tr);
if (row.child.isShown()){
row.child.hide();
@@ -995,7 +944,7 @@ Request.JSONF = function(options){
}else{
var ind = 0;
var tampil = '<ul class="list-unstyled">';
api.columns().every(function() {
api.columns().every(function(){
var kol = this.header();
if (kol.className.indexOf('dtr-hidden') != -1){
tampil += '<li class="py-1"><span class="d-inline-block" style="min-width:100px;">' + kol.textContent + '</span><span class="text-break">' + row.data()[ind] + '</span></li>';
@@ -1009,10 +958,22 @@ Request.JSONF = function(options){
});
}
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) {
jQuery.validator.setDefaults({
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'
};
this.construct = function (port, options){//oke
this.construct = function (port, options){
$.extend(_options, options);
_cd_port = port;
};
@@ -85,7 +85,7 @@ var cPOLEDISPLAY = function(port, options){
return " ".repeat(lPadding) + text + " ".repeat(rPadding);
};
this.cd_Error = function (err){//oke
this.cd_Error = function (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);
};