Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
198:ab239b3b67b3 | 199:39311c7dad77 |
---|---|
206 self.id = data['id'] | 206 self.id = data['id'] |
207 self.content = data['content'] | 207 self.content = data['content'] |
208 self.author = data['author'] | 208 self.author = data['author'] |
209 self.timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here | 209 self.timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here |
210 | 210 |
211 class MicroblogEntry(SimplePanel): | 211 class MicroblogEntry(SimplePanel, ClickHandler): |
212 | 212 |
213 def __init__(self, host, mblog_entry): | 213 def __init__(self, blog_panel, mblog_entry): |
214 SimplePanel.__init__(self) | 214 SimplePanel.__init__(self) |
215 self._blog_panel = blog_panel | |
215 | 216 |
216 self.author = mblog_entry.author | 217 self.author = mblog_entry.author |
217 self.timestamp = mblog_entry.timestamp | 218 self.timestamp = mblog_entry.timestamp |
218 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) | 219 _datetime = datetime.fromtimestamp(mblog_entry.timestamp) |
219 | 220 |
225 </div> | 226 </div> |
226 """ % {"author": html_sanitize(self.author), | 227 """ % {"author": html_sanitize(self.author), |
227 "timestamp": _datetime, | 228 "timestamp": _datetime, |
228 "body": html_sanitize(mblog_entry.content) | 229 "body": html_sanitize(mblog_entry.content) |
229 }) | 230 }) |
230 self.avatar = Image(host.getAvatar(self.author)) | 231 self.avatar = Image(blog_panel.host.getAvatar(self.author)) |
231 self.panel.add(self.avatar, "id_avatar") | 232 self.panel.add(self.avatar, "id_avatar") |
232 self.panel.setStyleName('mb_entry') | 233 self.panel.setStyleName('mb_entry') |
233 self.add(self.panel) | 234 self.add(self.panel) |
235 ClickHandler.__init__(self) | |
236 self.addClickListener(self) | |
234 | 237 |
235 def updateAvatar(self, new_avatar): | 238 def updateAvatar(self, new_avatar): |
236 """Change the avatar of the entry | 239 """Change the avatar of the entry |
237 @param new_avatar: path to the new image""" | 240 @param new_avatar: path to the new image""" |
238 self.avatar.setUrl(new_avatar) | 241 self.avatar.setUrl(new_avatar) |
242 | |
243 def onClick(self, sender): | |
244 print "microblog entry selected (author=%s)" % self.author | |
245 self._blog_panel.setSelectedEntry(self) | |
239 | 246 |
240 | 247 |
241 class MicroblogPanel(base_widget.LiberviaWidget): | 248 class MicroblogPanel(base_widget.LiberviaWidget): |
242 | 249 |
243 def __init__(self, host, accepted_groups): | 250 def __init__(self, host, accepted_groups): |
244 """Panel used to show microblog | 251 """Panel used to show microblog |
245 @param accepted_groups: groups displayed in this panel, if empty, show all microblogs from all contacts | 252 @param accepted_groups: groups displayed in this panel, if empty, show all microblogs from all contacts |
246 """ | 253 """ |
247 base_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups)) | 254 base_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups), selectable = True) |
248 #base_widget.ScrollPanelWrapper.__init__(self) | 255 #base_widget.ScrollPanelWrapper.__init__(self) |
249 #DropCell.__init__(self) | 256 #DropCell.__init__(self) |
250 self.accepted_groups = accepted_groups | 257 self.accepted_groups = accepted_groups |
251 self.entries = {} | 258 self.entries = {} |
259 self.selected_entry = None | |
252 self.vpanel = VerticalPanel() | 260 self.vpanel = VerticalPanel() |
253 self.vpanel.setStyleName('microblogPanel') | 261 self.vpanel.setStyleName('microblogPanel') |
254 self.setWidget(self.vpanel) | 262 self.setWidget(self.vpanel) |
255 | 263 |
256 @classmethod | 264 @classmethod |
298 """Add an entry to the panel | 306 """Add an entry to the panel |
299 @param mblog_entry: MicroblogItem instance | 307 @param mblog_entry: MicroblogItem instance |
300 """ | 308 """ |
301 if mblog_entry.id in self.entries: | 309 if mblog_entry.id in self.entries: |
302 return | 310 return |
303 _entry = MicroblogEntry(self.host, mblog_entry) | 311 _entry = MicroblogEntry(self, mblog_entry) |
304 self.entries[mblog_entry.id] = _entry | 312 self.entries[mblog_entry.id] = _entry |
305 | 313 |
306 # we look for the right index to insert our entry: | 314 # we look for the right index to insert our entry: |
307 # we insert the entry above the first entry | 315 # we insert the entry above the first entry |
308 # in the past | 316 # in the past |
312 break | 320 break |
313 if child.timestamp < mblog_entry.timestamp: | 321 if child.timestamp < mblog_entry.timestamp: |
314 break | 322 break |
315 idx+=1 | 323 idx+=1 |
316 self.vpanel.insert(_entry,idx) | 324 self.vpanel.insert(_entry,idx) |
325 | |
326 def setSelectedEntry(self, entry): | |
327 if self.selected_entry == entry: | |
328 entry = None | |
329 if self.selected_entry: | |
330 self.selected_entry.removeStyleName('selected_entry') | |
331 if entry: | |
332 entry.addStyleName('selected_entry') | |
333 self.selected_entry = entry | |
334 | |
317 | 335 |
318 def updateValue(self, type, jid, value): | 336 def updateValue(self, type, jid, value): |
319 """Update a jid value in entries | 337 """Update a jid value in entries |
320 @param type: one of 'avatar', 'nick' | 338 @param type: one of 'avatar', 'nick' |
321 @param jid: jid concerned | 339 @param jid: jid concerned |