Mercurial > libervia-web
comparison libervia/web/pages/_browser/dialog.py @ 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 | e47c24204449 |
children | 0a4433a343a3 |
comparison
equal
deleted
inserted
replaced
1588:4ecae80d6d39 | 1589:7228fc3c4744 |
---|---|
17 self.message = message | 17 self.message = message |
18 self.ok_label = ok_label | 18 self.ok_label = ok_label |
19 assert ok_color in ("success", "danger") | 19 assert ok_color in ("success", "danger") |
20 self.ok_color = ok_color | 20 self.ok_color = ok_color |
21 self.cancel_label = cancel_label | 21 self.cancel_label = cancel_label |
22 self._notif_elt = None | |
22 self.reset() | 23 self.reset() |
23 | 24 |
24 def reset(self): | 25 def reset(self): |
25 """Reset values of callbacks and notif element""" | 26 """Reset values of callbacks and notif element""" |
26 self._ok_cb = None | 27 self._ok_cb = None |
27 self._cancel_cb = None | 28 self._cancel_cb = None |
28 self._reject_cb = None | 29 self._reject_cb = None |
29 self._notif_elt = None | 30 if self._notif_elt is not None: |
31 self._notif_elt.remove() | |
32 self._notif_elt = None | |
30 | 33 |
31 def _default_cancel_cb(self, evt, notif_elt): | 34 def _default_cancel_cb(self, evt, notif_elt): |
32 notif_elt.remove() | 35 notif_elt.remove() |
33 | 36 |
34 def cancel(self): | 37 def cancel(self): |
38 """ | 41 """ |
39 if self._notif_elt is None: | 42 if self._notif_elt is None: |
40 log.warning("calling cancel on an unshown dialog") | 43 log.warning("calling cancel on an unshown dialog") |
41 else: | 44 else: |
42 self._notif_elt.remove() | 45 self._notif_elt.remove() |
46 self._notif_elt = None | |
43 if self._reject_cb is not None: | 47 if self._reject_cb is not None: |
44 self._reject_cb(CancelError) | 48 self._reject_cb(CancelError) |
45 else: | 49 else: |
46 log.warning("no reject callback set") | 50 log.warning("no reject callback set") |
47 self.reset() | 51 self.reset() |
48 | 52 |
49 def on_ok_click(self, evt): | 53 def on_ok_click(self, evt): |
54 evt.preventDefault() | |
55 evt.stopPropagation() | |
50 assert self._ok_cb is not None | 56 assert self._ok_cb is not None |
51 self._ok_cb(evt, self._notif_elt) | 57 self._ok_cb(evt, self._notif_elt) |
52 self.reset() | 58 self.reset() |
53 | 59 |
54 def on_cancel_click(self, evt) -> None: | 60 def on_cancel_click(self, evt) -> None: |
61 evt.preventDefault() | |
62 evt.stopPropagation() | |
55 assert self._cancel_cb is not None | 63 assert self._cancel_cb is not None |
56 self._cancel_cb(evt, self._notif_elt) | 64 self._cancel_cb(evt, self._notif_elt) |
57 self.reset() | 65 self.reset() |
58 | 66 |
59 def show(self, ok_cb, cancel_cb=None, reject_cb=None): | 67 def show(self, ok_cb, cancel_cb=None, reject_cb=None): |