Files
BeWoPlaner/BeWoPlanerMobil/Views/Main/RestoreServiceRecordInputsPartial.cshtml
2025-12-03 18:31:50 +01:00

497 lines
20 KiB
Plaintext

@using BeWoPlanerMobil.Service
@using BeWoPlanerMobil.Util
@model BeWoPlanerMobil.Models.MainModel
<script type="text/javascript">
@if(TempData[TempDataConstants.AfterRestoreKey] is true)
{
<text>
clearLocalBeWoStorage();
saveSingleBookingLocally();
</text>
}
function saveSingleBookingLocally() {
const bookingMode = @((int) Model.CurrentBookingMode);
if(bookingMode === 0) {
const cb2ScRelOid = $("#sb-cb2ScRelOid").val();
const eOid = $("#sb-employee-input").val();
const categoryOid = $("#sb-category-select option:selected").val();
const descriptionOid = $("#sb-leistung-select option:selected").val();
updateCbScRelOids("sb", cb2ScRelOid);
updateEmployeeOids("sb", eOid);
updateCategory("sb", categoryOid);
updateServiceDescription("sb", descriptionOid);
}
}
var keyMap = new Map(
[
[`${getLocalStorageKey()}-SbCb2ScRelOid`, "Hilfeplan"],
[`${getLocalStorageKey()}-SbEmployeeOids`, "Mitarbeiter"],
[`${getLocalStorageKey()}-SbCategory`, "Kategorie"],
[`${getLocalStorageKey()}-SbServiceDescription`, "Leistung"],
[`${getLocalStorageKey()}-SbStartDate`, "Start"],
[`${getLocalStorageKey()}-SbEndDate`, "Enddatum"],
[`${getLocalStorageKey()}-SbStartTime`, "Von"],
[`${getLocalStorageKey()}-SbEndTime`, "Bis"],
[`${getLocalStorageKey()}-SbDuration`, "Dauer"],
[`${getLocalStorageKey()}-SbDurationUnit`, "Einheit der Dauer"],
[`${getLocalStorageKey()}-SbDistance`, "Gefahrene Kilometer"],
[`${getLocalStorageKey()}-SbMarker`, "Marker"],
[`${getLocalStorageKey()}-SbBetrag`, "Betrag"],
[`${getLocalStorageKey()}-SbDoku1`, "Doku 1"],
[`${getLocalStorageKey()}-SbDoku2`, "Doku 2"],
[`${getLocalStorageKey()}-SbDoku3`, "Doku 3"],
[`${getLocalStorageKey()}-SbDoku4`, "Doku 4"],
[`${getLocalStorageKey()}-SbDoku5`, "Doku 5"],
[`${getLocalStorageKey()}-SbDoku6`, "Doku 6"],
[`${getLocalStorageKey()}-SbGoals2Ratings`, "Ziele & Maßnahmen"],
[`${getLocalStorageKey()}-SbCurrentPage`, "Ausgewählte Seite"],
[`${getLocalStorageKey()}-GbCb2ScRelOids`, "Hilfepläne"],
[`${getLocalStorageKey()}-GbEmployeeOids`, "Mitarbeiter"],
[`${getLocalStorageKey()}-GbCategory`, "Kategorie"],
[`${getLocalStorageKey()}-GbServiceDescription`, "Leistung"],
[`${getLocalStorageKey()}-GbStartDate`, "Start"],
[`${getLocalStorageKey()}-GbEndDate`, "Enddatum"],
[`${getLocalStorageKey()}-GbStartTime`, "Von"],
[`${getLocalStorageKey()}-GbEndTime`, "Bis"],
[`${getLocalStorageKey()}-GbDuration`, "Dauer"],
[`${getLocalStorageKey()}-GbDurationUnit`, "Einheit der Dauer"],
[`${getLocalStorageKey()}-GbDistance`, "Gefahrene Kilometer"],
[`${getLocalStorageKey()}-GbMarker`, "Marker"],
[`${getLocalStorageKey()}-GbBetrag`, "Betrag"],
[`${getLocalStorageKey()}-GbDoku1`, "Doku 1"],
[`${getLocalStorageKey()}-GbDoku2`, "Doku 2"],
[`${getLocalStorageKey()}-GbDoku3`, "Doku 3"],
[`${getLocalStorageKey()}-GbDoku4`, "Doku 4"],
[`${getLocalStorageKey()}-GbDoku5`, "Doku 5"],
[`${getLocalStorageKey()}-GbDoku6`, "Doku 6"],
[`${getLocalStorageKey()}-GbGoals2Ratings`, "Ziele & Maßnahmen"],
[`${getLocalStorageKey()}-MbCb2ScRelOids`, "Hilfepläne"],
[`${getLocalStorageKey()}-MbEmployeeOids`, "Mitarbeiter"],
[`${getLocalStorageKey()}-MbCategory`, "Kategorie"],
[`${getLocalStorageKey()}-MbServiceDescription`, "Leistung"],
[`${getLocalStorageKey()}-MbStartDate`, "Start"],
[`${getLocalStorageKey()}-MbEndDate`, "Enddatum"],
[`${getLocalStorageKey()}-MbStartTime`, "Von"],
[`${getLocalStorageKey()}-MbEndTime`, "Bis"],
[`${getLocalStorageKey()}-MbDuration`, "Dauer"],
[`${getLocalStorageKey()}-MbDurationUnit`, "Einheit der Dauer"],
[`${getLocalStorageKey()}-MbDistance`, "Gefahrene Kilometer"],
[`${getLocalStorageKey()}-MbMarker`, "Marker"],
[`${getLocalStorageKey()}-MbBetrag`, "Betrag"],
[`${getLocalStorageKey()}-MbDoku1`, "Doku 1"],
[`${getLocalStorageKey()}-MbDoku2`, "Doku 2"],
[`${getLocalStorageKey()}-MbDoku3`, "Doku 3"],
[`${getLocalStorageKey()}-MbDoku4`, "Doku 4"],
[`${getLocalStorageKey()}-MbDoku5`, "Doku 5"],
[`${getLocalStorageKey()}-MbDoku6`, "Doku 6"],
[`${getLocalStorageKey()}-MbGoals2Ratings`, "Ziele & Maßnahmen"]
]
);
var timeRegex = /^(?:[01]\d|2[0-3]):[0-5]\d$/;
function saveLocally(key, value) {
if(value === undefined || value === null || value.length === 0) {
return;
}
localStorage.setItem(key, value);
}
function getLocalStorageKey() {
return "@MobileSessionFacade.LocalStorageKey";
}
function updateGoalRating(prefix, goalOid, ratingTypeOid) {
const localStorageKey = `@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Goals2Ratings`;
const storedValue = localStorage.getItem(localStorageKey);
const goals2Ratings = storedValue ? new Map(JSON.parse(storedValue)) : new Map();
if(goals2Ratings.has(goalOid)) {
goals2Ratings.set(goalOid, ratingTypeOid);
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Goals2Ratings`, JSON.stringify([...goals2Ratings]));
}
}
function updateGoals2Ratings(prefix, newMap) {
const localStorageKey = `@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Goals2Ratings`;
if(newMap === null || newMap === undefined || newMap.length === 0) {
localStorage.removeItem(localStorageKey);
return;
}
const storedValue = localStorage.getItem(localStorageKey);
const oldMap = storedValue ? new Map(JSON.parse(storedValue)) : new Map();
const mergedMap = new Map();
newMap.forEach((value, key, map) => {
const possibleRating = oldMap.has(key) ? oldMap.get(key) : null;
mergedMap.set(key, possibleRating);
});
const strigified = JSON.stringify([...mergedMap]);
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Goals2Ratings`, strigified);
}
function updateCbScRelOids(prefix, csv) {
if(csv === null || csv === undefined || csv.length === 0) {
logInfo2(`csv ist leer: ${csv}; Entferne @MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Cb2ScRelOid${(prefix === "sb" ? "" : "s")}`);
localStorage.removeItem(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Cb2ScRelOid${(prefix === "sb" ? "" : "s")}`);
return;
}
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Cb2ScRelOid${(prefix === "sb" ? "" : "s")}`, csv);
}
function updateEmployeeOids(prefix, csv) {
if(csv === null || csv === undefined || csv.length === 0) {
localStorage.removeItem(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}EmployeeOids`);
return;
}
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}EmployeeOids`, csv);
}
function updateCategory(prefix, categoryOid) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Category`, categoryOid);
}
function updateServiceDescription(prefix, serviceDescriptionOid) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}ServiceDescription`, serviceDescriptionOid);
}
function updateStartDate(prefix, startDate) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}StartDate`, startDate);
}
function updateStartTime(prefix, startTime) {
if(false === timeRegex.test(startTime)) {
return;
}
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}StartTime`, startTime);
}
function updateEndDate(prefix, endDate) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}EndDate`, endDate);
}
function updateEndTime(prefix, endTime) {
if(false === timeRegex.test(endTime)) {
return;
}
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}EndTime`, endTime);
}
function updateDuration(prefix, duration) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Duration`, duration);
}
function updateDistance(prefix, distance) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Distance`, distance);
}
function updateMarker(prefix, marker) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Marker`, marker);
}
function updateBetrag(prefix, betrag) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Betrag`, betrag);
}
function updateDokuText(prefix, text, nr) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Doku${(nr + 1)}`, text);
}
function removeGoals2Ratings(prefix) {
localStorage.removeItem(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Goals2Ratings`);
}
function updateDurationUnit(prefix, durationUnit) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}DurationUnit`, durationUnit);
}
function updateCurrentPage(currentPage) {
saveLocally(`@MobileSessionFacade.LocalStorageKey-SbCurrentPage`, currentPage);
}
function clearLocalBeWoStorage(prefix) {
const keyArray = [];
for(let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if(key.startsWith(`@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}`)) {
keyArray.push(key);
}
}
for(let i = 0; i < keyArray.length; i++) {
localStorage.removeItem(keyArray[i]);
}
}
function updateGoal2Rating(prefix, goalOid, ratingTypeOid) {
const localStorageKey = `@MobileSessionFacade.LocalStorageKey-${firstCharToUpperCase(prefix)}Goals2Ratings`;
const stored = localStorage.getItem(localStorageKey);
const map = stored ? new Map(JSON.parse(stored)) : new Map();
map.set(goalOid, ratingTypeOid);
saveLocally(localStorageKey, JSON.stringify([...map]));
}
function printLocalStorage() {
@if(Html.IsInDebugMode())
{
<text>
$("#local-storage-popup-body").html("");
let output = "";
let singleBookingOutput = "<h2>Einzelbuchung</h2><table class='table table-sm table-striped'>" +
"<thead>" +
"<tr>" +
"<th scope='col'>Id</th>" +
"<th scope='col'>Wert</th>" +
"<th scope='col'>Feld</th>" +
"<th scope='col'></th>" +
"</tr>" +
"</thead>";
let groupBookingOutput = "<h2 class='mt-3'>Gruppenbuchung</h2><table class='table table-sm table-striped'>" +
"<thead>" +
"<tr>" +
"<th scope='col'>Id</th>" +
"<th scope='col'>Wert</th>" +
"<th scope='col'>Feld</th>" +
"<th scope='col'></th>" +
"</tr>" +
"</thead>";
let multiBookingOutput = "<h2 class='mt-3'>Mehrfachbuchung</h2><table class='table table-sm table-striped'>" +
"<thead>" +
"<tr>" +
"<th scope='col'>Id</th>" +
"<th scope='col'>Wert</th>" +
"<th scope='col'>Feld</th>" +
"<th scope='col'></th>" +
"</tr>" +
"</thead>";
for(let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if(false === key.startsWith(`@MobileSessionFacade.LocalStorageKey-`)) {
continue;
}
const value = localStorage.getItem(key);
if(key.startsWith(`@MobileSessionFacade.LocalStorageKey-Sb`)) {
singleBookingOutput += `<tr><td>${key}</td><td>${keyMap.get(key)}</td><td>${value}</td><td><button type="button" class="btn btn-sm btn-danger" onclick="localStorage.removeItem('${key}');printLocalStorage();"><i class="fas fa-trash"></i></button></td></tr>`;
} else if(key.startsWith(`@MobileSessionFacade.LocalStorageKey-Gb`)) {
groupBookingOutput += `<tr><td>${key}</td><td>${keyMap.get(key)}</td><td>${value}</td><td><button type="button" class="btn btn-sm btn-danger" onclick="localStorage.removeItem('${key}');printLocalStorage();"><i class="fas fa-trash"></i></button></td></tr>`;
} else if(key.startsWith(`@MobileSessionFacade.LocalStorageKey-Mb`)) {
multiBookingOutput += `<tr><td>${key}</td><td>${keyMap.get(key)}</td><td>${value}</td><td><button type="button" class="btn btn-sm btn-danger" onclick="localStorage.removeItem('${key}');printLocalStorage();"><i class="fas fa-trash"></i></button></td></tr>`;
}
}
singleBookingOutput += "</table>";
groupBookingOutput += "</table>";
multiBookingOutput += "</table>";
output += singleBookingOutput + "<hr>" + groupBookingOutput + "<hr>" + multiBookingOutput;
$("#local-storage-popup-body").html(`<div class='btn-group my-1' role='group'><button type='button' class='btn btn-outline-danger' onclick='clearLocalBeWoStorage();printLocalStorage();'><span class='fas fa-trash-alt'></span>Leeren</button></div><hr>${output}`);
$("#local-storage-popup").modal("show");
</text>
}
}
function restoreAllFields() {
showSpinner();
const bookingMode = @((int) Model.CurrentBookingMode);
const prefix = bookingMode === 0 ? "Sb" : bookingMode === 1 ? "Gb" : "Mb";
$("#srr-gb-cb2sc-oids").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-GbCb2ScRelOids`));
$("#srr-gb-emp-oids").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-GbEmployeeOids`));
$("#srr-mb-cb2sc-oids").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-MbCb2ScRelOids`));
$("#srr-mb-emp-oids").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-MbEmployeeOids`));
$("#srr-start-date-input").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}StartDate`));
$("#srr-start-time-input").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}StartTime`));
$("#srr-end-date-input").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}EndDate`));
$("#srr-end-time-input").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}EndTime`));
$("#srr-marker-cb").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Marker`));
$("#srr-betrag").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Betrag`));
$("#srr-duration-input").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Duration`));
$("#srr-duration-unit").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}DurationUnit`));
$("#srr-distance-input").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Distance`));
$("#srr-doku-textarea-1").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Doku1`));
$("#srr-doku-textarea-2").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Doku2`));
$("#srr-doku-textarea-3").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Doku3`));
$("#srr-doku-textarea-4").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Doku4`));
$("#srr-doku-textarea-5").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Doku5`));
$("#srr-doku-textarea-6").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Doku6`));
$("#srr-leistung-select").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}ServiceDescription`));
$("#srr-goals-ratings").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-${prefix}Goals2Ratings`));
$("#srr-booking-mode").val(bookingMode);
$("#srr-sb-cb2sc-oid").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-SbCb2ScRelOid`));
$("#srr-current-page").val(localStorage.getItem(`@MobileSessionFacade.LocalStorageKey-SbCurrentPage`));
$("#restore-service-record-form").submit();
}
function deleteBwpLocalStorage() {
const keyArray = [];
for(let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if(key.startsWith("bwp_demo_")) {
keyArray.push(key);
}
}
for(let i = 0; i < keyArray.length; i++) {
localStorage.removeItem(keyArray[i]);
}
}
function readWholeLocalStorage() {
console.log(`Es wurden ${localStorage.length} lokale gespeicherte Werte gefunden:`);
logInfo3(`Es wurden ${localStorage.length} lokale gespeicherte Werte gefunden:`);
for(let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
logInfo3(`${key}: ${localStorage.getItem(key)}`);
}
}
</script>
@using(Html.BeginForm("RestoreServiceRecordForm", "Main", FormMethod.Post, new { id = "restore-service-record-form" }))
{
<input type="hidden" id="srr-goals-ratings" name="@FormCollectionConstants.SelectedGoalOids" />
<input type="hidden" id="srr-current-page" name="@FormCollectionConstants.CurrentPageKey" />
<input type="hidden" id="srr-leistung-select" name="@FormCollectionConstants.ServiceDescriptionKey" />
<input type="hidden" id="srr-start-date-input" name="@FormCollectionConstants.DateKey" />
<input type="hidden" id="srr-end-time-input" name="@FormCollectionConstants.EndKey" />
<input type="hidden" id="srr-start-time-input" name="@FormCollectionConstants.StartKey" />
<input type="hidden" id="srr-end-date-input" name="@FormCollectionConstants.EndDateKey" />
<input type="hidden" id="srr-marker-cb" name="@FormCollectionConstants.MarkerKey" />
<input type="hidden" id="srr-betrag" name="@FormCollectionConstants.BetragKey" />
<input type="hidden" id="srr-duration-input" name="@FormCollectionConstants.DurationKey" />
<input type="hidden" id="srr-duration-unit" name="@FormCollectionConstants.DurationUnitKey" />
<input type="hidden" id="srr-distance-input" name="@FormCollectionConstants.DistanceKey" />
<input type="hidden" id="srr-doku-textarea-1" name="@FormCollectionConstants.Dokumentation1Key" />
<input type="hidden" id="srr-doku-textarea-2" name="@FormCollectionConstants.Dokumentation2Key" />
<input type="hidden" id="srr-doku-textarea-3" name="@FormCollectionConstants.Dokumentation3Key" />
<input type="hidden" id="srr-doku-textarea-4" name="@FormCollectionConstants.Dokumentation4Key" />
<input type="hidden" id="srr-doku-textarea-5" name="@FormCollectionConstants.Dokumentation5Key" />
<input type="hidden" id="srr-doku-textarea-6" name="@FormCollectionConstants.Dokumentation6Key" />
<input type="hidden" id="srr-sb-cb2sc-oid" name="@FormCollectionConstants.CostBearer2SupportConceptOidKey" />
<input type="hidden" id="srr-sb-emp-oid" name="@FormCollectionConstants.SingleBookingEmployeeOidKey" />
<input type="hidden" id="srr-gb-cb2sc-oids" name="@FormCollectionConstants.GroupBookingSelectedCb2ScOidsKey" />
<input type="hidden" id="srr-gb-emp-oids" name="@FormCollectionConstants.GroupBookingSelectedEmployeeOidsKey" />
<input type="hidden" id="srr-mb-cb2sc-oids" name="@FormCollectionConstants.MultiBookingSelectedCb2ScOidsKey" />
<input type="hidden" id="srr-mb-emp-oids" name="@FormCollectionConstants.MultiBookingSelectedEmployeeOidsKey" />
<input type="hidden" id="srr-booking-mode" name="@FormCollectionConstants.BookingModeKey" />
<button type="button" class="btn btn-bewo-dev bewo-restore-btn" onclick="window.restoreAllFields()">
<i class="fas fa-recycle"></i>
</button>
if(Html.IsInDebugMode())
{
<div class="btn-group">
<button type="button" class="btn btn-outline-danger" onclick="deleteBwpLocalStorage()">
<i class="fas fa-trash"></i>
</button>
<button type="button" class="btn btn-outline-info" onclick="readWholeLocalStorage()">
<i class="far fa-eye"></i>
</button>
<script type="text/javascript">
function devTest() {
try {
console.warn("Diese Methode ist noch ohne Funktion.");
} catch(error) {
console.error(error);
}
}
</script>
<button class="btn btn-outline-primary" type="button" onclick="devTest()">
<i class="fas fa-bug"></i>
</button>
</div>
}
}
@if(Html.IsInDebugMode())
{
<div class="modal" tabindex="-1" role="dialog" id="local-storage-popup">
<div class="modal-dialog modal-xl modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title font-weight-bold">Lokaler Speicher</h5>
<button class="close" type="button" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<div class="modal-body" id="local-storage-popup-body">
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" data-dismiss="modal">Schlie&szlig;en</button>
</div>
</div>
</div>
</div>
}