annotate libervia/web/pages/_browser/invitation.py @ 1574:4ab4bc3ae462

browser: new `tools` module with a first method to detect touch devices
author Goffi <goffi@goffi.org>
date Wed, 22 Nov 2023 16:31:36 +0100
parents d7c78722e4f8
children 7228fc3c4744
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1510
5ea06e8b06ed browser: make bridge API closer to the one use with other frontends:
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
1 from bridge import Bridge
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
2 from browser import document, timer, window
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
3 from cache import cache
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
4 import dialog
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
5 import javascript
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from template import Template
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
7
1510
5ea06e8b06ed browser: make bridge API closer to the one use with other frontends:
Goffi <goffi@goffi.org>
parents: 1509
diff changeset
8 bridge = Bridge()
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
9 # we use JS RegExp because Python's re is really long to import in Brython
1373
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
10 # FIXME: this is a naive JID regex, a more accurate should be used instead
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
11 jid_re = javascript.RegExp.new(r"^\w+@\w+\.\w+")
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 class InvitationManager:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 def __init__(self, invitation_type, invitation_data):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 self.invitation_type = invitation_type
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 self.invitation_data = invitation_data
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 manager_panel_tpl = Template('invitation/manager.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 self.manager_panel_elt = manager_panel_tpl.get_elt()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 self.invite_by_email_tpl = Template('invitation/invite_by_email.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 self.affiliation_tpl = Template('invitation/affiliation_item.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 self.new_item_tpl = Template('invitation/new_item.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 # list of item passing filter when adding a new contact
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 self._filtered_new_items = {}
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 self._idx = 0
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
29 async def attach(self, affiliations=None):
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 if affiliations is None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 affiliations = {}
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 self.affiliations = affiliations
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 self.side_panel = self.manager_panel_elt.select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 '.invitation_manager_side_panel')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 for close_elt in self.manager_panel_elt.select('.click_to_close'):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 close_elt.bind("click", self.on_manager_close)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.side_panel.bind("click", lambda evt: evt.stopPropagation())
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
1531
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
40 await cache.fill_identities(affiliations.keys())
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
41 for entity_jid, affiliation in self.affiliations.items():
d7c78722e4f8 browser (cache): make `fill_identities` async + use `json` module:
Goffi <goffi@goffi.org>
parents: 1518
diff changeset
42 self.set_affiliation(entity_jid, affiliation)
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 contact_elt = self.manager_panel_elt.select_one('input[name="contact"]')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 contact_elt.bind("input", self.on_contact_input)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 contact_elt.bind("keydown", self.on_contact_keydown)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 contact_elt.bind("focus", self.on_contact_focus)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 contact_elt.bind("blur", self.on_contact_blur)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 document['invite_email'].bind('click', self.on_invite_email_click)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 def open(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 """Re-attach and show a closed panel"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self._body_ori_style = document.body.style.height, document.body.style.overflow
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 document.body.style.height = '100vh'
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 document.body.style.overflow = 'hidden'
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 document.body <= self.manager_panel_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 timer.set_timeout(lambda: self.side_panel.classList.add("open"), 0)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def _on_close_transition_end(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.manager_panel_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 # FIXME: not working with Brython, to report upstream
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 # self.side_panel.unbind("transitionend", self._on_close_transition_end)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 self.side_panel.unbind("transitionend")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
64
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 def close(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 """Hide the panel"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 document.body.style.height, document.body.style.overflow = self._body_ori_style
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.side_panel.classList.remove('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 self.side_panel.bind("transitionend", self._on_close_transition_end)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
70
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
71 def _invite_jid(self, entity_jid, callback, errback=None):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
72 if errback is None:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
73 errback = lambda e: dialog.notification.show(f"invitation failed: {e}", "error")
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 if self.invitation_type == 'photos':
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
75 service = self.invitation_data["service"]
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 path = self.invitation_data["path"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 album_name = path.rsplit('/')[-1]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 print(f"inviting {entity_jid}")
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
79 bridge.fis_invite(
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 service,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 "photos",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 "",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 path,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 album_name,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 '',
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
87 callback=callback,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
88 errback=errback
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 )
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
90 elif self.invitation_type == 'pubsub':
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
91 service = self.invitation_data["service"]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
92 node = self.invitation_data["node"]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
93 name = self.invitation_data.get("name")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
94 namespace = self.invitation_data.get("namespace")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
95 extra = {}
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
96 if namespace:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
97 extra["namespace"] = namespace
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
98 print(f"inviting {entity_jid}")
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
99 bridge.ps_invite(
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
100 entity_jid,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
101 service,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
102 node,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
103 '',
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
104 name,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
105 javascript.JSON.stringify(extra),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
106 callback=callback,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
107 errback=errback
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
108 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
109 else:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
110 print(f"error: unknown invitation type: {self.invitation_type}")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
111
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
112 def invite_by_jid(self, entity_jid):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
113 self._invite_jid(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
114 entity_jid,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
115 callback=lambda entity_jid=entity_jid: self._on_jid_invitation_success(entity_jid),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
116 )
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
117
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 def on_manager_close(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 self.close()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 def _on_jid_invitation_success(self, entity_jid):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 form_elt = document['invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 contact_elt = form_elt.select_one('input[name="contact"]')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 contact_elt.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 contact_elt.dispatchEvent(window.Event.new('input'))
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
126 dialog.notification.show(
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 f"{entity_jid} has been invited",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 level="success",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 if entity_jid not in self.affiliations:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 self.set_affiliation(entity_jid, "member")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
132
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 def on_contact_invite(self, evt, entity_jid):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 """User is adding a contact"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 form_elt = document['invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 contact_elt = form_elt.select_one('input[name="contact"]')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 contact_elt.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 contact_elt.dispatchEvent(window.Event.new('input'))
1348
c74e5a488af6 browser (invitation): minor renaming
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
139 self.invite_by_jid(entity_jid)
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
140
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 def on_contact_keydown(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 if evt.key == "Escape":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 evt.target.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 evt.target.dispatchEvent(window.Event.new('input'))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 elif evt.key == "ArrowDown":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 content_elt = document['invitation_contact_search'].select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 ".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 if self._active_new_item == None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 self._active_new_item = content_elt.firstElementChild
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 next_item = self._active_new_item.nextElementSibling
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 if next_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 self._active_new_item.classList.remove('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 self._active_new_item = next_item
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 elif evt.key == "ArrowUp":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 content_elt = document['invitation_contact_search'].select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 ".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 if self._active_new_item == None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 self._active_new_item = content_elt.lastElementChild
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 previous_item = self._active_new_item.previousElementSibling
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 if previous_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 self._active_new_item.classList.remove('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 self._active_new_item = previous_item
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 elif evt.key == "Enter":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 if self._active_new_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 entity_jid = self._active_new_item.dataset.entityJid
1348
c74e5a488af6 browser (invitation): minor renaming
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
178 self.invite_by_jid(entity_jid)
1373
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
179 else:
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
180 if jid_re.exec(evt.target.value):
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
181 self.invite_by_jid(evt.target.value)
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
182 evt.target.value = ""
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
183
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 def on_contact_focus(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 search_dialog.classList.add('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 evt.target.dispatchEvent(window.Event.new('input'))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
189
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 def on_contact_blur(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 search_dialog.classList.remove('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 for elt in self._filtered_new_items.values():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 self._filtered_new_items.clear()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
196
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
197
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 def on_contact_input(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 text = evt.target.value.strip().lower()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 content_elt = search_dialog.select_one(".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 for (entity_jid, identity) in cache.identities.items():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 if not cache.match_identity(entity_jid, text, identity):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 # if the entity was present in last pass, we remove it
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 try:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 filtered_item = self._filtered_new_items.pop(entity_jid)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 except KeyError:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 pass
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 filtered_item.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 continue
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 if entity_jid not in self._filtered_new_items:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 # we only create a new element if the item was not already there
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 new_item_elt = self.new_item_tpl.get_elt({
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 "entity_jid": entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 "identities": cache.identities,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 })
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 content_elt <= new_item_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 self._filtered_new_items[entity_jid] = new_item_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 for elt in new_item_elt.select('.click_to_ok'):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 # we use mousedown instead of click because otherwise it would be
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 # ignored due to "blur" event manager (see
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 # https://stackoverflow.com/a/9335401)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 elt.bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 "mousedown",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 lambda evt, entity_jid=entity_jid: self.on_contact_invite(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 evt, entity_jid),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
229
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 if ((self._active_new_item is not None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 and not self._active_new_item.parentElement)):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 # active item has been filtered out
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
234
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 def _on_email_invitation_success(self, invitee_jid, email, name):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 self.set_affiliation(invitee_jid, "member")
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
237 dialog.notification.show(
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 f"{name} has been invited, he/she has received an email with a link",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 level="success",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
241
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
242 def invitation_simple_create_cb(self, invitation_data, email, name):
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
243 invitee_jid = invitation_data['jid']
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
244 self._invite_jid(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
245 invitee_jid,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
246 callback=lambda: self._on_email_invitation_success(invitee_jid, email, name),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
247 errback=lambda e: dialog.notification.show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
248 f"invitation failed for {email}: {e}",
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
249 "error"
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 )
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
251 )
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
252
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
253 # we update identities to have the name instead of the invitation jid in
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
254 # affiliations
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
255 cache.identities[invitee_jid] = {'nicknames': [name]}
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
256 cache.update()
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
257
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 def invite_by_email(self, email, name):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 guest_url_tpl = f'{window.URL.new("/g", document.baseURI).href}/{{uuid}}'
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
260 bridge.invitation_simple_create(
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 email,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 name,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 guest_url_tpl,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 '',
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
265 callback=lambda data: self.invitation_simple_create_cb(data, email, name),
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 errback=lambda e: window.alert(f"can't send email invitation: {e}")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
268
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 def on_invite_email_submit(self, evt, invite_email_elt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 form = document['email_invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 try:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 reportValidity = form.reportValidity
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 except AttributeError:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 print("reportValidity is not supported by this browser!")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 if not reportValidity():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 return
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 email = form.select_one('input[name="email"]').value
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 name = form.select_one('input[name="name"]').value
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 self.invite_by_email(email, name)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 invite_email_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
285
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 def on_invite_email_close(self, evt, invite_email_elt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 invite_email_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
291
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 def on_invite_email_click(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 invite_email_elt = self.invite_by_email_tpl.get_elt()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 document.body <= invite_email_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 document['email_invitation_submit'].bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 'click', lambda evt: self.on_invite_email_submit(evt, invite_email_elt)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 for close_elt in invite_email_elt.select('.click_to_close'):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 close_elt.bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 "click", lambda evt: self.on_invite_email_close(evt, invite_email_elt))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 self.close()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
304
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 ## affiliations
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
306
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
307 def _add_affiliation_bindings(self, entity_jid, affiliation_elt):
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
308 for elt in affiliation_elt.select(".click_to_delete"):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
309 elt.bind(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
310 "click",
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
311 lambda evt, entity_jid=entity_jid, affiliation_elt=affiliation_elt:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
312 self.on_affiliation_remove(entity_jid, affiliation_elt)
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
313 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
314 for elt in affiliation_elt.select(".click_to_set_publisher"):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
315 try:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
316 name = cache.identities[entity_jid]["nicknames"][0]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
317 except (KeyError, IndexError):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
318 name = entity_jid
1407
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
319 elt.bind(
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
320 "click",
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
321 lambda evt, entity_jid=entity_jid, name=name,
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
322 affiliation_elt=affiliation_elt:
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
323 self.on_affiliation_set(
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
324 entity_jid, name, affiliation_elt, "publisher"
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
325 ),
5a132b85e1ac browser (invitation): fix an indentation issue which was breaking invitations
Goffi <goffi@goffi.org>
parents: 1386
diff changeset
326 )
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
327 for elt in affiliation_elt.select(".click_to_set_member"):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
328 try:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
329 name = cache.identities[entity_jid]["nicknames"][0]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
330 except (KeyError, IndexError):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
331 name = entity_jid
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
332 elt.bind(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
333 "click",
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
334 lambda evt, entity_jid=entity_jid, name=name,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
335 affiliation_elt=affiliation_elt:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
336 self.on_affiliation_set(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
337 entity_jid, name, affiliation_elt, "member"
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
338 ),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
339 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
340
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 def set_affiliation(self, entity_jid, affiliation):
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
342 if affiliation not in ('owner', 'member', 'publisher'):
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 raise NotImplementedError(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 f'{affiliation} affiliation can not be set with this method for the '
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 'moment')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 if entity_jid not in self.affiliations:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 self.affiliations[entity_jid] = affiliation
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 affiliation_elt = self.affiliation_tpl.get_elt({
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 "entity_jid": entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 "affiliation": affiliation,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 "identities": cache.identities,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 })
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 document['affiliations'] <= affiliation_elt
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
354 self._add_affiliation_bindings(entity_jid, affiliation_elt)
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
355
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
356 def _on_affiliation_remove_success(self, affiliation_elt, entity_jid):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 affiliation_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 del self.affiliations[entity_jid]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
359
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 def on_affiliation_remove(self, entity_jid, affiliation_elt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
361 if self.invitation_type == 'photos':
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 path = self.invitation_data["path"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 service = self.invitation_data["service"]
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
364 bridge.fis_affiliations_set(
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 service,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 "",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 path,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 {entity_jid: "none"},
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 callback=lambda: self._on_affiliation_remove_success(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
370 affiliation_elt, entity_jid),
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
371 errback=lambda e: dialog.notification.show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
372 f"can't remove affiliation: {e}", "error")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
373 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
374 elif self.invitation_type == 'pubsub':
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
375 service = self.invitation_data["service"]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
376 node = self.invitation_data["node"]
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
377 bridge.ps_node_affiliations_set(
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
378 service,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
379 node,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
380 {entity_jid: "none"},
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
381 callback=lambda: self._on_affiliation_remove_success(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
382 affiliation_elt, entity_jid),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
383 errback=lambda e: dialog.notification.show(
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
384 f"can't remove affiliation: {e}", "error")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
385 )
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
386 else:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
387 dialog.notification.show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
388 f"error: unknown invitation type: {self.invitation_type}",
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
389 "error"
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
390 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
391
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
392 def _on_affiliation_set_success(self, entity_jid, name, affiliation_elt, affiliation):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
393 dialog.notification.show(f"permission updated for {name}")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
394 self.affiliations[entity_jid] = affiliation
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
395 new_affiliation_elt = self.affiliation_tpl.get_elt({
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
396 "entity_jid": entity_jid,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
397 "affiliation": affiliation,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
398 "identities": cache.identities,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
399 })
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
400 affiliation_elt.replaceWith(new_affiliation_elt)
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
401 self._add_affiliation_bindings(entity_jid, new_affiliation_elt)
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
402
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
403 def _on_affiliation_set_ok(self, entity_jid, name, affiliation_elt, affiliation):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
404 if self.invitation_type == 'pubsub':
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
405 service = self.invitation_data["service"]
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
406 node = self.invitation_data["node"]
1509
106bae41f5c8 massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 1407
diff changeset
407 bridge.ps_node_affiliations_set(
1386
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
408 service,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
409 node,
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
410 {entity_jid: affiliation},
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
411 callback=lambda: self._on_affiliation_set_success(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
412 entity_jid, name, affiliation_elt, affiliation
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
413 ),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
414 errback=lambda e: dialog.notification.show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
415 f"can't set affiliation: {e}", "error")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
416 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
417 else:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
418 dialog.notification.show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
419 f"error: unknown invitation type: {self.invitation_type}",
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
420 "error"
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
421 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
422
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
423 def _on_affiliation_set_cancel(self, evt, notif_elt):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
424 notif_elt.remove()
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
425 self.open()
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
426
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
427 def on_affiliation_set(self, entity_jid, name, affiliation_elt, affiliation):
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
428 if affiliation == "publisher":
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
429 message = f"Give autorisation to publish to {name}?"
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
430 elif affiliation == "member":
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
431 message = f"Remove autorisation to publish from {name}?"
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
432 else:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
433 dialog.notification.show(f"unmanaged affiliation: {affiliation}", "error")
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
434 return
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
435 dialog.Confirm(message).show(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
436 ok_cb=lambda evt, notif_elt:
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
437 self._on_affiliation_set_ok(
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
438 entity_jid, name, affiliation_elt, affiliation
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
439 ),
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
440 cancel_cb=self._on_affiliation_set_cancel
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
441 )
83be300d17e3 browser (invitations): handle Pubsub invitation
Goffi <goffi@goffi.org>
parents: 1378
diff changeset
442 self.close()