Files
BeWoPlaner/BeWoPlanerMobil/Scripts/mobileUtils.js

383 lines
10 KiB
JavaScript

function showSpinner() {
$("#mySpinner").modal(
{
backdrop: "static",
keyboard: false
}
);
}
function hideSpinner() {
$("#mySpinner").modal("hide");
}
function showMessagePopup(title, message) {
$("#popupTitle").text(title);
if(message !== null) {
$("#modal-body").html("<p id=\"popupMessage\"></p>");
}
$("#popupMessage").text(message);
$("#messagePopup").modal(
{
backdrop: "static",
keyboard: false
}
);
}
function showMessagePopupWithHtml(title, messageAsHtml) {
$("#popupTitle").text(title);
$("#modal-body").html(messageAsHtml);
$("#messagePopup").modal(
{
backdrop: "static",
keyboard: false
}
);
}
function showMessagePopupWithCallback(title, message, callback, executeCallbackByBothButtons) {
$("#popupTitle").text(title);
if (message !== null) {
$("#modal-body").html("<p id=\"popupMessage\"></p>");
}
$("#popupMessage").text(message);
$("#message-popup-ok-btn").off("click");
$("#message-popup-ok-btn").on("click", function() {
callback();
});
if(executeCallbackByBothButtons === true) {
$("#message-popup-close-btn, #message-popup-esc-btn").off("click");
$("#message-popup-close-btn, #message-popup-esc-btn").on("click",
function() {
callback();
});
}
$("#messagePopup").modal(
{
backdrop: "static",
keyboard: false
}
);
}
function submitForm(submitButton) {
if(hasEmptyRequiredFields($(submitButton.form))) {
return;
}
showSpinner();
submitButton.form.submit();
}
function showMessagePopupWithHtml(title, html) {
$("#popupTitle").text(title);
if(html !== null) {
$("#modal-body").html("<p id=\"popupMessage\"></p>");
}
$("#popupMessage").html(html);
$("#messagePopup").modal(
{
backdrop: "static",
keyboard: false
}
);
}
function hasEmptyRequiredFields(form) {
var count = 0;
form.each(function() {
var requiredElements = $(this, "input, textarea, select").find("[required]");
requiredElements.each(function(index, element) {
if ($(element).val().length === 0) {
count++;
}
});
});
return count > 0;
}
function showAboutPopup() {
// Auf deutsch?
var text = "SignaturePad:<br/>Copyright (c) 2018 Szymon Nowak<br/><br/>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights<br/>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:<br/>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.<br/>THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.";
$("#message-popup-ok-btn").unbind();
$("#message-popup-close-btn").unbind();
$("#popupTitle").text("Copyrights");
$("#modal-body").html("<p id=\"popupMessage\"></p>");
$("#modal-body").html(text);
$("#messagePopup").modal(
{
backdrop: "static",
keyboard: false
}
);
}
function cloneCanvas(oldCanvas) {
var newCanvas = document.createElement("canvas");
var context = newCanvas.getContext("2d");
newCanvas.width = oldCanvas.width;
newCanvas.height = oldCanvas.height;
context.drawImage(oldCanvas, 0, 0);
return newCanvas;
}
function showAlertMessageBoxWithoutCallback(title, message) {
$("#popupTitle").text(title);
$("#messagePopup .modal-body").html('<div class="alert alert-danger" role="alert">' + message + "</div>");
$("#popupMessage").text(message);
$("#message-popup-ok-btn").off("click");
$("#message-popup-close-btn").off("click");
$("#messagePopup").modal(
{
backdrop: "static",
keyboard: false
}
);
}
function showAlertMessageBox(title, message, callback, executeCallbackByBothButtons) {
$("#popupTitle").text(title);
$("#messagePopup .modal-body").html('<div class="alert alert-danger" role="alert">' + message + "</div>");
$("#popupMessage").text(message);
$("#message-popup-ok-btn").off("click");
$("#message-popup-ok-btn").on("click", function() {
callback();
});
if(executeCallbackByBothButtons === true) {
$("#message-popup-close-btn").off("click");
$("#message-popup-close-btn").on("click", function() {
callback();
});
}
$("#messagePopup").modal(
{
backdrop: "static",
keyboard: false
}
);
}
function showWarningMessageBox(title, message, callback, executeCallbackByBothButtons) {
$("#popupTitle").text(title);
$("#messagePopup .modal-body").html('<div class="alert alert-warning" role="alert">' + message + "</div>");
$("#popupMessage").text(message);
$("#message-popup-ok-btn").off("click");
$("#message-popup-ok-btn").on("click", callback);
if(executeCallbackByBothButtons === true) {
$("#message-popup-close-btn").off("click");
$("#message-popup-close-btn").on("click", callback);
}
$("#messagePopup").modal(
{
backdrop: "static",
keyboard: false
}
);
}
function isUndefinedOrNull(obj) {
return obj == null;
}
function areUndefinedOrNull(array) {
if (array == null) {
return true;
}
if (!Array.isArray(array)) {
return true;
}
for (var i = 0; i < array.length; i++) {
if(array[i] != null) {
return false;
}
}
return true;
}
function cardHeaderClick(chevronId, cardBodyId) {
try {
$(cardBodyId).toggle();
toggleChevron(chevronId, cardBodyId);
}
catch(error) {
showErrorPopup(error);
}
}
// Muss manuell im onclick-Event des Buttons aufgerufen werden
function cardHeaderButtonClick(cardBodyId) {
try {
$(cardBodyId).toggle();
}
catch(error) {
showErrorPopup(error);
}
}
function toggleChevron(chevronId, cardBodyId) {
try {
var isDown = $(cardBodyId).css("display") !== "none";
var chevron = $(chevronId);
var iconToRemove = isDown ? "fa-chevron-down" : "fa-chevron-up";
var iconToAdd = isDown ? "fa-chevron-up" : "fa-chevron-down";
chevron.removeClass(iconToRemove);
chevron.addClass(iconToAdd);
} catch (error) {
showErrorPopup(error);
}
}
function validateNonEmptyString(stringValue) {
return !isUndefinedOrNull(stringValue) && !isEmptyOrSpaces(stringValue) && typeof stringValue === "string";
}
function showCollapsable(collapsableElement) {
try {
if (collapsableElement === null || collapsableElement === undefined) {
return;
}
if (!collapsableElement.hasClass("show")) {
collapsableElement.addClass("show");
}
} catch (error) {
showErrorPopup(error);
}
}
function hideCollapsable(collapsableElement) {
try {
if (collapsableElement === null || collapsableElement === undefined) {
return;
}
if (collapsableElement.hasClass("show")) {
collapsableElement.removeClass("show");
}
} catch (error) {
showErrorPopup(error);
}
}
function treeSearchOnChange(searchInputId, textClass, cardClass, nameLabelClass, itemListClass) {
try {
var text = $("#" + searchInputId).val().toLowerCase();
var entries = $("." + textClass);
if(text.length === 0 || !text.replace(/\s\g/, '').length) {
resetTreeSearch(searchInputId, textClass, cardClass);
return;
}
$.each(entries, function (index, entry) {
var checkbox = $(entry);
var treeCard = checkbox.closest("." + cardClass);
var header = treeCard.find(".tree-card-header");
var list = treeCard.find(".collapse");
var treeItemName = checkbox.find("." + nameLabelClass).text().toLowerCase();
var includesText = treeItemName.includes(text) || header.html().toLowerCase().includes(text);
if (includesText) {
checkbox.show();
treeCard.show();
showCollapsable($(list));
} else {
checkbox.hide();
}
});
var lists = $("." + itemListClass);
var cardsToHide = [];
$.each(lists, function (index, item) {
var children = $(item).children();
var hasAtLeastOneVisibleChild = false;
var card = $(item).parent().parent();
for(var i = 0; i < children.length; i++) {
var child = children[i];
hasAtLeastOneVisibleChild = $(child).css("display") === "block";
if(hasAtLeastOneVisibleChild === true) {
break;
}
}
if(hasAtLeastOneVisibleChild === false) {
cardsToHide.push(card);
}
});
$.each(cardsToHide, function (index, item) {
$(item).hide();
});
} catch (error) {
showErrorPopup(error);
}
}
function resetTreeSearch(searchInputId, textClass, cardClass) {
try {
$("#" + searchInputId).val("");
var entries = $("." + textClass);
var treeCard = $("." + cardClass);
var collapsable = treeCard.find(".collapse");
entries.show();
treeCard.show();
hideCollapsable(collapsable);
} catch (error) {
showErrorPopup(error);
}
}