Files
BeWoPlaner/BeWoPlanerMobil/Scripts/ownSoft-Scripts/mobileUtils.js

458 lines
13 KiB
JavaScript

function showSpinner() {
$("#mySpinner").modal(
{
keyboard: false
}
);
}
function hideSpinner() {
$("#mySpinner").modal("hide");
$("#loading-info-p").text("Lade ...");
}
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);
$("#message-popup-ok-btn").off("click");
$("#message-popup-ok-btn").on("click", function () {
$("#messagePopup").modal("hide");
});
$("#messagePopup").modal(
{
backdrop: "static",
keyboard: false
}
);
}
function showMessagePopupWithHtmlAndCallback(title, messageAsHtml, callback, executeCallbackByBothButtons) {
$("#popupTitle").text(title);
$("#modal-body").html(messageAsHtml);
$("#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 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 hasEmptyRequiredFields(form) {
var count = 0;
form.each(function() {
const 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?
const 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) {
const newCanvas = document.createElement("canvas");
const context = newCanvas.getContext("2d", {willReadFrequently: true});
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="row"><div class="col-auto"><span class="fas fa-exclamation-triangle fa-3x text-danger"></span></div><div class="col">${message}</div></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="row"><div class="col-auto"><span class="fas fa-exclamation-triangle fa-3x text-danger"></span></div><div class="col">${message}</div></div>`);
$("#popupMessage").text(message);
$("#message-popup-ok-btn").off("click");
$("#message-popup-ok-btn").on("click", function() {
callback();
});
$("#message-popup-close-btn").off("click");
if(executeCallbackByBothButtons === true) {
$("#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="row"><div class="col-auto"><span class="fas fa-exclamation-triangle fa-3x text-warning"></span></div><div class="col">${message}</div></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(let i = 0; i < array.length; i++) {
if(array[i] != null) {
return false;
}
}
return true;
}
function cardHeaderClick(chevronId, cardBodyId) {
$(cardBodyId).collapse("toggle");
toggleChevron(chevronId, cardBodyId);
}
function cardHeaderClick2(element, callback) {
if(element === undefined || element === null) {
console.logWarning("element is undefined or null!");
return;
}
const chevronDown = $(element).find(".fa-chevron-down");
const chevronUp = $(element).find(".fa-chevron-up");
chevronDown.removeClass("fa-chevron-down").addClass("fa-chevron-up");
chevronUp.removeClass("fa-chevron-up").addClass("fa-chevron-down");
$(element).next(".collapse").collapse("toggle");
if(typeof callback === "function") {
callback();
}
}
// Muss manuell im onclick-Event des Buttons aufgerufen werden
function cardHeaderButtonClick(cardBodyId) {
$(cardBodyId).collapse("toggle");
}
// ToDo: Hier am 21.08.2023 weitermachen!
function toggleChevron(chevronId, cardBodyId) {
const isDown = $(cardBodyId).css("display") !== "none";
const chevron = $(chevronId);
const iconToRemove = isDown ? "fa-chevron-down" : "fa-chevron-up";
const iconToAdd = isDown ? "fa-chevron-up" : "fa-chevron-down";
chevron.removeClass(iconToRemove);
chevron.addClass(iconToAdd);
}
function validateNonEmptyString(stringValue) {
return !isUndefinedOrNull(stringValue) && !isEmptyOrSpaces(stringValue) && typeof stringValue === "string";
}
function showCollapsable(collapsableElement) {
if(collapsableElement === null || collapsableElement === undefined) {
return;
}
if(!collapsableElement.hasClass("show")) {
collapsableElement.addClass("show");
}
}
function hideCollapsable(collapsableElement) {
if (collapsableElement === null || collapsableElement === undefined) {
return;
}
if (collapsableElement.hasClass("show")) {
collapsableElement.removeClass("show");
}
}
function treeSearchOnChange(searchInputId, textClass, cardClass, nameLabelClass, itemListClass) {
var text = $(`#${searchInputId}`).val().toLowerCase();
const entries = $(`.${textClass}`);
if(text.length === 0 || !text.replace(/\s\g/, "").length) {
resetTreeSearch(searchInputId, textClass, cardClass);
return;
}
$.each(entries, function (index, entry) {
const checkbox = $(entry);
const treeCard = checkbox.closest(`.${cardClass}`);
const header = treeCard.find(".tree-card-header");
const list = treeCard.find(".collapse");
const treeItemName = checkbox.find(`.${nameLabelClass}`).text().toLowerCase();
const includesText = treeItemName.includes(text) || header.html().toLowerCase().includes(text);
if (includesText) {
checkbox.show();
treeCard.show();
showCollapsable($(list));
} else {
checkbox.hide();
}
});
const lists = $(`.${itemListClass}`);
var cardsToHide = [];
$.each(lists, function (index, item) {
const children = $(item).children();
var hasAtLeastOneVisibleChild = false;
const card = $(item).parent().parent();
for(let i = 0; i < children.length; i++) {
const 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();
});
}
function resetTreeSearch(searchInputId, textClass, cardClass) {
$(`#${searchInputId}`).val("");
const entries = $(`.${textClass}`);
const treeCard = $(`.${cardClass}`);
const collapsable = treeCard.find(".collapse");
entries.show();
treeCard.show();
hideCollapsable(collapsable);
}
function showMessagePopupWithHtmlAndCallback(title, messageAsHtml, hasCloseButton, callback, executeCallbackByBothButtons) {
$("#popupTitle").text(title);
if (messageAsHtml !== null) {
$("#modal-body").html("<p id=\"popupMessage\"></p>");
}
$("#popupMessage").html(messageAsHtml);
$("#message-popup-ok-btn").off("click");
if(typeof callback === "function") {
$("#message-popup-ok-btn").on("click", function () {
callback();
});
}
if (hasCloseButton === false) {
$("#message-popup-close-btn").hide();
} else {
$("#message-popup-close-btn").show();
}
if(executeCallbackByBothButtons === true && typeof callback === "function") {
$("#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 stringContainsDoctype(strValue) {
return strValue !== undefined && strValue !== null && (typeof strValue === "string" || strValue instanceof String) && strValue.length > 0 && strValue.includes("DOCTYPE");
}
function parseJason(jsonToParse) {
try {
return $.parseJSON(jsonToParse);
} catch (error) {
if(stringContainsDoctype(jsonToParse)) {
window.showErrorPopup(error, jsonToParse);
} else {
window.showErrorPopup(error);
}
}
}
function getCurrentTimeStamp() {
const now = new Date(Date.now());
const date = String(2).padStart(2, now.getDate().toString());
const month = String(2).padStart(2, now.getMonth().toString());
const hours = String(2).padStart(2, now.getHours().toString());
const minutes = String(2).padStart(2, now.getMinutes().toString());
const seconds = String(2).padStart(2, now.getSeconds().toString());
const milliseconds = String(3).padStart(3, now.getMilliseconds().toString());
return `${date}.${month}.${now.getFullYear()} ${hours}:${minutes}:${seconds}.${milliseconds}`;
}