annotate src/browser/sat_browser/blog.py @ 633:617f7a5c5312 frontends_multi_profiles

browser side (contact list): use of c.bool for parameter conversion
author Goffi <goffi@goffi.org>
date Mon, 23 Feb 2015 18:43:15 +0100
parents 5baca9d46c34
children 2c41ce0c3b3f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
4 # Libervia: a Salut à Toi frontend
340
ce5b33f499c5 dates update
Goffi <goffi@goffi.org>
parents: 339
diff changeset
5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org>
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
10 # (at your option) any later version.
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
15 # GNU Affero General Public License for more details.
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 334
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
19
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
20 import pyjd # this is dummy in pyjs
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
21 from sat.core.log import getLogger
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
22 log = getLogger(__name__)
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 442
diff changeset
23
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 442
diff changeset
24 from sat.core.i18n import _
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 442
diff changeset
25
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.SimplePanel import SimplePanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.VerticalPanel import VerticalPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pyjamas.ui.HorizontalPanel import HorizontalPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from pyjamas.ui.HTMLPanel import HTMLPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from pyjamas.ui.Label import Label
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
31 from pyjamas.ui.Button import Button
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
32 from pyjamas.ui.HTML import HTML
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
33 from pyjamas.ui.Image import Image
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
34 from pyjamas.ui.ClickListener import ClickHandler
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
35 from pyjamas.ui.FlowPanel import FlowPanel
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
36 from pyjamas.ui.KeyboardListener import KEY_ENTER, KeyboardHandler
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
37 from pyjamas.ui.FocusListener import FocusHandler
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
38 from pyjamas.Timer import Timer
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
39
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
40 from datetime import datetime
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
41 from time import time
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 442
diff changeset
42
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 463
diff changeset
43 import html_tools
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 463
diff changeset
44 import base_panels
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 442
diff changeset
45 import dialog
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 442
diff changeset
46 import base_widget
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 442
diff changeset
47 import richtext
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
48 from constants import Const as C
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
49 from sat_frontends.quick_frontend import quick_widgets
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
50 from sat_frontends.tools import jid
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
51
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
52 # TODO: at some point we should decide which behaviors to keep and remove these two constants
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
53 TOGGLE_EDITION_USE_ICON = False # set to True to use an icon inside the "toggle syntax" button
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
54 NEW_MESSAGE_USE_BUTTON = False # set to True to display the "New message" button instead of an empty entry
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
55
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
56 unicode = str # XXX: pyjamas doesn't manage unicode
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
57
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
58
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
59 class MicroblogItem():
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
60 # XXX: should be moved in a separated module
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
61
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
62 def __init__(self, data):
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
63 self.id = data['id']
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
64 self.type = data.get('type', 'main_item')
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
65 self.empty = data.get('new', False)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
66 self.title = data.get('title', '')
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
67 self.title_xhtml = data.get('title_xhtml', '')
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
68 self.content = data.get('content', '')
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
69 self.content_xhtml = data.get('content_xhtml', '')
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
70 self.author = jid.JID(data['author'])
307
44b46db7dfef browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents: 306
diff changeset
71 self.updated = float(data.get('updated', 0)) # XXX: int doesn't work here
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
72 self.published = float(data.get('published', self.updated)) # XXX: int doesn't work here
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
73 self.service = data.get('service', '')
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
74 self.node = data.get('node', '')
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
75 self.comments = data.get('comments', False)
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
76 self.comments_service = data.get('comments_service', '')
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
77 self.comments_node = data.get('comments_node', '')
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
78
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
79
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
80 class MicroblogEntry(SimplePanel, ClickHandler, FocusHandler, KeyboardHandler):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
81
350
f1b9ec412769 browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents: 349
diff changeset
82 def __init__(self, blog_panel, data):
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
83 """
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
84 @param blog_panel: the parent panel
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
85 @param data: dict containing the blog item data, or a MicroblogItem instance.
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
86 """
350
f1b9ec412769 browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents: 349
diff changeset
87 self._base_item = data if isinstance(data, MicroblogItem) else MicroblogItem(data)
f1b9ec412769 browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents: 349
diff changeset
88 for attr in ['id', 'type', 'empty', 'title', 'title_xhtml', 'content', 'content_xhtml',
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
89 'author', 'updated', 'published', 'comments', 'service', 'node',
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
90 'comments_service', 'comments_node']:
350
f1b9ec412769 browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents: 349
diff changeset
91 getter = lambda attr: lambda inst: getattr(inst._base_item, attr)
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
92 setter = lambda attr: lambda inst, value: setattr(inst._base_item, attr, value)
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
93 setattr(MicroblogEntry, attr, property(getter(attr), setter(attr)))
350
f1b9ec412769 browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents: 349
diff changeset
94
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
95 SimplePanel.__init__(self)
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
96 self._blog_panel = blog_panel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
97
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
98 self.panel = FlowPanel()
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
99 self.panel.setStyleName('mb_entry')
307
44b46db7dfef browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents: 306
diff changeset
100
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
101 self.header = HTMLPanel('')
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
102 self.panel.add(self.header)
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
103
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
104 self.entry_actions = VerticalPanel()
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
105 self.entry_actions.setStyleName('mb_entry_actions')
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
106 self.panel.add(self.entry_actions)
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
107
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
108 entry_avatar = SimplePanel()
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
109 entry_avatar.setStyleName('mb_entry_avatar')
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
110 assert isinstance(self.author, jid.JID) # FIXME: temporary
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
111 self.avatar = Image(self._blog_panel.host.getAvatarURL(self.author)) # FIXME: self.author should be initially a jid.JID
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
112 entry_avatar.add(self.avatar)
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
113 self.panel.add(entry_avatar)
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
114
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
115 if TOGGLE_EDITION_USE_ICON:
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
116 self.entry_dialog = HorizontalPanel()
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
117 else:
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
118 self.entry_dialog = VerticalPanel()
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
119 self.entry_dialog.setStyleName('mb_entry_dialog')
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
120 self.panel.add(self.entry_dialog)
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
121
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
122 self.add(self.panel)
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
123 ClickHandler.__init__(self)
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
124 self.addClickListener(self)
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
125
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
126 self.__pub_data = (self.service, self.node, self.id)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
127 self.__setContent()
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
128
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
129 def __setContent(self):
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
130 """Actually set the entry content (header, icons, bubble...)"""
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
131 self.delete_label = self.update_label = self.comment_label = None
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
132 self.bubble = self._current_comment = None
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
133 self.__setHeader()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
134 self.__setBubble()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
135 self.__setIcons()
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
136
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
137 def __setHeader(self):
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
138 """Set the entry header"""
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
139 if self.empty:
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
140 return
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
141 update_text = u" — ✍ " + "<span class='mb_entry_timestamp'>%s</span>" % datetime.fromtimestamp(self.updated)
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
142 self.header.setHTML("""<div class='mb_entry_header'>
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
143 <span class='mb_entry_author'>%(author)s</span> on
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
144 <span class='mb_entry_timestamp'>%(published)s</span>%(updated)s
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
145 </div>""" % {'author': html_tools.html_sanitize(unicode(self.author)),
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
146 'published': datetime.fromtimestamp(self.published),
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
147 'updated': update_text if self.published != self.updated else ''
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
148 }
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
149 )
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
150
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
151 def __setIcons(self):
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
152 """Set the entry icons (delete, update, comment)"""
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
153 if self.empty:
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
154 return
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
155
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
156 def addIcon(label, title):
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
157 label = Label(label)
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
158 label.setTitle(title)
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
159 label.addClickListener(self)
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
160 self.entry_actions.add(label)
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
161 return label
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
162
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
163 if self.comments:
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
164 self.comment_label = addIcon(u"↶", "Comment this message")
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
165 self.comment_label.setStyleName('mb_entry_action_larger')
366
39ae5bf92786 browser_side: allow one blogger to moderate the comments made on his own blog messages.
souliane <souliane@mailoo.org>
parents: 365
diff changeset
166 is_publisher = self.author == self._blog_panel.host.whoami.bare
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
167 if is_publisher:
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
168 self.update_label = addIcon(u"✍", "Edit this message")
366
39ae5bf92786 browser_side: allow one blogger to moderate the comments made on his own blog messages.
souliane <souliane@mailoo.org>
parents: 365
diff changeset
169 if is_publisher or str(self.node).endswith(self._blog_panel.host.whoami.bare):
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
170 self.delete_label = addIcon(u"✗", "Delete this message")
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
171
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
172 def updateAvatar(self, new_avatar):
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
173 """Change the avatar of the entry
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
174 @param new_avatar: path to the new image"""
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
175 self.avatar.setUrl(new_avatar)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
176
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
177 def onClick(self, sender):
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
178 if sender == self:
322
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
179 self._blog_panel.setSelectedEntry(self)
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
180 elif sender == self.delete_label:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
181 self._delete()
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
182 elif sender == self.update_label:
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
183 self.edit(True)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
184 elif sender == self.comment_label:
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
185 self._comment()
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
186
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
187 def __modifiedCb(self, content):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
188 """Send the new content to the backend
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
189 @return: False to restore the original content if a deletion has been cancelled
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
190 """
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
191 if not content['text']: # previous content has been emptied
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
192 self._delete(True)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
193 return False
307
44b46db7dfef browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents: 306
diff changeset
194 extra = {'published': str(self.published)}
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
195 if isinstance(self.bubble, richtext.RichTextEditor):
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
196 # TODO: if the user change his parameters after the message edition started,
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
197 # the message syntax could be different then the current syntax: pass the
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
198 # message syntax in extra for the frontend to use it instead of current syntax.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
199 extra.update({'content_rich': content['text'], 'title': content['title']})
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
200 if self.empty:
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
201 if self.type == 'main_item':
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
202 self._blog_panel.host.bridge.call('sendMblog', None, None, self._blog_panel.accepted_groups, content['text'], extra)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
203 else:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
204 self._blog_panel.host.bridge.call('sendMblogComment', None, self._parent_entry.comments, content['text'], extra)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
205 else:
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
206 self._blog_panel.host.bridge.call('updateMblog', None, self.__pub_data, self.comments, content['text'], extra)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
207 return True
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
208
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
209 def __afterEditCb(self, content):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
210 """Remove the entry if it was an empty one (used for creating a new blog post).
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
211 Data for the actual new blog post will be received from the bridge"""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
212 if self.empty:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
213 self._blog_panel.removeEntry(self.type, self.id)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
214 if self.type == 'main_item': # restore the "New message" button
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
215 self._blog_panel.refresh()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
216 else: # allow to create a new comment
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
217 self._parent_entry._current_comment = None
425
19bd203daa27 browser_side: set microblog editor width to 80%
souliane <souliane@mailoo.org>
parents: 422
diff changeset
218 self.entry_dialog.setWidth('auto')
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
219 try:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
220 self.toggle_syntax_button.removeFromParent()
595
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
221 except (AttributeError, TypeError):
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
222 pass
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
223
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
224 def __setBubble(self, edit=False):
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
225 """Set the bubble displaying the initial content."""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
226 content = {'text': self.content_xhtml if self.content_xhtml else self.content,
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
227 'title': self.title_xhtml if self.title_xhtml else self.title}
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
228 if self.content_xhtml:
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
229 content.update({'syntax': C.SYNTAX_XHTML})
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
230 if self.author != self._blog_panel.host.whoami.bare:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
231 options = ['read_only']
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
232 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
233 options = [] if self.empty else ['update_msg']
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
234 self.bubble = richtext.RichTextEditor(self._blog_panel.host, content, self.__modifiedCb, self.__afterEditCb, options)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
235 else: # assume raw text message have no title
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 463
diff changeset
236 self.bubble = base_panels.LightTextEditor(content, self.__modifiedCb, self.__afterEditCb, options={'no_xhtml': True})
425
19bd203daa27 browser_side: set microblog editor width to 80%
souliane <souliane@mailoo.org>
parents: 422
diff changeset
237 self.bubble.addStyleName("bubble")
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
238 try:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
239 self.toggle_syntax_button.removeFromParent()
595
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
240 except (AttributeError, TypeError):
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
241 pass
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
242 self.entry_dialog.add(self.bubble)
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
243 self.edit(edit)
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
244 self.bubble.addEditListener(self.__showWarning)
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
245
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
246 def __showWarning(self, sender, keycode):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
247 if keycode == KEY_ENTER:
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
248 self._blog_panel.host.showWarning(None, None)
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
249 else:
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
250 self._blog_panel.host.showWarning(*self._blog_panel.getWarningData(self.type == 'comment'))
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
251
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
252 def _delete(self, empty=False):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
253 """Ask confirmation for deletion.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
254 @return: False if the deletion has been cancelled."""
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
255 def confirm_cb(answer):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
256 if answer:
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
257 self._blog_panel.host.bridge.call('deleteMblog', None, self.__pub_data, self.comments)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
258 else: # restore the text if it has been emptied during the edition
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
259 self.bubble.setContent(self.bubble._original_content)
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
260
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
261 if self.empty:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
262 text = _("New ") + (_("message") if self.comments else _("comment")) + _(" without body has been cancelled.")
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
263 dialog.InfoDialog(_("Information"), text).show()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
264 return
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
265 text = ""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
266 if empty:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
267 text = (_("Message") if self.comments else _("Comment")) + _(" body has been emptied.<br/>")
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
268 target = _('message and all its comments') if self.comments else _('comment')
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
269 text += _("Do you really want to delete this %s?") % target
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
270 dialog.ConfirmDialog(confirm_cb, text=text).show()
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
271
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
272 def _comment(self):
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
273 """Add an empty entry for a new comment"""
315
09205b410a53 browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents: 314
diff changeset
274 if self._current_comment:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
275 self._current_comment.bubble.setFocus(True)
496
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
276 self._blog_panel.setSelectedEntry(self._current_comment, True)
315
09205b410a53 browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents: 314
diff changeset
277 return
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
278 data = {'id': str(time()),
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
279 'new': True,
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
280 'type': 'comment',
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
281 'author': unicode(self._blog_panel.host.whoami.bare),
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
282 'service': self.comments_service,
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
283 'node': self.comments_node
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
284 }
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
285 entry = self._blog_panel.addEntry(data)
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
286 if entry is None:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
287 log.info("The entry of id %s can not be commented" % self.id)
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
288 return
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
289 entry._parent_entry = self
315
09205b410a53 browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents: 314
diff changeset
290 self._current_comment = entry
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
291 self.edit(True, entry)
496
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
292 self._blog_panel.setSelectedEntry(entry, True)
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
293
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
294 def edit(self, edit, entry=None):
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
295 """Toggle the bubble between display and edit mode
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
296 @edit: boolean value
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
297 @entry: MicroblogEntry instance, or None to use self
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
298 """
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
299 if entry is None:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
300 entry = self
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
301 try:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
302 entry.toggle_syntax_button.removeFromParent()
595
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
303 except (AttributeError, TypeError):
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
304 pass
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
305 entry.bubble.edit(edit)
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
306 if edit:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
307 if isinstance(entry.bubble, richtext.RichTextEditor):
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
308 image = '<a class="richTextIcon">A</a>'
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
309 html = '<a style="color: blue;">raw text</a>'
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
310 title = _('Switch to raw text edition')
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
311 else:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
312 image = '<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>'
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
313 html = '<a style="color: blue;">rich text</a>'
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
314 title = _('Switch to rich text edition')
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
315 if TOGGLE_EDITION_USE_ICON:
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
316 entry.entry_dialog.setWidth('80%')
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
317 entry.toggle_syntax_button = Button(image, entry.toggleContentSyntax)
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
318 entry.toggle_syntax_button.setTitle(title)
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
319 entry.entry_dialog.add(entry.toggle_syntax_button)
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
320 else:
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
321 entry.toggle_syntax_button = HTML(html)
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
322 entry.toggle_syntax_button.addClickListener(entry.toggleContentSyntax)
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
323 entry.toggle_syntax_button.addStyleName('mb_entry_toggle_syntax')
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
324 entry.entry_dialog.add(entry.toggle_syntax_button)
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
325 entry.toggle_syntax_button.setStyleAttribute('top', '-20px') # XXX: need to force CSS
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
326 entry.toggle_syntax_button.setStyleAttribute('left', '-20px')
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
327
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
328 def toggleContentSyntax(self):
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
329 """Toggle the editor between raw and rich text"""
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
330 original_content = self.bubble.getOriginalContent()
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
331 rich = not isinstance(self.bubble, richtext.RichTextEditor)
400
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 397
diff changeset
332 if rich:
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
333 original_content['syntax'] = C.SYNTAX_XHTML
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
334
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
335 def setBubble(text):
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
336 self.content = text
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
337 self.content_xhtml = text if rich else ''
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
338 self.content_title = self.content_title_xhtml = ''
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
339 self.bubble.removeFromParent()
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
340 self.__setBubble(True)
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
341 self.bubble.setOriginalContent(original_content)
400
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 397
diff changeset
342 if rich:
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 397
diff changeset
343 self.bubble.setDisplayContent() # needed in case the edition is aborted, to not end with an empty bubble
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
344
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
345 text = self.bubble.getContent()['text']
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
346 if not text:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
347 setBubble(' ') # something different than empty string is needed to initialize the rich text editor
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
348 return
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
349 if not rich:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
350 def confirm_cb(answer):
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
351 if answer:
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
352 self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, C.SYNTAX_CURRENT, C.SYNTAX_TEXT)
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
353 dialog.ConfirmDialog(confirm_cb, text=_("Do you really want to lose the title and text formatting?")).show()
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
354 else:
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
355 self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, C.SYNTAX_TEXT, C.SYNTAX_XHTML)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
356
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
357
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
358 class MicroblogPanel(quick_widgets.QuickWidget, base_widget.LiberviaWidget):
499
ec3f30253040 browser_side: also display the warning banner when writing to a single contact and unibox is disabled
souliane <souliane@mailoo.org>
parents: 498
diff changeset
359 warning_msg_public = "This message will be <b>PUBLIC</b> and everybody will be able to see it, even people you don't know"
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
360 warning_msg_group = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>"
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
361 # FIXME: all the generic parts must be moved to quick_frontends
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
362
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
363 def __init__(self, host, accepted_groups, profiles=None):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
364 """Panel used to show microblog
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
365
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
366 @param accepted_groups: groups displayed in this panel, if empty, show all microblogs from all contacts
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
367 """
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
368 self.setAcceptedGroup(accepted_groups)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
369 quick_widgets.QuickWidget.__init__(self, host, self.target, C.PROF_KEY_NONE)
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
370 base_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups), selectable=True)
58
4fa3d57f72f8 browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents: 57
diff changeset
371 self.entries = {}
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
372 self.comments = {}
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
373 self.selected_entry = None
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
374 self.vpanel = VerticalPanel()
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
375 self.vpanel.setStyleName('microblogPanel')
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
376 self.setWidget(self.vpanel)
607
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
377 host.addListerner('avatar', self.onAvatarUpdate)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
378
595
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
379 def __str__(self):
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
380 return u"Blog Widget [target: {}, profile: {}]".format(self.target, self.profile)
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
381
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
382 @property
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
383 def target(self):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
384 return tuple(self.accepted_groups)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
385
607
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
386 def onDelete(self):
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
387 quick_widgets.QuickWidget.onDelete(self)
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
388 self.host.removeListener('avatar', self.onAvatarUpdate)
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
389
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
390 def onAvatarUpdate(self, jid_, hash_, profile):
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
391 """Called on avatar update events
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
392
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
393 @param jid_: jid of the entity with updated avatar
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
394 @param hash_: hash of the avatar
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
395 @param profile: should be C.PROF_KEY_NONE
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
396 """
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
397 whoami = self.host.profiles[self.profile].whoami.bare
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
398 if self.isJidAccepted(jid_) or jid_.bare == whoami.bare:
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
399 self.updateValue('avatar', jid_, hash_)
537649f6a2d0 browser side (blog, contact list): use of new listener mechanism to update avatar
Goffi <goffi@goffi.org>
parents: 606
diff changeset
400
326
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
401 def refresh(self):
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
402 """Refresh the display of this widget. If the unibox is disabled,
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
403 display the 'New message' button or an empty bubble on top of the panel"""
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
404 if hasattr(self, 'new_button'):
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
405 self.new_button.setVisible(self.host.uni_box is None)
326
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
406 return
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
407 if self.host.uni_box is None:
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
408 def addBox():
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
409 if hasattr(self, 'new_button'):
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
410 self.new_button.setVisible(False)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
411 data = {'id': str(time()),
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
412 'new': True,
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
413 'author': unicode(self.host.whoami.bare),
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
414 }
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
415 entry = self.addEntry(data)
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
416 entry.edit(True)
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
417 if NEW_MESSAGE_USE_BUTTON:
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
418 self.new_button = Button("New message", listener=addBox)
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
419 self.new_button.setStyleName("microblogNewButton")
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
420 self.vpanel.insert(self.new_button, 0)
461
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
421 elif not self.getNewMainEntry():
442
17259c2ff96f browser_side: changes about the UI (remarks from Franck):
souliane <souliane@mailoo.org>
parents: 439
diff changeset
422 addBox()
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
423
461
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
424 def getNewMainEntry(self):
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
425 """Get the new entry being edited, or None if it doesn't exists.
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
426
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
427 @return (MicroblogEntry): the new entry being edited.
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
428 """
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
429 try:
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
430 first = self.vpanel.children[0]
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
431 except IndexError:
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
432 return None
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
433 assert(first.type == 'main_item')
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
434 return first if first.empty else None
4f25aa5039b3 browser_side: avoid adding more than one new message bubble on top of the microblog panel
souliane <souliane@mailoo.org>
parents: 451
diff changeset
435
598
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
436 @staticmethod
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
437 def onGroupDrop(host, item):
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
438 """Generic panel creation for one, several or all groups (meta).
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
439
617
5baca9d46c34 browser_side: add/improve some docstrings
souliane <souliane@mailoo.org>
parents: 616
diff changeset
440 @param host (SatWebFrontend): the SatWebFrontend instance
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
441 @param item: single group as a string, list of groups
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
442 (as an array) or None (for the meta group = "all groups")
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
443 @return: the created MicroblogPanel
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
444 """
597
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
445 items_ = tuple(item) if isinstance(item, list) else (() if item is None else (item,))
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
446 type_ = 'ALL' if items_ == () else 'GROUP'
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
447 # XXX: pyjamas doesn't support use of cls directly
616
1c0d5a87c554 browser_side: add and use method displayWidget to harmonize widget's management in Libervia (not completely done, there are some issues)
souliane <souliane@mailoo.org>
parents: 607
diff changeset
448 widget = host.displayWidget(MicroblogPanel, items_, dropped=True)
598
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
449 host.FillMicroblogPanel(widget)
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
450 host.bridge.getMassiveLastMblogs(type_, items_, 10, profile=C.PROF_KEY_NONE, callback=widget.massiveInsert)
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
451 widget.refresh() # FIXME: needed ?
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
452 return widget
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
453
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
454 @property
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
455 def accepted_groups(self):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
456 return self._accepted_groups
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
457
574
b07f0fe2763a browser_side: safer attributes handling in getOrCreateLiberviaWidget + use it to create MUC panels
souliane <souliane@mailoo.org>
parents: 573
diff changeset
458 def matchEntity(self, item):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
459 """
574
b07f0fe2763a browser_side: safer attributes handling in getOrCreateLiberviaWidget + use it to create MUC panels
souliane <souliane@mailoo.org>
parents: 573
diff changeset
460 @param item: single group as a string, list of groups
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
461 (as an array) or None (for the meta group = "all groups")
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
462 @return: True if self matches the given entity
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
463 """
574
b07f0fe2763a browser_side: safer attributes handling in getOrCreateLiberviaWidget + use it to create MUC panels
souliane <souliane@mailoo.org>
parents: 573
diff changeset
464 groups = item if isinstance(item, list) else ([] if item is None else [item])
b07f0fe2763a browser_side: safer attributes handling in getOrCreateLiberviaWidget + use it to create MUC panels
souliane <souliane@mailoo.org>
parents: 573
diff changeset
465 groups.sort() # sort() do not return the sorted list: do it here, not on the "return" line
b07f0fe2763a browser_side: safer attributes handling in getOrCreateLiberviaWidget + use it to create MUC panels
souliane <souliane@mailoo.org>
parents: 573
diff changeset
466 return self.accepted_groups == groups
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
467
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
468 def getWarningData(self, comment=None):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
469 """
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
470 @param comment: True if the composed message is a comment. If None, consider we are
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
471 composing from the unibox and guess the message type from self.selected_entry
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
472 @return: a couple (type, msg) for calling self.host.showWarning"""
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
473 if comment is None: # composing from the unibox
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
474 if self.selected_entry and not self.selected_entry.comments:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
475 log.error("an item without comment is selected")
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
476 return ("NONE", None)
362
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
477 comment = self.selected_entry is not None
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 361
diff changeset
478 if comment:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
479 return ("PUBLIC", "This is a <span class='warningTarget'>comment</span> and keep the initial post visibility, so it is potentialy public")
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
480 elif not self._accepted_groups:
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
481 # we have a meta MicroblogPanel, we publish publicly
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
482 return ("PUBLIC", self.warning_msg_public)
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
483 else:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
484 # we only accept one group at the moment
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
485 # FIXME: manage several groups
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
486 return ("GROUP", self.warning_msg_group % self._accepted_groups[0])
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
487
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
488 def onTextEntered(self, text):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
489 if self.selected_entry:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
490 # we are entering a comment
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
491 comments_url = self.selected_entry.comments
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
492 if not comments_url:
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
493 raise Exception("ERROR: the comments URL is empty")
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
494 target = ("COMMENT", comments_url)
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
495 elif not self._accepted_groups:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
496 # we are entering a public microblog
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
497 target = ("PUBLIC", None)
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
498 else:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
499 # we are entering a microblog restricted to a group
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
500 # FIXME: manage several groups
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
501 target = ("GROUP", self._accepted_groups[0])
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
502 self.host.send([target], text)
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
503
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
504 def accept_all(self):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
505 return not self._accepted_groups # we accept every microblog only if we are not filtering by groups
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
506
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
507 def getEntries(self):
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
508 """Ask all the entries for the currenly accepted groups,
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
509 and fill the panel"""
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
510
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
511 def massiveInsert(self, mblogs):
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
512 """Insert several microblogs at once
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
513 @param mblogs: dictionary of microblogs, as the result of getMassiveLastGroupBlogs
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
514 """
579
4a0f2f294ea2 browser_side (blogs): massive insertion display the actual number of blogs being inserted
souliane <souliane@mailoo.org>
parents: 577
diff changeset
515 count = sum([len(value) for value in mblogs.values()])
4a0f2f294ea2 browser_side (blogs): massive insertion display the actual number of blogs being inserted
souliane <souliane@mailoo.org>
parents: 577
diff changeset
516 log.debug("Massive insertion of %d microblogs" % count)
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
517 for publisher in mblogs:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
518 log.debug("adding blogs for [%s]" % publisher)
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
519 for mblog in mblogs[publisher]:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
520 if not "content" in mblog:
580
79fbc20c786b browser_side: fixes call to logging method with more than one argument
souliane <souliane@mailoo.org>
parents: 579
diff changeset
521 log.warning("No content found in microblog [%s]" % mblog)
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
522 continue
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
523 self.addEntry(mblog)
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
524
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
525 def mblogsInsert(self, mblogs):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
526 """ Insert several microblogs at once
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
527 @param mblogs: list of microblogs
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
528 """
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
529 for mblog in mblogs:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
530 if not "content" in mblog:
580
79fbc20c786b browser_side: fixes call to logging method with more than one argument
souliane <souliane@mailoo.org>
parents: 579
diff changeset
531 log.warning("No content found in microblog [%s]" % mblog)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
532 continue
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
533 self.addEntry(mblog)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
534
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
535 def _chronoInsert(self, vpanel, entry, reverse=True):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
536 """ Insert an entry in chronological order
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
537 @param vpanel: VerticalPanel instance
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
538 @param entry: MicroblogEntry
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
539 @param reverse: more recent entry on top if True, chronological order else"""
463
b62c1cf0dbf7 browser side: a new message being edited should always stay on top position (or last position for a comment)
souliane <souliane@mailoo.org>
parents: 462
diff changeset
540 assert(isinstance(reverse, bool))
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
541 if entry.empty:
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
542 entry.published = time()
135
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
543 # we look for the right index to insert our entry:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
544 # if reversed, we insert the entry above the first entry
135
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
545 # in the past
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
546 idx = 0
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
547
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
548 for child in vpanel.children:
135
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
549 if not isinstance(child, MicroblogEntry):
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
550 idx += 1
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
551 continue
463
b62c1cf0dbf7 browser side: a new message being edited should always stay on top position (or last position for a comment)
souliane <souliane@mailoo.org>
parents: 462
diff changeset
552 condition_to_stop = child.empty or (child.published > entry.published)
b62c1cf0dbf7 browser side: a new message being edited should always stay on top position (or last position for a comment)
souliane <souliane@mailoo.org>
parents: 462
diff changeset
553 if condition_to_stop != reverse: # != is XOR
b62c1cf0dbf7 browser side: a new message being edited should always stay on top position (or last position for a comment)
souliane <souliane@mailoo.org>
parents: 462
diff changeset
554 break
210
3092f6b1710c browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 206
diff changeset
555 idx += 1
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
556
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
557 vpanel.insert(entry, idx)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
558
597
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
559
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
560 def addEntryIfAccepted(self, sender, groups, mblog_entry):
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
561 """Check if an entry can go in MicroblogPanel and add to it
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
562
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
563 @param sender(jid.JID): jid of the entry sender
597
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
564 @param groups: groups which can receive this entry
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
565 @param mblog_entry: panels.MicroblogItem instance
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
566 """
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
567 assert isinstance(sender, jid.JID) # FIXME temporary
597
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
568 if (mblog_entry.type == "comment"
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
569 or self.isJidAccepted(sender)
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
570 or (groups == None and sender == self.host.profiles[self.profile].whoami.bare)
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
571 or (groups and groups.intersection(self.accepted_groups))):
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
572 self.addEntry(mblog_entry)
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
573
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
574 def addEntry(self, data, ignore_invalid=False):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
575 """Add an entry to the panel
597
be2891462e63 browser side (blog): added addEntryIfAccepeted method in MicroblogPanel, so it decide itself is an entry should be added, it's not done anymore in libervia_main.
Goffi <goffi@goffi.org>
parents: 595
diff changeset
576
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
577 @param data: dict containing the item data
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
578 @return: the added entry, or None
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
579 """
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
580 _entry = MicroblogEntry(self, data)
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
581 if _entry.type == "comment":
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
582 comments_hash = (_entry.service, _entry.node)
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
583 if not comments_hash in self.comments:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
584 # The comments node is not known in this panel
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
585 return None
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
586 parent = self.comments[comments_hash]
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
587 parent_idx = self.vpanel.getWidgetIndex(parent)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
588 # we find or create the panel where the comment must be inserted
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
589 try:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
590 sub_panel = self.vpanel.getWidget(parent_idx + 1)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
591 except IndexError:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
592 sub_panel = None
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
593 if not sub_panel or not isinstance(sub_panel, VerticalPanel):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
594 sub_panel = VerticalPanel()
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
595 sub_panel.setStyleName('microblogPanel')
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
596 sub_panel.addStyleName('subPanel')
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
597 self.vpanel.insert(sub_panel, parent_idx + 1)
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
598 for idx in xrange(0, len(sub_panel.getChildren())):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
599 comment = sub_panel.getIndexedChild(idx)
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
600 if comment.id == _entry.id:
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
601 # update an existing comment
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
602 sub_panel.remove(comment)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
603 sub_panel.insert(_entry, idx)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
604 return _entry
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
605 # we want comments to be inserted in chronological order
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
606 self._chronoInsert(sub_panel, _entry, reverse=False)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
607 return _entry
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
608
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
609 if _entry.id in self.entries: # update
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
610 idx = self.vpanel.getWidgetIndex(self.entries[_entry.id])
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
611 self.vpanel.remove(self.entries[_entry.id])
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
612 self.vpanel.insert(_entry, idx)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
613 else: # new entry
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
614 self._chronoInsert(self.vpanel, _entry)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
615 self.entries[_entry.id] = _entry
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
616
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
617 if _entry.comments:
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
618 # entry has comments, we keep the comments service/node as a reference
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
619 comments_hash = (_entry.comments_service, _entry.comments_node)
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
620 self.comments[comments_hash] = _entry
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
621 self.host.bridge.call('getMblogComments', self.mblogsInsert, _entry.comments_service, _entry.comments_node)
312
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
622
b4781a350483 browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
souliane <souliane@mailoo.org>
parents: 311
diff changeset
623 return _entry
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
624
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
625 def removeEntry(self, type_, id_):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
626 """Remove an entry from the panel
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
627 @param type_: entry type ('main_item' or 'comment')
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
628 @param id_: entry id
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
629 """
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
630 for child in self.vpanel.getChildren():
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
631 if isinstance(child, MicroblogEntry) and type_ == 'main_item':
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
632 if child.id == id_:
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
633 main_idx = self.vpanel.getWidgetIndex(child)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
634 try:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
635 sub_panel = self.vpanel.getWidget(main_idx + 1)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
636 if isinstance(sub_panel, VerticalPanel):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
637 sub_panel.removeFromParent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
638 except IndexError:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
639 pass
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
640 child.removeFromParent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
641 self.selected_entry = None
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
642 break
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
643 elif isinstance(child, VerticalPanel) and type_ == 'comment':
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
644 for comment in child.getChildren():
365
a74a2dfbe4f5 browser_side: groupblog: handle main items with no associated comments node + do not mix up attributes names between the item own service/node and the comments service/node
souliane <souliane@mailoo.org>
parents: 362
diff changeset
645 if comment.id == id_:
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
646 comment.removeFromParent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
647 self.selected_entry = None
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
648 break
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
649
496
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
650 def ensureVisible(self, entry):
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
651 """Scroll to an entry to ensure its visibility
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
652
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
653 @param entry (MicroblogEntry): the entry
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
654 """
322
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
655 try:
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
656 self.vpanel.getParent().ensureVisible(entry) # scroll to the clicked entry
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
657 except AttributeError:
439
d52f529a6d42 browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents: 433
diff changeset
658 log.warning("FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!")
496
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
659
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
660 def setSelectedEntry(self, entry, ensure_visible=False):
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
661 """Select an entry.
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
662
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
663 @param entry (MicroblogEntry): the entry to select
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
664 @param ensure_visible (boolean): if True, also scroll to the entry
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
665 """
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
666 if ensure_visible:
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
667 self.ensureVisible(entry)
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
668
322
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
669 if not self.host.uni_box or not entry.comments:
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
670 entry.addStyleName('selected_entry') # blink the clicked entry
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
671 clicked_entry = entry # entry may be None when the timer is done
496
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
672 Timer(500, lambda timer: clicked_entry.removeStyleName('selected_entry'))
322
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
673 if not self.host.uni_box:
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
674 return # unibox is disabled
496
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
675
322
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
676 # from here the previous behavior (toggle main item selection) is conserved
971e3812903a browser_side: scroll to the clicked microblog post and blink it (previous behavior is conserved when the unibox is enabled)
souliane <souliane@mailoo.org>
parents: 319
diff changeset
677 entry = entry if entry.comments else None
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
678 if self.selected_entry == entry:
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
679 entry = None
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
680 if self.selected_entry:
496
0924710b666a browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents: 495
diff changeset
681 self.selected_entry.removeStyleName('selected_entry')
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
682 if entry:
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
683 log.debug("microblog entry selected (author=%s)" % unicode(entry.author))
199
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
684 entry.addStyleName('selected_entry')
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
685 self.selected_entry = entry
39311c7dad77 browser side: it is now possible to select a microblog panel or an entry inside it
Goffi <goffi@goffi.org>
parents: 195
diff changeset
686
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
687 def updateValue(self, type_, jid_, value):
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
688 """Update a jid value in entries
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
689
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
690 @param type_: one of 'avatar', 'nick'
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
691 @param jid_(jid.JID): jid concerned
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
692 @param value: new value"""
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
693 assert isinstance(jid_, jid.JID) # FIXME: temporary
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
694 def updateVPanel(vpanel):
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
695 avatar_url = self.host.getAvatarURL(jid_)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
696 for child in vpanel.children:
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
697 if isinstance(child, MicroblogEntry) and child.author == jid_:
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
698 child.updateAvatar(avatar_url)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
699 elif isinstance(child, VerticalPanel):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
700 updateVPanel(child)
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
701 if type_ == 'avatar':
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
702 updateVPanel(self.vpanel)
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
703
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
704 def setAcceptedGroup(self, group):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
705 """Add one or more group(s) which can be displayed in this panel.
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
706
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
707 Prevent from duplicate values and keep the list sorted.
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
708 @param group: string of the group, or list of string
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
709 """
589
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
710 if isinstance(group, basestring):
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
711 groups = [group]
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
712 else:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
713 groups = list(group)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
714 try:
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
715 self._accepted_groups.extend(groups)
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
716 except (AttributeError, TypeError): # XXX: should be AttributeError, but pyjamas bugs here
a5019e62c3e9 browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents: 585
diff changeset
717 self._accepted_groups = groups
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
718 self._accepted_groups.sort()
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
719
595
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
720 def isJidAccepted(self, jid_):
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
721 """Tell if a jid is actepted and must be shown in this panel
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
722
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
723 @param jid_(jid.JID): jid to check
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
724 @return: True if the jid is accepted
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
725 """
606
7af8f4ab3675 browser side: fixed avatar getting + better DEFAULT/EMPTY avatars constants + use of jid.JID for microblog's author
Goffi <goffi@goffi.org>
parents: 598
diff changeset
726 assert isinstance(jid_, jid.JID) # FIXME temporary
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
727 if self.accept_all():
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
728 return True
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
729 for group in self._accepted_groups:
595
d78126d82ca0 browser side (blog module): fixed isJidAccepted + added __str__ method to facilitate debugging + use of AttributeError and TypeError in some exception (because pyjamas can raise both depending on compilation options)
Goffi <goffi@goffi.org>
parents: 589
diff changeset
730 if self.host.contact_lists[self.profile].isEntityInGroup(jid_, group):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
731 return True
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
732 return False
598
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
733
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
734
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
735 base_widget.LiberviaWidget.addDropKey("GROUP", MicroblogPanel.onGroupDrop)
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
736
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
737 # Needed for the drop keys to not be mixed between meta panel and panel for "Contacts" group
ed6d8f7c6026 browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents: 597
diff changeset
738 base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", lambda host, item: MicroblogPanel.onGroupDrop(host, None))