Mercurial > libervia-web
diff browser_side/panels.py @ 199:39311c7dad77
browser side: it is now possible to select a microblog panel or an entry inside it
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 20 Mar 2013 23:42:53 +0100 |
parents | dd27072d8ae0 |
children | 0f5c2f799913 |
line wrap: on
line diff
--- a/browser_side/panels.py Thu Mar 07 01:16:13 2013 +0100 +++ b/browser_side/panels.py Wed Mar 20 23:42:53 2013 +0100 @@ -208,10 +208,11 @@ self.author = data['author'] self.timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here -class MicroblogEntry(SimplePanel): +class MicroblogEntry(SimplePanel, ClickHandler): - def __init__(self, host, mblog_entry): + def __init__(self, blog_panel, mblog_entry): SimplePanel.__init__(self) + self._blog_panel = blog_panel self.author = mblog_entry.author self.timestamp = mblog_entry.timestamp @@ -227,15 +228,21 @@ "timestamp": _datetime, "body": html_sanitize(mblog_entry.content) }) - self.avatar = Image(host.getAvatar(self.author)) + self.avatar = Image(blog_panel.host.getAvatar(self.author)) self.panel.add(self.avatar, "id_avatar") self.panel.setStyleName('mb_entry') self.add(self.panel) + ClickHandler.__init__(self) + self.addClickListener(self) def updateAvatar(self, new_avatar): """Change the avatar of the entry @param new_avatar: path to the new image""" self.avatar.setUrl(new_avatar) + + def onClick(self, sender): + print "microblog entry selected (author=%s)" % self.author + self._blog_panel.setSelectedEntry(self) class MicroblogPanel(base_widget.LiberviaWidget): @@ -244,11 +251,12 @@ """Panel used to show microblog @param accepted_groups: groups displayed in this panel, if empty, show all microblogs from all contacts """ - base_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups)) + base_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups), selectable = True) #base_widget.ScrollPanelWrapper.__init__(self) #DropCell.__init__(self) self.accepted_groups = accepted_groups self.entries = {} + self.selected_entry = None self.vpanel = VerticalPanel() self.vpanel.setStyleName('microblogPanel') self.setWidget(self.vpanel) @@ -300,7 +308,7 @@ """ if mblog_entry.id in self.entries: return - _entry = MicroblogEntry(self.host, mblog_entry) + _entry = MicroblogEntry(self, mblog_entry) self.entries[mblog_entry.id] = _entry # we look for the right index to insert our entry: @@ -315,6 +323,16 @@ idx+=1 self.vpanel.insert(_entry,idx) + def setSelectedEntry(self, entry): + if self.selected_entry == entry: + entry = None + if self.selected_entry: + self.selected_entry.removeStyleName('selected_entry') + if entry: + entry.addStyleName('selected_entry') + self.selected_entry = entry + + def updateValue(self, type, jid, value): """Update a jid value in entries @param type: one of 'avatar', 'nick'