changeset 1589:7228fc3c4744

browser (dialog): be sure to remove dialog on `OK` and `Cancel` click + avoid side effects
author Goffi <goffi@goffi.org>
date Sun, 10 Dec 2023 11:00:44 +0100
parents 4ecae80d6d39
children 1d464c72ac12
files libervia/web/pages/_browser/dialog.py libervia/web/pages/_browser/invitation.py
diffstat 2 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/web/pages/_browser/dialog.py	Sun Dec 10 10:59:25 2023 +0100
+++ b/libervia/web/pages/_browser/dialog.py	Sun Dec 10 11:00:44 2023 +0100
@@ -19,6 +19,7 @@
         assert ok_color in ("success", "danger")
         self.ok_color = ok_color
         self.cancel_label = cancel_label
+        self._notif_elt = None
         self.reset()
 
     def reset(self):
@@ -26,7 +27,9 @@
         self._ok_cb = None
         self._cancel_cb = None
         self._reject_cb = None
-        self._notif_elt = None
+        if self._notif_elt is not None:
+            self._notif_elt.remove()
+            self._notif_elt = None
 
     def _default_cancel_cb(self, evt, notif_elt):
         notif_elt.remove()
@@ -40,6 +43,7 @@
             log.warning("calling cancel on an unshown dialog")
         else:
             self._notif_elt.remove()
+            self._notif_elt = None
             if self._reject_cb is not None:
                 self._reject_cb(CancelError)
             else:
@@ -47,11 +51,15 @@
         self.reset()
 
     def on_ok_click(self, evt):
+        evt.preventDefault()
+        evt.stopPropagation()
         assert self._ok_cb is not None
         self._ok_cb(evt, self._notif_elt)
         self.reset()
 
     def on_cancel_click(self, evt) -> None:
+        evt.preventDefault()
+        evt.stopPropagation()
         assert self._cancel_cb is not None
         self._cancel_cb(evt, self._notif_elt)
         self.reset()
--- a/libervia/web/pages/_browser/invitation.py	Sun Dec 10 10:59:25 2023 +0100
+++ b/libervia/web/pages/_browser/invitation.py	Sun Dec 10 11:00:44 2023 +0100
@@ -421,7 +421,6 @@
             )
 
     def _on_affiliation_set_cancel(self, evt, notif_elt):
-        notif_elt.remove()
         self.open()
 
     def on_affiliation_set(self, entity_jid, name, affiliation_elt, affiliation):