comparison libervia/pages/_browser/dialog.py @ 1299:053141849206

browser: module to handle dialogs, first draft
author Goffi <goffi@goffi.org>
date Fri, 19 Jun 2020 16:47:51 +0200
parents
children 683e50799d6d
comparison
equal deleted inserted replaced
1298:8aba2a2078ca 1299:053141849206
1 """manage common dialogs"""
2
3 from browser import document, timer
4 from template import Template
5
6
7 class Confirm:
8
9 def __init__(self, message, ok_label="", cancel_label=""):
10 self._tpl = Template("dialogs/confirm.html")
11 self.message = message
12 self.ok_label = ok_label
13 self.cancel_label = cancel_label
14
15 def cancel_cb(self, evt, notif_elt):
16 notif_elt.remove()
17
18 def show(self, ok_cb, cancel_cb=None):
19 if cancel_cb is None:
20 cancel_cb = self.cancel_cb
21 notif_elt = self._tpl.get_elt({
22 "message": self.message,
23 "ok_label": self.ok_label,
24 "cancel_label": self.cancel_label,
25 })
26
27 document['notifs_area'] <= notif_elt
28 timer.set_timeout(lambda: notif_elt.classList.add('state_appended'), 0)
29 for cancel_elt in notif_elt.select(".click_to_cancel"):
30 cancel_elt.bind("click", lambda evt: cancel_cb(evt, notif_elt))
31 for cancel_elt in notif_elt.select(".click_to_ok"):
32 cancel_elt.bind("click", lambda evt: ok_cb(evt, notif_elt))