changeset 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 86055ccf69c3
children 63e9b680d3e7
files browser_side/contact.py browser_side/menu.py browser_side/panels.py libervia.py libervia.tac public/libervia.css
diffstat 6 files changed, 65 insertions(+), 20 deletions(-) [+]
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"""
--- a/browser_side/menu.py	Tue Oct 15 13:36:51 2013 +0200
+++ b/browser_side/menu.py	Fri Oct 18 11:14:55 2013 +0200
@@ -186,7 +186,7 @@
     def onDisconnect(self):
         def confirm_cb(answer):
             if answer:
-                print "déconnexion"
+                print "disconnection"
                 self.host.bridge.call('disconnect', None)
         _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to disconnect ?")
         _dialog.show()
@@ -218,14 +218,14 @@
         edit = TextBox()
 
         def addContactCb(sender):
-            if not re.match(r'^.+@.+\..+',edit.getText(), re.IGNORECASE):
-                Window.alert('You must enter a valid contact JID (like "contact@libervia.org")')
+            if not re.match(r'^.+@.+\..+', edit.getText(), re.IGNORECASE):
+                Window.alert('You must enter a valid contact JID (like "contact@%s")' % self.host._defaultDomain)
                 _dialog.show()
             else:
                 self.host.bridge.call('addContact', None, edit.getText(), '', _dialog.getSelectedGroups() )
 
         label = Label("new contact identifier (JID):")
-        edit.setText('@libervia.org')
+        edit.setText('@%s' % self.host._defaultDomain)
         edit.setWidth('100%')
         _dialog = dialog.GroupSelector([label, edit], self.host.contact_panel.getGroups(), [],
                                        "Add", addContactCb)
@@ -285,7 +285,7 @@
 
         def onOK(sender):
             if not _edit.getText():
-                Window.alert('You must enter a room jid in the form libervia@conference.libervia.org')
+                Window.alert('You must enter a room jid in the form room@chat.%s' % self.host._defaultDomain)
             if self.host.whoami:
                 nick = self.host.whoami.node
                 self.host.bridge.call('joinMUC', None, _edit.getText(), nick)
@@ -325,7 +325,7 @@
         #self.host.tab_panel.add(EmptyPanel(self.host), "Tarot")
         def onPlayersSelected(other_players):
             self.host.bridge.call('launchTarotGame', None, other_players)
-        dialog.ContactsChooser(self.host, onPlayersSelected, 3, text="Please select 3 other players").getContacts() 
+        dialog.ContactsChooser(self.host, onPlayersSelected, 3, text="Please select 3 other players").getContacts()
 
     def onXiangqiGame(self):
         Window.alert("A Xiangqi game is planed, but not available yet")
--- a/browser_side/panels.py	Tue Oct 15 13:36:51 2013 +0200
+++ b/browser_side/panels.py	Fri Oct 18 11:14:55 2013 +0200
@@ -455,7 +455,7 @@
         """Insert several microblogs at once
         @param mblogs: dictionary of microblogs, as the result of getMassiveLastGroupBlogs
         """
-        print "Massive insertion of microblogs"
+        print "Massive insertion of %d microblogs" % len(mblogs)
         for publisher in mblogs:
             print "adding blogs for [%s]" % publisher
             for mblog in mblogs[publisher]:
@@ -1001,6 +1001,8 @@
             item.setStyleName(self.item_style)
             item.setTitle(entry["desc"] if "desc" in entry.keys() else title)
             menu.add(item)
+        if len(menu.getChildren()) == 0:
+            return
         self.add(menu)
         if self.vertical is True:
             x = sender.getAbsoluteLeft() + sender.getOffsetWidth()
--- a/libervia.py	Tue Oct 15 13:36:51 2013 +0200
+++ b/libervia.py	Fri Oct 18 11:14:55 2013 +0200
@@ -118,9 +118,10 @@
                          "tarotGameContratChoosed", "tarotGamePlayCards", "launchRadioCollective",
                          "getWaitingSub", "subscription", "delContact", "updateContact", "getCard",
                          "getEntityData", "getParamsUI", "asyncGetParamA", "setParam", "launchAction",
-                         "disconnect", "chatStateComposing"
+                         "disconnect", "chatStateComposing", "getNewAccountDomain"
                         ])
 
+
 class BridgeSignals(LiberviaJsonProxy):
     RETRY_BASE_DELAY = 1000
 
@@ -305,6 +306,15 @@
         #We want to know our own jid
         self.bridge.call('getProfileJid', self._getProfileJidCB)
 
+        def domain_cb(value):
+            self._defaultDomain = value
+            print("new account domain: %s" % value)
+
+        def domain_eb(value):
+            self._defaultDomain = "libervia.org"
+
+        self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb))
+
     def _getContactsCB(self, contacts_data):
         for contact in contacts_data:
             jid, attributes, groups = contact
@@ -575,7 +585,6 @@
             if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
                 getattr(lib_wid.getGame("RadioCol"), event_name)(*args)
 
-
     def _getPresenceStatusCb(self, presence_data):
         for entity in presence_data:
             for resource in presence_data[entity]:
--- a/libervia.tac	Tue Oct 15 13:36:51 2013 +0200
+++ b/libervia.tac	Fri Oct 18 11:14:55 2013 +0200
@@ -429,12 +429,16 @@
         return self.sat_host.bridge.launchAction(action_type, data, profile)
         
     def jsonrpc_chatStateComposing(self, to_jid_s):
-        """Broadcast a signal for "composing" state.
+        """Call the method to process a "composing" state.
         @param to_jid_s: contact the user is composing to
         """
         profile = ISATSession(self.session).profile
         self.sat_host.bridge.chatStateComposing(to_jid_s, profile)
 
+    def jsonrpc_getNewAccountDomain(self):
+        """@return: the domain for new account creation"""
+        d = self.asyncBridgeCall("getNewAccountDomain")
+        return d
 
 class Register(JSONRPCMethodManager):
     """This class manage the registration procedure with SàT
--- a/public/libervia.css	Tue Oct 15 13:36:51 2013 +0200
+++ b/public/libervia.css	Fri Oct 18 11:14:55 2013 +0200
@@ -453,6 +453,14 @@
     padding: 3px 10px 3px 10px;
 }
 
+.contact-menu {
+    font-size: 1em;
+    margin-top: 3px;
+    padding: 3px 10px 3px 10px;
+    border-radius: 5px;
+	background-color: rgb(175, 175, 175);
+}
+
 .contactConnected {
     color: #3c7e0c;
     font-weight: bold;