summaryrefslogtreecommitdiffstats
path: root/src/wwwroot/scripts/reservationForm.js
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-10-19 23:41:23 +0200
committerivar <i@oiee.no>2025-10-19 23:41:23 +0200
commit3f4c0720e1e3421431e7baa20882a4a4512a7fab (patch)
tree734ca81d7d0841d8863e3f523ebba14c282dc681 /src/wwwroot/scripts/reservationForm.js
downloadfagprove-master.tar.xz
fagprove-master.zip
InitialHEADmaster
Diffstat (limited to 'src/wwwroot/scripts/reservationForm.js')
-rw-r--r--src/wwwroot/scripts/reservationForm.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/wwwroot/scripts/reservationForm.js b/src/wwwroot/scripts/reservationForm.js
new file mode 100644
index 0000000..75c7b7a
--- /dev/null
+++ b/src/wwwroot/scripts/reservationForm.js
@@ -0,0 +1,92 @@
+const calendarElement = $("#calendar");
+calendarElement.kendoDateRangePicker({
+ value: new Date(),
+ weekNumber: true,
+ footer: false,
+ min: new Date(),
+ culture: "no",
+ format: "dd-MM-yyyy",
+ messages: {
+ startLabel: "Fra",
+ endLabel: "Til"
+ }
+}).data("kendoDateRangePicker");
+
+function setDisabledDates(arrayOfDateStrings) {
+ let calendar = calendarElement.data('kendoDateRangePicker');
+ let options = calendar.options;
+ options.disableDates = null; // if the new cabin pick does not disable any dates, the "old" dates carries over.
+ if (arrayOfDateStrings) {
+ options.disableDates = arrayOfDateStrings.map(v => new Date(v));
+ }
+ calendar.destroy();
+ calendarElement.html("");
+ calendarElement.kendoDateRangePicker(options);
+ calendarElement.data('kendoDateRangePicker').enable();
+ calendarElement.data('kendoDateRangePicker').open();
+}
+
+function pickCabin(element, id) {
+ $("#second-step").fadeOut();
+ $(".card").removeClass("raised green");
+ $(".choose-cabin-button").text("Velg");
+ $(".choose-cabin-button").removeClass("green");
+ $(element).closest(".card").addClass("raised green");
+ $(element).closest(".card").children(".card-title").show();
+ $(element).closest(".choose-cabin-button").text("Valgt");
+ $(element).closest(".choose-cabin-button").addClass("green");
+ sessionStorage["cabinId"] = id;
+ $.ajax({
+ url: "/api/reservations/occupancy?cabinId=" + id,
+ method: "get",
+ success: function (e) {
+ $("#second-step").fadeIn();
+ setDisabledDates(e);
+ }
+ })
+}
+
+$("#submitReservation").on("click", function () {
+ if ($("#consent").checkbox("is checked") === false) {
+ $.notificate("Ugyldig", "Du må samtykke til bruksvilkårene", "error");
+ return;
+ }
+ let extra = $("#comment").val();
+ let from = calendarElement.data("kendoDateRangePicker").range().start;
+ let to = calendarElement.data("kendoDateRangePicker").range().end;
+ let cabinId = sessionStorage["cabinId"];
+ if (!cabinId) {
+ $.notificate("Ugyldig", "En hytte må velges", "error");
+ return;
+ }
+ if (!from) {
+ $.notificate("Ugyldig", "En innsjeks dato er påkrevd", "error");
+ return;
+ }
+ if (!to) {
+ $.notificate("Ugyldig", "En utsjekks dato er påkrevd", "error");
+ return;
+ }
+ let data = {
+ ReservationObjectId: cabinId,
+ From: new Date(from).toISOString(),
+ To: new Date(to).toISOString(),
+ Extra: extra
+ };
+
+ $.ajax({
+ url: "/api/reservations/create",
+ method: "post",
+ data: JSON.stringify(data),
+ processData: false,
+ contentType: "application/json",
+ success: function (e) {
+ $.notificate("Registrert", "Din reservasjon er registrert og venter nå på godkjenning fra en administrator", "success");
+ $("#submitReservation").remove();
+ },
+ error: function (e) {
+ console.log(e);
+ $.notificate("En feil oppstod", e.responseJSON.error ? e.responseJSON.error : "Vennligst prøv igjen senere", "error");
+ }
+ })
+});