@jtandrelevicius/utils-js-library 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +160 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -361,17 +361,176 @@ class ServicoExportacao {
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
/**
|
|
365
|
+
* ServicoPagina
|
|
366
|
+
* Manipuladores de Página e Navegação Sankhya-W
|
|
367
|
+
*/
|
|
368
|
+
class ServicoPagina {
|
|
369
|
+
/**
|
|
370
|
+
* Retorna a URL atual da pagina com o caminho opcional.
|
|
371
|
+
* @param { String } path Caminho a ser adicionado a URL atual
|
|
372
|
+
* @returns { String } A URL com o protocolo HTTPS ou HTTP
|
|
373
|
+
*/
|
|
374
|
+
static getUrl(path) {
|
|
375
|
+
return `${window.location.origin}${path ? '/' + path.replace('/', '') : ''}`;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Remove o frame da página de BI
|
|
380
|
+
* * @param { { instancia: String, paginaInicial: String, opcoes: any } } configuracoes Configuracoes gerais da pagina
|
|
381
|
+
* * **instancia**: Nome exato do componente de BI
|
|
382
|
+
* * **paginaInicial**: URL (a partir da pasta raiz) e nome do arquivo da pagina inicial
|
|
383
|
+
* * **opcoes**: [opcional] Campos com valores a serem recebidos pela pagina
|
|
384
|
+
* * _Padrao_: `{ instancia: '', paginaInicial: 'app.jsp' }`
|
|
385
|
+
* * @example JPSK.removerFrame ({ instancia: 'TELA_HTML5', paginaInicial: 'index.jsp'});
|
|
386
|
+
*/
|
|
387
|
+
static removerFrame({ instancia, paginaInicial, ...opcoes } = { instancia: '', paginaInicial: 'app.jsp' }) {
|
|
388
|
+
|
|
389
|
+
new Promise(resolve => {
|
|
390
|
+
|
|
391
|
+
if (window.parent.document.getElementsByTagName('body').length) {
|
|
392
|
+
|
|
393
|
+
if (window.parent.document.querySelector('div.gwt-PopupPanel.alert-box.box-shadow'))
|
|
394
|
+
window.parent.document.querySelector('div.gwt-PopupPanel.alert-box.box-shadow')
|
|
395
|
+
.style.display = 'none';
|
|
396
|
+
|
|
397
|
+
window.parent.document.getElementsByTagName('body')[0].style.overflow = 'hidden';
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (window.parent.parent.document.getElementsByTagName('body').length) {
|
|
401
|
+
|
|
402
|
+
if (window.parent.parent.document.querySelector('div.gwt-PopupPanel.alert-box.box-shadow'))
|
|
403
|
+
window.parent.parent.document.querySelector('div.gwt-PopupPanel.alert-box.box-shadow')
|
|
404
|
+
.style.display = 'none';
|
|
405
|
+
|
|
406
|
+
window.parent.parent.document.getElementsByTagName('body')[0].style.overflow = 'hidden';
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (
|
|
410
|
+
window.parent.document
|
|
411
|
+
.querySelector('div.GI-BUHVBPVC > div > div > div > div > div > table > tbody > tr > td > div')
|
|
412
|
+
) {
|
|
413
|
+
instancia = window.parent.document
|
|
414
|
+
.querySelector('div.GI-BUHVBPVC > div > div > div > div > div > table > tbody > tr > td > div')
|
|
415
|
+
.textContent;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (instancia && instancia.length > 0) {
|
|
419
|
+
ServicoDados.consultar(`SELECT NUGDG FROM TSIGDG WHERE TITULO = '${instancia}'`).
|
|
420
|
+
then(e => resolve({ gadGetID: 'html5_z6dld', nuGdt: e[0].NUGDG, ...opcoes }));
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
resolve({ gadGetID: 'html5_z6dld', nuGdt: 0, ...opcoes });
|
|
424
|
+
}
|
|
425
|
+
}).
|
|
426
|
+
then(o =>
|
|
427
|
+
setTimeout(() => {
|
|
428
|
+
if (typeof window.parent.document.getElementsByClassName('DashWindow')[0] != 'undefined') {
|
|
429
|
+
|
|
430
|
+
const opcoesUrl =
|
|
431
|
+
Object.
|
|
432
|
+
keys(o).
|
|
433
|
+
filter(item => !['params', 'UID', 'instance', 'nuGdg', 'gadGetID'].includes(item)).
|
|
434
|
+
map(item => `&${item}=${o[item]}`).
|
|
435
|
+
join('');
|
|
436
|
+
|
|
437
|
+
const url = `/mge/html5component.mge?entryPoint=${paginaInicial}&nuGdg=${o.nuGdt}${opcoesUrl}`
|
|
438
|
+
|
|
439
|
+
setTimeout(() =>
|
|
440
|
+
window.parent.document.getElementsByClassName('dyna-gadget')[0].innerHTML =
|
|
441
|
+
`<iframe src="${url}" class="gwt-Frame" style="width: 100%; height: 100%;"></iframe>`
|
|
442
|
+
, 500);
|
|
443
|
+
|
|
444
|
+
setTimeout(() => document.getElementsByClassName('popupContent').length
|
|
445
|
+
? document.getElementsByClassName('popupContent')[0].parentElement.remove()
|
|
446
|
+
: (() => { /**/ })()
|
|
447
|
+
, 20000);
|
|
448
|
+
|
|
449
|
+
setTimeout(() => (document.getElementById('stndz-style').parentElement.parentElement)
|
|
450
|
+
.getElementsByTagName('body')[0].style.overflow = 'hidden'
|
|
451
|
+
, 20000);
|
|
452
|
+
}
|
|
453
|
+
})
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Abre uma nova guia com a pagina atual
|
|
459
|
+
*
|
|
460
|
+
* @param { boolean } forcado - [Opcional] Indica se a abertura da nova guia deve ser forcada
|
|
461
|
+
* * @example JPSK.novaGuia ();
|
|
462
|
+
*/
|
|
463
|
+
static novaGuia(forcado = false) {
|
|
464
|
+
|
|
465
|
+
if ((window.parent.parent.document.querySelector('.Taskbar-container') && !forcado) || forcado) {
|
|
466
|
+
Object.assign(document.createElement('a'), { target: '_blank', href: window.location.href }).click();
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Abre uma pagina dentro do Sankhya-W.
|
|
473
|
+
* * - Se o resourceID nao existir, o sistema informara que a tela nao existe.
|
|
474
|
+
* - Se as chaves primarias nao forem informadas, a tela sera aberta na pagina inicial.
|
|
475
|
+
* - Se existirem chaves primarias, mas nao forem encontradas, a tela ssera aberta como visualizacao de um registro vazio (para inclusao)
|
|
476
|
+
* - Se existirem chaves primarias e forem encontradas, a tela sera aberta no registro encontrado.
|
|
477
|
+
* * @param { String } resourceID ID do recurso a ser aberto
|
|
478
|
+
* @param { Object } chavesPrimarias Chaves de identificacao do registro
|
|
479
|
+
* * @example JPSK.abrirPagina ('br.com.sankhya.core.cad.marcas', { CODIGO: 999 });
|
|
480
|
+
*/
|
|
481
|
+
static abrirPagina(resourceID, chavesPrimarias) {
|
|
482
|
+
|
|
483
|
+
let url = ServicoPagina.getUrl(`/mge/system.jsp#app/%resID`);
|
|
484
|
+
url = url.replace('%resID', btoa(resourceID));
|
|
485
|
+
|
|
486
|
+
if (chavesPrimarias) {
|
|
487
|
+
|
|
488
|
+
let body = {};
|
|
489
|
+
|
|
490
|
+
Object.keys(chavesPrimarias).forEach(function (chave) {
|
|
491
|
+
body[chave] = isNaN(chavesPrimarias[chave])
|
|
492
|
+
? String(chavesPrimarias[chave])
|
|
493
|
+
: Number(chavesPrimarias[chave])
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
url = url.concat(`/${btoa(JSON.stringify(body))}`);
|
|
497
|
+
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
Object.assign(document.createElement('a'), {
|
|
501
|
+
target: '_top',
|
|
502
|
+
href: url
|
|
503
|
+
}).click();
|
|
504
|
+
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Fecha a pagina atual.
|
|
509
|
+
* * Ele verifica se a pagina atual esta dentro do Sankhya-W para fechar, senao ele fecha a aba do navegador.
|
|
510
|
+
*/
|
|
511
|
+
static fecharPagina() {
|
|
512
|
+
if (window.parent.parent.document.querySelector('.Taskbar-container')) {
|
|
513
|
+
window.parent.parent.document.querySelector(
|
|
514
|
+
'li.ListItem.AppItem.AppItem-selected div.Taskbar-icon.icon-close').click();
|
|
515
|
+
} else {
|
|
516
|
+
window.close();
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
364
521
|
const lib = {
|
|
365
522
|
ServicoDados,
|
|
366
523
|
UtilitariosFormatacao,
|
|
367
524
|
UtilitariosOrdenacao,
|
|
368
525
|
ServicoExportacao,
|
|
526
|
+
ServicoPagina,
|
|
369
527
|
|
|
370
528
|
// Aliases
|
|
371
529
|
JSK: ServicoDados,
|
|
372
530
|
JFSK: UtilitariosFormatacao,
|
|
373
531
|
JOSK: UtilitariosOrdenacao,
|
|
374
|
-
JEXSK: ServicoExportacao
|
|
532
|
+
JEXSK: ServicoExportacao,
|
|
533
|
+
JPSK: ServicoPagina
|
|
375
534
|
};
|
|
376
535
|
|
|
377
536
|
if (typeof module !== 'undefined' && module.exports) {
|