annotate libervia/pages/_browser/invitation.py @ 1380:df79874947d7

pages: fix browser data re-creation on dev mode reload
author Goffi <goffi@goffi.org>
date Sat, 20 Feb 2021 13:51:11 +0100
parents e3e303a30a74
children 83be300d17e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 from browser import document, window, timer
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 from bridge import Bridge
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from template import Template
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from dialog import notification
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from cache import cache
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1373
diff changeset
6 # 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
7 from javascript import RegExp
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
8
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 bridge = Bridge()
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
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
11 jid_re = 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
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 def attach(self, affiliations=None):
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
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 cache.fill_identities(affiliations.keys(), callback=self._set_affiliations)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 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
43 contact_elt.bind("input", self.on_contact_input)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 contact_elt.bind("keydown", self.on_contact_keydown)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 contact_elt.bind("focus", self.on_contact_focus)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 contact_elt.bind("blur", self.on_contact_blur)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 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
48
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 def _set_affiliations(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 for entity_jid, affiliation in self.affiliations.items():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.set_affiliation(entity_jid, affiliation)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def open(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 """Re-attach and show a closed panel"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 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
56 document.body.style.height = '100vh'
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 document.body.style.overflow = 'hidden'
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 document.body <= self.manager_panel_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 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
60
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 def _on_close_transition_end(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self.manager_panel_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 # FIXME: not working with Brython, to report upstream
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 # 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
65 self.side_panel.unbind("transitionend")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 def close(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 """Hide the panel"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 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
70 self.side_panel.classList.remove('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 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
72
1348
c74e5a488af6 browser (invitation): minor renaming
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
73 def invite_by_jid(self, entity_jid):
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 if self.invitation_type == 'photos':
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 path = self.invitation_data["path"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 service = self.invitation_data["service"]
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}")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 bridge.FISInvite(
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 '',
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 callback=lambda entity_jid=entity_jid:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self._on_jid_invitation_success(entity_jid),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 errback=lambda e: notification.show(f"invitation failed: {e}", "error")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
91
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 def on_manager_close(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self.close()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
94
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def _on_jid_invitation_success(self, entity_jid):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 form_elt = document['invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 contact_elt = form_elt.select_one('input[name="contact"]')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 contact_elt.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 contact_elt.dispatchEvent(window.Event.new('input'))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 notification.show(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 f"{entity_jid} has been invited",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 level="success",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 if entity_jid not in self.affiliations:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.set_affiliation(entity_jid, "member")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
106
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 def on_contact_invite(self, evt, entity_jid):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 """User is adding a contact"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 form_elt = document['invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 contact_elt = form_elt.select_one('input[name="contact"]')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 contact_elt.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 contact_elt.dispatchEvent(window.Event.new('input'))
1348
c74e5a488af6 browser (invitation): minor renaming
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
113 self.invite_by_jid(entity_jid)
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
114
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 def on_contact_keydown(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 if evt.key == "Escape":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 evt.target.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 evt.target.dispatchEvent(window.Event.new('input'))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 elif evt.key == "ArrowDown":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 content_elt = document['invitation_contact_search'].select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 ".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 if self._active_new_item == None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 self._active_new_item = content_elt.firstElementChild
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 next_item = self._active_new_item.nextElementSibling
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 if next_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 self._active_new_item.classList.remove('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 self._active_new_item = next_item
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 elif evt.key == "ArrowUp":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 content_elt = document['invitation_contact_search'].select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 ".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 if self._active_new_item == None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 self._active_new_item = content_elt.lastElementChild
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 previous_item = self._active_new_item.previousElementSibling
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 if previous_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 self._active_new_item.classList.remove('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self._active_new_item = previous_item
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 elif evt.key == "Enter":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 if self._active_new_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 entity_jid = self._active_new_item.dataset.entityJid
1348
c74e5a488af6 browser (invitation): minor renaming
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
152 self.invite_by_jid(entity_jid)
1373
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
153 else:
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
154 if jid_re.exec(evt.target.value):
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
155 self.invite_by_jid(evt.target.value)
2938d1b65bd5 browser (invitation): allow invitation of unknown JID:
Goffi <goffi@goffi.org>
parents: 1348
diff changeset
156 evt.target.value = ""
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
157
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 def on_contact_focus(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 search_dialog.classList.add('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 evt.target.dispatchEvent(window.Event.new('input'))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
163
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 def on_contact_blur(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 search_dialog.classList.remove('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 for elt in self._filtered_new_items.values():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 self._filtered_new_items.clear()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
170
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
171
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 def on_contact_input(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 text = evt.target.value.strip().lower()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 content_elt = search_dialog.select_one(".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 for (entity_jid, identity) in cache.identities.items():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 if not cache.match_identity(entity_jid, text, identity):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 # 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
179 try:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 filtered_item = self._filtered_new_items.pop(entity_jid)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 except KeyError:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 pass
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 filtered_item.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 continue
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 if entity_jid not in self._filtered_new_items:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 # 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
188 new_item_elt = self.new_item_tpl.get_elt({
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 "entity_jid": entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 "identities": cache.identities,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 })
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 content_elt <= new_item_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 self._filtered_new_items[entity_jid] = new_item_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 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
195 # 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
196 # ignored due to "blur" event manager (see
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 # https://stackoverflow.com/a/9335401)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 elt.bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 "mousedown",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 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
201 evt, entity_jid),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
203
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 if ((self._active_new_item is not None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 and not self._active_new_item.parentElement)):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 # active item has been filtered out
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
208
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 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
210 self.set_affiliation(invitee_jid, "member")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 notification.show(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 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
213 level="success",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
215
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 def invitationSimpleCreateCb(self, invitation_data, email, name):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 if self.invitation_type == 'photos':
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 path = self.invitation_data["path"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 service = self.invitation_data["service"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 invitee_jid = invitation_data['jid']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 album_name = path.rsplit('/')[-1]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 bridge.FISInvite(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 invitee_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 service,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 "photos",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 "",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 path,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 album_name,
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 callback=lambda: self._on_email_invitation_success(invitee_jid, email, name),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 errback=lambda e: window.alert(f"invitation failed for {email}: {e}")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
233
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 # we update identities to have the name instead of the invitation jid in
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 # affiliations
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 cache.identities[invitee_jid] = {'nicknames': [name]}
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 cache.update()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
238
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 def invite_by_email(self, email, name):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 guest_url_tpl = f'{window.URL.new("/g", document.baseURI).href}/{{uuid}}'
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 bridge.invitationSimpleCreate(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 email,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 name,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 guest_url_tpl,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 '',
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 callback=lambda data: self.invitationSimpleCreateCb(data, email, name),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 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
248 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
249
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 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
251 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 form = document['email_invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 try:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 reportValidity = form.reportValidity
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 except AttributeError:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 print("reportValidity is not supported by this browser!")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 if not reportValidity():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 return
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 email = form.select_one('input[name="email"]').value
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 name = form.select_one('input[name="name"]').value
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 self.invite_by_email(email, name)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 invite_email_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
266
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 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
268 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 invite_email_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
272
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 def on_invite_email_click(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 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
277 document.body <= invite_email_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 document['email_invitation_submit'].bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 '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
280 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 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
282 close_elt.bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 "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
284 self.close()
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 ## affiliations
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
287
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 def set_affiliation(self, entity_jid, affiliation):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 if affiliation not in ('owner', 'member'):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 raise NotImplementedError(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 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
292 'moment')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 if entity_jid not in self.affiliations:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 self.affiliations[entity_jid] = affiliation
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 affiliation_elt = self.affiliation_tpl.get_elt({
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 "entity_jid": entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 "affiliation": affiliation,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 "identities": cache.identities,
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 document['affiliations'] <= affiliation_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 for elt in affiliation_elt.select(".click_to_delete"):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 elt.bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 "click",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 lambda evt, entity_jid=entity_jid, affiliation_elt=affiliation_elt:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 self.on_affiliation_remove(entity_jid, affiliation_elt)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
307
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 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
309 affiliation_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 del self.affiliations[entity_jid]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
311
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 def on_affiliation_remove(self, entity_jid, affiliation_elt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 if self.invitation_type == 'photos':
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 path = self.invitation_data["path"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 service = self.invitation_data["service"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 bridge.FISAffiliationsSet(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 service,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 "",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 path,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 {entity_jid: "none"},
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 callback=lambda: self._on_affiliation_remove_success(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 affiliation_elt, entity_jid),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
323 errback=lambda e: notification.show(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 f"can't remove affiliation: {e}", "error")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 )