blob: e4ea2ca9f01a22ba11d1bb86344cfabc46a64a5e [file] [log] [blame]
DTabidze0757f8a2024-03-28 16:49:09 +04001const confirmationDialog = document.getElementById("confirmation");
2const cancelButton = document.getElementById("cancel-button");
3const confirmButton = document.getElementById("confirm-button");
4
5function showConfirmationDialog(form) {
6 const message = form.dataset.confirmationMessage;
7 document.getElementById("confirmation-message").innerHTML = message;
8 confirmationDialog.showModal();
9 let confirmed;
10 let p = new Promise((resolve) => {
11 confirmed = resolve;
12 });
13 confirmButton.onclick = () => {
14 confirmed(true);
15 };
16 cancelButton.onclick = () => {
17 hideConfirmationDialog();
18 confirmed(false);
19 };
20 return p;
21}
22
23function hideConfirmationDialog() {
24 confirmationDialog.close();
25}
26
27async function handleRemoveOwnerSubmit(form) {
28 event.preventDefault();
29 return await showConfirmationDialog(form);
30}
31
32document.addEventListener("DOMContentLoaded", function () {
33 const removeOwnerForms = document.querySelectorAll(".remove-form");
34 removeOwnerForms.forEach((form) => {
35 form.addEventListener("submit", async function (event) {
36 event.preventDefault();
37 try {
38 isConfirmed = await handleRemoveOwnerSubmit(form);
39 if (isConfirmed) {
40 form.submit();
41 }
42 } catch (error) {
43 console.error(error);
44 }
45 });
46 });
47});