Files
BeWoPlaner/BeWoPlanerMobil/Scripts/serviceRecordValidation.js

169 lines
5.0 KiB
JavaScript

var isValidRecord = true;
function validateServiceRecordBeforeSubmit() {
var hasDokutext = false;
if (window.isServiceRecordNoticeMandatory) {
if (window.numberOfDocumentationTypes < 2) {
hasDokutext = !isEmptyOrSpaces($("#notiz_textbox").val());
} else {
for (var q = 0; q < window.numberOfDocumentationTypes; q++) {
hasDokutext = !isEmptyOrSpaces($("#notiz_textbox" + (q + 1)).val());
if (hasDokutext) {
break;
}
}
}
if (!hasDokutext) {
hideSanduhr();
var fehlertext;
if (window.numberOfDocumentationTypes > 1) {
fehlertext = "Es muss mindestens ein Dokumentationstextfeld ausgefüllt sein!";
} else {
fehlertext = "Das Dokumentationstextfeld darf nicht leer sein!";
}
toggleErrorPopup(fehlertext);
return;
}
}
var dateStr = $("#datum_textbox").val();
var startStr = $("#start_textbox").val();
var endStr = $("#ende_textbox").val();
console.log("dateStr: " + dateStr + "\nstartStr: " + startStr + "\nendStr: " + endStr);
if (!validateDate(dateStr) || !validateTime(startStr) || !validateTime(endStr)) {
hideSanduhr();
console.log("\nIst das Startdatum korrekt: " + validateDate($("#datum_textbox").val()) + "\nIst die Startzeit korrekt: " + validateTime($("#start_textbox").val()) + "\nIst die Endzeit korrekt: " + validateTime($("#ende_textbox").val()));
var errorMessage = "Bitte geben Sie gültige Datums- und/oder Zeitangaben ein";
toggleErrorPopup(errorMessage);
return;
}
var x = getDateObj(true);
var y;
if ($("#enddatum_textbox").val() !== "") {
y = getEndDateObj();
} else {
y = getDateObj(false);
}
var vonDatum = getDateTimeStringWithLeadingZeros(x);
var bisDatum = getDateTimeStringWithLeadingZeros(y);
makeAjaxCall("POST", window.checkRightsUrl, validationOnSuccess, { von: vonDatum, bis: bisDatum, inEditMode: $("#anlegenEditierenBtn").val() === "Speichern", dateString: dateStr, startString: startStr, endString: endStr });
}
function validationOnSuccess(json) {
$("#URLSave").val(dataURL);
$("#TimeStampSave").val(newday);
if (json === "SessionTimeout") {
window.location.href = redirectLink;
return;
}
if (json === "StartGreaterEnd") {
hideSanduhr();
writeFatalErrorMessage("Die Startzeit darf nicht größer als die Endzeit sein!");
return;
}
var meldungen = $.parseJSON(json);
kannTrotzdemGespeichertWerden = meldungen.KannTrotzdemGespeichertWerden;
if (meldungen.Message === null) {
submitCreationForm();
return;
}
showValidationPopup(meldungen.Message);
}
var kannTrotzdemGespeichertWerden = false;
function submitCreationForm() {
hideValidationPopup();
if (kannTrotzdemGespeichertWerden) {
$(".modalWrapper").show();
$(".warte-animation").show();
$("#createSRForm").submit();
} else {
$(".warte-animation").hide();
}
}
function showValidationPopup(validationMessage) {
$(".warte-animation").hide();
var popupDiv = $("#validationPopupDiv");
popupDiv.show();
$("#validationPopupText").html(validationMessage);
var t = $("#validationPopupTitle").outerHeight();
var u = $("#validationPopupText").outerHeight();
var v = $("#validationBtn1").outerHeight();
var w = $("#validationBtn2").outerHeight();
var x = $("#validationResultList").outerHeight();
var h = t + u + v + w + w + x;
popupDiv.css("height", h + "px");
popupDiv.css("top", window.pageYOffset + window.innerHeight / 2 - h / 2);
popupDiv.css("margin-top", "0");
}
function hideValidationPopup() {
$(".warte-animation").hide();
var popupDiv = $("#validationPopupDiv");
popupDiv.hide();
$(".modalWrapper").hide();
popupDiv.css("margin-top", "auto");
}
function toggleValidationPopup(validationMessage) {
$(".warte-animation").hide();
var popupDiv = $("#validationPopupDiv");
if (validationMessage !== null && validationMessage !== undefined && validationMessage.length > 0) {
popupDiv.toggle();
}
if (popupDiv.css("display") === "block" && validationMessage !== null && validationMessage !== undefined && validationMessage.length > 0) {
$("#validationPopupText").html(validationMessage);
var t = $("#validationPopupTitle").outerHeight();
var u = $("#validationPopupText").outerHeight();
var v = $("#validationBtn1").outerHeight();
var w = $("#validationBtn2").outerHeight();
var x = $("#validationResultList").outerHeight();
var h = t + u + v + w + w + x;
popupDiv.css("height", h + "px");
popupDiv.css("top", window.pageYOffset + window.innerHeight / 2 - h / 2);
popupDiv.css("margin-top", "0");
} else {
$(".modalWrapper").hide();
popupDiv.css("margin-top", "auto");
}
}