Mercurial > libervia-web
comparison browser_side/contact.py @ 242:a25aa882e09a
browser_side: add context menu for contact:
- for now only when a blog exists on the current libervia's server
- retrieve the server domain with the bridge method getNewAccountDomain
- getNewAccountDomain is also used to display the current libervia domain
in the dialogs (new contact default domain, messages for invalid contact or group)
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 18 Oct 2013 11:14:55 +0200 |
parents | 266e9678eec0 |
children | b77940d8a9bf |
comparison
equal
deleted
inserted
replaced
241:86055ccf69c3 | 242:a25aa882e09a |
---|---|
24 from pyjamas.ui.ScrollPanel import ScrollPanel | 24 from pyjamas.ui.ScrollPanel import ScrollPanel |
25 from pyjamas.ui.VerticalPanel import VerticalPanel | 25 from pyjamas.ui.VerticalPanel import VerticalPanel |
26 from pyjamas.ui.ClickListener import ClickHandler | 26 from pyjamas.ui.ClickListener import ClickHandler |
27 from pyjamas.ui.Label import Label | 27 from pyjamas.ui.Label import Label |
28 from pyjamas.ui.HTML import HTML | 28 from pyjamas.ui.HTML import HTML |
29 from jid import JID | |
29 from pyjamas import Window | 30 from pyjamas import Window |
30 from pyjamas import DOM | 31 from pyjamas import DOM |
31 | 32 |
32 from browser_side.panels import ChatPanel, MicroblogPanel | 33 from browser_side.panels import ChatPanel, MicroblogPanel, PopupMenuPanel, WebPanel |
33 from browser_side.tools import DragLabel, html_sanitize | 34 from browser_side.tools import DragLabel, html_sanitize |
34 from __pyjamas__ import doc | 35 from __pyjamas__ import doc |
36 | |
35 | 37 |
36 class GroupLabel(DragLabel, Label, ClickHandler): | 38 class GroupLabel(DragLabel, Label, ClickHandler): |
37 def __init__(self, host, group): | 39 def __init__(self, host, group): |
38 self.group = group | 40 self.group = group |
39 self.host = host | 41 self.host = host |
92 def remove(self, group): | 94 def remove(self, group): |
93 for wid in self: | 95 for wid in self: |
94 if isinstance(wid, GroupLabel) and wid.group == group: | 96 if isinstance(wid, GroupLabel) and wid.group == group: |
95 VerticalPanel.remove(self, wid) | 97 VerticalPanel.remove(self, wid) |
96 | 98 |
99 | |
97 class ContactList(VerticalPanel): | 100 class ContactList(VerticalPanel): |
98 | 101 |
99 def __init__(self, host): | 102 def __init__(self, host): |
100 VerticalPanel.__init__(self) | 103 VerticalPanel.__init__(self) |
101 self.host = host | 104 self.host = host |
102 self.contacts = set() | 105 self.contacts = set() |
106 self.menu_entries = {"blog": {"title": "Public blog..."}} | |
107 self.context_menu = PopupMenuPanel(entries=self.menu_entries, | |
108 hide=self.contextMenuHide, | |
109 callback=self.contextMenuCallback, | |
110 vertical=False, menu_style="menu") | |
111 | |
112 def contextMenuHide(self, sender, key): | |
113 """Return True if the item for that sender should be hidden.""" | |
114 # TODO: enable the blogs of users that are on another server | |
115 return JID(sender.jid).domain != self.host._defaultDomain | |
116 | |
117 def contextMenuCallback(self, sender, key): | |
118 if key == "blog": | |
119 # TODO: use the bare when all blogs can be retrieved | |
120 node = JID(sender.jid).node | |
121 web_panel = WebPanel(self.host, "blog/%s" % node) | |
122 self.host.addTab(web_panel, "%s's blog" % node) | |
123 else: | |
124 sender.onClick(sender) | |
103 | 125 |
104 def add(self, jid, name=None): | 126 def add(self, jid, name=None): |
105 if jid in self.contacts: | 127 if jid in self.contacts: |
106 return | 128 return |
107 self.contacts.add(jid) | 129 self.contacts.add(jid) |
108 _item = ContactLabel(self.host, jid, name) | 130 _item = ContactLabel(self.host, jid, name) |
109 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") | 131 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") |
110 VerticalPanel.add(self, _item) | 132 VerticalPanel.add(self, _item) |
133 self.context_menu.registerRightClickSender(_item) | |
111 | 134 |
112 def remove(self, jid): | 135 def remove(self, jid): |
113 wid = self.getContactLabel(jid) | 136 wid = self.getContactLabel(jid) |
114 if not wid: | 137 if not wid: |
115 return | 138 return |
203 tab_bar_h = DOM.getAbsoluteTop(_elts.item(0)) or height # getAbsoluteTop can be 0 if tabBar is hidden | 226 tab_bar_h = DOM.getAbsoluteTop(_elts.item(0)) or height # getAbsoluteTop can be 0 if tabBar is hidden |
204 | 227 |
205 ideal_height = tab_bar_h - DOM.getAbsoluteTop(contact_panel_elt) - 5 | 228 ideal_height = tab_bar_h - DOM.getAbsoluteTop(contact_panel_elt) - 5 |
206 self.scroll_panel.setHeight("%s%s" % (ideal_height, "px")); | 229 self.scroll_panel.setHeight("%s%s" % (ideal_height, "px")); |
207 | 230 |
208 | |
209 def updateContact(self, jid, attributes, groups): | 231 def updateContact(self, jid, attributes, groups): |
210 """Add a contact to the panel if it doesn't exist, update it else | 232 """Add a contact to the panel if it doesn't exist, update it else |
211 @param jid: jid | 233 @param jid: jid |
212 @attributes: cf SàT Bridge API's newContact | 234 @attributes: cf SàT Bridge API's newContact |
213 @param groups: list of groups""" | 235 @param groups: list of groups""" |
224 self._groupList.remove(group) | 246 self._groupList.remove(group) |
225 self.host.uni_box.removeKey(_key % group) | 247 self.host.uni_box.removeKey(_key % group) |
226 | 248 |
227 for group in _new_groups.difference(_current_groups): | 249 for group in _new_groups.difference(_current_groups): |
228 # We add the contact to the groups he joined | 250 # We add the contact to the groups he joined |
229 if not self.groups.has_key(group): | 251 if not group in self.groups.keys(): |
230 self.groups[group] = set() | 252 self.groups[group] = set() |
231 self._groupList.add(group) | 253 self._groupList.add(group) |
232 self.host.uni_box.addKey(_key % group) | 254 self.host.uni_box.addKey(_key % group) |
233 self.groups[group].add(jid) | 255 self.groups[group].add(jid) |
234 | 256 |
274 if self.isContactInGroup(group, contact_jid): | 296 if self.isContactInGroup(group, contact_jid): |
275 result.add(group) | 297 result.add(group) |
276 return result | 298 return result |
277 | 299 |
278 def isContactInGroup(self, group, contact_jid): | 300 def isContactInGroup(self, group, contact_jid): |
279 """Test if the contact_jid is in the group | 301 """Test if the contact_jid is in the group |
280 @param group: string of single group, or list of string | 302 @param group: string of single group, or list of string |
281 @param contact_jid: jid to test | 303 @param contact_jid: jid to test |
282 @return: True if contact_jid is in on of the groups""" | 304 @return: True if contact_jid is in on of the groups""" |
283 if group in self.groups and contact_jid in self.groups[group]: | 305 if group in self.groups and contact_jid in self.groups[group]: |
284 return True | 306 return True |
285 return False | 307 return False |
286 | 308 |
287 def isContactInRoster(self, contact_jid): | 309 def isContactInRoster(self, contact_jid): |
288 """Test if the contact is in our roster list""" | 310 """Test if the contact is in our roster list""" |
289 for _contact_label in self._contact_list: | 311 for _contact_label in self._contact_list: |
290 if contact_jid == _contact_label.jid: | 312 if contact_jid == _contact_label.jid: |