summaryrefslogtreecommitdiffstats
path: root/src/wwwroot/scripts/reservations.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/wwwroot/scripts/reservations.js')
-rw-r--r--src/wwwroot/scripts/reservations.js128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/wwwroot/scripts/reservations.js b/src/wwwroot/scripts/reservations.js
new file mode 100644
index 0000000..f2f371a
--- /dev/null
+++ b/src/wwwroot/scripts/reservations.js
@@ -0,0 +1,128 @@
+const reservationsGrid = $("#reservationsGrid");
+const reservationsModal = $("#reservationModal");
+reservationsGrid.kendoGrid({
+ noRecords: {
+ template: "Fant ingen reservasjoner"
+ },
+ filterable: true,
+ sortable: false,
+ resizable: true,
+ scrollable: true,
+ editable: false,
+ dataSource: {
+ transport: {
+ read: "/api/reservations/all",
+ }
+ },
+ schema: {
+ model: {
+ id: "id",
+ fields: {
+ id: {editable: false}
+ }
+ }
+ },
+ error: function (e) {
+ if (e.xhr.responseJSON.error) {
+ $.notificate("En feil oppstod", e.xhr.responseJSON.error, "error");
+ }
+ },
+ columns:
+ [
+ {
+ field: "name",
+ title: "Navn",
+ filterable: {
+ multi: true,
+ search: true
+ }
+ },
+ {
+ title: "Fra/Til",
+ template: "#= data.from # / #= data.to #"
+ },
+ {
+ field: "status",
+ title: "Status",
+ filterable: {
+ multi: true,
+ search: false
+ },
+ values: [
+ {
+ text: "Ventende",
+ value: 0
+ },
+ {
+ text: "Godkjent",
+ value: 1,
+ },
+ {
+ text: "Avvist",
+ value: 2
+ },
+ {
+ text: "Inaktiv",
+ value: 3
+ },
+ ],
+ template: $("#reservationStatusTextTemplate").html()
+ },
+ {
+ field: "cabin",
+ title: "Hytte",
+ filterable: {
+ multi: true,
+ search: false
+ }
+ },
+ {
+ command:
+ {
+ template: $("#reservationsRowCommandButtons").html()
+ },
+ title: " ",
+ }
+ ]
+});
+
+function inspectReservation(e) {
+ let dataItem = reservationsGrid.data("kendoGrid").dataItem($(e).closest("tr"));
+ let template = kendo.template($("#reservationInfoTemplate").html());
+ let generatedHtml = template(dataItem);
+ reservationsModal.html(generatedHtml);
+ reservationsModal.modal("show");
+}
+
+function grantReservation(e) {
+ let dataItem = reservationsGrid.data("kendoGrid").dataItem($(e).closest("tr"));
+ $.ajax({
+ url: "/api/reservations/grant?id=" + dataItem.id,
+ method: "get",
+ success: function (e) {
+ $.notificate("Reservasjon godkjent", dataItem.name + " har fått en statusoppdatering på mail", "success");
+ reservationsGrid.data("kendoGrid").dataSource.read();
+ },
+ error: function (e) {
+ $.notificate("En feil oppstod", e.error ? e.error : "Vennligst prøv igjen senere", "error");
+ reservationsGrid.data("kendoGrid").dataSource.read();
+ }
+ })
+}
+
+function rejectReservation(e) {
+ let dataItem = reservationsGrid.data("kendoGrid").dataItem($(e).closest("tr"));
+ $.ajax({
+ url: "/api/reservations/deny?id=" + dataItem.id,
+ method: "get",
+ success: function (e) {
+ $.notificate("Reservasjon avvist", dataItem.name + " har fått en statusoppdatering på mail", "success");
+ reservationsGrid.data("kendoGrid").dataSource.read();
+ },
+ error: function (e) {
+ $.notificate("En feil oppstod", e.error ? e.error : "Vennligst prøv igjen senere", "error");
+ reservationsGrid.data("kendoGrid").dataSource.read();
+ }
+ })
+
+}