Files
BeWoPlaner/BeWoPlanerMobil/Scripts/initialization.js

419 lines
13 KiB
JavaScript
Raw Normal View History

2016-06-27 01:45:38 +02:00
var isEnddateSet;
var numberOfDocumentationTypes;
var canvasWidth;
$(document).ready(function() {
startBeWoMobile();
});
function startBeWoMobile() {
if (!$("#zeiterfassung").length) {
2016-06-27 01:45:38 +02:00
return;
}
2018-03-12 12:07:53 +01:00
toggleErrorPopup2("errorPopupDiv2");
2016-06-27 01:45:38 +02:00
2017-04-26 14:57:32 +02:00
$("#leistungen_select,#kategorien_select,#recordLoader_select,#textbausteine_select").prop("disabled", false);
2016-06-27 01:45:38 +02:00
toggleSelectClassesForElement("#kategorien_select", "#kategorien-select-container");
toggleSelectClassesForElement("#leistungen_select", "#leistungen-select-container");
toggleSelectClassesForElement("#recordLoader_select", "#record-loader-select-container");
2017-04-26 14:57:32 +02:00
toggleSelectClassesForElement("#textbausteine_select", "#textbausteine-select-container");
2016-06-27 01:45:38 +02:00
2017-04-26 14:57:32 +02:00
initializeDocumentationTextareas();
2016-06-27 01:45:38 +02:00
checkEndDate();
initBeWoMobile(loadGoalsUrl);
2018-06-29 16:35:19 +02:00
var height = $("#datum_textbox").css("height");
2016-06-27 01:45:38 +02:00
$(".dropdownlist-for").css("height", height);
2016-06-27 01:45:38 +02:00
$("#statistik-button").css("height", height);
$("#statistik-button").css("width", height);
2016-06-27 01:45:38 +02:00
$("#statistik-button-td").css("width", height);
2018-03-12 12:07:53 +01:00
$(".gruppenbuchungsCheckboxContainer").css("width", height);
2016-06-27 01:45:38 +02:00
//if(localStorage.getItem("Zeitdaten") != null || localStorage.getItem("Kalenderdaten") != null) {
// console.log("a service record has been found in the local storage");
// if($("#ErrorZeiterfassungAfterCrashSchalter").value == 1 ||
// $("#ErrorZeiterfassungAfterCrashSchalter").value == null ||
// $("#ErrorZeiterfassungAfterCrashSchalter").value == 0) {
// console.log("loading service records...");
2017-02-01 13:53:59 +01:00
// LoadOnly(1, 2);
// clearLocalStorage(1);
// clearLocalStorage(2);
2017-02-01 13:53:59 +01:00
// } else {
// showErrorAfterCrash();
// console.log("an error occurred")
// }
2017-02-01 13:53:59 +01:00
//} else {
// console.log("Ich bin hier drinne weil Storage nicht vorhanden");
//}
2016-06-27 01:45:38 +02:00
ErfolgteSpx();
var count = 0;
if (typeof vm !== 'undefined') {
count = vm.vorname.getSubscriptionsCount();
}
2016-06-27 01:45:38 +02:00
vm = new KlientenVM();
if (count === 0) {
ko.applyBindings(vm);
}
2016-06-27 01:45:38 +02:00
var documentWidth = $(document).width();
canvasWidth = documentWidth * scaleFactor;
$("#sketchpad").prop("width", canvasWidth);
loadSettingsAccordingToBWP();
}
2016-06-27 01:45:38 +02:00
var scaleFactor = .8;
$(window).resize(function() {
var documentWidth = $(document).width();
if(canvasWidth !== (documentWidth * scaleFactor) && $("#sketchpad").css("display") === "inline") {
$("#sketchpad").prop("width", documentWidth * scaleFactor);
}
});
2016-06-27 01:45:38 +02:00
function initBeWoMobile(actionPath) {
try {
2017-04-26 14:57:32 +02:00
$("#recordLoader_select, #kategorien_select, #leistungen_select, #textbausteine_select").prop("disabled", true);
2016-06-27 01:45:38 +02:00
toggleSelectClassesForElement("#kategorien_select", "#kategorien-select-container");
toggleSelectClassesForElement("#leistungen_select", "#leistungen-select-container");
toggleSelectClassesForElement("#recordLoader_select", "#record-loader-select-container");
2017-04-26 14:57:32 +02:00
toggleSelectClassesForElement("#textbausteine_select", "#textbausteine-select-container");
2016-06-27 01:45:38 +02:00
var selectedServiceCategory = $("#scDropDown").find(":selected").val()
2016-06-27 01:45:38 +02:00
if(isInGroupBookingMode() && isInEditingMode()) {
if(getGroupEditingFlag().flag === false) {
loadSavedValuesIntoForm();
} else {
saveFormValuesLocally();
}
setGroupEditingFlag(false);
}
var shouldActivateForm = isInGroupBookingMode() ? $("#leftContent input:checked").length > 0 : selectedServiceCategory !== "-1";
2016-06-27 01:45:38 +02:00
if(shouldActivateForm) {
$("#recordLoader_select").prop("disabled", false);
activateForm(actionPath);
2016-06-27 01:45:38 +02:00
if(!isInEditingMode()) {
$("#datum_textbox").val(getDateStringWithLeadingZeros(new Date()));
}
2016-06-27 01:45:38 +02:00
}
$(".not-required-input").on("click blur change focus",
function() {
2018-06-29 16:35:19 +02:00
var v = $(this).attr("id");
setTimeout(function() { toggleLabel(v); }, 1);
2016-06-27 01:45:38 +02:00
}
);
$("#start_textbox").on("blur", function() {
2018-06-29 16:35:19 +02:00
var startHasValue = $("#start_textbox").val() !== "";
var endHasValue = $("#ende_textbox").val() !== "";
var durationHasValue = $("#duration_textbox").val() !== "";
2016-06-27 01:45:38 +02:00
if(startHasValue && endHasValue) {
2016-06-27 01:45:38 +02:00
calcDurationByStartEnd();
} else if(startHasValue && durationHasValue) {
2016-06-27 01:45:38 +02:00
calcEndByStartDuration();
}
});
$("#ende_textbox").on("blur", function () {
2018-06-29 16:35:19 +02:00
var startHasValue = $("#start_textbox").val() !== "";
var endHasValue = $("#ende_textbox").val() !== "";
var durationHasValue = $("#duration_textbox").val() !== "";
2016-06-27 01:45:38 +02:00
if(endHasValue && startHasValue) {
2016-06-27 01:45:38 +02:00
calcDurationByStartEnd();
} else if(endHasValue && durationHasValue) {
2016-06-27 01:45:38 +02:00
calcStartByEndDuration();
}
});
$("#duration_textbox").on("blur", function () {
2018-06-29 16:35:19 +02:00
var startHasValue = $("#start_textbox").val() !== "";
var endHasValue = $("#ende_textbox").val() !== "";
var durationHasValue = $("#duration_textbox").val() !== "";
2016-06-27 01:45:38 +02:00
clearZED();
if(durationHasValue && startHasValue) {
2016-06-27 01:45:38 +02:00
calcEndByStartDuration();
} else if (durationHasValue && endHasValue) {
calcStartByEndDuration();
}
});
var supportConceptTableHasEntries = $("#leftContent input:checked").length;
var employeesTableHasEntries = $("#employeeCollapsible input:checked").length;
if (isInGroupBookingMode()) {
var value = supportConceptTableHasEntries > 0 && employeesTableHasEntries > 0 ? false : true;
2018-11-26 13:27:16 -04:00
$("#anlegenEditierenBtn").prop("disabled", value);
}
} catch(err) {
console.log('Fehler: ' + err.message);
2016-06-27 01:45:38 +02:00
}
}
function toggleSelectClassesForElement(elementIdentifier, parentElement) {
2018-06-29 16:35:19 +02:00
var enabled = $(elementIdentifier).prop("disabled") === "false";
if(enabled) {
2016-06-27 01:45:38 +02:00
$(parentElement).removeClass("disabled-select-container");
$(parentElement).addClass("styled-select-div");
} else {
$(parentElement).removeClass("styled-select-div");
$(parentElement).addClass("disabled-select-container");
}
}
function toggleErrorPopup2(errorMessage) {
2018-06-29 16:35:19 +02:00
var isDisplayNone = $("#errorPopupDiv2").css("display") === "none";
var displayValue = isDisplayNone ? "block" : "none";
2016-06-27 01:45:38 +02:00
$("#errorPopupDiv2").css("display", displayValue);
$(".modalWrapper").css("display", displayValue);
$(".modalWrapper").css("height", $(document).height());
2018-03-12 12:07:53 +01:00
if(isDisplayNone) {
2016-06-27 01:45:38 +02:00
$("#errorPopupText2").text(errorMessage);
2018-06-29 16:35:19 +02:00
var h = 0;
var t = $("#errorPopupTitle2").outerHeight();
var u = $("#errorPopupText2").outerHeight();
var v = $("#errorPopupBtnDiv2").outerHeight();
var w = $("#errorPopupOkBtn2").outerHeight();
2016-06-27 01:45:38 +02:00
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) {
2016-06-27 01:45:38 +02:00
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;
2016-06-27 01:45:38 +02:00
function loadSettingsAccordingToBWP() {
$.ajax({
type: "GET",
url: LoadSessionSettingsFromBWPUrl,
success: function (json) {
2018-06-29 16:35:19 +02:00
var timeOutSettingsString = $.parseJSON(json);
timeoutSetting = parseInt(timeOutSettingsString);
logoutSettingsAccordingToBWP(timeoutSetting);
2016-06-27 01:45:38 +02:00
}
});
}
2017-04-26 14:57:32 +02:00
function initializeDocumentationTextareas() {
makeAjaxCall(
"GET",
CheckDokuReiterUrl,
function (json) {
var dokuTypes = $.parseJSON(json);
numberOfDocumentationTypes = dokuTypes.length;
2016-06-27 01:45:38 +02:00
var tabWidth = 100 / numberOfDocumentationTypes;
$(".doku-tab-link").css("width", tabWidth + "%");
if (numberOfDocumentationTypes === 0) {
2017-04-26 14:57:32 +02:00
$("#tddokureiter").css("display", "none");
$("#trnormalDoku").css("display", "table-row");
window.focusedDokuTextarea = $("#notiz_textbox");
2017-04-26 14:57:32 +02:00
} else {
window.focusedDokuTextarea = $("#notiz_textbox1");
2016-06-27 01:45:38 +02:00
}
if (numberOfDocumentationTypes === 1) {
2017-04-26 14:57:32 +02:00
$("#tddokureiter").css("display", "none");
$("#trnormalDoku").css("display", "table-row");
$("#trnormalDokuLabel").text(dokuTypes[0].TypeDescription);
2016-06-27 01:45:38 +02:00
}
2017-04-26 14:57:32 +02:00
if (numberOfDocumentationTypes > 1) {
var height = 0;
for (var i = 0; i < numberOfDocumentationTypes; i++) {
2018-06-29 16:35:19 +02:00
var idNumber = i + 1;
2017-04-26 14:57:32 +02:00
var dokuTab = $("#doku-name-" + idNumber);
dokuTab.html(dokuTypes[i].TypeDescription);
dokuTab.show();
var outerHeight = dokuTab.outerHeight();
if (outerHeight > height) {
height = outerHeight;
}
}
$(".doku-tab-link").css("height", height + "px");
2016-06-27 01:45:38 +02:00
}
2017-02-01 13:53:59 +01:00
if (numberOfDocumentationTypes > 0) {
focusOnDoku(1);
2017-02-01 13:53:59 +01:00
}
},
null,
null
);
}
// Formulardaten im Browser speichern, um nach einem erneuten Laden der Seite (z.B. beim Hinzufügen von Hilfeplänen bzw. Gruppen oder Mitarbeitern) die Daten wiederherzustellen.
var savedEditFormValues = {};
$(document).on("change", ".edit-form-input",
function() {
saveFormValuesLocally();
});
function saveFormValuesLocally() {
2018-06-29 16:35:19 +02:00
var recordObject = {
category: $("#kategorien_select").val(),
serviceDescription: $("#leistungen_select").val(),
startDate: $("#datum_textbox").val(),
endDate: $("#enddatum_textbox").val(),
startTime: $("#start_textbox").val(),
endTime: $("#ende_textbox").val(),
duration: $("#duration_textbox").val(),
distance: $("#distance_textbox").val(),
notice: $("#notiz_textbox").val(),
notice2: $("#notiz_textbox2").val(),
notice3: $("#notiz_textbox3").val(),
notice4: $("#notiz_textbox4").val(),
notice5: $("#notiz_textbox5").val()
};
savedEditFormValues.obj = recordObject;
localStorage.savedEditFormValues = JSON.stringify(savedEditFormValues);
}
function deleteSavedEditFormValues() {
localStorage.savedEditFormValues = undefined;
savedEditFormValues = undefined;
}
function loadSavedEditFormValues() {
2018-06-29 16:35:19 +02:00
var storageData = localStorage.savedEditFormValues;
if(storageData !== "undefined") {
savedEditFormValues = JSON.parse(storageData);
} else {
savedEditFormValues = {};
}
return savedEditFormValues.obj;
}
function loadSavedValuesIntoForm() {
2018-06-29 16:35:19 +02:00
var values = loadSavedEditFormValues();
if(values.category !== "undefined") {
$("#kategorien_select").val(values.category);
}
if(values.serviceDescription !== "undefined") {
$("#leistungen_select").val(values.serviceDescription);
}
if(values.startDate !== "undefined") {
$("#datum_textbox").val(values.startDate);
}
if(values.endDate !== "undefined") {
$("#enddatum_textbox").val(values.endDate);
}
if(values.startTime !== "undefined") {
$("#start_textbox").val(values.startTime);
}
if(values.endTime !== "undefined") {
$("#ende_textbox").val(values.endTime);
}
if(values.duration !== "undefined") {
$("#duration_textbox").val(values.duration);
}
if(values.distance !== "undefined") {
$("#distance_textbox").val(values.distance);
}
if(values.notice !== "undefined") {
$("#notiz_textbox").val(values.notice);
}
if(values.notice1 !== "undefined") {
$("#notiz_textbox1").val(values.notice);
}
if(values.notice2 !== "undefined") {
$("#notiz_textbox2").val(values.notice2);
}
if(values.notice3 !== "undefined") {
$("#notiz_textbox3").val(values.notice3);
}
if(values.notice4 !== "undefined") {
$("#notiz_textbox4").val(values.notice4);
}
if(values.notice5 !== "undefined") {
$("#notiz_textbox5").val(values.notice5);
}
}