Mercurial > libervia-web
diff 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 |
line wrap: on
line diff
--- a/browser_side/contact.py Tue Oct 15 13:36:51 2013 +0200 +++ b/browser_side/contact.py Fri Oct 18 11:14:55 2013 +0200 @@ -26,13 +26,15 @@ from pyjamas.ui.ClickListener import ClickHandler from pyjamas.ui.Label import Label from pyjamas.ui.HTML import HTML +from jid import JID from pyjamas import Window from pyjamas import DOM -from browser_side.panels import ChatPanel, MicroblogPanel +from browser_side.panels import ChatPanel, MicroblogPanel, PopupMenuPanel, WebPanel from browser_side.tools import DragLabel, html_sanitize from __pyjamas__ import doc + class GroupLabel(DragLabel, Label, ClickHandler): def __init__(self, host, group): self.group = group @@ -94,12 +96,32 @@ if isinstance(wid, GroupLabel) and wid.group == group: VerticalPanel.remove(self, wid) + class ContactList(VerticalPanel): def __init__(self, host): VerticalPanel.__init__(self) self.host = host self.contacts = set() + self.menu_entries = {"blog": {"title": "Public blog..."}} + self.context_menu = PopupMenuPanel(entries=self.menu_entries, + hide=self.contextMenuHide, + callback=self.contextMenuCallback, + vertical=False, menu_style="menu") + + def contextMenuHide(self, sender, key): + """Return True if the item for that sender should be hidden.""" + # TODO: enable the blogs of users that are on another server + return JID(sender.jid).domain != self.host._defaultDomain + + def contextMenuCallback(self, sender, key): + if key == "blog": + # TODO: use the bare when all blogs can be retrieved + node = JID(sender.jid).node + web_panel = WebPanel(self.host, "blog/%s" % node) + self.host.addTab(web_panel, "%s's blog" % node) + else: + sender.onClick(sender) def add(self, jid, name=None): if jid in self.contacts: @@ -108,6 +130,7 @@ _item = ContactLabel(self.host, jid, name) DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") VerticalPanel.add(self, _item) + self.context_menu.registerRightClickSender(_item) def remove(self, jid): wid = self.getContactLabel(jid) @@ -205,7 +228,6 @@ ideal_height = tab_bar_h - DOM.getAbsoluteTop(contact_panel_elt) - 5 self.scroll_panel.setHeight("%s%s" % (ideal_height, "px")); - def updateContact(self, jid, attributes, groups): """Add a contact to the panel if it doesn't exist, update it else @param jid: jid @@ -226,7 +248,7 @@ for group in _new_groups.difference(_current_groups): # We add the contact to the groups he joined - if not self.groups.has_key(group): + if not group in self.groups.keys(): self.groups[group] = set() self._groupList.add(group) self.host.uni_box.addKey(_key % group) @@ -276,13 +298,13 @@ return result def isContactInGroup(self, group, contact_jid): - """Test if the contact_jid is in the group - @param group: string of single group, or list of string - @param contact_jid: jid to test - @return: True if contact_jid is in on of the groups""" - if group in self.groups and contact_jid in self.groups[group]: - return True - return False + """Test if the contact_jid is in the group + @param group: string of single group, or list of string + @param contact_jid: jid to test + @return: True if contact_jid is in on of the groups""" + if group in self.groups and contact_jid in self.groups[group]: + return True + return False def isContactInRoster(self, contact_jid): """Test if the contact is in our roster list"""