function UniversalModalDialog() {}; const UNIVERSAL_MODAL_DIALOG_STYLE = ` `; const UNIVERSAL_MODAL_DIALOG_HTML = ` `; UniversalModalDialog.searchOrCreateModalDialogContainer = function() { if ($("#universal-modal-warning").length <= 0) { $(document.body).append($(UNIVERSAL_MODAL_DIALOG_STYLE)); $(document.body).append($(UNIVERSAL_MODAL_DIALOG_HTML)); } } UniversalModalDialog.initializeModalDialogWindow = function() { if (!UniversalModalDialog.wasEventsInited) { UniversalModalDialog.wasEventsInited = true; UniversalModalDialog.searchOrCreateModalDialogContainer(); $('#universal-modal-warning').on('hidden.bs.modal', function (e) { $('#universal-modal-warning').addClass("fade"); if ($('#universal-modal-warning').hasClass("modal-result-yes")) { if (UniversalModalDialog.onModalDialogPrimaryClick) UniversalModalDialog.onModalDialogPrimaryClick(); } else { if (UniversalModalDialog.onModalDialogSecondaryClick) UniversalModalDialog.onModalDialogSecondaryClick(); } if (UniversalModalDialog.onModalDialogHide) UniversalModalDialog.onModalDialogHide(); }); $('#universal-modal-warning').on('shown.bs.modal', function (e) { $('#universal-modal-warning').removeClass("modal-result-yes"); $('#universal-modal-warning').removeClass("fade"); $("#universal-modal-warning").find("input").focus(); var element = $("#universal-modal-warning").find("input")[0]; if (element) element.selectionStart = element.selectionEnd = element.value.length; if (UniversalModalDialog.onModalDialogShow) UniversalModalDialog.onModalDialogShow(); }); $('#universal-modal-dlg-button-primary').on('click', function (e) { $('#universal-modal-warning').addClass("modal-result-yes"); $('#universal-modal-warning').modal('hide', false); }); } } UniversalModalDialog.showModalDialogWindow = function(onModalDialogPrimaryClick, onModalDialogSecondaryClick) { UniversalModalDialog.onModalDialogPrimaryClick = onModalDialogPrimaryClick; UniversalModalDialog.onModalDialogSecondaryClick = onModalDialogSecondaryClick; $('#universal-modal-warning').modal('show', false); } UniversalModalDialog.showPromptText = function(caption, description, paramValue, onSelectValueCallback, canBeEmpty) { canBeEmpty = (isDefined(canBeEmpty)) ? canBeEmpty : false; var dialogHTML = "" if (description != "") dialogHTML = "

" + description + "

" + dialogHTML; UniversalModalDialog.showModalDialog(caption, dialogHTML, "OK", "Cancel", function() { var selectedText = $("#universal-modal-body").find(".modal-dialog-input-control").val().trim(); var shouldSend = (selectedText != ""); shouldSend = shouldSend || (canBeEmpty); shouldSend = shouldSend && (paramValue != selectedText); if (shouldSend) onSelectValueCallback(selectedText); }); } UniversalModalDialog.showModalDialog = function(caption, dialogHTML, primaryButtonCaption, secondaryButtonCaption, onModalDialogPrimaryClick, onModalDialogSecondaryClick) { secondaryButtonCaption = secondaryButtonCaption || ""; UniversalModalDialog.initializeModalDialogWindow(); $("#universal-modal-body").html(dialogHTML); $("#universal-modal-warning-caption").html(caption); $("#universal-modal-dlg-button-primary").html(primaryButtonCaption); $("#universal-modal-dlg-button-secondary").html(secondaryButtonCaption); if (secondaryButtonCaption == "") $("#universal-modal-dlg-button-secondary").hide(); else $("#universal-modal-dlg-button-secondary").show(); UniversalModalDialog.showModalDialogWindow(onModalDialogPrimaryClick, onModalDialogSecondaryClick); } UniversalModalDialog.showMessage = function(caption, message, imageURL) { let messageHTML = "
"; if (imageURL) messageHTML += "
"; messageHTML += "
" + message + "
"; messageHTML += "
"; UniversalModalDialog.showModalDialog(caption, messageHTML, "OK"); } UniversalModalDialog.showYesNoModalDialog = function(caption, dialogHTML, onModalDialogYesClick, onModalDialogNoClick) { UniversalModalDialog.showModalDialog(caption, dialogHTML, "Да", "Нет", onModalDialogYesClick, onModalDialogNoClick); } UniversalModalDialog.wasEventsInited = false; UniversalModalDialog.onModalDialogShow = null; UniversalModalDialog.onModalDialogHide = null;