503 lines
14 KiB
JavaScript
503 lines
14 KiB
JavaScript
function selectSupportConcept(cb2ScOid) {
|
|
showSpinner();
|
|
$("#CostBearer2SupportConceptOid").val(cb2ScOid);
|
|
$("#selectSupportConceptForm").submit();
|
|
}
|
|
|
|
function setSelectedEmployee() {
|
|
const employeeOid = parseInt($("#employeesDropDown").find(":selected").val());
|
|
|
|
if (isNaN(employeeOid)) {
|
|
return;
|
|
}
|
|
|
|
$.get(window.getSetServiceRecordEmployeeUrl(), { employeeOid: employeeOid });
|
|
}
|
|
|
|
function checkJson(str) {
|
|
try {
|
|
JSON.parse(str);
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function showAlertMessage(message) {
|
|
$("#form-alert").html(message);
|
|
$("#form-alert").show();
|
|
}
|
|
|
|
function resetCreateForm() {
|
|
$("#serviceRecordCreationForm").trigger("reset");
|
|
|
|
const test = $("#has-any-rating-types").val().toLowerCase() === "true";
|
|
|
|
if(test) {
|
|
$(".goal-rating-badge").text("Bewerten");
|
|
} else {
|
|
$(".goal-rating-badge").text("");
|
|
}
|
|
}
|
|
|
|
function submitSingleBookingForm() {
|
|
showSpinner();
|
|
|
|
validateForm($("#singleBookingForm"), "sb");
|
|
}
|
|
|
|
function submitGroupBookingEditForm() {
|
|
showSpinner();
|
|
|
|
validateForm($("#groupBookingEditingForm"), "gb");
|
|
}
|
|
|
|
function submitGroupBookingForm() {
|
|
showSpinner();
|
|
|
|
validateForm($("#groupBookingForm"), "gb");
|
|
}
|
|
|
|
function toggleGroupBookingForm() {
|
|
const isEnabled = $("#selected-cb2sc-list").children().length > 0;
|
|
|
|
changeGroupBookingFormEnableState(!isEnabled);
|
|
}
|
|
|
|
function changeMultiBookingFormEnableState(enableState) {
|
|
$(
|
|
"#multi-booking-employees-button, " +
|
|
"#category-select, " +
|
|
"#leistung-select, " +
|
|
"#mb-start-date-input, " +
|
|
"#mb-end-date-input, " +
|
|
"#mb-start-time-input, " +
|
|
"#mb-end-time-input, " +
|
|
"#mb-duration-input, " +
|
|
"#mb-distance-input, " +
|
|
"textarea, " +
|
|
"#mb-reset-btn, " +
|
|
"#mb-create-btn, " +
|
|
"#mb-betrag," +
|
|
"#mb-textbausteine-btn, " +
|
|
"#mb-hours-minutes-dropdown-btn, " +
|
|
"#mb-marker-cb, " +
|
|
".bewo-restore-btn").prop("disabled", enableState);
|
|
}
|
|
|
|
function changeGroupBookingFormEnableState(enableState) {
|
|
$(
|
|
"#employees-button, " +
|
|
"#category-select, " +
|
|
"#leistung-select, " +
|
|
"#gb-start-date-input, " +
|
|
"#gb-end-date-input, " +
|
|
"#gb-start-time-input, " +
|
|
"#gb-end-time-input, " +
|
|
"#gb-duration-input, " +
|
|
"#gb-distance-input, " +
|
|
"textarea, " +
|
|
"#reset-button, " +
|
|
"#create-button, " +
|
|
"#gb-textbausteine-btn, " +
|
|
"#gb-hours-minutes-dropdown-btn, " +
|
|
"#gb-marker-cb, " +
|
|
"#gb-betrag, " +
|
|
".bewo-restore-btn"
|
|
).prop("disabled", enableState);
|
|
}
|
|
|
|
function changeSingleBookingFormEnableState(enableState) {
|
|
$(
|
|
"#employeesDropDown, " +
|
|
"#category-select, " +
|
|
"#leistung-select, " +
|
|
"#sb-start-date-input, " +
|
|
"#sb-end-date-input, " +
|
|
"#sb-start-time-input, " +
|
|
"#sb-end-time-input, " +
|
|
"#sb-duration-input, " +
|
|
"#sb-hours-minutes-dropdown-btn, " +
|
|
"#sb-distance-input, " +
|
|
"#sb-textbausteine-btn, " +
|
|
"#goals-button, " +
|
|
"textarea, " +
|
|
"#reset-button, " +
|
|
"#create-button, " +
|
|
"#statistics-button, " +
|
|
"#timeFrameSelect, " +
|
|
"#sb-marker-cb, " +
|
|
"#sb-betrag, " +
|
|
".bewo-restore-btn"
|
|
).prop("disabled", enableState);
|
|
}
|
|
|
|
function deleteServiceRecord(serviceRecordOid) {
|
|
showMessagePopupWithCallback("Eintrag löschen", "Sind Sie sicher, dass Sie den Eintrag löschen möchten?",
|
|
function() {
|
|
const url = window.getValidateServiceRecordDeletionUrl();
|
|
|
|
$.get(url, { serviceRecordOidString: serviceRecordOid }).done(function(result) {
|
|
if(result === "Error") {
|
|
hideSpinner();
|
|
showAlertMessageBox("Fehler", "Es ist ein Fehler aufgetreten", null, false);
|
|
return;
|
|
}
|
|
|
|
if(false === checkJson(result)) {
|
|
logWarning("deleteServiceRecord: Der zurückgegebene Wert ist kein gültiges JSON!");
|
|
hideSpinner();
|
|
return;
|
|
}
|
|
|
|
var form = $("#deletion-form");
|
|
|
|
if(result.length === 0) {
|
|
if(form.length !== 0) {
|
|
$("#oidHolder").val(serviceRecordOid);
|
|
|
|
showSpinner();
|
|
form.submit();
|
|
}
|
|
} else { // Meldungen
|
|
hideSpinner();
|
|
|
|
const validationResult = parseJason(result);
|
|
|
|
if(validationResult.Message === null) {
|
|
$("#oidHolder").val(serviceRecordOid);
|
|
|
|
showSpinner();
|
|
form.submit();
|
|
return;
|
|
}
|
|
|
|
$("#oidHolder").val(serviceRecordOid);
|
|
|
|
var kannTrotzdemGespeichertWerden = validationResult.KannTrotzdemGespeichertWerden;
|
|
|
|
const validationCallback = function() {
|
|
$("#messagePopup .modal-body").html();
|
|
if(kannTrotzdemGespeichertWerden) {
|
|
showSpinner();
|
|
form.submit();
|
|
}
|
|
};
|
|
|
|
if(kannTrotzdemGespeichertWerden) {
|
|
showWarningMessageBox("Fehler", validationResult.Message, validationCallback, false);
|
|
} else {
|
|
showAlertMessageBox("Fehler", validationResult.Message, validationCallback, false);
|
|
}
|
|
}
|
|
});
|
|
}, false);
|
|
}
|
|
|
|
function validateForm(form, prefix) {
|
|
if(form === undefined || form === null) {
|
|
hideSpinner();
|
|
return;
|
|
}
|
|
|
|
if(prefix === undefined || prefix === null) {
|
|
prefix = "";
|
|
}
|
|
|
|
var errorMessage = "";
|
|
var isNoticeMandatory = window.getIsDocumentationMandatory();
|
|
var numberOfNoticeTextareas = window.getNumberOfDokutypes();
|
|
|
|
var isValid = true;
|
|
|
|
if(isNoticeMandatory) {
|
|
if(numberOfNoticeTextareas === 0) {
|
|
var doku = $(`#${prefix}-dokufeld-textarea`).val();
|
|
|
|
if(doku === undefined || doku === null) {
|
|
doku = "";
|
|
}
|
|
|
|
isValid = doku.length > 0;
|
|
} else {
|
|
for(var i = 0; i < numberOfNoticeTextareas; i++) {
|
|
var d = $(`#${prefix}-doku-textarea-${i}`).val();
|
|
|
|
if(d === undefined || d === null) {
|
|
d = "";
|
|
}
|
|
|
|
isValid = d.length > 0;
|
|
|
|
if(isValid) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(isValid === false) {
|
|
errorMessage = `Bitte füllen Sie ${numberOfNoticeTextareas > 1 ? "mindestens ein" : "das"} Dokumentationsfeld aus.<br>`;
|
|
}
|
|
}
|
|
|
|
var startAndEndDates = getStartAndEndDate(prefix);
|
|
|
|
if(startAndEndDates === null && isValid) {
|
|
isValid = false;
|
|
errorMessage += "Die Datums- und / oder Zeitangaben sind nicht korrekt.<br>";
|
|
}
|
|
|
|
if(isValid === false) {
|
|
hideSpinner();
|
|
|
|
showAlertMessageBox("Fehler",
|
|
errorMessage,
|
|
function() {
|
|
$("#messagePopup .modal-body").html();
|
|
},
|
|
true);
|
|
|
|
return;
|
|
}
|
|
|
|
if(startAndEndDates !== null && isValid) {
|
|
var [start, end] = startAndEndDates;
|
|
|
|
if(end.getTime() < start.getTime()) {
|
|
showAlertMessageBox("Fehler", "Der Start muss vor dem Ende liegen!", null, false);
|
|
hideSpinner();
|
|
return;
|
|
}
|
|
|
|
var [doku1, doku2, doku3, doku4, doku5] = getDokuTexte(prefix);
|
|
|
|
var startTimeInput = $(`#${prefix}-start-time-input`);
|
|
var endTimeInput = $(`#${prefix}-end-time-input`);
|
|
|
|
$("#srv-date").val(`${getDateAsString(start)}`);
|
|
$("#srv-end-date").val(`${getDateAsString(end)}`);
|
|
$("#srv-start").val(startTimeInput.val());
|
|
$("#srv-end").val(endTimeInput.val());
|
|
|
|
$("#srv-doku1").val(doku1);
|
|
$("#srv-doku2").val(doku2);
|
|
$("#srv-doku3").val(doku3);
|
|
$("#srv-doku4").val(doku4);
|
|
$("#srv-doku5").val(doku5);
|
|
$("#srv-distance").val($(`#${prefix}-distance-input`).val());
|
|
$("#srv-form-id").val(form.attr("id"));
|
|
$("#srv-marker").val($(`#${prefix}-marker-cb`).is(":checked") ? "on" : "off");
|
|
$("#srv-service-description").val($(`#${prefix}-leistung-select`).find(":selected").val());
|
|
$("#srv-duration").val($(`#${prefix}-duration-input`).val());
|
|
$("#srv-betrag").val($(`#${prefix}-betrag`).val());
|
|
|
|
showSpinner();
|
|
$("#service-record-validation-form").submit();
|
|
}
|
|
}
|
|
|
|
function getDokuTexte(prefix) {
|
|
const noticeList = [null, null, null, null, null];
|
|
|
|
try {
|
|
const hasMultipleDokufelder = $(`#${prefix}-dokufeld-textarea`).length === 0;
|
|
|
|
let dokufeldCounter = 0;
|
|
|
|
if(hasMultipleDokufelder) {
|
|
for(let i = 0; i < 5; i++) {
|
|
const dokufeld = $(`#${prefix}-doku-textarea-${i}`);
|
|
|
|
if(dokufeld.length > 0) {
|
|
noticeList[i] = dokufeld.val();
|
|
dokufeldCounter++;
|
|
}
|
|
}
|
|
} else {
|
|
noticeList[0] = $(`#${prefix}-dokufeld-textarea`).val();
|
|
dokufeldCounter = 1;
|
|
}
|
|
|
|
let x = "";
|
|
for(let j = 0; j < dokufeldCounter; j++) {
|
|
x += noticeList[j];
|
|
|
|
if(j < noticeList.length - 1) {
|
|
x += ", ";
|
|
}
|
|
}
|
|
} catch(error) {
|
|
window.showErrorPopup(error);
|
|
} finally {
|
|
return noticeList;
|
|
}
|
|
}
|
|
|
|
function showGoalRatingPopup(goalOid) {
|
|
try {
|
|
$("#goal-rating-popup").modal("show");
|
|
$("#goal-to-rate-oid").val(goalOid);
|
|
} catch (error) {
|
|
window.showErrorPopup(error);
|
|
}
|
|
}
|
|
|
|
function hideGoalRatingPopup() {
|
|
try {
|
|
$("#goal-rating-popup").modal("hide");
|
|
} catch (error) {
|
|
window.showErrorPopup(error);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function checkChildNodes(parentOid) {
|
|
const rootElement = $(`#c-${parentOid}`);
|
|
const checkboxes = rootElement.find("input");
|
|
|
|
var isChecked = $(`#${parentOid}`).prop("checked") === true;
|
|
|
|
$.each(checkboxes, function(index, checkbox) {
|
|
const box = $(checkbox);
|
|
const id = box.attr("id");
|
|
|
|
if(!id !== parentOid) {
|
|
box.prop("checked", isChecked);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function validateDistanceInput() {
|
|
checkNumberInput("distance");
|
|
}
|
|
|
|
function checkNumberInput(inputId) {
|
|
const input = $(`#${inputId}`).val();
|
|
|
|
return /^\d+$/.test(input);
|
|
}
|
|
|
|
// Wird bei der Validierung des Formulars benutzt
|
|
function getStartAndEndDate(prefix) {
|
|
if(prefix === undefined || prefix === null) {
|
|
prefix = "";
|
|
}
|
|
|
|
const startDateInput = $(`#${prefix}-start-date-input`);
|
|
const endDateInput = $(`#${prefix}-end-date-input`);
|
|
const startTimeInput = $(`#${prefix}-start-time-input`);
|
|
const endTimeInput = $(`#${prefix}-end-time-input`);
|
|
logInfo(`Prefix: ${prefix}`);
|
|
return validateStartAndEndInputs(startDateInput, startTimeInput, endDateInput, endTimeInput, true);
|
|
}
|
|
|
|
function validateStartAndEndInputs(startDateInput, startTimeInput, endDateInput, endTimeInput, isServiceRecord) {
|
|
if(isServiceRecord === undefined || isServiceRecord === null) {
|
|
isServiceRecord = false;
|
|
}
|
|
|
|
logInfo2(`Startdatum: ${startDateInput.prop("id")}`);
|
|
|
|
const startDate = new Date(startDateInput.val());
|
|
const startTime = startTimeInput.val();
|
|
|
|
let endDate = new Date(endDateInput.val());
|
|
const endTime = endTimeInput.val();
|
|
|
|
if(endDateInput.length === 0) {
|
|
endDate = startDate;
|
|
}
|
|
|
|
const isStartDateValid = false === isNaN(startDate.getTime());
|
|
const isEndDateValid = endDateInput.length ? false === isNaN(endDate.getTime()) : true;
|
|
|
|
if(isStartDateValid && startTime.length === 0 || isEndDateValid && endTime.length === 0) {
|
|
const startValue = `${getDateAsString(startDate)}T00:00:0${(isServiceRecord ? "1" : "0")}`;
|
|
const endValue = `${getDateAsString(endDate)}T00:00:0${(isServiceRecord ? "1" : "0")}`;
|
|
|
|
return [new Date(startValue), new Date(endValue)];
|
|
}
|
|
|
|
const isStartTimeValid = startTime.length > 0;
|
|
const isEndTimeValid = endTime.length > 0;
|
|
|
|
if(false === isStartTimeValid || false === isStartDateValid || false === isEndTimeValid || false === isEndDateValid) {
|
|
return null;
|
|
}
|
|
|
|
return [combineDateAndTime(startDate, startTime), combineDateAndTime(endDate, endTime)];
|
|
}
|
|
|
|
|
|
function supportConceptSearchOnChange() {
|
|
try {
|
|
var text = $("#support-concept-search-input").val().toLowerCase();
|
|
|
|
const links = $(".blubb-test");
|
|
|
|
if (text.length === 0) {
|
|
links.show();
|
|
}
|
|
|
|
$.each(links,
|
|
function(index, item) {
|
|
const supportConcept = $(item);
|
|
|
|
if(supportConcept.find(".supportconcept-name-header").text().toLowerCase().includes(text)) {
|
|
supportConcept.show();
|
|
} else {
|
|
supportConcept.hide();
|
|
}
|
|
});
|
|
|
|
} catch (error) {
|
|
window.showErrorPopup(error);
|
|
}
|
|
}
|
|
|
|
function resetSupportConceptSearch() {
|
|
try {
|
|
$("#support-concept-search-input").val("");
|
|
$(".blubb-test").show();
|
|
} catch (error) {
|
|
window.showErrorPopup(error);
|
|
}
|
|
}
|
|
|
|
function getSignatureImage(serviceRecordOid, signatureOid) {
|
|
try {
|
|
const url = window.getGetSignatureImageUrl();
|
|
|
|
$.get(url, { serviceRecordOid: serviceRecordOid, signatureOid: signatureOid }).done(function(textAndImage) {
|
|
const text2Image = textAndImage.split(";");
|
|
|
|
const serviceRecordDescription = text2Image[0];
|
|
const imageData = text2Image[1] + ";" + text2Image[2];
|
|
|
|
$("#signature-text").html(serviceRecordDescription);
|
|
$("#signature-img").attr("src", imageData);
|
|
|
|
$("#signature-img-popup").modal("show");
|
|
});
|
|
} catch (error) {
|
|
window.showErrorPopup(error);
|
|
}
|
|
}
|
|
|
|
function setServiceDescription(id) {
|
|
try {
|
|
const url = window.getSetServiceDescriptionUrl();
|
|
|
|
const selectedServiceDescription = $(`#${id}`).find(":selected").val();
|
|
|
|
$.get(url, {pServiceDescriptionOid: selectedServiceDescription});
|
|
} catch(error) {
|
|
window.showErrorPopup(error);
|
|
}
|
|
} |