Mercurial > libervia-web
comparison libervia/pages/_browser/dialog.py @ 1385:4b6f711b09cb
browser (dialog): new `ashow` method to use `Confirm` in async methods
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 20 Feb 2021 13:58:01 +0100 |
parents | 8729d2708f65 |
children | 409d10211b20 |
comparison
equal
deleted
inserted
replaced
1384:b61509c47cac | 1385:4b6f711b09cb |
---|---|
1 """manage common dialogs""" | 1 """manage common dialogs""" |
2 | 2 |
3 from browser import document, timer | 3 from browser import document, window, timer |
4 from template import Template | 4 from template import Template |
5 | 5 |
6 | 6 |
7 class Confirm: | 7 class Confirm: |
8 | 8 |
32 for cancel_elt in notif_elt.select(".click_to_cancel"): | 32 for cancel_elt in notif_elt.select(".click_to_cancel"): |
33 cancel_elt.bind("click", lambda evt: cancel_cb(evt, notif_elt)) | 33 cancel_elt.bind("click", lambda evt: cancel_cb(evt, notif_elt)) |
34 for cancel_elt in notif_elt.select(".click_to_ok"): | 34 for cancel_elt in notif_elt.select(".click_to_ok"): |
35 cancel_elt.bind("click", lambda evt: ok_cb(evt, notif_elt)) | 35 cancel_elt.bind("click", lambda evt: ok_cb(evt, notif_elt)) |
36 | 36 |
37 def _ashow_cb(self, evt, notif_elt, resolve_cb, confirmed): | |
38 evt.stopPropagation() | |
39 notif_elt.remove() | |
40 resolve_cb(confirmed) | |
41 | |
42 async def ashow(self): | |
43 return window.Promise.new( | |
44 lambda resolve_cb, reject_cb: | |
45 self.show( | |
46 lambda evt, notif_elt: self._ashow_cb(evt, notif_elt, resolve_cb, True), | |
47 lambda evt, notif_elt: self._ashow_cb(evt, notif_elt, resolve_cb, False) | |
48 ) | |
49 ) | |
50 | |
37 | 51 |
38 class Notification: | 52 class Notification: |
39 | 53 |
40 def __init__(self): | 54 def __init__(self): |
41 self._tpl = Template("dialogs/notification.html") | 55 self._tpl = Template("dialogs/notification.html") |