Files
BeWoPlaner/BeWoPlanerMobil/Scripts/utils.js

223 lines
6.2 KiB
JavaScript

function makeAjaxCall(pType, pUrl, pSuccess, pData, pComplete) {
$.ajax({
type: pType,
url: pUrl,
data: pData,
success: pSuccess,
error: showAjaxError,
complete: pComplete
});
}
function removeElementFromArray(pArray, pKey) {
var newArray = {};
for(var key in pArray) {
var keyAsNumber = Number(key);
if(keyAsNumber !== pKey) {
newArray[keyAsNumber] = pArray[keyAsNumber];
}
}
return newArray;
}
function toggleLabel(inputId) {
var label = $('label[for="' + inputId + '"]');
var topValue;
if($('#' + inputId).is(":focus")) {
$(label).animate({ top: "-6px" }, 100);
return;
}
topValue = "12px";
if($('#' + inputId).val()) {
topValue = "-6px";
}
$(label).animate({ top: topValue }, 75);
}
function adjustLabel(inputId) {
var label = $('label[for="' + inputId + '"]');
var topValue;
topValue = "12px";
if($('#' + inputId).val()) {
topValue = "-6px";
}
$(label).animate({ top: topValue }, 75);
}
function isInEditingMode() {
return $("#isInEditModeIndicator").val() === "true";
}
function isElementInArray(array, element) {
try {
var contains = false;
array.forEach(function (e, index) {
if (e === element) {
contains = true;
}
});
return contains;
} catch (error) {
console.log(error.message);
return false;
}
}
function isEmptyOrSpaces(str) {
return str === null || str === undefined || str.match(/^ *$/) !== null;
}
function toggleSelectClassesForElement(elementIdentifier, parentElement) {
var enabled = $(elementIdentifier).prop("disabled") === "false";
if (enabled) {
$(parentElement).removeClass("disabled-select-container");
$(parentElement).addClass("styled-select-div");
} else {
$(parentElement).removeClass("styled-select-div");
$(parentElement).addClass("disabled-select-container");
}
}
function activateInput(parentElement) {
$(parentElement).removeClass("disabled-select-container");
$(parentElement).addClass("styled-select-div");
}
function disableInput(parentElement) {
$(parentElement).removeClass("styled-select-div");
$(parentElement).addClass("disabled-select-container");
}
function toggleErrorPopup2(errorMessage) {
var isDisplayNone = $("#errorPopupDiv2").css("display") === "none";
var displayValue = isDisplayNone ? "block" : "none";
$("#errorPopupDiv2").css("display", displayValue);
$(".modalWrapper").css("display", displayValue);
$(".modalWrapper").css("height", $(document).height());
if (isDisplayNone) {
$("#errorPopupText2").text(errorMessage);
var h = 0;
var t = $("#errorPopupTitle2").outerHeight();
var u = $("#errorPopupText2").outerHeight();
var v = $("#errorPopupBtnDiv2").outerHeight();
var w = $("#errorPopupOkBtn2").outerHeight();
h += t + u + v + w + w;
$("#errorPopupDiv2").css("height", h + "px");
$("#errorPopupDiv2").css("top", window.pageYOffset + window.innerHeight / 2 - h / 2);
$("#errorPopupDiv2").css("margin-top", "0");
} else {
$("#errorPopupDiv2").css("margin-top", "auto");
}
}
function disableElement(pElement) {
pElement.prop("disabled", true);
}
function enableElement(pElement) {
pElement.prop("disabled", false);
}
function deactivateInputForm() {
$("#statistik-button").prop("disabled", true);
$("#statistik-button").css("background-image", "url('../Content/images/statistik-disabled.svg')");
$("#recordLoader_select").prop("disabled", true);
disableInput("#record-loader-select-container");
$("#kategorien_select").prop("disabled", true);
disableInput("#kategorien-select-container");
$("#leistungen_select").prop("disabled", true);
disableInput("#leistungen-select-container");
$("#textbausteine_select").prop("disabled", true);
disableInput("#textbausteine-select-container");
}
function activateInputForm(actionPath, shouldLoadServiceDescriptions) {
enableElement($("#recordLoader_select"));
activateInput("#record-loader-select-container");
$("#kategorien_select").prop("disabled", false);
activateInput("#kategorien-select-container");
$("#leistungen_select").prop("disabled", false);
activateInput("#leistungen-select-container");
$("#textbausteine_select").prop("disabled", false);
activateInput("#textbausteine-select-container");
activateInput("#employee-select-container");
$("#statistik-button").prop("disabled", false);
$("#statistik-button").css("background-image", "url('../Content/images/statistik-orange.svg')");
activateForm(actionPath, shouldLoadServiceDescriptions);
if (!isInEditingMode()) {
$("#datum_textbox").val(getDateStringWithLeadingZeros(new Date()));
}
}
function deactivateInputFormCompletely() {
deactivateInputForm();
disableElement($("#datum_textbox"));
disableElement($("#start_textbox"));
disableElement($("#ende_textbox"));
disableElement($("#duration_textbox"));
disableElement($("#distance_textbox"));
disableElement($("#kollabier-btn2"));
disableElement($("#doku-name-1"));
disableElement($("#doku-name-2"));
disableElement($("#doku-name-3"));
disableElement($("#doku-name-4"));
disableElement($("#doku-name-5"));
disableElement($("#notiz_textbox"));
disableElement($("#notiz_textbox1"));
disableElement($("#notiz_textbox2"));
disableElement($("#notiz_textbox3"));
disableElement($("#notiz_textbox4"));
disableElement($("#notiz_textbox5"));
disableElement($("#abbrechenBtn"));
disableElement($("#anlegenEditierenBtn"));
}
function getSixDigitHexColorCode(rawColor) {
var result = "#000000";
if(rawColor === null || rawColor === undefined || rawColor.length < 6) {
return result;
}
if(rawColor.length === 9) {
return "#" + rawColor.substring(3);
} else {
return rawColor;
}
}