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:
+76
-72
@@ -4,82 +4,86 @@
|
|||||||
Desc. : Fungsi-fungsi download data & laporan
|
Desc. : Fungsi-fungsi download 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 : October 2nd, 2026.
|
Last Modified : November 2nd, 2026.
|
||||||
|
|
||||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||||
|
|
||||||
*******************************************************************/
|
*******************************************************************
|
||||||
|
*
|
||||||
|
* Class Download
|
||||||
|
*
|
||||||
|
* Download atau Share file.
|
||||||
|
*
|
||||||
|
* @license MIT, https://www.3fonia.com
|
||||||
|
* @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]>
|
||||||
|
*
|
||||||
|
* @param {object} options
|
||||||
|
* @param {string} options.url - Endpoint URL File
|
||||||
|
* @param {string} [options.filename='file.bin'] - Default file name for download is header is missing
|
||||||
|
* @param {string} [options.title] - Title for share file
|
||||||
|
* @param {string} [options.text] - Text for share file
|
||||||
|
* @param {Array} [options.params] - Request payload
|
||||||
|
*/
|
||||||
|
|
||||||
var Download = function(options) {
|
class Download {
|
||||||
var _options = {
|
constructor(options = {}) {
|
||||||
'url': '',
|
this.url = typeof options === 'string' ? options : options.url || '';
|
||||||
'filename': 'file.bin',
|
this.filename = options.filename || 'file.bin';
|
||||||
'title': '',
|
this.title = options.title || '';
|
||||||
'text': 'share dari aplikasi'
|
this.text = options.text || '';
|
||||||
};
|
this.params = options.params || [];
|
||||||
var _params = [];
|
|
||||||
|
|
||||||
this.construct = function(options){
|
|
||||||
if (typeof options == 'object') {
|
|
||||||
$.extend(_options, options);
|
|
||||||
} else _options.url = options;
|
|
||||||
};
|
|
||||||
this.set_url = function (url){
|
|
||||||
_options.url = url;
|
|
||||||
};
|
|
||||||
this.add_param = function(par_id, par_val) {
|
|
||||||
var _getvalue = (par_val) ? par_id + '=' + encodeURIComponent(par_val) : par_id;
|
|
||||||
_params.push(_getvalue);
|
|
||||||
};
|
|
||||||
this._exec = async function(is_share) {
|
|
||||||
if (!_options.url) {
|
|
||||||
console.warn('cek url !');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const blob = await $.ajax({
|
|
||||||
type: 'POST',
|
|
||||||
url: _options.url,
|
|
||||||
data: FoniaJS.RequestParam(_params),
|
|
||||||
xhrFields: {
|
|
||||||
responseType: 'blob'
|
|
||||||
},
|
|
||||||
success: async function (data, status, xhr) {
|
|
||||||
const disposition = xhr.getResponseHeader('Content-Disposition');
|
|
||||||
if (disposition && disposition.indexOf('attachment') !== -1) {
|
|
||||||
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
|
||||||
const matches = filenameRegex.exec(disposition);
|
|
||||||
if (matches != null && matches[1]) {
|
|
||||||
_options.filename = matches[1].replace(/['"]/g, '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const file = new File([blob], _options.filename, { type: blob.type });
|
|
||||||
|
|
||||||
if (is_share === true && 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) {
|
addParam(id, val) {
|
||||||
console.error('Download / sharing gagal :', error);
|
this.params.push(val !== undefined ? `${id}=${encodeURIComponent(val)}` : id);
|
||||||
};
|
|
||||||
return this;
|
return this;
|
||||||
};
|
}
|
||||||
this.share = async function() {
|
|
||||||
await this._exec(true);
|
async _exec(isShare = false) {
|
||||||
};
|
if (!this.url) {
|
||||||
this.download = async function() {
|
console.warn('Url File Download dibutuhkan!');
|
||||||
await this._exec(false);
|
return;
|
||||||
};
|
}
|
||||||
this.construct(options);
|
await $.ajax({
|
||||||
};
|
type: 'POST',
|
||||||
|
url: this.url,
|
||||||
|
data: FoniaJS.RequestParam(this.params),
|
||||||
|
xhrFields: { responseType: 'blob' }
|
||||||
|
})
|
||||||
|
.done((blob, status, xhr) => {
|
||||||
|
let filename = this.filename;
|
||||||
|
const disposition = xhr.getResponseHeader('Content-Disposition');
|
||||||
|
const match = disposition?.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
|
||||||
|
if (match?.[1]) filename = match[1].replace(/['"]/g, '');
|
||||||
|
|
||||||
|
if (!isShare) {
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const link = Object.assign(document.createElement('a'), {
|
||||||
|
href: url,
|
||||||
|
download: filename
|
||||||
|
});
|
||||||
|
link.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
} else {
|
||||||
|
const file = new File([blob], filename, { type: blob.type });
|
||||||
|
if (isShare && navigator.canShare?.({ files: [file] })) {
|
||||||
|
navigator.share({
|
||||||
|
files: [file],
|
||||||
|
title: this.title || filename,
|
||||||
|
text: this.text
|
||||||
|
});
|
||||||
|
}
|
||||||
|
file = null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail((xhr, status, err) => console.error('Gagal download File karena : ', err));
|
||||||
|
}
|
||||||
|
|
||||||
|
share() {
|
||||||
|
return this._exec(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
download() {
|
||||||
|
return this._exec(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+3
-6
@@ -784,7 +784,7 @@ class Request_JSF extends Request {
|
|||||||
|
|
||||||
const opsi = {
|
const opsi = {
|
||||||
responsive: true,
|
responsive: true,
|
||||||
columnDefs: [{ responsivePriority: 1, targets: 0 }, { responsivePriority: 2, targets: 1 }, { responsivePriority: 0, targets: -1 }],
|
columnDefs: [{ responsivePriority: 1, targets: 0 }, { responsivePriority: 2, targets: 1 }],
|
||||||
lengthMenu: [],
|
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>>',
|
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,
|
autoWidth: false,
|
||||||
@@ -866,7 +866,7 @@ class Request_JSF extends Request {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ini.option.length > 0) opsi.columnDefs.push({ responsivePriority: 3, targets: -1 }, { orderable: false, targets: -1 });
|
if (ini.option.length > 0) opsi.columnDefs.push({ responsivePriority: 0, targets: -1 }, { orderable: false, targets: -1 });
|
||||||
if (ini.navi.no_navi === true) opsi.paging = false;
|
if (ini.navi.no_navi === true) opsi.paging = false;
|
||||||
|
|
||||||
if (ini.config.scrollbar === true) {
|
if (ini.config.scrollbar === true) {
|
||||||
@@ -900,7 +900,7 @@ class Request_JSF extends Request {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
opsi.drawCallback = () => {
|
opsi.drawCallback = function() {
|
||||||
$(`#${ini.id}Tabel tbody td:last-child:has(span.rowcss)`).each((i, el) => {
|
$(`#${ini.id}Tabel tbody td:last-child:has(span.rowcss)`).each((i, el) => {
|
||||||
const span = $(el).find('span').attr('class').replace('rowcss ', '');
|
const span = $(el).find('span').attr('class').replace('rowcss ', '');
|
||||||
$(el).parent().addClass(span);
|
$(el).parent().addClass(span);
|
||||||
@@ -1014,9 +1014,6 @@ class Request_JSF extends Request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//const Request = (options) => new _Request(options);
|
|
||||||
//RequestF = (options) => new _Request_JSONF(options);
|
|
||||||
|
|
||||||
// jQuery Validator setup
|
// jQuery Validator setup
|
||||||
if (jQuery.validator) {
|
if (jQuery.validator) {
|
||||||
jQuery.validator.setDefaults({
|
jQuery.validator.setDefaults({
|
||||||
|
|||||||
+113
-53
@@ -4,63 +4,123 @@
|
|||||||
Desc. : JS - Cetak Laporan PDF
|
Desc. : JS - Cetak Laporan PDF
|
||||||
Created By : Siau Pheng (siaupheng@3fonia.com).
|
Created By : Siau Pheng (siaupheng@3fonia.com).
|
||||||
Created Date : April 6th, 2015.
|
Created Date : April 6th, 2015.
|
||||||
Last Modified : October 18th, 2020.
|
Last Modified : November 2nd, 2026.
|
||||||
|
|
||||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||||
|
|
||||||
*******************************************************************/
|
*******************************************************************
|
||||||
|
*
|
||||||
|
* Class Pdf
|
||||||
|
*
|
||||||
|
* Preview dan download file pdf.
|
||||||
|
*
|
||||||
|
* @license MIT, https://www.3fonia.com
|
||||||
|
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
|
||||||
|
*
|
||||||
|
* @param {object} options
|
||||||
|
* @param {string} options.url - Endpoint PDF File URL
|
||||||
|
* @param {number} [options.zoom=80] - Zoom percentage in PDF viewer
|
||||||
|
* @param {string} [options.filename='report.pdf'] - Default file name for download is header is missing
|
||||||
|
* @param {Array} [options.params] - Request payload
|
||||||
|
*/
|
||||||
|
|
||||||
var Pdf = function(options){
|
class Pdf {
|
||||||
var vars = {
|
constructor(options = {}) {
|
||||||
'url': '',
|
this.url = typeof options === 'string' ? options : options.url || '';
|
||||||
'zoom': 80,
|
this.zoom = options.zoom || 80;
|
||||||
'param': []
|
this.filename = options.filename || 'report.pdf';
|
||||||
};
|
this.params = options.params || [];
|
||||||
this.construct = function(options){
|
|
||||||
if (typeof options == 'object') {
|
|
||||||
$.extend(vars, options);
|
|
||||||
} else vars.url = options;
|
|
||||||
};
|
|
||||||
this.set_url = function (url){
|
|
||||||
vars.url = url;
|
|
||||||
};
|
|
||||||
this.set_zoom = function (zoom){
|
|
||||||
if (zoom) vars.zoom = zoom;
|
|
||||||
},
|
|
||||||
this.add_param = function (par_id, par_val){
|
|
||||||
var _getvalue = (par_val) ? par_id + "=" + escape(par_val) : par_id;
|
|
||||||
vars.param.push(_getvalue);
|
|
||||||
},
|
|
||||||
this.downloadPDF = function(){
|
|
||||||
if (!vars.url) {
|
|
||||||
console.warn(vars.param + ", cek url php!");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
$.ajax({
|
|
||||||
type: 'POST',
|
addParam(id, val) {
|
||||||
url: vars.url,
|
this.params.push(val !== undefined ? `${id}=${encodeURIComponent(val)}` : id);
|
||||||
data: FoniaJS.RequestParam(vars.param),
|
|
||||||
success: (typeof vars.onSuccess === "function") ? vars.onSuccess : null,
|
|
||||||
error: (typeof vars.onFailure === "function") ? vars.onFailure : null,
|
|
||||||
}).always(FoniaJS.FormDecorated);
|
|
||||||
return this;
|
return this;
|
||||||
};
|
}
|
||||||
this.showPDF = function(){
|
|
||||||
var _proto = window.location.protocol + '//';
|
async downloadPdf() {
|
||||||
var _src = _proto + FoniaJS.WEB_HOST + vars.url + '?' + $.param(FoniaJS.RequestParam(vars.param)) + '#zoom='+vars.zoom+',0,0&page=1';
|
if (!this.url) {
|
||||||
var _wtxt =
|
console.warn('Url PDF dibutuhkan!');
|
||||||
'<div class="modal fade" id="winAPPPDF" tabindex="-1" role="dialog" data-bs-keyboard="false" data-bs-show="false" data-bs-backdrop="static" aria-labelledby="winAPPPDFLabel" aria-hidden="true">'+
|
return;
|
||||||
'<div class="modal-dialog modal-dialog-centered modal-fs" role="document">'+
|
}
|
||||||
'<div class="modal-content">'+
|
await $.ajax({
|
||||||
'<div class="modal-header"><h5 class="modal-title" id="winAPPPDFLabel">Preview PDF</h5><button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button></div>'+
|
type: 'POST',
|
||||||
'<div class="modal-body mb-0 p-0"><div class="ratio ratio-21x9"><object type="application/pdf" data="'+_src+'"><p>Tidak Mendukung Preview PDF</p></object></div></div>'+
|
url: this.url,
|
||||||
'</div></div></div>';
|
data: FoniaJS.RequestParam(this.params),
|
||||||
if ($('#winAPPPDF')) $('#winAPPPDF').modal('dispose').remove();
|
xhrFields: { responseType: 'blob' }
|
||||||
$(_wtxt).on('shown.bs.modal', function(e){
|
})
|
||||||
FoniaJS.FormDecorated();
|
.done((blob, status, xhr) => {
|
||||||
}).on('hidden.bs.modal', function(e){
|
let filename = this.filename;
|
||||||
|
const disposition = xhr.getResponseHeader('Content-Disposition');
|
||||||
|
const match = disposition?.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
|
||||||
|
if (match?.[1]) filename = match[1].replace(/['"]/g, '');
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const link = Object.assign(document.createElement('a'), {
|
||||||
|
href: url,
|
||||||
|
download: filename
|
||||||
|
});
|
||||||
|
link.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
})
|
||||||
|
.fail((xhr, status, err) => console.error('Gagal proses download PDF karena : ', err));
|
||||||
|
}
|
||||||
|
|
||||||
|
async showPdf() {
|
||||||
|
if (!this.url) {
|
||||||
|
console.warn('Url PDF dibutuhkan!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await $.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: this.url,
|
||||||
|
data: FoniaJS.RequestParam(this.params),
|
||||||
|
xhrFields: { responseType: 'blob' }
|
||||||
|
})
|
||||||
|
.done((blob, status, xhr) => {
|
||||||
|
let filename = this.filename;
|
||||||
|
const disposition = xhr.getResponseHeader('Content-Disposition');
|
||||||
|
const match = disposition?.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
|
||||||
|
if (match?.[1]) filename = match[1].replace(/['"]/g, '');
|
||||||
|
|
||||||
|
const objectUrl = URL.createObjectURL(blob);
|
||||||
|
const pdfSrc = `${objectUrl}#zoom=${zoom}&page=1`;
|
||||||
|
|
||||||
|
const modalHtml = `
|
||||||
|
<div class="modal fade" id="winAPPPDF" tabindex="-1" data-bs-backdrop="static" aria-labelledby="winAPPPDFLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered modal-xl" style="height: 90vh;">
|
||||||
|
<div class="modal-content h-100">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="winAPPPDFLabel">${filename}</h5>
|
||||||
|
<div class="ms-auto d-flex align-items-center gap-2">
|
||||||
|
<a href="${objectUrl}" download="${filename}" class="btn btn-sm btn-outline-primary">
|
||||||
|
<i class="bi bi-download"></i> Download
|
||||||
|
</a>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body p-0 h-100">
|
||||||
|
<object data="${pdfSrc}" type="application/pdf" class="w-100 h-100">
|
||||||
|
<iframe src="${pdfSrc}" class="w-100 h-100" style="border: none;">
|
||||||
|
<p class="p-3">Ada kendala dalam Preview PDF di browser Anda.
|
||||||
|
<a href="${objectUrl}" download="${filename}">Unduh ${filename}</a> instead.
|
||||||
|
</p>
|
||||||
|
</iframe>
|
||||||
|
</object>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
$('#winAPPPDF').modal('dispose').remove();
|
||||||
|
$(modalHtml)
|
||||||
|
.appendTo('body')
|
||||||
|
//.on('shown.bs.modal', () => FoniaJS.FormDecorated())
|
||||||
|
.on('hidden.bs.modal', function () {
|
||||||
|
URL.revokeObjectURL(objectUrl);
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
}).modal('show');
|
})
|
||||||
};
|
.modal('show');
|
||||||
this.construct(options);
|
})
|
||||||
};
|
.fail((xhr, status, err) => console.error('Gagal proses preview PDF karena : ', err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ class PoleDisplay {
|
|||||||
qz.serial.openPort(this.port, this.options)
|
qz.serial.openPort(this.port, this.options)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.pole = this.port;
|
this.pole = this.port;
|
||||||
this.cd_Error(`${this.port} opened`);
|
this._conerr(`${this.port} opened`);
|
||||||
return qz.serial.sendData(this.pole, { type: 'HEX', data: 'x1Bx40' }, this.options);
|
return qz.serial.sendData(this.pole, { type: 'HEX', data: 'x1Bx40' }, this.options);
|
||||||
})
|
})
|
||||||
.catch(this.cd_Error);
|
.catch(this._conerr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Close() {
|
Close() {
|
||||||
@@ -42,9 +42,9 @@ class PoleDisplay {
|
|||||||
qz.serial.closePort(this.port)
|
qz.serial.closePort(this.port)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.pole = '';
|
this.pole = '';
|
||||||
this.cd_Error(`${this.port} closed`);
|
this._conerr(`${this.port} closed`);
|
||||||
})
|
})
|
||||||
.catch(this.cd_Error);
|
.catch(this._conerr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Send(txt) {
|
Send(txt) {
|
||||||
@@ -57,15 +57,15 @@ class PoleDisplay {
|
|||||||
|
|
||||||
let textToSend = txt;
|
let textToSend = txt;
|
||||||
if (Array.isArray(txt)) {
|
if (Array.isArray(txt)) {
|
||||||
textToSend = txt.map(ele => this.cd_Text(ele.t, ele.a)).join('');
|
textToSend = txt.map(ele => this._aligntext(ele.t, ele.a)).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
const hexData = `x10C${asciiToHex(textToSend)}`;
|
const hexData = `x10C${asciiToHex(textToSend)}`;
|
||||||
qz.serial.sendData(this.pole, { type: 'HEX', data: hexData }, this.options)
|
qz.serial.sendData(this.pole, { type: 'HEX', data: hexData }, this.options)
|
||||||
.catch(this.cd_Error);
|
.catch(this._conerr);
|
||||||
}
|
}
|
||||||
|
|
||||||
cd_Text(text, align = 'L') {
|
_aligntext(text, align = 'L') {
|
||||||
const totWidth = 20;
|
const totWidth = 20;
|
||||||
if (text.length >= totWidth) return text.substring(0, totWidth);
|
if (text.length >= totWidth) return text.substring(0, totWidth);
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ class PoleDisplay {
|
|||||||
return ' '.repeat(lPadding) + text + ' '.repeat(rPadding);
|
return ' '.repeat(lPadding) + text + ' '.repeat(rPadding);
|
||||||
}
|
}
|
||||||
|
|
||||||
cd_Error(err) {
|
_conerr(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+201
-169
@@ -4,233 +4,265 @@
|
|||||||
Desc. : JS Class Printer & Printer POS
|
Desc. : JS Class Printer & Printer POS
|
||||||
Created By : Siau Pheng (siaupheng@3fonia.com).
|
Created By : Siau Pheng (siaupheng@3fonia.com).
|
||||||
Created Date : May 27th, 2007.
|
Created Date : May 27th, 2007.
|
||||||
Last Modified : September 21st, 2026.
|
Last Modified : November 2nd, 2026.
|
||||||
|
|
||||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||||
|
|
||||||
*******************************************************************/
|
*******************************************************************
|
||||||
|
*
|
||||||
|
* Class Printer
|
||||||
|
*
|
||||||
|
* Standard Web Document Printing & Report Preview Class
|
||||||
|
*
|
||||||
|
* @license MIT, https://www.3fonia.com
|
||||||
|
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
|
||||||
|
*
|
||||||
|
* @param {object} options
|
||||||
|
* @param {string} options.url - Endpoint URL Print Page
|
||||||
|
* @param {number} [options.zoom=90] - Zoom percentage in viewer
|
||||||
|
* @param {Array} [options.params] - Request payload
|
||||||
|
*/
|
||||||
|
|
||||||
var Printer = function(options){
|
class Printer {
|
||||||
var vars = {
|
constructor(options = {}) {
|
||||||
'url': '',
|
this.url = typeof options === 'string' ? options : options.url || '';
|
||||||
'zoom': 90,
|
this.zoom = options.zoom || 90;
|
||||||
'param': []
|
this.params = options.params || [];
|
||||||
};
|
}
|
||||||
this.construct = function(options){
|
|
||||||
if (typeof options == 'object') {
|
addParam(id, val) {
|
||||||
$.extend(vars, options);
|
this.params.push(val !== undefined ? `${id}=${encodeURIComponent(val)}` : id);
|
||||||
} else vars.url = options;
|
return this;
|
||||||
};
|
}
|
||||||
this.set_url = function (url){
|
|
||||||
vars.url = url;
|
doPrint() {
|
||||||
};
|
if (!this.url) {
|
||||||
this.set_zoom = function (zoom){
|
console.warn('Url Laporan dibutuhkan!');
|
||||||
if (zoom) vars.zoom = zoom;
|
return;
|
||||||
},
|
|
||||||
this.add_param = function (par_id, par_val){
|
|
||||||
var _getvalue = (par_val) ? par_id + "=" + escape(par_val) : par_id;
|
|
||||||
vars.param.push(_getvalue);
|
|
||||||
},
|
|
||||||
this.doPrint = function(){
|
|
||||||
if (!vars.url) {
|
|
||||||
console.warn(vars.param + ", cek url php!");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: vars.url,
|
url: this.url,
|
||||||
data: FoniaJS.RequestParam(vars.param),
|
data: FoniaJS.RequestParam(this.params),
|
||||||
success: (txt) => {
|
success: (txt) => {
|
||||||
var $printData = $('#dataPrint');
|
let $printData = $('#dataPrint');
|
||||||
if (!$printData.length) {
|
if (!$printData.length) {
|
||||||
$printData = $('<div/>', {id:'dataPrint','class':'d-none d-print-block print-body'}).appendTo('body');
|
$printData = $('<div/>', {
|
||||||
|
id: 'dataPrint',
|
||||||
|
class: 'd-none d-print-block print-body'
|
||||||
|
}).appendTo('body');
|
||||||
}
|
}
|
||||||
$printData.html(txt);
|
$printData.html(txt);
|
||||||
window.print();
|
window.print();
|
||||||
},
|
},
|
||||||
error: (typeof vars.onFailure === "function") ? vars.onFailure : null,
|
error: typeof this.onFailure === 'function' ? this.onFailure : null
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
};
|
}
|
||||||
this.doPreview = function(){
|
|
||||||
if (!vars.url) console.warn(vars.param + ", cek url php!");
|
doPreview() {
|
||||||
|
if (!this.url) {
|
||||||
|
console.warn('Url Laporan dibutuhkan!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: vars.url,
|
url: this.url,
|
||||||
data: FoniaJS.RequestParam(vars.param),
|
data: FoniaJS.RequestParam(this.params),
|
||||||
success: (txt) => {
|
success: (txt) => {
|
||||||
if ('' == txt) {
|
if (!txt) {
|
||||||
FoniaJS.showInfo('Tidak ada data untuk pembuatan laporan !');
|
FoniaJS.showInfo('Tidak ada data untuk pembuatan laporan !');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var _wtxt =
|
const modalHtml = `
|
||||||
'<div class="modal fade" id="winAPPPrint" tabindex="-1" role="dialog" data-bs-keyboard="false" data-bs-show="false" data-bs-backdrop="static" aria-labelledby="winAPPPrintLabel" aria-hidden="true">'+
|
<div class="modal fade" id="winAPPPrint" tabindex="-1" role="dialog" data-bs-keyboard="false" data-bs-show="false" data-bs-backdrop="static" aria-labelledby="winAPPPrintLabel" aria-hidden="true">
|
||||||
'<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-fs" role="document">'+
|
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-fs" role="document">
|
||||||
'<div class="modal-content">'+
|
<div class="modal-content">
|
||||||
'<div class="modal-header"><h5 class="modal-title" id="winAPPPrintLabel">Preview Laporan</h5><div class="ms-auto"><button class="btn me-2" id="tombCetak" type="button" aria-label="Cetak"><i class="bi-printer me-2"></i><span aria-hidden="true">Cetak</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-header">
|
||||||
'<div class="modal-body print-body" id="divPrintP">'+txt+'</div>'+
|
<h5 class="modal-title" id="winAPPPrintLabel">Preview Laporan</h5>
|
||||||
'</div></div></div>';
|
<div class="ms-auto">
|
||||||
if ($('#winAPPPrint')) $('#winAPPPrint').modal('dispose').remove();
|
<button class="btn me-2" id="tombCetak" type="button" aria-label="Cetak">
|
||||||
$(_wtxt).on('shown.bs.modal', (e) => {
|
<i class="bi-printer me-2"></i><span aria-hidden="true">Cetak</span>
|
||||||
$('#winAPPPrint').find('#tombCetak').click(() => {
|
</button>
|
||||||
var $printData = $('#dataPrint');
|
<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 print-body" id="divPrintP">${txt}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
$('#winAPPPrint').modal('dispose').remove();
|
||||||
|
$(modalHtml)
|
||||||
|
.on('shown.bs.modal', () => {
|
||||||
|
$('#winAPPPrint #tombCetak').off('click').on('click', () => {
|
||||||
|
let $printData = $('#dataPrint');
|
||||||
if (!$printData.length) {
|
if (!$printData.length) {
|
||||||
$printData = $('<div/>', {id:'dataPrint','class':'d-none d-print-block print-body'}).appendTo('body');
|
$printData = $('<div/>', {
|
||||||
|
id: 'dataPrint',
|
||||||
|
class: 'd-none d-print-block print-body'
|
||||||
|
}).appendTo('body');
|
||||||
}
|
}
|
||||||
$printData.html($('#divPrintP').html());
|
$printData.html($('#divPrintP').html());
|
||||||
FoniaJS.closeWindow($('#winAPPPrint'));
|
FoniaJS.closeWindow($('#winAPPPrint'));
|
||||||
window.print();
|
window.print();
|
||||||
});
|
});
|
||||||
}).on('hidden.bs.modal', (e) => {
|
})
|
||||||
|
.on('hidden.bs.modal', function () {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
}).modal('show');
|
})
|
||||||
|
.modal('show');
|
||||||
},
|
},
|
||||||
error: (typeof vars.onFailure === "function") ? vars.onFailure : null,
|
error: typeof this.onFailure === 'function' ? this.onFailure : null
|
||||||
});
|
});
|
||||||
};
|
return this;
|
||||||
this.construct(options);
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
var PrinterPos = function(options) {
|
/**
|
||||||
var b_default = false;
|
* Class PrinterPos
|
||||||
var _options = {
|
*
|
||||||
'url': '',
|
* Direct Thermal POS Printer Class (via QZ Tray API)
|
||||||
'param': [],
|
*
|
||||||
'printer': null,
|
* @license MIT, https://www.3fonia.com
|
||||||
'cut_paper': "\x1D\x56\x41",
|
* @copyright Copyright (c) 2008-2026, Siau Pheng <siaupheng@3fonia.com>
|
||||||
'open_draw': "\x1B\x70\x30\x19\x19",
|
*
|
||||||
'chr_norm': "\x1B\x21\x01",
|
* @param {object} options
|
||||||
'chr_bold': "\x1B\x21\x10",
|
* @param {string} options.url - Endpoint URL Print Page
|
||||||
'chr_sbold': "\x1B\x21\x31",
|
* @param {number} [options.printer=FoniaJS._def_printer] - Printer Name
|
||||||
'chr_uline': "\x1B\x21\x80"
|
* @param {Array} [options.params] - Request payload
|
||||||
};
|
*/
|
||||||
this.construct = function(options) {
|
|
||||||
if (typeof options == 'object') {
|
class PrinterPos {
|
||||||
$.extend(_options, options);
|
constructor(options = {}) {
|
||||||
} else _options.url = options;
|
this.url = typeof options === 'string' ? options : options.url || '';
|
||||||
if (FoniaJS._def_printer) _options.printer = FoniaJS._def_printer;
|
this.printer = options.printer || (FoniaJS._def_printer ?? null);
|
||||||
};
|
this.cut_paper = options.cut_paper || '\x1D\x56\x41';
|
||||||
this.detectPrinter = function() {
|
this.open_draw = options.open_draw || '\x1B\x70\x30\x19\x19';
|
||||||
if (!qz.websocket.isActive()) {
|
this.chr_norm = options.chr_norm || '\x1B\x21\x01';
|
||||||
|
this.chr_bold = options.chr_bold || '\x1B\x21\x10';
|
||||||
|
this.chr_sbold = options.chr_sbold || '\x1B\x21\x31';
|
||||||
|
this.chr_uline = options.chr_uline || '\x1B\x21\x80';
|
||||||
|
this.params = options.params || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
_detectPrinter() {
|
||||||
|
if (!qz?.websocket?.isActive?.()) {
|
||||||
FoniaJS.showInfo('Status Printer belum Active !');
|
FoniaJS.showInfo('Status Printer belum Active !');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
|
||||||
this.getPrinters = function() {
|
|
||||||
return [];
|
|
||||||
};
|
|
||||||
this.setPrinter = function(nprint) {
|
|
||||||
(nprint != null) && (_options.printer = nprint);
|
|
||||||
};
|
|
||||||
this.useDefaultPrinter = function() {
|
|
||||||
b_default = true;
|
|
||||||
};
|
|
||||||
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;
|
|
||||||
_options.param.push(_getvalue);
|
|
||||||
};
|
|
||||||
this.exec = function() {
|
|
||||||
if (!this.detectPrinter()) return;
|
|
||||||
if (this.b_default) {
|
|
||||||
var parent = this;
|
|
||||||
qz.printers.getDefault().then(function(data) {
|
|
||||||
var nama_p = data;
|
|
||||||
if (data.name != undefined) {
|
|
||||||
nama_p = data.name;
|
|
||||||
}
|
}
|
||||||
parent._options.param.push('Printer='+nama_p);
|
|
||||||
return parent.do_print(nama_p, parent._options.url, parent._options.param);
|
setPrinter(nprint) {
|
||||||
}, function(data) {
|
if (nprint != null) this.printer = nprint;
|
||||||
FoniaJS.showInfo(data);
|
return this;
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var _nprinter = _options.printer;
|
|
||||||
if (typeof _nprinter === 'object' && _nprinter.name == undefined) {
|
|
||||||
if (_nprinter.file != undefined) _nprinter = _nprinter.file;
|
|
||||||
if (_nprinter.host != undefined) _nprinter = _nprinter.host + ":" + _nprinter.port;
|
|
||||||
} else {
|
|
||||||
if (_nprinter.name != undefined) _nprinter = _nprinter.name;
|
|
||||||
if (_nprinter== undefined) _nprinter = 'None';
|
|
||||||
}
|
}
|
||||||
_options.param.push('Printer='+_nprinter);
|
|
||||||
this.do_print(_options.printer, _options.url, _options.param);
|
addParam(id, val) {
|
||||||
|
this.params.push(val !== undefined ? `${id}=${encodeURIComponent(val)}` : id);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
this.do_print = function(nama_p, url, params) {
|
async exec() {
|
||||||
var qzcfg = qz.configs.create(nama_p);
|
if (!this._detectPrinter()) return;
|
||||||
|
|
||||||
|
let printerName = this.printer;
|
||||||
|
if (typeof printerName === 'object' && printerName !== null) {
|
||||||
|
if (printerName.name !== undefined) {
|
||||||
|
printerName = printerName.name;
|
||||||
|
} else if (printerName.file !== undefined) {
|
||||||
|
printerName = printerName.file;
|
||||||
|
} else if (printerName.host !== undefined) {
|
||||||
|
printerName = `${printerName.host}:${printerName.port}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printerName = printerName ?? 'None';
|
||||||
|
this.params.push(`Printer=${printerName}`);
|
||||||
|
this.doPrint(this.printer, this.url, this.params);
|
||||||
|
}
|
||||||
|
|
||||||
|
doPrint(printerName, url, params) {
|
||||||
|
const qzcfg = qz.configs.create(printerName);
|
||||||
new Request({
|
new Request({
|
||||||
url: url,
|
url,
|
||||||
sendParam: params,
|
sendParam: params,
|
||||||
onSuccess: (ajson) => {
|
onSuccess: (ajson) => {
|
||||||
if (typeof ajson === "object") {
|
if (typeof ajson === 'object' && ajson !== null) {
|
||||||
var hasil_cetak = (ajson.type == "escp") ? this.gen_escp(ajson) : this.gen_epl(ajson);
|
const printPayload = ajson.type === 'escp' ? this.genEscp(ajson) : this.genEpl(ajson);
|
||||||
qz.print(qzcfg, hasil_cetak);
|
qz.print(qzcfg, printPayload);
|
||||||
} else {
|
} else {
|
||||||
FoniaJS.showInfo('Error dalam proses Cetak.');
|
FoniaJS.showInfo('Error dalam proses Cetak.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).send();
|
}).send();
|
||||||
};
|
|
||||||
this.gen_escp = function(adata) {
|
|
||||||
var ohead = [];
|
|
||||||
var osheet = [], ocetak = [];
|
|
||||||
ohead.push("\x1B\x40");
|
|
||||||
ohead.push("\x1B\x61\x01");
|
|
||||||
if (adata.config.logo != null) {
|
|
||||||
//ohead.push({type:'raw',format:'image',data:adata.config.logo,options:{language:'ESCPOS',dotDensity:'double'}});
|
|
||||||
//ohead.push("\x1B\x32");
|
|
||||||
ohead.push({type:'raw',format:'image',flavor:'base64',data:adata.config.logo,options:{language:'ESCPOS',dotDensity:'double'}});
|
|
||||||
ohead.push("\x1B\x32");
|
|
||||||
}
|
}
|
||||||
if (parseInt(adata.config.fontsize) == 2) {
|
|
||||||
_options.chr_norm = "\x1B\x21\x02";
|
genEscp(adata) {
|
||||||
|
const ohead = ['\x1B\x40', '\x1B\x61\x01'];
|
||||||
|
if (adata.config?.logo) {
|
||||||
|
ohead.push({
|
||||||
|
type: 'raw',
|
||||||
|
format: 'image',
|
||||||
|
flavor: 'base64',
|
||||||
|
data: adata.config.logo,
|
||||||
|
options: { language: 'ESCPOS', dotDensity: 'double' }
|
||||||
|
});
|
||||||
|
ohead.push('\x1B\x32');
|
||||||
}
|
}
|
||||||
if (adata.header.length > 0) {
|
if (parseInt(adata.config?.fontsize, 10) === 2) {
|
||||||
for (i = 0; i < adata.header.length; i++) {
|
this.chr_norm = '\x1B\x21\x02';
|
||||||
if (i==0 && adata.config.logo==null) ohead.push(_options.chr_bold);
|
|
||||||
ohead.push(adata.header[i] + "\x0A");
|
|
||||||
if (i==0 && adata.config.logo==null) ohead.push(_options.chr_norm);
|
|
||||||
}
|
}
|
||||||
|
if (Array.isArray(adata.header)) {
|
||||||
|
adata.header.forEach((headerLine, index) => {
|
||||||
|
if (index === 0 && !adata.config?.logo) ohead.push(this.chr_bold);
|
||||||
|
ohead.push(`${headerLine}\x0A`);
|
||||||
|
if (index === 0 && !adata.config?.logo) ohead.push(this.chr_norm);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
for (s = 0; s < adata.content.length; s++) {
|
|
||||||
if (adata.content[s].length == 0) continue;
|
let ocetak = [];
|
||||||
osheet = ohead.slice(0);
|
if (Array.isArray(adata.content)) {
|
||||||
for (i = 0; i < adata.content[s].length; i++) {
|
adata.content.forEach((sheetContent) => {
|
||||||
var tmp_cont = adata.content[s][i];
|
if (!sheetContent?.length) return;
|
||||||
tmp_cont = tmp_cont.replace('_SBOLD_', _options.chr_sbold)
|
const osheet = [...ohead];
|
||||||
.replace('_BOLD_', _options.chr_bold)
|
sheetContent.forEach((line) => {
|
||||||
.replace('_NORM_', _options.chr_norm)
|
const formattedLine = line
|
||||||
.replace('_ULINE_', _options.chr_uline);
|
.replace('_SBOLD_', this.chr_sbold)
|
||||||
osheet.push(tmp_cont + "\x0A");
|
.replace('_BOLD_', this.chr_bold)
|
||||||
}
|
.replace('_NORM_', this.chr_norm)
|
||||||
if (adata.config.cutpaper) {
|
.replace('_ULINE_', this.chr_uline);
|
||||||
osheet.push(_options.cut_paper + "\x0A");
|
osheet.push(`${formattedLine}\x0A`);
|
||||||
|
});
|
||||||
|
if (adata.config?.cutpaper) {
|
||||||
|
osheet.push(`${this.cut_paper}\x0A`);
|
||||||
}
|
}
|
||||||
ocetak = ocetak.concat(osheet);
|
ocetak = ocetak.concat(osheet);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
var notaout = [];
|
|
||||||
if (adata.config.opendraw) {
|
let notaout = [];
|
||||||
notaout.push(_options.open_draw);
|
if (adata.config?.opendraw) {
|
||||||
|
notaout.push(this.open_draw);
|
||||||
}
|
}
|
||||||
for (i = 0; i < adata.config.times; i++) {
|
const times = adata.config?.times || 1;
|
||||||
|
for (let i = 0; i < times; i++) {
|
||||||
notaout = notaout.concat(ocetak);
|
notaout = notaout.concat(ocetak);
|
||||||
}
|
}
|
||||||
return notaout;
|
return notaout;
|
||||||
};
|
|
||||||
this.gen_epl = function(adata) {
|
|
||||||
var cetak = [];
|
|
||||||
for (i = 0; i < adata.content.length; i++) {
|
|
||||||
cetak.push(adata.content[i] + "\r\n");
|
|
||||||
}
|
}
|
||||||
var notaout = [];
|
|
||||||
for (i = 0; i < adata.config.times; i++) {
|
genEpl(adata) {
|
||||||
|
const cetak = (adata.content || []).map((line) => `${line}\r\n`);
|
||||||
|
let notaout = [];
|
||||||
|
const times = adata.config?.times || 1;
|
||||||
|
|
||||||
|
for (let i = 0; i < times; i++) {
|
||||||
notaout = notaout.concat(cetak);
|
notaout = notaout.concat(cetak);
|
||||||
}
|
}
|
||||||
return notaout;
|
return notaout;
|
||||||
};
|
}
|
||||||
this.construct(options);
|
}
|
||||||
};
|
|
||||||
|
|||||||
+80
-53
@@ -1,60 +1,87 @@
|
|||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
|
|
||||||
Module : /assets/js/simulator.js
|
Module : /assets/js/simulator.js
|
||||||
Desc. : JS Class Simulator Data dalam Code
|
Desc. : JS Class Simulator Data dalam Code
|
||||||
Created By : Siau Pheng (siaupheng@3fonia.com).
|
Created By : Siau Pheng (siaupheng@3fonia.com).
|
||||||
Created Date : March 18th, 2021.
|
Created Date : March 18th, 2021.
|
||||||
Last Modified : December 26th, 2025.
|
Last Modified : November 2nd, 2026.
|
||||||
|
|
||||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
(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 <siaupheng@3fonia.com>
|
||||||
|
*
|
||||||
|
* @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){
|
addParam(id, val) {
|
||||||
var vars = {
|
this.params.push(val !== undefined ? `${id}=${encodeURIComponent(val)}` : id);
|
||||||
'url': '',
|
return this;
|
||||||
'param': []
|
}
|
||||||
};
|
|
||||||
this.construct = function(options){
|
doPreview() {
|
||||||
if (typeof options == 'object') {
|
if (!this.url) {
|
||||||
$.extend(vars, options);
|
console.warn('Url Simulator dibutuhkan!');
|
||||||
} else vars.url = options;
|
return;
|
||||||
};
|
}
|
||||||
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!");
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: vars.url,
|
url: this.url,
|
||||||
data: FoniaJS.RequestParam(vars.param),
|
data: FoniaJS.RequestParam(this.params),
|
||||||
success: function(data){
|
dataType: 'json',
|
||||||
if (data.length == 0) {
|
error: typeof onFailure === 'function' ? onFailure : null,
|
||||||
|
success: (data) => {
|
||||||
|
if (!data || data.length === 0) {
|
||||||
FoniaJS.showInfo('Tidak ada data !');
|
FoniaJS.showInfo('Tidak ada data !');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var _divd = '';
|
|
||||||
for (var no = 0; no < data.length; no++) {
|
const divContent = data
|
||||||
_divd += '<div class="sim-code px-2 py-2 mb-1 border border-info">' + data[no] + '</div>';
|
.map(item => `<div class="sim-code px-2 py-2 mb-1 border border-info">${item}</div>`)
|
||||||
}
|
.join('');
|
||||||
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">'+
|
const modalHtml = `
|
||||||
'<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-fs" role="document">'+
|
<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-content">'+
|
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-fs" role="document">
|
||||||
'<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-content">
|
||||||
'<div class="modal-body">'+_divd+'</div>'+
|
<div class="modal-header">
|
||||||
'</div></div></div>';
|
<h5 class="modal-title" id="winAPPSimLabel">Code Simulator</h5>
|
||||||
if ($('#winAPPSim')) $('#winAPPSim').modal('dispose').remove();
|
<div class="ms-auto">
|
||||||
$(_wtxt).on('shown.bs.modal', function(e){
|
<button class="btn me-2" id="tombSalin" type="button" aria-label="Salin Semua">
|
||||||
$('#winAPPSim').find('#tombSalin').click(function(){
|
<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();
|
window.getSelection().removeAllRanges();
|
||||||
$('.sim-code').each(function(i, ele) {
|
$('.sim-code').each((_, ele) => {
|
||||||
var range = document.createRange();
|
const range = document.createRange();
|
||||||
range.selectNode(ele);
|
range.selectNode(ele);
|
||||||
window.getSelection().addRange(range);
|
window.getSelection().addRange(range);
|
||||||
});
|
});
|
||||||
@@ -62,23 +89,23 @@ var Simulator = function(options){
|
|||||||
window.getSelection().removeAllRanges();
|
window.getSelection().removeAllRanges();
|
||||||
FoniaJS.showInfo('Sukses salin semua Kode !');
|
FoniaJS.showInfo('Sukses salin semua Kode !');
|
||||||
});
|
});
|
||||||
$('#winAPPSim').find('.sim-code').click(function(){
|
|
||||||
var range = document.createRange();
|
// Copy individual code block and hide it
|
||||||
|
$modal.find('.sim-code').on('click', function () {
|
||||||
|
const range = document.createRange();
|
||||||
range.selectNode(this);
|
range.selectNode(this);
|
||||||
window.getSelection().removeAllRanges();
|
window.getSelection().removeAllRanges();
|
||||||
window.getSelection().addRange(range);
|
window.getSelection().addRange(range);
|
||||||
document.execCommand('copy');
|
document.execCommand('copy');
|
||||||
window.getSelection().removeAllRanges();
|
window.getSelection().removeAllRanges();
|
||||||
//$(this).addClass('bg-success');
|
|
||||||
$(this).addClass('d-none');
|
$(this).addClass('d-none');
|
||||||
});
|
});
|
||||||
}).on('hidden.bs.modal', function(e){
|
})
|
||||||
|
.on('hidden.bs.modal', function () {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
}).modal('show');
|
})
|
||||||
},
|
.modal('show');
|
||||||
error: (typeof vars.onFailure === "function") ? vars.onFailure : null,
|
}
|
||||||
dataType: 'json'
|
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
this.construct(options);
|
}
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user