Neueste Version
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
export default {
|
||||
async openBookingWidget() {
|
||||
const calendarModel = Custom5.model || {};
|
||||
const selection = calendarModel.calendarSelection || null;
|
||||
|
||||
if (!selection) {
|
||||
showAlert(
|
||||
"Bitte zuerst einen Tag oder Zeitraum auswählen.",
|
||||
"warning"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
function pad(value) {
|
||||
return String(value).padStart(2, "0");
|
||||
}
|
||||
|
||||
function parseLocalDateTime(value) {
|
||||
if (!value) return null;
|
||||
|
||||
const text = String(value).trim();
|
||||
const parts = text.split(/[-T:]/g);
|
||||
|
||||
if (parts.length < 3) 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)
|
||||
);
|
||||
|
||||
return Number.isNaN(date.getTime()) ? null : date;
|
||||
}
|
||||
|
||||
function formatDate(date) {
|
||||
return [
|
||||
date.getFullYear(),
|
||||
pad(date.getMonth() + 1),
|
||||
pad(date.getDate())
|
||||
].join("-");
|
||||
}
|
||||
|
||||
function formatTime(date) {
|
||||
return [
|
||||
pad(date.getHours()),
|
||||
pad(date.getMinutes())
|
||||
].join(":");
|
||||
}
|
||||
|
||||
function formatDateTimeForSql(date) {
|
||||
return `${formatDate(date)} ${formatTime(date)}:00`;
|
||||
}
|
||||
|
||||
const start = parseLocalDateTime(selection.start);
|
||||
const end = parseLocalDateTime(selection.end);
|
||||
|
||||
if (!start || !end) {
|
||||
showAlert(
|
||||
"Die Kalenderauswahl enthält kein gültiges Datum.",
|
||||
"error"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const seatId = String(
|
||||
Custom4.model?.seatId ||
|
||||
appsmith.store.selectedSeatId ||
|
||||
""
|
||||
).trim();
|
||||
|
||||
const seatName = String(
|
||||
Custom4.model?.seatName ||
|
||||
appsmith.store.selectedSeatName ||
|
||||
""
|
||||
).trim();
|
||||
|
||||
if (!seatId) {
|
||||
showAlert(
|
||||
"Es wurde kein Sitzplatz ausgewählt.",
|
||||
"error"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const bookedBy =
|
||||
appsmith.user?.email ||
|
||||
appsmith.user?.username ||
|
||||
null;
|
||||
|
||||
if (!bookedBy) {
|
||||
showAlert(
|
||||
"Der angemeldete Benutzer konnte nicht ermittelt werden.",
|
||||
"error"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const isAllDay =
|
||||
selection.allDay === true ||
|
||||
selection.type === "day" ||
|
||||
selection.type === "days";
|
||||
|
||||
let endDate;
|
||||
let startTime = null;
|
||||
let endTime = null;
|
||||
let endDateTime = end;
|
||||
|
||||
if (isAllDay) {
|
||||
const lastSelectedDay = new Date(end);
|
||||
lastSelectedDay.setDate(lastSelectedDay.getDate() - 1);
|
||||
endDate = formatDate(lastSelectedDay);
|
||||
endDateTime = new Date(lastSelectedDay);
|
||||
endDateTime.setHours(23, 59, 59, 0);
|
||||
} else {
|
||||
endDate = formatDate(end);
|
||||
startTime = formatTime(start);
|
||||
endTime = formatTime(end);
|
||||
}
|
||||
|
||||
const recurringCheckbox =
|
||||
typeof RecurringCheckbox !== "undefined"
|
||||
? RecurringCheckbox
|
||||
: null;
|
||||
|
||||
const bookingFormData = {
|
||||
seatId,
|
||||
seatName,
|
||||
bookedBy,
|
||||
title: "Platzbuchung",
|
||||
type: selection.type || null,
|
||||
startDate: formatDate(start),
|
||||
endDate,
|
||||
startTime,
|
||||
endTime,
|
||||
startDateTime: formatDateTimeForSql(start),
|
||||
endDateTime: formatDateTimeForSql(endDateTime),
|
||||
allDay: Boolean(isAllDay),
|
||||
recurring: Boolean(
|
||||
recurringCheckbox?.isChecked || false
|
||||
)
|
||||
};
|
||||
|
||||
try {
|
||||
await storeValue(
|
||||
"bookingFormData",
|
||||
bookingFormData,
|
||||
false
|
||||
);
|
||||
|
||||
await showModal("Platzbuchung");
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"Buchungsdaten konnten nicht gespeichert werden:",
|
||||
error
|
||||
);
|
||||
|
||||
showAlert(
|
||||
"Die Buchungsdaten konnten nicht gespeichert werden.",
|
||||
"error"
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"gitSyncId": "6a6b5b477ebc9edeca96e2f8_7feb3701-9036-42b6-bda5-53267d59b24e",
|
||||
"id": "Sitzplätze_BookingSelect",
|
||||
"unpublishedCollection": {
|
||||
"name": "BookingSelect",
|
||||
"pageId": "Sitzplätze",
|
||||
"pluginId": "js-plugin",
|
||||
"pluginType": "JS",
|
||||
"variables": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user