comparison 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
comparison
equal deleted inserted replaced
199:39311c7dad77 200:0f5c2f799913
21 21
22 import pyjd # this is dummy in pyjs 22 import pyjd # this is dummy in pyjs
23 from pyjamas.ui.SimplePanel import SimplePanel 23 from pyjamas.ui.SimplePanel import SimplePanel
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.Label import Label 27 from pyjamas.ui.Label import Label
27 from pyjamas.ui.HTML import HTML 28 from pyjamas.ui.HTML import HTML
28 from pyjamas import Window 29 from pyjamas import Window
29 from pyjamas import DOM 30 from pyjamas import DOM
30 31
32 from browser_side.panels import ChatPanel, MicroblogPanel
31 from browser_side.tools import DragLabel, html_sanitize 33 from browser_side.tools import DragLabel, html_sanitize
32 from __pyjamas__ import doc 34 from __pyjamas__ import doc
33 35
34 class GroupLabel(DragLabel, Label): 36 class GroupLabel(DragLabel, Label, ClickHandler):
35 def __init__(self, group): 37 def __init__(self, host, group):
36 self.group = group 38 self.group = group
39 self.host = host
37 Label.__init__(self, group) #, Element=DOM.createElement('div') 40 Label.__init__(self, group) #, Element=DOM.createElement('div')
38 self.setStyleName('group') 41 self.setStyleName('group')
39 DragLabel.__init__(self, group, "GROUP") 42 DragLabel.__init__(self, group, "GROUP")
43 ClickHandler.__init__(self)
44 self.addClickListener(self)
45
46 def onClick(self, sender):
47 new_wid = MicroblogPanel.createGroup(self.host, self.group)
48 self.host.addWidget(new_wid)
40 49
41 50
42 class ContactLabel(DragLabel, HTML): 51 class ContactLabel(DragLabel, HTML, ClickHandler):
43 def __init__(self, jid, name=None): 52 def __init__(self, host, jid, name=None):
44 HTML.__init__(self) 53 HTML.__init__(self)
54 self.host = host
45 self.name = name or jid 55 self.name = name or jid
46 self.waiting = False 56 self.waiting = False
47 self.jid=jid 57 self.jid=jid
48 self._fill() 58 self._fill()
49 self.setStyleName('contact') 59 self.setStyleName('contact')
50 DragLabel.__init__(self, jid, "CONTACT") 60 DragLabel.__init__(self, jid, "CONTACT")
61 ClickHandler.__init__(self)
62 self.addClickListener(self)
51 63
52 def _fill(self): 64 def _fill(self):
53 if self.waiting: 65 if self.waiting:
54 _wait_html = "<b>(*)</b>&nbsp;" 66 _wait_html = "<b>(*)</b>&nbsp;"
55 self.setHTML("%(wait)s%(name)s" % {'wait': _wait_html, 67 self.setHTML("%(wait)s%(name)s" % {'wait': _wait_html,
59 """Show a visual indicator if message are waiting 71 """Show a visual indicator if message are waiting
60 @param waiting: True if message are waiting""" 72 @param waiting: True if message are waiting"""
61 self.waiting = waiting 73 self.waiting = waiting
62 self._fill() 74 self._fill()
63 75
76 def onClick(self, sender):
77 new_wid = ChatPanel.createChat(self.host, self.jid)
78 self.host.addWidget(new_wid)
79
64 class GroupList(VerticalPanel): 80 class GroupList(VerticalPanel):
65 81
66 def __init__(self, parent): 82 def __init__(self, parent):
67 VerticalPanel.__init__(self) 83 VerticalPanel.__init__(self)
68 self.setStyleName('groupList') 84 self.setStyleName('groupList')
69 self._parent = parent 85 self._parent = parent
70 86
71 def add(self, group): 87 def add(self, group):
72 _item = GroupLabel(group) 88 _item = GroupLabel(self._parent.host, group)
73 _item.addMouseListener(self._parent) 89 _item.addMouseListener(self._parent)
74 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") 90 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
75 VerticalPanel.add(self, _item) 91 VerticalPanel.add(self, _item)
76 92
77 def remove(self, group): 93 def remove(self, group):
79 if isinstance(wid, GroupLabel) and wid.group == group: 95 if isinstance(wid, GroupLabel) and wid.group == group:
80 VerticalPanel.remove(self, wid) 96 VerticalPanel.remove(self, wid)
81 97
82 class ContactList(VerticalPanel): 98 class ContactList(VerticalPanel):
83 99
84 def __init__(self): 100 def __init__(self, host):
85 VerticalPanel.__init__(self) 101 VerticalPanel.__init__(self)
102 self.host = host
86 self.contacts = set() 103 self.contacts = set()
87 104
88 def add(self, jid, name=None): 105 def add(self, jid, name=None):
89 if jid in self.contacts: 106 if jid in self.contacts:
90 return 107 return
91 self.contacts.add(jid) 108 self.contacts.add(jid)
92 _item = ContactLabel(jid, name) 109 _item = ContactLabel(self.host, jid, name)
93 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer") 110 DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
94 VerticalPanel.add(self, _item) 111 VerticalPanel.add(self, _item)
95 112
96 def remove(self, jid): 113 def remove(self, jid):
97 wid = self.getContactLabel(jid) 114 wid = self.getContactLabel(jid)
132 else: 149 else:
133 _item.addStyleName('contactConnected') 150 _item.addStyleName('contactConnected')
134 elif type == 'messageWaiting': 151 elif type == 'messageWaiting':
135 _item.setMessageWaiting(state) 152 _item.setMessageWaiting(state)
136 153
137 class ContactTitleLabel(DragLabel, Label): 154 class ContactTitleLabel(DragLabel, Label, ClickHandler):
138 def __init__(self, text): 155 def __init__(self, host, text):
139 Label.__init__(self, text) #, Element=DOM.createElement('div') 156 Label.__init__(self, text) #, Element=DOM.createElement('div')
157 self.host = host
140 self.setStyleName('contactTitle') 158 self.setStyleName('contactTitle')
141 DragLabel.__init__(self, text, "CONTACT_TITLE") 159 DragLabel.__init__(self, text, "CONTACT_TITLE")
160 ClickHandler.__init__(self)
161 self.addClickListener(self)
162
163 def onClick(self, sender):
164 new_wid = MicroblogPanel.createMeta(self.host, None)
165 self.host.addWidget(new_wid)
142 166
143 class ContactPanel(SimplePanel): 167 class ContactPanel(SimplePanel):
144 """Manage the contacts and groups""" 168 """Manage the contacts and groups"""
145 169
146 def __init__(self, host): 170 def __init__(self, host):
151 self.host = host 175 self.host = host
152 self.groups={} 176 self.groups={}
153 self.connected = {} #jid connected as key and their status 177 self.connected = {} #jid connected as key and their status
154 178
155 self.vPanel = VerticalPanel() 179 self.vPanel = VerticalPanel()
156 _title = ContactTitleLabel('Contacts') 180 _title = ContactTitleLabel(host, 'Contacts')
157 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer") 181 DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer")
158 182
159 self._contact_list = ContactList() 183 self._contact_list = ContactList(host)
160 self._contact_list.setStyleName('contactList') 184 self._contact_list.setStyleName('contactList')
161 self._groupList = GroupList(self) 185 self._groupList = GroupList(self)
162 self._groupList.setStyleName('groupList') 186 self._groupList.setStyleName('groupList')
163 187
164 self.vPanel.add(_title) 188 self.vPanel.add(_title)