Mercurial > libervia-web
annotate libervia/pages/_browser/dialog.py @ 1321:eb85ef26cb4a
server: use `bulma` theme as default for default site:
`default` theme is not used for now as real default, because dev work is focusing on bulma
theme, and the default one may be broken. This should (or may not) change in the future.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 Aug 2020 16:56:04 +0200 |
parents | 053141849206 |
children | 683e50799d6d |
rev | line source |
---|---|
1299
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 """manage common dialogs""" |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 from browser import document, timer |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 from template import Template |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 class Confirm: |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 def __init__(self, message, ok_label="", cancel_label=""): |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 self._tpl = Template("dialogs/confirm.html") |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 self.message = message |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 self.ok_label = ok_label |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 self.cancel_label = cancel_label |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 def cancel_cb(self, evt, notif_elt): |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 notif_elt.remove() |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 def show(self, ok_cb, cancel_cb=None): |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 if cancel_cb is None: |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 cancel_cb = self.cancel_cb |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 notif_elt = self._tpl.get_elt({ |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 "message": self.message, |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 "ok_label": self.ok_label, |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 "cancel_label": self.cancel_label, |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 }) |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 document['notifs_area'] <= notif_elt |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 timer.set_timeout(lambda: notif_elt.classList.add('state_appended'), 0) |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 for cancel_elt in notif_elt.select(".click_to_cancel"): |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 cancel_elt.bind("click", lambda evt: cancel_cb(evt, notif_elt)) |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 for cancel_elt in notif_elt.select(".click_to_ok"): |
053141849206
browser: module to handle dialogs, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 cancel_elt.bind("click", lambda evt: ok_cb(evt, notif_elt)) |