uc-base-libraries
Version:
Typescript libraries for UC projects
386 lines • 15.9 kB
JavaScript
System.register(["./EventHandler", "./Debug"], function (exports_1, context_1) {
"use strict";
var EventHandler, Debug, lastDialogNumber, dialogReturn, dialogCloseEvents, DialogTypeEnum;
var __moduleName = context_1 && context_1.id;
function changeDialogIFrameHeight(height) {
window.changeDialogIFrameHeight(height);
}
exports_1("changeDialogIFrameHeight", changeDialogIFrameHeight);
function resetPage() {
setTimeout(() => {
window.location.replace(window.location.href);
}, 2000);
}
exports_1("resetPage", resetPage);
function closeDialog() {
window.closeBasePopupDialog('');
resetPage();
}
exports_1("closeDialog", closeDialog);
function showBlockUI(msg) {
if (msg == null) {
msg = ' Processing...';
}
$.blockUI({ message: '<h1><span class="spinner"> </span>' + msg + '</h1>' });
}
exports_1("showBlockUI", showBlockUI);
function hideBlockUI() {
$.unblockUI();
}
exports_1("hideBlockUI", hideBlockUI);
function getBootstrapDialogSettings(settings, callOnClose, onComplete, title, footer) {
if (title != null && (typeof title === 'string' || title instanceof String)) {
title = $('<span>' + title + '</span>');
}
if (footer != null && (typeof footer === 'string' || footer instanceof String)) {
footer = $('<span>' + footer + '</span>');
}
return {
dialogType: DialogTypeEnum.Bootstrap,
width: null,
height: null,
callOnClose,
onComplete,
title: title,
// item: null,
settings,
footer: footer,
};
}
exports_1("getBootstrapDialogSettings", getBootstrapDialogSettings);
function getJqueryUiDialogSettings(width, height, title, settings, callOnClose, onComplete) {
return {
dialogType: DialogTypeEnum.JQueryDialog,
width,
height,
callOnClose,
onComplete,
title,
item: null,
settings,
};
}
exports_1("getJqueryUiDialogSettings", getJqueryUiDialogSettings);
function getDefaultDialogSettings(dialogType) {
if (dialogType === DialogTypeEnum.Bootstrap) {
return getBootstrapDialogSettings();
}
else {
return getJqueryUiDialogSettings();
}
}
exports_1("getDefaultDialogSettings", getDefaultDialogSettings);
function showHtmlInDialog(html, options, parent) {
let myParent = parent;
if (self !== top) {
return top.showHtmlInDialog(html, options, self);
}
if (!myParent) {
myParent = top;
}
const baseOptions = getDefaultDialogSettings(options != null ? options.dialogType : null);
const settings = $.extend(true, {}, baseOptions, options);
exports_1("lastDialogNumber", lastDialogNumber = lastDialogNumber + 1);
if (settings.dialogType === DialogTypeEnum.JQueryDialog) {
return showHtmlInJQDialog(html, settings, myParent);
}
else if (settings.dialogType === DialogTypeEnum.Bootstrap) {
return showHtmlInBootstrap(html, settings, myParent);
}
}
exports_1("showHtmlInDialog", showHtmlInDialog);
function showInDialog(url, title, options) {
if (url === '') {
return;
}
if (url.indexOf('?') !== -1) {
url = url + '&Format=CleanHTML';
}
else {
url = url + '?Format=CleanHTML';
}
return showHtmlInDialog($("<iframe style='border:0px; width:100%; height: 99%; overflow: auto;' seamless='seamless' class='dialog' title='" +
title +
"' />").attr('src', url), options);
}
exports_1("showInDialog", showInDialog);
function confirmDialogAsync(msg, dialogType = DialogTypeEnum.Bootstrap) {
return new Promise((resolve) => {
confirmDialog(msg, dialogType, (success) => {
resolve(success);
});
});
}
exports_1("confirmDialogAsync", confirmDialogAsync);
function confirmDialog(msg, dialogType = DialogTypeEnum.Bootstrap, callback) {
const mg = '<p style="padding: 20px;"><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>' +
msg +
'</p>';
let diaSettings = null;
if (dialogType === DialogTypeEnum.Bootstrap) {
let callReturned = false;
const buttons = $(`<div>
<button type="button" class="btn btn-primary">Ok</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>`);
const bootSettings = getBootstrapDialogSettings(null, null, () => {
if (callback && !callReturned) {
callback(false);
}
}, 'Confirm', buttons);
const okBtn = buttons.find('.btn-primary');
okBtn.on('click', () => {
callReturned = true;
if (callback) {
callback(true);
}
window.closeBasePopupDialog(null);
});
diaSettings = bootSettings;
}
else {
diaSettings = getJqueryUiDialogSettings(300, 200, '', {
resizable: false,
buttons: {
Ok: () => {
window.closeBasePopupDialog(null);
if (callback) {
callback(true);
}
},
Cancel: () => {
window.closeBasePopupDialog(null);
if (callback) {
callback(false);
}
},
},
});
}
return showHtmlInDialog(mg, diaSettings);
}
exports_1("confirmDialog", confirmDialog);
function showHtmlInBootstrap(html, settings, myParent) {
const dialogNum = lastDialogNumber;
const modalSettings = {
backdrop: 'static',
keyboard: false,
show: true,
};
let sizeString = '';
let sizeString2 = '';
const maxWidth = $(top).width();
const maxHeight = $(top).height();
if (!(settings.width === null || '' + settings.width === '')) {
settings.width = parseInt('' + settings.width, 10);
if (settings.width > maxWidth) {
settings.width = maxWidth;
}
if (settings.width > 0) {
sizeString = 'max-width: ' + settings.width + 'px;';
}
}
if (!(settings.height === null || '' + settings.height === '')) {
settings.height = parseInt('' + settings.height, 10);
if (settings.height > maxHeight) {
settings.height = maxHeight;
}
if (settings.height > 0) {
sizeString2 = 'min-height: ' + settings.height + 'px;';
}
}
const mSettings = $.extend(true, {}, modalSettings, settings.settings);
const dialogContent = `<div id='globalPopUpDialog_` +
dialogNum +
`' class='modal fade' tabindex='-1' aria-labelledby='' aria-hidden='true'>
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable" style="` +
sizeString +
`">
<div class="modal-content" style="` +
sizeString2 +
`">
</div>
</div>
</div>`;
$(document.body).append(dialogContent);
const pUp = $('#globalPopUpDialog_' + dialogNum);
let contArea = pUp.find('.modal-content');
const ht = $(html);
if ((settings === null || settings === void 0 ? void 0 : settings.title) !== null || (settings === null || settings === void 0 ? void 0 : settings.footer) !== null) {
const headerArea = $(`<div class="modal-header">
</div>`);
const bodyArea = $(`<div class="modal-body">
</div>`);
const footerArea = $(`<div class="modal-footer">
</div>`);
headerArea.append(settings.title)
.append(`<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>`);
// bodyArea.append(body);
footerArea.append(settings.footer);
contArea.append(headerArea);
contArea.append(bodyArea);
contArea.append(footerArea);
contArea = bodyArea;
}
else {
}
const iframe = ht.find('iframe');
const url = iframe.attr('src');
if (url !== null && url !== '' && url !== undefined) {
iframe.attr('src', 'about:blank');
}
contArea.append(ht);
// const myModal = new bootstrap.Modal(pUp[0], mSettings)
const modal = $(pUp).modal(mSettings);
Debug.debugWrite('Bootstrap Modal Shown');
modal.modal('show');
modal.on('hidden.bs.modal', () => {
Debug.debugWrite('Bootstrap Modal Hidden');
$('#globalPopUpDialog_' + dialogNum).remove();
Debug.debugWrite('Bootstrap Modal CallonClose = [' + settings.callOnClose + ']');
if (settings.callOnClose && settings.callOnClose !== '') {
const fn = myParent[settings.callOnClose];
if (typeof fn === 'function') {
Debug.debugWrite('Bootstrap Modal Calling on Close');
fn(settings, dialogReturn);
}
}
Debug.debugWrite('Bootstrap Modal onComplete = [' + (settings.onComplete != null) + ']');
if (settings.onComplete != null) {
Debug.debugWrite('Bootstrap Modal Calling on Complete');
settings.onComplete();
}
exports_1("dialogReturn", dialogReturn = null);
});
if (url !== null && url !== '' && url !== undefined) {
iframe.attr('src', url);
}
return pUp;
}
function showHtmlInJQDialog(html, settings, myParent) {
const dialogNum = lastDialogNumber;
let DialogSettings = {
autoOpen: true,
modal: true,
title: settings.title,
width: 700,
height: 500,
close: () => {
$('#globalPopUpDialog_' + dialogNum).remove();
if (settings.callOnClose && settings.callOnClose !== '') {
const fn = myParent[settings.callOnClose];
if (typeof fn === 'function') {
fn(settings, dialogReturn);
}
}
if (settings.onComplete != null) {
settings.onComplete();
}
exports_1("dialogReturn", dialogReturn = null);
},
};
if (!(settings.width === null || '' + settings.width === '')) {
settings.width = parseInt('' + settings.width, 10);
if (settings.width > 0) {
DialogSettings.width = settings.width;
}
}
if (!(settings.height === null || '' + settings.height === '')) {
settings.height = parseInt('' + settings.height, 10);
if (settings.height > 0) {
DialogSettings.height = settings.height;
}
}
DialogSettings = $.extend(true, {}, settings.settings, DialogSettings);
const maxWidth = $(top).width();
if (DialogSettings.width > maxWidth) {
DialogSettings.width = maxWidth;
}
$(document.body).append("<div id='globalPopUpDialog_" + dialogNum + "'></div>");
const pUp = $('#globalPopUpDialog_' + dialogNum);
const ht = $(html);
const url = ht.attr('src');
ht.attr('src', 'about:blank');
pUp.append(ht);
pUp.dialog(DialogSettings);
pUp.find('iframe').attr('src', url);
return pUp;
}
return {
setters: [
function (EventHandler_1) {
EventHandler = EventHandler_1;
},
function (Debug_1) {
Debug = Debug_1;
}
],
execute: function () {
if (Window != null) {
Window.prototype.closeBasePopupDialog = (data) => {
if (self !== top) {
top.closeBasePopupDialog(data);
return;
}
exports_1("dialogReturn", dialogReturn = data);
dialogCloseEvents.trigger();
try {
$('#globalPopUpDialog_' + lastDialogNumber).dialog('close');
exports_1("lastDialogNumber", lastDialogNumber = lastDialogNumber - 1);
}
catch (err) { }
try {
$('#globalPopUpDialog_' + lastDialogNumber).modal('hide');
}
catch (err) { }
};
Window.prototype.showHtmlInDialog = (html, settings, parent) => {
return showHtmlInDialog(html, settings, parent);
};
Window.prototype.changeDialogIFrameHeight = (height) => {
// tslint:disable-next-line:no-console
console.log('changeDialogIFrameHeight called');
if (self !== top) {
// tslint:disable-next-line:no-console
console.log('changeDialogIFrameHeight not top, calling top.changeDialogIFrameHeight');
top.changeDialogIFrameHeight(height);
return;
}
const dlg = $('#globalPopUpDialog_' + lastDialogNumber);
if (dlg.length === 0) {
// tslint:disable-next-line:no-console
console.log('changeDialogIFrameHeight dlg ' + lastDialogNumber + ' not found');
}
const iFrame = dlg.find('iframe');
if (iFrame.length === 0) {
// tslint:disable-next-line:no-console
console.log('changeDialogIFrameHeight iFrame in dlg ' + lastDialogNumber + ' not found');
}
// tslint:disable-next-line:no-console
console.log('changeDialogIFrameHeight height ' + height + '');
if (height < 50) {
height = 200;
// tslint:disable-next-line:no-console
console.log('changeDialogIFrameHeight adjusted height to ' + height + ' (shouldnt happen)');
}
iFrame.height(height);
try {
dlg.modal('handleUpdate');
}
catch (err) { }
};
}
exports_1("lastDialogNumber", lastDialogNumber = 1234);
exports_1("dialogReturn", dialogReturn = null);
exports_1("dialogCloseEvents", dialogCloseEvents = new EventHandler.EventHandler());
(function (DialogTypeEnum) {
DialogTypeEnum[DialogTypeEnum["JQueryDialog"] = 0] = "JQueryDialog";
DialogTypeEnum[DialogTypeEnum["Bootstrap"] = 1] = "Bootstrap";
})(DialogTypeEnum || (DialogTypeEnum = {}));
exports_1("DialogTypeEnum", DialogTypeEnum);
}
};
});
//# sourceMappingURL=Dialog.js.map