/******************************************************************* Module : /assets/js/simulator.js Desc. : JS Class Simulator Data dalam Code Created By : Siau Pheng (siaupheng@3fonia.com). Created Date : March 18th, 2021. 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 * * @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 || []; } 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: 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; } const divContent = data .map(item => `
${item}
`) .join(''); const modalHtml = ` `; $('#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 !'); }); // 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'); } }); } }