Mercurial > libervia-web
changeset 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 | 39311c7dad77 |
children | aa76793da353 |
files | browser_side/contact.py browser_side/panels.py libervia.py |
diffstat | 3 files changed, 47 insertions(+), 17 deletions(-) [+] |
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')
--- a/browser_side/panels.py Wed Mar 20 23:42:53 2013 +0100 +++ b/browser_side/panels.py Mon Mar 25 14:09:10 2013 +0100 @@ -263,11 +263,11 @@ @classmethod def registerClass(cls): - base_widget.LiberviaWidget.addDropKey("GROUP", cls.onDropCreateGroup) - base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", cls.onDropCreateMeta) + base_widget.LiberviaWidget.addDropKey("GROUP", cls.createGroup) + base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", cls.createMeta) @classmethod - def onDropCreateGroup(cls, host, item): + def createGroup(cls, host, item): _new_panel = MicroblogPanel(host, [item]) #XXX: pyjamas doesn't support use of cls directly _new_panel.setAcceptedGroup(item) host.FillMicroblogPanel(_new_panel) @@ -275,7 +275,7 @@ return _new_panel @classmethod - def onDropCreateMeta(cls, host, item): + def createMeta(cls, host, item): _new_panel = MicroblogPanel(host, []) #XXX: pyjamas doesn't support use of cls directly host.FillMicroblogPanel(_new_panel) host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, 'ALL', [], 10) @@ -476,10 +476,10 @@ @classmethod def registerClass(cls): - base_widget.LiberviaWidget.addDropKey("CONTACT", cls.onDropCreate) + base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createChat) @classmethod - def onDropCreate(cls, host, item): + def createChat(cls, host, item): _contact = JID(item) host.contact_panel.setContactMessageWaiting(_contact.bare, False) _new_panel = ChatPanel(host, _contact) #XXX: pyjamas doesn't seems to support creating with cls directly
--- a/libervia.py Wed Mar 20 23:42:53 2013 +0100 +++ b/libervia.py Mon Mar 25 14:09:10 2013 +0100 @@ -234,6 +234,12 @@ self.tab_panel.add(_widgets_panel, label) self.tab_panel.selectTab(self.tab_panel.getWidgetCount() - 1) + def addWidget(self, wid): + """ Add a widget at the bottom of the current tab + @param wid: LiberviaWidget to add """ + panel = self.tab_panel.getCurrentPanel() + panel.addWidget(wid) + def _isRegisteredCB(self, registered): if not registered: self._register_box = RegisterBox(self.logged)