annotate libervia/pages/_browser/invitation.py @ 1361:626b7bbb7f90

server: mechanism to exit Libervia with an exit code: the new `SysExit` exception can now be used to quit Libervia with a given shell exit code.
author Goffi <goffi@goffi.org>
date Sat, 14 Nov 2020 22:24:58 +0100
parents c74e5a488af6
children 2938d1b65bd5
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
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 bridge = Bridge()
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
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 class InvitationManager:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 def __init__(self, invitation_type, invitation_data):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 self.invitation_type = invitation_type
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 self.invitation_data = invitation_data
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 manager_panel_tpl = Template('invitation/manager.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 self.manager_panel_elt = manager_panel_tpl.get_elt()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 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
18 self.affiliation_tpl = Template('invitation/affiliation_item.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 self.new_item_tpl = Template('invitation/new_item.html')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 # 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
21 self._filtered_new_items = {}
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 self._idx = 0
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
24
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 def attach(self, affiliations=None):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 if affiliations is None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 affiliations = {}
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 self.affiliations = affiliations
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 self.side_panel = self.manager_panel_elt.select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 '.invitation_manager_side_panel')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 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
33 close_elt.bind("click", self.on_manager_close)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 self.side_panel.bind("click", lambda evt: evt.stopPropagation())
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 cache.fill_identities(affiliations.keys(), callback=self._set_affiliations)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 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
39 contact_elt.bind("input", self.on_contact_input)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 contact_elt.bind("keydown", self.on_contact_keydown)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 contact_elt.bind("focus", self.on_contact_focus)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 contact_elt.bind("blur", self.on_contact_blur)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 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
44
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def _set_affiliations(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 for entity_jid, affiliation in self.affiliations.items():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.set_affiliation(entity_jid, affiliation)
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 open(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 """Re-attach and show a closed panel"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 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
52 document.body.style.height = '100vh'
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 document.body.style.overflow = 'hidden'
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 document.body <= self.manager_panel_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 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
56
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 def _on_close_transition_end(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.manager_panel_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 # FIXME: not working with Brython, to report upstream
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 # 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
61 self.side_panel.unbind("transitionend")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
62
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def close(self):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 """Hide the panel"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 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
66 self.side_panel.classList.remove('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 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
68
1348
c74e5a488af6 browser (invitation): minor renaming
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
69 def invite_by_jid(self, entity_jid):
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 if self.invitation_type == 'photos':
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 path = self.invitation_data["path"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 service = self.invitation_data["service"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 album_name = path.rsplit('/')[-1]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 print(f"inviting {entity_jid}")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 bridge.FISInvite(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 service,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 "photos",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 "",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 path,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 album_name,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 '',
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 callback=lambda entity_jid=entity_jid:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self._on_jid_invitation_success(entity_jid),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 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
86 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
87
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 def on_manager_close(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.close()
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 def _on_jid_invitation_success(self, entity_jid):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 form_elt = document['invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 contact_elt = form_elt.select_one('input[name="contact"]')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 contact_elt.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 contact_elt.dispatchEvent(window.Event.new('input'))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 notification.show(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 f"{entity_jid} has been invited",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 level="success",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 if entity_jid not in self.affiliations:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 self.set_affiliation(entity_jid, "member")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
102
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 def on_contact_invite(self, evt, entity_jid):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 """User is adding a contact"""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 form_elt = document['invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 contact_elt = form_elt.select_one('input[name="contact"]')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 contact_elt.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 contact_elt.dispatchEvent(window.Event.new('input'))
1348
c74e5a488af6 browser (invitation): minor renaming
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
109 self.invite_by_jid(entity_jid)
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
110
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 def on_contact_keydown(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 if evt.key == "Escape":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 evt.target.value = ""
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 evt.target.dispatchEvent(window.Event.new('input'))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 elif evt.key == "ArrowDown":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 content_elt = document['invitation_contact_search'].select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 ".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 if self._active_new_item == None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 self._active_new_item = content_elt.firstElementChild
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 next_item = self._active_new_item.nextElementSibling
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 if next_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self._active_new_item.classList.remove('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 self._active_new_item = next_item
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 elif evt.key == "ArrowUp":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 content_elt = document['invitation_contact_search'].select_one(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 ".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 if self._active_new_item == None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 self._active_new_item = content_elt.lastElementChild
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 previous_item = self._active_new_item.previousElementSibling
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 if previous_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 self._active_new_item.classList.remove('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 self._active_new_item = previous_item
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 self._active_new_item.classList.add('selected')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 elif evt.key == "Enter":
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 if self._active_new_item is not None:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 entity_jid = self._active_new_item.dataset.entityJid
1348
c74e5a488af6 browser (invitation): minor renaming
Goffi <goffi@goffi.org>
parents: 1331
diff changeset
148 self.invite_by_jid(entity_jid)
1331
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
149
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 def on_contact_focus(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 search_dialog.classList.add('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 evt.target.dispatchEvent(window.Event.new('input'))
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
155
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 def on_contact_blur(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 search_dialog.classList.remove('open')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 for elt in self._filtered_new_items.values():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 self._filtered_new_items.clear()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
162
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_input(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 text = evt.target.value.strip().lower()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 search_dialog = document['invitation_contact_search']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 content_elt = search_dialog.select_one(".search_dialog__content")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 for (entity_jid, identity) in cache.identities.items():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 if not cache.match_identity(entity_jid, text, identity):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 # 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
171 try:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 filtered_item = self._filtered_new_items.pop(entity_jid)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 except KeyError:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 pass
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 filtered_item.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 continue
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 if entity_jid not in self._filtered_new_items:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 # 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
180 new_item_elt = self.new_item_tpl.get_elt({
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 "entity_jid": entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 "identities": cache.identities,
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 content_elt <= new_item_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 self._filtered_new_items[entity_jid] = new_item_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 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
187 # 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
188 # ignored due to "blur" event manager (see
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 # https://stackoverflow.com/a/9335401)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 elt.bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 "mousedown",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 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
193 evt, entity_jid),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
195
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 if ((self._active_new_item is not None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 and not self._active_new_item.parentElement)):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 # active item has been filtered out
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 self._active_new_item = None
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
200
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 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
202 self.set_affiliation(invitee_jid, "member")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 notification.show(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 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
205 level="success",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
207
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 def invitationSimpleCreateCb(self, invitation_data, email, name):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 if self.invitation_type == 'photos':
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 path = self.invitation_data["path"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 service = self.invitation_data["service"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 invitee_jid = invitation_data['jid']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 album_name = path.rsplit('/')[-1]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 bridge.FISInvite(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 invitee_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 service,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 "photos",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 "",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 path,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 album_name,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 '',
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 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
223 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
224 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
225
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 # 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
227 # affiliations
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 cache.identities[invitee_jid] = {'nicknames': [name]}
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 cache.update()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
230
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 def invite_by_email(self, email, name):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 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
233 bridge.invitationSimpleCreate(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 email,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 name,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 guest_url_tpl,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 '',
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 callback=lambda data: self.invitationSimpleCreateCb(data, email, name),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 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
240 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
241
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 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
243 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 form = document['email_invitation_form']
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 try:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 reportValidity = form.reportValidity
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 except AttributeError:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 print("reportValidity is not supported by this browser!")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 else:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 if not reportValidity():
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 return
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 email = form.select_one('input[name="email"]').value
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 name = form.select_one('input[name="name"]').value
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 self.invite_by_email(email, name)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 invite_email_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
258
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 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
260 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 invite_email_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 self.open()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
264
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 def on_invite_email_click(self, evt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 evt.stopPropagation()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 evt.preventDefault()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 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
269 document.body <= invite_email_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 document['email_invitation_submit'].bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 '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
272 )
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 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
274 close_elt.bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 "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
276 self.close()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
277
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 ## affiliations
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
279
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 def set_affiliation(self, entity_jid, affiliation):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 if affiliation not in ('owner', 'member'):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 raise NotImplementedError(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 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
284 'moment')
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 if entity_jid not in self.affiliations:
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 self.affiliations[entity_jid] = affiliation
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 affiliation_elt = self.affiliation_tpl.get_elt({
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 "entity_jid": entity_jid,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 "affiliation": affiliation,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 "identities": cache.identities,
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 document['affiliations'] <= affiliation_elt
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 for elt in affiliation_elt.select(".click_to_delete"):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 elt.bind(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 "click",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 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
297 self.on_affiliation_remove(entity_jid, affiliation_elt)
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 )
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 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
301 affiliation_elt.remove()
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 del self.affiliations[entity_jid]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
303
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 def on_affiliation_remove(self, entity_jid, affiliation_elt):
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 if self.invitation_type == 'photos':
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 path = self.invitation_data["path"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 service = self.invitation_data["service"]
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 bridge.FISAffiliationsSet(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 service,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 "",
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 path,
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 {entity_jid: "none"},
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 callback=lambda: self._on_affiliation_remove_success(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 affiliation_elt, entity_jid),
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 errback=lambda e: notification.show(
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 f"can't remove affiliation: {e}", "error")
fe353fceec38 browser (invitation, photos/album): invitation manager improvments:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 )