Files
BeWoPlaner/BeWoPlanerMobil/Scripts/initialization.js
2017-04-26 14:57:32 +02:00

309 lines
11 KiB
JavaScript

var isEnddateSet;
$(document).ready(function () {
if (!$("#zeiterfassung").length) {
return;
}
toggleErrorPopup2('errorPopupDiv2');
$("#leistungen_select,#kategorien_select,#recordLoader_select,#textbausteine_select").prop("disabled", false);
toggleSelectClassesForElement("#kategorien_select", "#kategorien-select-container");
toggleSelectClassesForElement("#leistungen_select", "#leistungen-select-container");
toggleSelectClassesForElement("#recordLoader_select", "#record-loader-select-container");
toggleSelectClassesForElement("#textbausteine_select", "#textbausteine-select-container");
//Lade Dokumentationsreiter aus Bewo
initializeDocumentationTextareas();
//ist EndDate Gewünscht
checkEndDate();
initBeWoMobile(loadGoalsUrl);
var h = $("#datum_textbox").css("height");
$(".dropdownlist-for").css("height", h);
$("#statistik-button").css("height", h);
$("#statistik-button").css("width", h);
$("#statistik-button-td").css("width", h);
//if (localStorage.getItem("Zeitdaten") != null || localStorage.getItem("Kalenderdaten") != null) {
// console.log("Ich bin hier drinne weil Storage vorhanden");
// if (document.getElementById("ErrorZeiterfassungAfterCrashSchalter").value == 1 ||
// document.getElementById("ErrorZeiterfassungAfterCrashSchalter").value == null ||
// document.getElementById("ErrorZeiterfassungAfterCrashSchalter").value == 0) {
// console.log("Ich bin hier beim Laden einer Zeiterfassung ");
// LoadOnly(1, 2);
// DeletStorage(1);
// DeletStorage(2);
// } else {
// ErrorZeiterfassungAfterCrash();
// console.log(" ich bin hier nach dem Crash ")
// }
//} else {
// console.log("Ich bin hier drinne weil Storage nicht vorhanden");
//}
ErfolgteSpx();
vm = new KlientenVM();
ko.applyBindings(vm);
loadSettingsAccordingToBWP();
});
function initBeWoMobile(actionPath) {
try {
$("#recordLoader_select, #kategorien_select, #leistungen_select, #textbausteine_select").prop("disabled", true);
toggleSelectClassesForElement("#kategorien_select", "#kategorien-select-container");
toggleSelectClassesForElement("#leistungen_select", "#leistungen-select-container");
toggleSelectClassesForElement("#recordLoader_select", "#record-loader-select-container");
toggleSelectClassesForElement("#textbausteine_select", "#textbausteine-select-container");
var selectedSC = $($("#scDropDown")).find(":selected").val();
if (selectedSC !== "-1") {
$("#recordLoader_select").prop("disabled", false);
if ($("#anlegenEditierenBtn").val() == "Anlegen") {
activateForm(actionPath);
}
$("#datum_textbox").val(getDateStringWithLeadingZeros(new Date()));
}
$(".not-required-input").on("click blur change focus",
function () {
var v = $(this).attr("id");
setTimeout(function () { toggleLabel(v); }, 1);
}
);
$("#start_textbox").on("blur", function () {
var startHasValue = $("#start_textbox").val() != "";
var endHasValue = $("#ende_textbox").val() != "";
var durationHasValue = $("#duration_textbox").val() != "";
if (startHasValue && endHasValue) {
calcDurationByStartEnd();
} else if (startHasValue && durationHasValue) {
calcEndByStartDuration();
}
});
$("#ende_textbox").on("blur", function () {
var startHasValue = $("#start_textbox").val() != "";
var endHasValue = $("#ende_textbox").val() != "";
var durationHasValue = $("#duration_textbox").val() != "";
if (endHasValue && startHasValue) {
calcDurationByStartEnd();
} else if (endHasValue && durationHasValue) {
calcStartByEndDuration();
}
});
$("#duration_textbox").on("blur", function () {
var startHasValue = $("#start_textbox").val() != "";
var endHasValue = $("#ende_textbox").val() != "";
var durationHasValue = $("#duration_textbox").val() != "";
clearZED();
if (durationHasValue && startHasValue) {
calcEndByStartDuration();
} else if (durationHasValue && endHasValue) {
calcStartByEndDuration();
}
});
} catch (err) {
console.log("Fehler: " + err.message);
}
}
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 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 logoutSettingsAccordingToBWP(timeoutTime) {
if (timeoutTime > 0) {
timeoutTime = timeoutTime * 1000 * 60;
clearTimeout();
setTimeout(function() {
$.ajax({
type: "POST",
url: LogoutUrl,
success: function() {
writeFatalErrorMessage("Ihre Sitzung ist abgelaufen.");
setTimeout(function() {
location.reload();
}, 3000);
},
error: function() {}
});
}, timeoutTime);
}
}
var TimeoutSetting;
function loadSettingsAccordingToBWP() {
$.ajax({
type: "GET",
url: LoadSessionSettingsFromBWPUrl,
success: function (json) {
var s = $.parseJSON(json);
TimeoutSetting = parseInt(s);
logoutSettingsAccordingToBWP(TimeoutSetting);
}
});
}
function checkEndDate() {
$.ajax({
type: "GET",
url: CheckEndDateUrl,
success: function (json) {
var s = $.parseJSON(json);
var EndDateSetting = parseInt(s);
if (EndDateSetting == 1) {
document.getElementById('EndDate_div').style.display = 'block';
$("#enddatum_textbox").val($("#datum_textbox").val());
}
else {
document.getElementById('EndDate_div').style.display = 'none';
}
}
});
}
function initializeDocumentationTextareas() {
$.ajax({
type: "GET",
url: CheckDokuReiterUrl,
success: function (json) {
var s = $.parseJSON(json);
console.log(json);
var x = s.length;
if (x == 0) {
$("#tddokureiter").css("display", "none");
$("#trnormalDoku").css("display", "table-row");
$("#notiz_textbox").css("width", "100%");
focusedDokuTextarea = $("#notiz_textbox");
} else {
focusedDokuTextarea = $("#notiz_textbox1");
}
if (x == 1) {
$("#tddokureiter").css("display", "none");
$("#trnormalDoku").css("display", "table-row");
$("#notiz_textbox").css("width", "100%");
$("#trnormalDokuLabel").text(s[0].TypeDescription);
}
if (x == 2) {
$("#DokName1").text(s[0].TypeDescription);
$("#DokName2").text(s[1].TypeDescription);
$("#notiz_textbox1, #notiz_textbox2").css("width", "40%");
$("#Dokumentation1, #Dokumentation2").css("display", "block");
$("#Dokumentation1, #Dokumentation2").css("width","250%");
}
if (x == 3) {
$("#DokName1").text(s[0].TypeDescription);
$("#DokName2").text(s[1].TypeDescription);
$("#DokName3").text(s[2].TypeDescription);
$("#notiz_textbox1, #notiz_textbox2, #notiz_textbox3").css("width", "50%");
$("#Dokumentation1, #Dokumentation2, #Dokumentation3").css("display", "block");
$("#Dokumentation1, #Dokumentation2, #Dokumentation3").css("width", "250%");
}
if (x == 4) {
$("#DokName1").text(s[0].TypeDescription);
$("#DokName2").text(s[1].TypeDescription);
$("#DokName3").text(s[2].TypeDescription);
$("#DokName4").text(s[3].TypeDescription);
$("#notiz_textbox1, #notiz_textbox2, #notiz_textbox3, #notiz_textbox4").css("width", "76.9%");
$("#Dokumentation1, #Dokumentation2, #Dokumentation3, #Dokumentation4, #Dokumentation5").css("display", "block");
$("#Dokumentation1, #Dokumentation2, #Dokumentation3, #Dokumentation4, #Dokumentation5").css("width", "130%");
}
if (x == 5) {
$("#DokName1").text(s[0].TypeDescription);
$("#DokName2").text(s[1].TypeDescription);
$("#DokName3").text(s[2].TypeDescription);
$("#DokName4").text(s[3].TypeDescription);
$("#DokName5").text(s[4].TypeDescription);
$("#notiz_textbox1, #notiz_textbox2, #notiz_textbox3, #notiz_textbox4, #notiz_textbox5").css("width", "101%");
$("#Dokumentation1, #Dokumentation2, #Dokumentation3, #Dokumentation4, #Dokumentation5").css("display", "block");
$("#Dokumentation1, #Dokumentation2, #Dokumentation3, #Dokumentation4, #Dokumentation5").css("width", "99%");
}
if (x > 0) {
$("#DokName1").click();
}
}
});
}