Refactor multiple JavaScript classes to use ES6 syntax, including Download, Pdf, Printer, PrinterPos, PoleDisplay, and Simulator. Update method names for consistency and improve error handling. Modify AJAX requests to enhance functionality and user experience.

This commit is contained in:
2026-11-02 16:10:36 +07:00
parent 929f3af79a
commit 11e17bd978
6 changed files with 560 additions and 440 deletions
+95 -68
View File
@@ -1,84 +1,111 @@
/*******************************************************************
Module : /assets/js/simulator.js
Desc. : JS Class Simulator Data dalam Code
Created By : Siau Pheng ([email protected]).
Created Date : March 18th, 2021.
Last Modified : December 26th, 2025.
Last Modified : November 2nd, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************
*
* Class Simulator
*
* Simulator Data untuk sinkron data dengan JSON
*
* @license MIT, https://www.3fonia.com
* @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]>
*
* @param {object} options
* @param {string} options.url - Endpoint URL Print Page
* @param {Array} [options.params] - Request payload
*/
*******************************************************************/
class Simulator {
constructor(options = {}) {
this.url = typeof options === 'string' ? options : options.url || '';
this.params = options.params || [];
}
var Simulator = function(options){
var vars = {
'url': '',
'param': []
};
this.construct = function(options){
if (typeof options == 'object') {
$.extend(vars, options);
} else vars.url = options;
};
this.set_url = function (url){
vars.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);
},
this.doPreview = function(){
if (!vars.url) console.warn(vars.param + ", cek url php!");
addParam(id, val) {
this.params.push(val !== undefined ? `${id}=${encodeURIComponent(val)}` : id);
return this;
}
doPreview() {
if (!this.url) {
console.warn('Url Simulator dibutuhkan!');
return;
}
$.ajax({
type: 'POST',
url: vars.url,
data: FoniaJS.RequestParam(vars.param),
success: function(data){
if (data.length == 0) {
url: this.url,
data: FoniaJS.RequestParam(this.params),
dataType: 'json',
error: typeof onFailure === 'function' ? onFailure : null,
success: (data) => {
if (!data || data.length === 0) {
FoniaJS.showInfo('Tidak ada data !');
return false;
}
var _divd = '';
for (var no = 0; no < data.length; no++) {
_divd += '<div class="sim-code px-2 py-2 mb-1 border border-info">' + data[no] + '</div>';
}
var _wtxt =
'<div class="modal fade" id="winAPPSim" tabindex="-1" role="dialog" data-bs-keyboard="false" data-bs-show="false" data-bs-backdrop="static" aria-labelledby="winAPPSimLabel" aria-hidden="true">'+
'<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-fs" role="document">'+
'<div class="modal-content">'+
'<div class="modal-header"><h5 class="modal-title" id="winAPPSimLabel">Code Simulator</h5><div class="ms-auto"><button class="btn me-2" id="tombSalin" type="button" aria-label="Salin Semua"><i class="bi-copy me-2"></i><span aria-hidden="true">Salin Semua</span></button><button class="btn" type="button" data-bs-dismiss="modal" aria-label="Tutup"><i class="bi-x-lg me-2"></i><span aria-hidden="true">Tutup</span></button></div></div>'+
'<div class="modal-body">'+_divd+'</div>'+
'</div></div></div>';
if ($('#winAPPSim')) $('#winAPPSim').modal('dispose').remove();
$(_wtxt).on('shown.bs.modal', function(e){
$('#winAPPSim').find('#tombSalin').click(function(){
window.getSelection().removeAllRanges();
$('.sim-code').each(function(i, ele) {
var range = document.createRange();
range.selectNode(ele);
window.getSelection().addRange(range);
const divContent = data
.map(item => `<div class="sim-code px-2 py-2 mb-1 border border-info">${item}</div>`)
.join('');
const modalHtml = `
<div class="modal fade" id="winAPPSim" tabindex="-1" role="dialog" data-bs-keyboard="false" data-bs-show="false" data-bs-backdrop="static" aria-labelledby="winAPPSimLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-fs" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="winAPPSimLabel">Code Simulator</h5>
<div class="ms-auto">
<button class="btn me-2" id="tombSalin" type="button" aria-label="Salin Semua">
<i class="bi-copy me-2"></i><span aria-hidden="true">Salin Semua</span>
</button>
<button class="btn" type="button" data-bs-dismiss="modal" aria-label="Tutup">
<i class="bi-x-lg me-2"></i><span aria-hidden="true">Tutup</span>
</button>
</div>
</div>
<div class="modal-body">${divContent}</div>
</div>
</div>
</div>`;
$('#winAPPSim').modal('dispose').remove();
$(modalHtml)
.on('shown.bs.modal', function () {
const $modal = $(this);
// Copy all code blocks
$modal.find('#tombSalin').on('click', () => {
window.getSelection().removeAllRanges();
$('.sim-code').each((_, ele) => {
const range = document.createRange();
range.selectNode(ele);
window.getSelection().addRange(range);
});
document.execCommand('copy');
window.getSelection().removeAllRanges();
FoniaJS.showInfo('Sukses salin semua Kode !');
});
document.execCommand('copy');
window.getSelection().removeAllRanges();
FoniaJS.showInfo('Sukses salin semua Kode !');
});
$('#winAPPSim').find('.sim-code').click(function(){
var range = document.createRange();
range.selectNode(this);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
//$(this).addClass('bg-success');
$(this).addClass('d-none');
});
}).on('hidden.bs.modal', function(e){
$(this).remove();
}).modal('show');
},
error: (typeof vars.onFailure === "function") ? vars.onFailure : null,
dataType: 'json'
// Copy individual code block and hide it
$modal.find('.sim-code').on('click', function () {
const range = document.createRange();
range.selectNode(this);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
$(this).addClass('d-none');
});
})
.on('hidden.bs.modal', function () {
$(this).remove();
})
.modal('show');
}
});
};
this.construct(options);
};
}
}