diff browser_side/contact.py @ 200:0f5c2f799913

browser side: clicking on the contacts list (contact item, group or the "contacts" main title) open a discussion or microblog
author Goffi <goffi@goffi.org>
date Mon, 25 Mar 2013 14:09:10 +0100
parents c2639c9f86ea
children 744426c2b699
line wrap: on
line diff
--- a/browser_side/contact.py	Wed Mar 20 23:42:53 2013 +0100
+++ b/browser_side/contact.py	Mon Mar 25 14:09:10 2013 +0100
@@ -23,31 +23,43 @@
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.ScrollPanel import ScrollPanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
+from pyjamas.ui.ClickListener import ClickHandler
 from pyjamas.ui.Label import Label
 from pyjamas.ui.HTML import HTML
 from pyjamas import Window
 from pyjamas import DOM
 
+from browser_side.panels import ChatPanel, MicroblogPanel
 from browser_side.tools import DragLabel, html_sanitize
 from __pyjamas__ import doc
 
-class GroupLabel(DragLabel, Label):
-    def __init__(self, group):
+class GroupLabel(DragLabel, Label, ClickHandler):
+    def __init__(self, host, group):
         self.group = group
+        self.host = host
         Label.__init__(self, group) #, Element=DOM.createElement('div')
         self.setStyleName('group')
         DragLabel.__init__(self, group, "GROUP")
+        ClickHandler.__init__(self)
+        self.addClickListener(self)
+
+    def onClick(self, sender):
+        new_wid = MicroblogPanel.createGroup(self.host, self.group)
+        self.host.addWidget(new_wid)
     
 
-class ContactLabel(DragLabel, HTML):
-    def __init__(self, jid, name=None):
+class ContactLabel(DragLabel, HTML, ClickHandler):
+    def __init__(self, host, jid, name=None):
         HTML.__init__(self)
+        self.host = host
         self.name = name or jid
         self.waiting = False
         self.jid=jid
         self._fill()
         self.setStyleName('contact')
         DragLabel.__init__(self, jid, "CONTACT")
+        ClickHandler.__init__(self)
+        self.addClickListener(self)
 
     def _fill(self):
         if self.waiting:
@@ -61,6 +73,10 @@
         self.waiting = waiting
         self._fill()
 
+    def onClick(self, sender):
+        new_wid = ChatPanel.createChat(self.host, self.jid)
+        self.host.addWidget(new_wid)
+
 class GroupList(VerticalPanel):
 
     def __init__(self, parent):
@@ -69,7 +85,7 @@
         self._parent = parent
 
     def add(self, group):
-        _item = GroupLabel(group)
+        _item = GroupLabel(self._parent.host, group)
         _item.addMouseListener(self._parent)
         DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
         VerticalPanel.add(self, _item)
@@ -81,15 +97,16 @@
     
 class ContactList(VerticalPanel):
 
-    def __init__(self):
+    def __init__(self, host):
         VerticalPanel.__init__(self)
+        self.host = host
         self.contacts = set()
 
     def add(self, jid, name=None):
         if jid in self.contacts:
             return
         self.contacts.add(jid)
-        _item = ContactLabel(jid, name)
+        _item = ContactLabel(self.host, jid, name)
         DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
         VerticalPanel.add(self, _item)
 
@@ -134,11 +151,18 @@
             elif type == 'messageWaiting':
                 _item.setMessageWaiting(state)
 
-class ContactTitleLabel(DragLabel, Label):
-    def __init__(self, text):
+class ContactTitleLabel(DragLabel, Label, ClickHandler):
+    def __init__(self, host, text):
         Label.__init__(self, text) #, Element=DOM.createElement('div')
+        self.host = host
         self.setStyleName('contactTitle')
         DragLabel.__init__(self, text, "CONTACT_TITLE")
+        ClickHandler.__init__(self)
+        self.addClickListener(self)
+
+    def onClick(self, sender):
+        new_wid = MicroblogPanel.createMeta(self.host, None)
+        self.host.addWidget(new_wid)
 
 class ContactPanel(SimplePanel):
     """Manage the contacts and groups"""
@@ -153,10 +177,10 @@
         self.connected = {} #jid connected as key and their status
 
         self.vPanel = VerticalPanel()
-        _title = ContactTitleLabel('Contacts')
+        _title = ContactTitleLabel(host, 'Contacts')
         DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer")
 
-        self._contact_list = ContactList()
+        self._contact_list = ContactList(host)
         self._contact_list.setStyleName('contactList')
         self._groupList = GroupList(self)
         self._groupList.setStyleName('groupList')