562 lines
18 KiB
JavaScript
562 lines
18 KiB
JavaScript
function selectSupportConcept(cb2ScOid) {
|
|
showSpinner();
|
|
$("#CostBearer2SupportConceptOid").val(cb2ScOid);
|
|
$("#selectSupportConceptForm").submit();
|
|
}
|
|
|
|
function setSelectedEmployee() {
|
|
var employeeOid = parseInt($("#employeesDropDown").find(":selected").val());
|
|
|
|
if (isNaN(employeeOid)) {
|
|
return;
|
|
}
|
|
|
|
$.get(getSetServiceRecordEmployeeUrl(), { employeeOid: employeeOid });
|
|
}
|
|
|
|
function loadServiceDescriptions() {
|
|
var selectedCategoryOid = $("#category-select").find(":selected").val();
|
|
|
|
if (selectedCategoryOid === null || selectedCategoryOid === undefined) {
|
|
return;
|
|
}
|
|
|
|
$.get(getLoadServiceCategoriesUrl(), { pServiceCategoryOid: selectedCategoryOid })
|
|
.done(function (data) {
|
|
var serviceDescriptions = $.parseJSON(data);
|
|
var serviceDescriptionsSelect = $("#leistung-select");
|
|
|
|
serviceDescriptionsSelect.empty();
|
|
serviceDescriptionsSelect.val("");
|
|
|
|
$.each(serviceDescriptions, function (index, serviceDescription) {
|
|
serviceDescriptionsSelect.append('<option value="' + serviceDescription.ServiceDescriptionOid + '">' + serviceDescription.Name + "</option>");
|
|
});
|
|
|
|
var serviceDescriptionToEdit = getServiceDescriptionToEdit();
|
|
|
|
var selectedOid = 0;
|
|
|
|
if (serviceDescriptionToEdit > 0) {
|
|
$("#leistung-select > option").each(function() {
|
|
var val = $(this).val();
|
|
|
|
if (serviceDescriptionToEdit == val) {
|
|
serviceDescriptionsSelect.val(val);
|
|
selectedOid = val;
|
|
}
|
|
});
|
|
} else {
|
|
if(serviceDescriptions[0] !== undefined) {
|
|
serviceDescriptionsSelect.val(serviceDescriptions[0].ServiceDescriptionOid);
|
|
selectedOid = serviceDescriptions[0].ServiceDescriptionOid;
|
|
}
|
|
}
|
|
|
|
if (selectedOid > 0) {
|
|
$.get(getSetServiceDescriptionUrl(), { pServiceDescriptionOid: selectedOid });
|
|
}
|
|
|
|
$.get(getLoadTextbausteineForServiceCategoryUrl(), { pServiceCategoryOid: selectedCategoryOid }).done(function(result) {
|
|
if(checkJson(result) === false) {
|
|
return;
|
|
}
|
|
|
|
$("#tree").treeview({
|
|
data: result,
|
|
onNodeSelected: function (event, data) {
|
|
var tags = data.tags;
|
|
|
|
if (tags === undefined || tags === null || tags.length === 0) {
|
|
return;
|
|
}
|
|
|
|
var textbausteinOid = parseInt(tags[0], 10);
|
|
var focusedDokuFeld;
|
|
|
|
$.get(getLoadCompleteTextbausteinByOidUrl(), { pTextbausteinOid: textbausteinOid }).done(function (textModuleText) {
|
|
if ($("#dokufeld").length > 0) {
|
|
focusedDokuFeld = $("#dokufeld");
|
|
} else {
|
|
var numberOfDokutypes = getNumberOfDokutypes();
|
|
|
|
for (var i = 0; i < numberOfDokutypes; i++) {
|
|
var currentElement = $("#doku_" + i);
|
|
|
|
if (currentElement.css("display") !== "none") {
|
|
focusedDokuFeld = $("#doku-textarea-" + i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
var cursorPosition = focusedDokuFeld.prop("selectionStart");
|
|
var v = focusedDokuFeld.val();
|
|
var textBefore = v.substring(0, cursorPosition);
|
|
var textAfter = v.substring(cursorPosition, v.length);
|
|
|
|
focusedDokuFeld.val(textBefore + textModuleText + textAfter);
|
|
|
|
$("#textbausteine-popup").modal("hide");
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function checkJson(str)
|
|
{
|
|
try {
|
|
JSON.parse(str);
|
|
} catch (error) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function serviceDescriptionSelectOnReset() {
|
|
setTimeout(function () {
|
|
loadServiceDescriptions();
|
|
}, 100);
|
|
}
|
|
|
|
function showAlertMessage(message) {
|
|
$("#form-alert").html(message);
|
|
$("#form-alert").show();
|
|
}
|
|
|
|
function calculateDuration(isInvocatedByHoursMinutesButton) {
|
|
var startTime = $("#start-time").val();
|
|
var endTime = $("#end-time").val();
|
|
var duration = $("#duration").val();
|
|
var hoursMinutesDropdownButton = $("#hours-minutes-dropdown-btn");
|
|
|
|
var startTimeCondition = startTime !== undefined && startTime !== null && startTime.length > 0;
|
|
var endTimeCondition = endTime !== undefined && endTime !== null && endTime.length > 0;
|
|
var durationNumber = hoursMinutesDropdownButton.length && hoursMinutesDropdownButton.text() === "Stunden" ? parseFloat(duration.replace(",", ".")) : parseInt(duration, 10);
|
|
var durationCondition = !isNaN(durationNumber);
|
|
var startDateString = $("#start-date-picker").datetimepicker("date");
|
|
var endDate = moment(new Date());
|
|
var startDate = moment(new Date());
|
|
|
|
if(startDateString.length !== 0) {
|
|
startDate = moment(startDateString);
|
|
endDate = startDate.clone();
|
|
}
|
|
|
|
if ($("#end-date-picker").length !== 0) {
|
|
var endDateString = $("#end-date-picker").datetimepicker("date");
|
|
|
|
if (endDateString.length !== 0) {
|
|
endDate = moment(endDateString);
|
|
}
|
|
}
|
|
|
|
var newDurationValue = 0;
|
|
|
|
if(startTimeCondition && endTimeCondition && isInvocatedByHoursMinutesButton === false) {
|
|
var startHHmm = parseTimeInputToIntegerArray(startTime);
|
|
var endHHmm = parseTimeInputToIntegerArray(endTime);
|
|
|
|
startDate.hours(startHHmm[0]);
|
|
startDate.minutes(startHHmm[1]);
|
|
endDate.hours(endHHmm[0]);
|
|
endDate.minutes(endHHmm[1]);
|
|
|
|
var momentDuration = moment.duration(endDate.diff(startDate));
|
|
|
|
if (hoursMinutesDropdownButton.length && hoursMinutesDropdownButton.text() === "Stunden") {
|
|
newDurationValue = momentDuration.asHours();
|
|
} else {
|
|
newDurationValue = momentDuration.asMinutes();
|
|
}
|
|
|
|
$("#duration").val(newDurationValue);
|
|
} else if(startTimeCondition && durationCondition) {
|
|
if(hoursMinutesDropdownButton.length && hoursMinutesDropdownButton.text() === "Stunden") {
|
|
durationNumber *= 60;
|
|
}
|
|
|
|
calculateTimeWithDuration(startTime, $("#end-time"), startDate, durationNumber);
|
|
} else if(endTimeCondition && durationCondition) {
|
|
if(hoursMinutesDropdownButton.length && hoursMinutesDropdownButton.text() === "Stunden") {
|
|
durationNumber *= 60;
|
|
}
|
|
|
|
calculateTimeWithDuration(endTime, $("#start-time"), startDate, durationNumber * -1);
|
|
}
|
|
}
|
|
|
|
function onDurationChange() {
|
|
var startTime = $("#start-time").val();
|
|
var endTime = $("#end-time").val();
|
|
var duration = $("#duration").val();
|
|
|
|
var hoursMinutesDropdownButton = $("#hours-minutes-dropdown-btn");
|
|
var startTimeCondition = startTime !== undefined && startTime !== null && startTime.length > 0;
|
|
var endTimeCondition = endTime !== undefined && endTime !== null && endTime.length > 0;
|
|
var durationNumber = hoursMinutesDropdownButton.length && hoursMinutesDropdownButton.text() === "Stunden" ? parseFloat(duration.replace(",", ".")) : parseInt(duration, 10);
|
|
var durationCondition = !isNaN(durationNumber);
|
|
|
|
if((false === startTimeCondition && false === endTimeCondition) || durationCondition === false) {
|
|
return;
|
|
}
|
|
|
|
var startDateString = $("#start-date-picker").datetimepicker("date");
|
|
var endDate = moment(new Date());
|
|
var startDate = moment(new Date());
|
|
|
|
if (startDateString.length !== 0) {
|
|
startDate = moment(startDateString);
|
|
endDate = startDate.clone();
|
|
}
|
|
|
|
if ($("#end-date-picker").length !== 0) {
|
|
var endDateString = $("#end-date-picker").datetimepicker("date");
|
|
endDate = moment(endDateString);
|
|
}
|
|
|
|
var h2m = [0, 0];
|
|
|
|
if(hoursMinutesDropdownButton.length && hoursMinutesDropdownButton.text() === "Stunden") {
|
|
durationNumber *= 60;
|
|
}
|
|
|
|
if (startTimeCondition === true) {
|
|
h2m = parseTimeInputToIntegerArray(startTime);
|
|
|
|
startDate.hours(h2m[0]).minutes(h2m[1]).add(durationNumber, "m");
|
|
$("#end-time").val(startDate.format("HH:mm"));
|
|
} else {
|
|
h2m = parseTimeInputToIntegerArray(endTime);
|
|
|
|
endDate.hours(h2m[0]).minutes(h2m[1]).add(durationNumber * -1, "m");
|
|
|
|
$("#start-time").val(endDate.format("HH:mm"));
|
|
}
|
|
}
|
|
|
|
function calculateTimeWithDuration(timeInputValue, timeElement, startDate, duration) {
|
|
var hoursToMinutes = parseTimeInputToIntegerArray(timeInputValue);
|
|
var hours = parseInt(hoursToMinutes[0]);
|
|
var minutes = parseInt(hoursToMinutes[1]);
|
|
console.log("duration: " + duration);
|
|
startDate.hours(hours);
|
|
startDate.minutes(minutes);
|
|
|
|
startDate.add(duration, "m");
|
|
|
|
timeInputValue = startDate.format("HH:mm");
|
|
|
|
timeElement.val(timeInputValue);
|
|
}
|
|
|
|
function resetCreateForm() {
|
|
$("#serviceRecordCreationForm").trigger("reset");
|
|
}
|
|
|
|
function resetSingleBookingForm() {
|
|
$("#singleBookingForm").trigger("reset");
|
|
}
|
|
|
|
function submitSingleBookingForm() {
|
|
showSpinner();
|
|
|
|
validateForm($("#singleBookingForm"));
|
|
}
|
|
|
|
function submitCreateForm() {
|
|
showSpinner();
|
|
|
|
validateForm($("#serviceRecordCreationForm"));
|
|
}
|
|
|
|
function submitEditForm() {
|
|
showSpinner();
|
|
|
|
validateForm($("#serviceRecordEditForm"));
|
|
}
|
|
|
|
function resetGroupBookingForm() {
|
|
$("#groupBookingCreationForm").trigger("reset");
|
|
}
|
|
|
|
function submitGroupBookingForm() {
|
|
showSpinner();
|
|
|
|
validateForm($("#groupBookingCreationForm"));
|
|
}
|
|
|
|
function submitGroupBookingEditForm() {
|
|
showSpinner();
|
|
|
|
validateForm($("#groupBookingEditingForm"));
|
|
}
|
|
|
|
function deactivateGroupBookingForm() {
|
|
$("#employees-button, #category-select, #leistung-select, #start-date, #end-date, #start-time, #end-time, #duration, #distance, textarea, #reset-button, #create-button, #textbausteine-button").prop("disabled", true);
|
|
}
|
|
|
|
function activateGroupBookingForm() {
|
|
$("#employees-button, #category-select, #leistung-select, #start-date, #end-date, #start-time, #end-time, #duration, #distance, textarea, #reset-button, #create-button, #textbausteine-button").prop("disabled", false);
|
|
}
|
|
|
|
function deleteServiceRecord(serviceRecordOid) {
|
|
showMessagePopupWithCallback("Eintrag löschen", "Sind Sie sicher, dass Sie den Eintrag löschen möchten?",
|
|
function() {
|
|
var form = $("#deletion-form");
|
|
|
|
if (form.length !== 0) {
|
|
$("#oidHolder").val(serviceRecordOid);
|
|
|
|
showSpinner();
|
|
form.submit();
|
|
}
|
|
}, false);
|
|
}
|
|
|
|
function validateForm(form) {
|
|
if (form === undefined || form === null) {
|
|
hideSpinner();
|
|
return;
|
|
}
|
|
|
|
var errorMessage = "";
|
|
var isNoticeMandatory = getIsDocumentationMandatory();
|
|
var numberOfNoticeTextareas = getNumberOfDokutypes();
|
|
|
|
var isValid = true;
|
|
|
|
if (isNoticeMandatory) {
|
|
if (numberOfNoticeTextareas === 0) {
|
|
var doku = $("#dokufeld").val();
|
|
|
|
isValid = doku.length > 0;
|
|
} else {
|
|
for (var i = 0; i < numberOfNoticeTextareas; i++) {
|
|
var d = $("#doku-textarea-" + i).val();
|
|
|
|
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();
|
|
|
|
if (startAndEndDates === null && isValid) {
|
|
isValid = false;
|
|
errorMessage += "Die Datums- und / oder Zeitangaben sind nicht korrekt.<br/>";
|
|
}
|
|
|
|
var isInEditingMode = getIsInEditingMode();
|
|
|
|
if(isValid === false) {
|
|
hideSpinner();
|
|
$("#messagePopup .modal-body").html('<div class="alert alert-danger" role="alert">' + errorMessage + "</div>");
|
|
|
|
showMessagePopupWithCallback("Fehler", null, function() {
|
|
$("#messagePopup .modal-body").html();
|
|
}, true);
|
|
return;
|
|
}
|
|
|
|
if(startAndEndDates !== null && isValid) {
|
|
var start = startAndEndDates[0];
|
|
var end = startAndEndDates[1];
|
|
|
|
$.get(getCheckRightsUrl(), { von: start.format("DD.MM.YYYY"), bis: end.format("DD.MM.YYYY"), inEditMode: isInEditingMode, dateString: start.format("DD.MM.YYYY"), startString: start.format("HH:mm"), endString: end.format("HH:mm") }).done(function(result) {
|
|
var message = $.parseJSON(result);
|
|
|
|
hideSpinner();
|
|
|
|
if (message.Message === null) {
|
|
form.submit();
|
|
} else {
|
|
var kannTrotzdemGespeichertWerden = message.KannTrotzdemGespeichertWerden;
|
|
|
|
var background = kannTrotzdemGespeichertWerden ? "alert-warning" : "alert-danger";
|
|
|
|
$("#messagePopup .modal-body").html('<div class="alert ' + background + '" role="alert">' + message.Message + "</div>");
|
|
|
|
showMessagePopupWithCallback("Fehler", null, function() {
|
|
$("#messagePopup .modal-body").html();
|
|
if(kannTrotzdemGespeichertWerden) {
|
|
showSpinner();
|
|
form.submit();
|
|
}
|
|
}, false);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
var treeHtml = "";
|
|
|
|
function buildGoalsTree(treeData) {
|
|
var container = $("#goals-container");
|
|
|
|
container.empty();
|
|
treeHtml = "";
|
|
|
|
$.each(treeData, function(index) {
|
|
buildGoaldTreeBranch(treeData[index]);
|
|
});
|
|
|
|
container.append(treeHtml);
|
|
}
|
|
|
|
function buildGoaldTreeBranch(goalItem) {
|
|
var goalOid = goalItem.ValueListEntryOid;
|
|
var goalHeader = goalItem.Header;
|
|
var isChecked = getSelectedGoalOids() !== null && isInArray(goalOid, getSelectedGoalOids()) ? "checked" : "";
|
|
|
|
if(!goalItem.IsLeaf) {
|
|
treeHtml +=
|
|
'<div class="card w-100 mb-3" id="c-' + goalOid + '">' +
|
|
'<div class="card-header px-1">' +
|
|
'<div class="custom-control custom-checkbox">' +
|
|
'<input type="checkbox" class="custom-control-input" id="' + goalOid + '" ' + isChecked + ' onclick="checkChildNodes(' + goalOid + ')" onchange="updateSelectedGoals()">' +
|
|
'<label class="custom-control-label" for="' + goalOid + '">' + goalHeader + "</label>" +
|
|
"</div>" +
|
|
"</div>" +
|
|
'<div class="card-body px-1 py-1">';
|
|
|
|
$.each(goalItem.Children, function(index) {
|
|
buildGoaldTreeBranch(goalItem.Children[index]);
|
|
});
|
|
|
|
treeHtml += "</div>";
|
|
} else {
|
|
treeHtml +=
|
|
'<div class="custom-control custom-checkbox">' +
|
|
'<input type="checkbox" class="custom-control-input" id="' + goalOid + '" ' + isChecked + ' onchange="updateSelectedGoals()">' +
|
|
'<label class="custom-control-label" for="' + goalOid + '">' + goalHeader + "</label>" +
|
|
"</div>";
|
|
}
|
|
}
|
|
|
|
function checkChildNodes(parentOid) {
|
|
var rootElement = $("#c-" + parentOid);
|
|
var checkboxes = rootElement.find("input");
|
|
|
|
var isChecked = $("#" + parentOid).prop("checked") === true;
|
|
|
|
$.each(checkboxes, function(index, checkbox) {
|
|
var box = $(checkbox);
|
|
var id = box.attr("id");
|
|
|
|
if(!id !== parentOid) {
|
|
box.prop("checked", isChecked);
|
|
}
|
|
});
|
|
}
|
|
|
|
function getCheckedGoals() {
|
|
var rootElement = $("#goals-container");
|
|
var checkboxes = rootElement.find("input");
|
|
|
|
var selectedGoals = "";
|
|
|
|
$.each(checkboxes, function(index, checkbox) {
|
|
var box = $(checkbox);
|
|
var id = box.attr("id");
|
|
|
|
if (box.prop("checked") === true && !id.includes("goal")) {
|
|
selectedGoals += id + ";";
|
|
}
|
|
});
|
|
|
|
return selectedGoals.substr(0, selectedGoals.length - 1);
|
|
}
|
|
|
|
function updateSelectedGoals() {
|
|
var selectedGoals = getCheckedGoals();
|
|
|
|
$.get(getUpdateGoalsUrl(), { pGoalOids: selectedGoals });
|
|
}
|
|
|
|
function validateDistanceInput() {
|
|
checkNumberInput("distance");
|
|
}
|
|
|
|
function checkNumberInput(inputId) {
|
|
var input = $("#" + inputId).val();
|
|
|
|
var isNum = /^\d+$/.test(input);
|
|
|
|
return isNum;
|
|
}
|
|
|
|
function getStartAndEndDate() {
|
|
var startTimePicker = $("#start-time-picker");
|
|
var endTimePicker = $("#end-time-picker");
|
|
var startDatePicker = $("#start-date-picker");
|
|
var endDatePicker = $("#end-date-picker");
|
|
|
|
if ($("#start-time").val().length === 0 || $("#end-time").val().length === 0) {
|
|
return null;
|
|
}
|
|
|
|
startTimePicker.datetimepicker("show");
|
|
startTimePicker.datetimepicker("hide");
|
|
|
|
startDatePicker.datetimepicker("show");
|
|
startDatePicker.datetimepicker("hide");
|
|
|
|
endTimePicker.datetimepicker("show");
|
|
endTimePicker.datetimepicker("hide");
|
|
|
|
endDatePicker.datetimepicker("show");
|
|
endDatePicker.datetimepicker("hide");
|
|
|
|
var startTime = startTimePicker.datetimepicker("date");
|
|
var endTime = endTimePicker.datetimepicker("date");
|
|
var startDate = startDatePicker.datetimepicker("date");
|
|
var endDate = endDatePicker.datetimepicker("date");
|
|
|
|
var a = startDate === undefined || startDate === null || !startDate.isValid();
|
|
var b = endDatePicker.length === 0 ? false : endDate === undefined || endDate === null || !endDate.isValid();
|
|
var c = startTime === undefined || startTime === null || !startTime.isValid();
|
|
var d = endTime === undefined || endTime === null || !endTime.isValid();
|
|
|
|
if(a || b || c || d) {
|
|
return null;
|
|
}
|
|
|
|
if(endDatePicker.length === 0 || endDate.isValid() === false) {
|
|
endDate = startDate.clone();
|
|
}
|
|
|
|
startDate = startDate.hours(startTime.hours());
|
|
startDate = startDate.minutes(startTime.minutes());
|
|
|
|
endDate = endDate.hours(endTime.hours());
|
|
endDate = endDate.minutes(endTime.minutes());
|
|
|
|
if(endDate.isBefore(startDate)) {
|
|
return null;
|
|
}
|
|
|
|
return [startDate, endDate];
|
|
}
|
|
|
|
function toggleHoursMinutesDropdownButton(element) {
|
|
var hoursMinutesDropdownButton = $("#hours-minutes-dropdown-btn");
|
|
|
|
var buttonText = $(element).text();
|
|
hoursMinutesDropdownButton.text(buttonText);
|
|
|
|
setInputFilter();
|
|
|
|
calculateDuration(true);
|
|
} |