From 3ffa9795b120884cb033adf34748bfbd150af93b Mon Sep 17 00:00:00 2001
From: "bojana.marojevikj" <bojana.marojevikj@finki.ukim.mk>
Date: Tue, 11 Feb 2025 17:01:39 +0100
Subject: [PATCH] bootbox confirm modal

---
 src/main/resources/templates/layout.html      |  3 +
 .../manageConsultations.html                  | 57 +++++++++++++++++--
 2 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/src/main/resources/templates/layout.html b/src/main/resources/templates/layout.html
index fce2d8a..a122bff 100644
--- a/src/main/resources/templates/layout.html
+++ b/src/main/resources/templates/layout.html
@@ -10,6 +10,9 @@
           integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
+    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
+    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/5.5.2/bootbox.min.js"></script>
     <title></title>
 </head>
 <body>
diff --git a/src/main/resources/templates/manageConsultations/manageConsultations.html b/src/main/resources/templates/manageConsultations/manageConsultations.html
index 3a9f0c9..5107999 100644
--- a/src/main/resources/templates/manageConsultations/manageConsultations.html
+++ b/src/main/resources/templates/manageConsultations/manageConsultations.html
@@ -5,6 +5,52 @@
 <head>
     <meta charset="UTF-8" content="no-cache">
     <title>FINKI - Consultations</title>
+    <script>
+        $(document).ready(function () {
+            $(document).on("click", ".delete-it", function (e) {
+                e.preventDefault();
+
+                const button = $(this);
+                let form;
+
+                if (button.closest("td").find("form").length > 0) {
+                    form = button.closest("td").find("form");
+                } else {
+                    console.error("Form not found for button:", button);
+                    return;
+                }
+
+                let message;
+                if (form.attr("action").includes("cancel")) {
+                    message = "Дали сте сигурни дека сакате да ја откажете консултацијата?";
+                } else if (form.attr("action").includes("deleteAllUpcomingWeekly")) {
+                    message = "Дали сте сигурни дека сакате да ги избришете сите идни консултации за овој термин?";
+                } else {
+                    message = "Дали сте сигурни дека сакате да ја извршите оваа акција?";
+                }
+
+                bootbox.confirm({
+                    message: message,
+                    buttons: {
+                        confirm: {
+                            label: 'Да',
+                            className: 'btn-danger'
+                        },
+                        cancel: {
+                            label: 'РќРµ',
+                            className: 'btn-secondary'
+                        }
+                    },
+                    callback: function (result) {
+                        if (result) {
+                            form.submit();
+                        }
+                    }
+                });
+            });
+        });
+    </script>
+
 </head>
 <body>
 <div class="mt-4" layout:fragment="content">
@@ -212,22 +258,21 @@
                                 </form>
                         </td>
                         <td class="col-1">
-                            <th:block th:if="${c.isEnded() != true && c.getStatus().toString()=='ACTIVE'}">
+                            <th:block th:if="${c.isEnded() != true && c.getStatus().toString() == 'ACTIVE'}">
                                 <form th:action="@{'/manage-consultations/'+ ${professorId} +'/cancel/'+ ${c.id}}" method="post"
                                       style="display: flex; justify-content: center;">
-                                    <button type="submit" class="btn btn-danger btn-md" title="Откажи"
-                                            onclick="return confirm('Are you sure you want to cancel this consultation?');">
+                                    <button type="button" class="btn btn-danger btn-md delete-it" title="Откажи">
                                         <i class="fas fa-times"></i>
                                     </button>
                                 </form>
                             </th:block>
                         </td>
                         <td class="col-1">
-                            <th:block th:if="${attendanceCountMap[c.id] == null && c.isEnded() != true && c.getType().toString()=='WEEKLY'}">
+                            <th:block th:if="${attendanceCountMap[c.id] == null && c.isEnded() != true && c.getType().toString() == 'WEEKLY'}">
                                 <form th:action="@{'/manage-consultations/'+ ${professorId} +'/deleteAllUpcomingWeekly/'+ ${c.id}}" method="post"
                                       style="display: flex; justify-content: center;">
-                                    <button type="submit" class="btn btn-md" style="border: 1px solid red;" title="Избриши ги сите наредни консултации од овој термин"
-                                            onclick="return confirm('Are you sure you want to delete this and every next weekly consultation?');">
+                                    <button type="button" class="btn btn-md delete-it" style="border: 1px solid red;"
+                                            title="Избриши ги сите наредни консултации од овој термин">
                                         <i class="fas fa-trash-alt"></i>
                                     </button>
                                 </form>
-- 
GitLab