Mercurial > libervia-web
changeset 598:ed6d8f7c6026 frontends_multi_profiles
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Feb 2015 19:25:17 +0100 |
parents | be2891462e63 |
children | a6b9809b9a68 |
files | src/browser/sat_browser/base_widget.py src/browser/sat_browser/blog.py src/browser/sat_browser/chat.py |
diffstat | 3 files changed, 37 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/src/browser/sat_browser/base_widget.py Fri Feb 06 19:23:08 2015 +0100 +++ b/src/browser/sat_browser/base_widget.py Fri Feb 06 19:25:17 2015 +0100 @@ -20,6 +20,7 @@ import pyjd # this is dummy in pyjs from sat.core.log import getLogger log = getLogger(__name__) +from sat_frontends.quick_frontend import quick_widgets from pyjamas.ui.SimplePanel import SimplePanel from pyjamas.ui.AbsolutePanel import AbsolutePanel from pyjamas.ui.VerticalPanel import VerticalPanel @@ -104,8 +105,14 @@ self.setStyleName('dropCell') @classmethod - def addDropKey(cls, key, callback): - DropCell.drop_keys[key] = callback + def addDropKey(cls, key, cb): + """Add a association between a key and a class to create on drop + + @param key: key to be associated (e.g. "CONTACT", "CHAT") + @param cb: either a LiberviaWidget instance, or a callback which return one + """ + DropCell.drop_keys[key] = cb + def onDragEnter(self, event): if self == LiberviaDragWidget.current:
--- a/src/browser/sat_browser/blog.py Fri Feb 06 19:23:08 2015 +0100 +++ b/src/browser/sat_browser/blog.py Fri Feb 06 19:25:17 2015 +0100 @@ -414,14 +414,10 @@ assert(first.type == 'main_item') return first if first.empty else None - @classmethod - def registerClass(cls): - base_widget.LiberviaWidget.addDropKey("GROUP", cls.createPanel) - base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", cls.createMetaPanel) + @staticmethod + def onGroupDrop(host, item): + """Generic panel creation for one, several or all groups (meta). - @classmethod - def createPanel(cls, host, item): - """Generic panel creation for one, several or all groups (meta). @parem host: the SatWebFrontend instance @param item: single group as a string, list of groups (as an array) or None (for the meta group = "all groups") @@ -430,17 +426,11 @@ items_ = tuple(item) if isinstance(item, list) else (() if item is None else (item,)) type_ = 'ALL' if items_ == () else 'GROUP' # XXX: pyjamas doesn't support use of cls directly - _new_panel = MicroblogPanel(host, _items) - host.FillMicroblogPanel(_new_panel) - host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, _type, _items, 10) - host.setSelected(_new_panel) - _new_panel.refresh() - return _new_panel - - @classmethod - def createMetaPanel(cls, host, item): - """Needed for the drop keys to not be mixed between meta panel and panel for "Contacts" group""" - return MicroblogPanel.createPanel(host, None) + widget = host.widgets.getOrCreateWidget(MicroblogPanel, items_, profile=C.PROF_KEY_NONE, on_new_widget=None, on_existing_widget=C.WIDGET_RECREATE) + host.FillMicroblogPanel(widget) + host.bridge.getMassiveLastMblogs(type_, items_, 10, profile=C.PROF_KEY_NONE, callback=widget.massiveInsert) + widget.refresh() # FIXME: needed ? + return widget @property def accepted_groups(self): @@ -716,3 +706,9 @@ if self.host.contact_lists[self.profile].isEntityInGroup(jid_, group): return True return False + + +base_widget.LiberviaWidget.addDropKey("GROUP", MicroblogPanel.onGroupDrop) + +# Needed for the drop keys to not be mixed between meta panel and panel for "Contacts" group +base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", lambda host, item: MicroblogPanel.onGroupDrop(host, None))
--- a/src/browser/sat_browser/chat.py Fri Feb 06 19:23:08 2015 +0100 +++ b/src/browser/sat_browser/chat.py Fri Feb 06 19:25:17 2015 +0100 @@ -77,7 +77,8 @@ @param host: SatWebFrontend instance @param target: entity (jid.JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) - @param type: one2one for simple conversation, group for MUC""" + @param type: one2one for simple conversation, group for MUC + """ QuickChat.__init__(self, host, target, type_, profiles=profiles) self.vpanel = VerticalPanel() self.vpanel.setSize('100%', '100%') @@ -127,20 +128,16 @@ assert len(self.profiles) == 1 and not self.PROFILES_MULTIPLE and not self.PROFILES_ALLOW_NONE return list(self.profiles)[0] - @classmethod - def registerClass(cls): - base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createPanel) - - @classmethod - def createPanel(cls, host, item, type_=C.CHAT_ONE2ONE): - assert(item) - _contact = item if isinstance(item, jid.JID) else jid.JID(item) - host.contact_panel.setContactMessageWaiting(_contact.bare, False) - _new_panel = Chat(host, _contact, type_) # XXX: pyjamas doesn't seems to support creating with cls directly - _new_panel.historyPrint() - host.setSelected(_new_panel) - _new_panel.refresh() - return _new_panel + # @classmethod + # def createPanel(cls, host, item, type_=C.CHAT_ONE2ONE): + # assert(item) + # _contact = item if isinstance(item, jid.JID) else jid.JID(item) + # host.contact_panel.setContactMessageWaiting(_contact.bare, False) + # _new_panel = Chat(host, _contact, type_) # XXX: pyjamas doesn't seems to support creating with cls directly + # _new_panel.historyPrint() + # host.setSelected(_new_panel) + # _new_panel.refresh() + # return _new_panel def refresh(self): """Refresh the display of this widget. If the unibox is disabled, @@ -361,4 +358,6 @@ #TODO pass + quick_widgets.register(QuickChat, Chat) +base_widget.LiberviaWidget.addDropKey("CONTACT", lambda host, item: host.widgets.getOrCreateWidget(Chat, jid.JID(item), profile=C.PROF_KEY_NONE, on_new_widget=None, on_existing_widget=C.WIDGET_RECREATE))