123
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"gitSyncId": "6a6b5b477ebc9edeca96e2f8_0058b22e-bf9c-4341-b180-8a805ee21d6f",
|
||||
"id": "Sitzplätze__$Bff$_Bff",
|
||||
"isPublic": true,
|
||||
"moduleInstanceId": "Sitzplätze_Bff",
|
||||
"rootModuleInstanceId": "Sitzplätze_Bff",
|
||||
"unpublishedCollection": {
|
||||
"contextType": "PAGE",
|
||||
"name": "_$Bff$_Bff",
|
||||
"pageId": "Sitzplätze",
|
||||
"pluginId": "js-plugin",
|
||||
"pluginType": "JS"
|
||||
}
|
||||
}
|
||||
@@ -4,84 +4,77 @@ export default {
|
||||
const selection = calendarModel.calendarSelection || null;
|
||||
|
||||
if (!selection) {
|
||||
showAlert(
|
||||
"Bitte zuerst einen Tag oder Zeitraum auswählen.",
|
||||
"warning"
|
||||
);
|
||||
showAlert("Bitte zuerst einen Tag oder Zeitraum auswählen.", "warning");
|
||||
return;
|
||||
}
|
||||
|
||||
function pad(value) {
|
||||
return String(value).padStart(2, "0");
|
||||
}
|
||||
const pad = (value) => String(value).padStart(2, "0");
|
||||
|
||||
function parseLocalDateTime(value) {
|
||||
const parseLocalDateTime = (value) => {
|
||||
if (!value) return null;
|
||||
|
||||
const text = String(value).trim();
|
||||
const parts = text.split(/[-T:]/g);
|
||||
const match = text.match(
|
||||
/^(\d{4})-(\d{2})-(\d{2})(?:T|\s)?(\d{2})?:?(\d{2})?:?(\d{2})?$/
|
||||
);
|
||||
|
||||
if (parts.length < 3) return null;
|
||||
if (!match) return null;
|
||||
|
||||
const date = new Date(
|
||||
Number(parts[0]),
|
||||
Number(parts[1]) - 1,
|
||||
Number(parts[2]),
|
||||
Number(parts[3] || 0),
|
||||
Number(parts[4] || 0),
|
||||
Number(parts[5] || 0)
|
||||
Number(match[1]),
|
||||
Number(match[2]) - 1,
|
||||
Number(match[3]),
|
||||
Number(match[4] || 0),
|
||||
Number(match[5] || 0),
|
||||
Number(match[6] || 0)
|
||||
);
|
||||
|
||||
return Number.isNaN(date.getTime()) ? null : date;
|
||||
}
|
||||
};
|
||||
|
||||
function formatDate(date) {
|
||||
return [
|
||||
date.getFullYear(),
|
||||
pad(date.getMonth() + 1),
|
||||
pad(date.getDate())
|
||||
].join("-");
|
||||
}
|
||||
const formatDate = (date) => [
|
||||
date.getFullYear(),
|
||||
pad(date.getMonth() + 1),
|
||||
pad(date.getDate())
|
||||
].join("-");
|
||||
|
||||
function formatTime(date) {
|
||||
return [
|
||||
pad(date.getHours()),
|
||||
pad(date.getMinutes())
|
||||
].join(":");
|
||||
}
|
||||
const formatTime = (date) => [
|
||||
pad(date.getHours()),
|
||||
pad(date.getMinutes())
|
||||
].join(":");
|
||||
|
||||
function formatDateTimeForSql(date) {
|
||||
return `${formatDate(date)} ${formatTime(date)}:00`;
|
||||
}
|
||||
const formatDateTimeForSql = (date) =>
|
||||
`${formatDate(date)} ${formatTime(date)}:00`;
|
||||
|
||||
const start = parseLocalDateTime(selection.start);
|
||||
const end = parseLocalDateTime(selection.end);
|
||||
|
||||
if (!start || !end) {
|
||||
if (!start || !end || end <= start) {
|
||||
showAlert(
|
||||
"Die Kalenderauswahl enthält kein gültiges Datum.",
|
||||
"Die Kalenderauswahl enthält kein gültiges Datum oder Zeitintervall.",
|
||||
"error"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const seatModel = Custom4.model || {};
|
||||
|
||||
const seatId = String(
|
||||
Custom4.model?.seatId ||
|
||||
seatModel.seatId ||
|
||||
seatModel.selectedSeat?.id ||
|
||||
appsmith.store.selectedSeatId ||
|
||||
""
|
||||
).trim();
|
||||
|
||||
const seatName = String(
|
||||
Custom4.model?.seatName ||
|
||||
seatModel.seatName ||
|
||||
seatModel.selectedSeat?.name ||
|
||||
appsmith.store.selectedSeatName ||
|
||||
""
|
||||
).trim();
|
||||
|
||||
if (!seatId) {
|
||||
showAlert(
|
||||
"Es wurde kein Sitzplatz ausgewählt.",
|
||||
"error"
|
||||
);
|
||||
showAlert("Es wurde kein Sitzplatz ausgewählt.", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -98,58 +91,86 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
const isAllDay =
|
||||
selection.allDay === true ||
|
||||
selection.type === "day" ||
|
||||
selection.type === "days";
|
||||
const isTimeSelection =
|
||||
selection.type === "time" &&
|
||||
selection.allDay !== true;
|
||||
|
||||
const isAllDay = !isTimeSelection;
|
||||
|
||||
let startDate;
|
||||
let endDate;
|
||||
let startTime = null;
|
||||
let endTime = null;
|
||||
let endDateTime = end;
|
||||
let startDateTime;
|
||||
let endDateTime;
|
||||
|
||||
if (isAllDay) {
|
||||
const startOfDay = new Date(start);
|
||||
startOfDay.setHours(0, 0, 0, 0);
|
||||
|
||||
const lastSelectedDay = new Date(end);
|
||||
lastSelectedDay.setDate(lastSelectedDay.getDate() - 1);
|
||||
|
||||
// FullCalendar liefert bei Ganztagsauswahl ein exklusives Ende.
|
||||
// Nur wenn end tatsächlich 00:00 Uhr ist, wird ein Tag abgezogen.
|
||||
const endIsMidnight =
|
||||
lastSelectedDay.getHours() === 0 &&
|
||||
lastSelectedDay.getMinutes() === 0 &&
|
||||
lastSelectedDay.getSeconds() === 0;
|
||||
|
||||
if (endIsMidnight) {
|
||||
lastSelectedDay.setDate(
|
||||
lastSelectedDay.getDate() - 1
|
||||
);
|
||||
}
|
||||
|
||||
lastSelectedDay.setHours(0, 0, 0, 0);
|
||||
|
||||
startDate = formatDate(startOfDay);
|
||||
endDate = formatDate(lastSelectedDay);
|
||||
endDateTime = new Date(lastSelectedDay);
|
||||
endDateTime.setHours(23, 59, 59, 0);
|
||||
startDateTime = `${startDate} 00:00:00`;
|
||||
endDateTime = `${endDate} 23:59:59`;
|
||||
} else {
|
||||
endDate = formatDate(end);
|
||||
// Bei einem Timeslot bleiben Start- und Enddatum gleich.
|
||||
startDate = formatDate(start);
|
||||
endDate = formatDate(start);
|
||||
startTime = formatTime(start);
|
||||
endTime = formatTime(end);
|
||||
startDateTime = formatDateTimeForSql(start);
|
||||
endDateTime = formatDateTimeForSql(end);
|
||||
}
|
||||
|
||||
const recurringCheckbox =
|
||||
typeof RecurringCheckbox !== "undefined"
|
||||
? RecurringCheckbox
|
||||
: null;
|
||||
const recurring =
|
||||
typeof RecurringCheckbox !== "undefined" &&
|
||||
RecurringCheckbox.isChecked === true;
|
||||
|
||||
const recurringWeeks =
|
||||
typeof RecurringWeeksSelect !== "undefined"
|
||||
? Number(RecurringWeeksSelect.selectedOptionValue || 1)
|
||||
: 1;
|
||||
|
||||
const recurringDays = appsmith.store.recurringDays || {};
|
||||
|
||||
const bookingFormData = {
|
||||
...(appsmith.store.bookingFormData || {}),
|
||||
seatId,
|
||||
seatName,
|
||||
bookedBy,
|
||||
title: "Platzbuchung",
|
||||
type: selection.type || null,
|
||||
startDate: formatDate(start),
|
||||
startDate,
|
||||
endDate,
|
||||
startTime,
|
||||
endTime,
|
||||
startDateTime: formatDateTimeForSql(start),
|
||||
endDateTime: formatDateTimeForSql(endDateTime),
|
||||
allDay: Boolean(isAllDay),
|
||||
recurring: Boolean(
|
||||
recurringCheckbox?.isChecked || false
|
||||
)
|
||||
startDateTime,
|
||||
endDateTime,
|
||||
allDay: isAllDay,
|
||||
recurring,
|
||||
recurringWeeks,
|
||||
recurringDays
|
||||
};
|
||||
|
||||
try {
|
||||
await storeValue(
|
||||
"bookingFormData",
|
||||
bookingFormData,
|
||||
false
|
||||
);
|
||||
|
||||
await storeValue("bookingFormData", bookingFormData, false);
|
||||
await showModal("Platzbuchung");
|
||||
} catch (error) {
|
||||
console.error(
|
||||
|
||||
Reference in New Issue
Block a user