| DTabidze | 0757f8a | 2024-03-28 16:49:09 +0400 | [diff] [blame] | 1 | const confirmationDialog = document.getElementById("confirmation"); |
| 2 | const cancelButton = document.getElementById("cancel-button"); |
| 3 | const confirmButton = document.getElementById("confirm-button"); |
| 4 | |
| 5 | function 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 | |
| 23 | function hideConfirmationDialog() { |
| 24 | confirmationDialog.close(); |
| 25 | } |
| 26 | |
| 27 | async function handleRemoveOwnerSubmit(form) { |
| 28 | event.preventDefault(); |
| 29 | return await showConfirmationDialog(form); |
| 30 | } |
| 31 | |
| 32 | document.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 | }); |
| DTabidze | 4b44ff4 | 2024-04-02 03:16:26 +0400 | [diff] [blame^] | 48 | |
| 49 | document.addEventListener("DOMContentLoaded", function () { |
| 50 | var errorCancelButton = document.getElementById("error-cancel-button"); |
| 51 | var errorMessageDialog = document.getElementById("error-message"); |
| 52 | errorCancelButton.addEventListener("click", function () { |
| 53 | errorMessageDialog.close(); |
| 54 | }); |
| 55 | }); |