Mercurial > libervia-web
comparison libervia/web/pages/_browser/invitation.py @ 1531:d7c78722e4f8
browser (cache): make `fill_identities` async + use `json` module:
- `json` module has been greatly improved in Brython, the former workaround is not needed
anymore.
- `fill_identities` is now async so an async method can wait for it to complete
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 22 Jun 2023 16:35:34 +0200 |
parents | eb00d593801d |
children | 7228fc3c4744 |
comparison
equal
deleted
inserted
replaced
1530:b338c31d5251 | 1531:d7c78722e4f8 |
---|---|
1 from browser import document, window, timer | |
2 from bridge import Bridge | 1 from bridge import Bridge |
2 from browser import document, timer, window | |
3 from cache import cache | |
4 import dialog | |
5 import javascript | |
3 from template import Template | 6 from template import Template |
4 import dialog | |
5 from cache import cache | |
6 import javascript | |
7 | 7 |
8 bridge = Bridge() | 8 bridge = Bridge() |
9 # we use JS RegExp because Python's re is really long to import in Brython | 9 # we use JS RegExp because Python's re is really long to import in Brython |
10 # FIXME: this is a naive JID regex, a more accurate should be used instead | 10 # FIXME: this is a naive JID regex, a more accurate should be used instead |
11 jid_re = javascript.RegExp.new(r"^\w+@\w+\.\w+") | 11 jid_re = javascript.RegExp.new(r"^\w+@\w+\.\w+") |
24 # list of item passing filter when adding a new contact | 24 # list of item passing filter when adding a new contact |
25 self._filtered_new_items = {} | 25 self._filtered_new_items = {} |
26 self._active_new_item = None | 26 self._active_new_item = None |
27 self._idx = 0 | 27 self._idx = 0 |
28 | 28 |
29 def attach(self, affiliations=None): | 29 async def attach(self, affiliations=None): |
30 if affiliations is None: | 30 if affiliations is None: |
31 affiliations = {} | 31 affiliations = {} |
32 self.affiliations = affiliations | 32 self.affiliations = affiliations |
33 self.side_panel = self.manager_panel_elt.select_one( | 33 self.side_panel = self.manager_panel_elt.select_one( |
34 '.invitation_manager_side_panel') | 34 '.invitation_manager_side_panel') |
35 self.open() | 35 self.open() |
36 for close_elt in self.manager_panel_elt.select('.click_to_close'): | 36 for close_elt in self.manager_panel_elt.select('.click_to_close'): |
37 close_elt.bind("click", self.on_manager_close) | 37 close_elt.bind("click", self.on_manager_close) |
38 self.side_panel.bind("click", lambda evt: evt.stopPropagation()) | 38 self.side_panel.bind("click", lambda evt: evt.stopPropagation()) |
39 | 39 |
40 cache.fill_identities(affiliations.keys(), callback=self._set_affiliations) | 40 await cache.fill_identities(affiliations.keys()) |
41 for entity_jid, affiliation in self.affiliations.items(): | |
42 self.set_affiliation(entity_jid, affiliation) | |
41 | 43 |
42 contact_elt = self.manager_panel_elt.select_one('input[name="contact"]') | 44 contact_elt = self.manager_panel_elt.select_one('input[name="contact"]') |
43 contact_elt.bind("input", self.on_contact_input) | 45 contact_elt.bind("input", self.on_contact_input) |
44 contact_elt.bind("keydown", self.on_contact_keydown) | 46 contact_elt.bind("keydown", self.on_contact_keydown) |
45 contact_elt.bind("focus", self.on_contact_focus) | 47 contact_elt.bind("focus", self.on_contact_focus) |
46 contact_elt.bind("blur", self.on_contact_blur) | 48 contact_elt.bind("blur", self.on_contact_blur) |
47 document['invite_email'].bind('click', self.on_invite_email_click) | 49 document['invite_email'].bind('click', self.on_invite_email_click) |
48 | |
49 def _set_affiliations(self): | |
50 for entity_jid, affiliation in self.affiliations.items(): | |
51 self.set_affiliation(entity_jid, affiliation) | |
52 | 50 |
53 def open(self): | 51 def open(self): |
54 """Re-attach and show a closed panel""" | 52 """Re-attach and show a closed panel""" |
55 self._body_ori_style = document.body.style.height, document.body.style.overflow | 53 self._body_ori_style = document.body.style.height, document.body.style.overflow |
56 document.body.style.height = '100vh' | 54 document.body.style.height = '100vh' |