annotate browser_side/panels.py @ 432:8ecc5a7062e4

browser and server sides: fixes module import + use enumerate instead of xrange
author souliane <souliane@mailoo.org>
date Sun, 27 Apr 2014 18:53:37 +0200
parents 77d8f55fc5f0
children bbdbee25123a
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
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from pyjamas.ui.SimplePanel import SimplePanel
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
22 from pyjamas.ui.AbsolutePanel import AbsolutePanel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.VerticalPanel import VerticalPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from pyjamas.ui.HorizontalPanel import HorizontalPanel
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.HTMLPanel import HTMLPanel
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
26 from pyjamas.ui.Frame import Frame
73
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
27 from pyjamas.ui.TextArea import TextArea
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pyjamas.ui.Label import Label
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
29 from pyjamas.ui.Button import Button
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
30 from pyjamas.ui.HTML import HTML
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
31 from pyjamas.ui.Image import Image
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
32 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
33 from pyjamas.ui.FlowPanel import FlowPanel
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
34 from pyjamas.ui.KeyboardListener import KEY_ENTER, KEY_UP, KEY_DOWN, KeyboardHandler
186
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
35 from pyjamas.ui.MouseListener import MouseHandler
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
36 from pyjamas.ui.FocusListener import FocusHandler
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
37 from pyjamas.Timer import Timer
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
38 from pyjamas import DOM
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
39 from pyjamas import Window
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
40 from __pyjamas__ import doc
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
41
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
42 from datetime import datetime
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
43 from time import time
370
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 366
diff changeset
44 from jid import JID
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 366
diff changeset
45
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 366
diff changeset
46 from html_tools import html_sanitize
401
ea03f898067f browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents: 400
diff changeset
47 from base_panels import ChatText, OccupantsList, PopupMenuPanel, BaseTextEditor, LightTextEditor, HTMLTextEditor
78
12680e220b35 browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents: 75
diff changeset
48 from card_game import CardPanel
127
e19a8de8b3de radio collective first draft
Goffi <goffi@goffi.org>
parents: 123
diff changeset
49 from radiocol import RadioColPanel
78
12680e220b35 browser side: refactoring: menu is now in its own module
Goffi <goffi@goffi.org>
parents: 75
diff changeset
50 from menu import Menu
432
8ecc5a7062e4 browser and server sides: fixes module import + use enumerate instead of xrange
souliane <souliane@mailoo.org>
parents: 426
diff changeset
51 from browser_side import dialog
8ecc5a7062e4 browser and server sides: fixes module import + use enumerate instead of xrange
souliane <souliane@mailoo.org>
parents: 426
diff changeset
52 from browser_side import base_widget
8ecc5a7062e4 browser and server sides: fixes module import + use enumerate instead of xrange
souliane <souliane@mailoo.org>
parents: 426
diff changeset
53 from browser_side import richtext
8ecc5a7062e4 browser and server sides: fixes module import + use enumerate instead of xrange
souliane <souliane@mailoo.org>
parents: 426
diff changeset
54 from browser_side import contact
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
55
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
56 from constants import Const
223
624a87377412 browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents: 218
diff changeset
57 from plugin_xep_0085 import ChatStateMachine
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
58 from sat_frontends.tools.strings import addURLToText
276
aebb96bfa8d1 frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents: 275
diff changeset
59 from sat_frontends.tools.games import SYMBOLS
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
60 from sat.core.i18n import _
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
61
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
62
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
63 class UniBoxPanel(HorizontalPanel):
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
64 """Panel containing the UniBox"""
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
65
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
66 def __init__(self, host):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
67 HorizontalPanel.__init__(self)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
68 self.host = host
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
69 self.setStyleName('uniBoxPanel')
309
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 307
diff changeset
70 self.unibox = None
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
71
326
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
72 def refresh(self):
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
73 """Enable or disable this panel. Contained widgets are created when necessary."""
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
74 enable = self.host.params_ui['unibox']['value']
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
75 self.setVisible(enable)
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
76 if enable and not self.unibox:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
77 self.button = Button('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>')
309
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 307
diff changeset
78 self.button.setTitle('Open the rich text editor')
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 307
diff changeset
79 self.button.addStyleName('uniBoxButton')
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 307
diff changeset
80 self.add(self.button)
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 307
diff changeset
81 self.unibox = UniBox(self.host)
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 307
diff changeset
82 self.add(self.unibox)
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 307
diff changeset
83 self.setCellWidth(self.unibox, '100%')
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
84 self.button.addClickListener(self.openRichMessageEditor)
309
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 307
diff changeset
85 self.unibox.addKey("@@: ")
380
5e0e2032928c browser_side: bug fixes microblogs:
souliane <souliane@mailoo.org>
parents: 370
diff changeset
86 self.unibox.onSelectedChange(self.host.getSelected())
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
87
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
88 def openRichMessageEditor(self):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
89 """Open the rich text editor."""
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
90 self.button.setVisible(False)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
91 self.unibox.setVisible(False)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
92 self.setCellWidth(self.unibox, '0px')
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
93 self.host.panel._contactsMove(self)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
94
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
95 def afterEditCb():
292
1a5dc08c2749 browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents: 291
diff changeset
96 Window.removeWindowResizeListener(self)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
97 self.host.panel._contactsMove(self.host.panel._hpanel)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
98 self.setCellWidth(self.unibox, '100%')
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
99 self.button.setVisible(True)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
100 self.unibox.setVisible(True)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
101 self.host.resize()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
102
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
103 richtext.RichMessageEditor.getOrCreate(self.host, self, afterEditCb)
292
1a5dc08c2749 browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents: 291
diff changeset
104 Window.addWindowResizeListener(self)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
105 self.host.resize()
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
106
292
1a5dc08c2749 browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents: 291
diff changeset
107 def onWindowResized(self, width, height):
1a5dc08c2749 browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents: 291
diff changeset
108 right = self.host.panel.menu.getAbsoluteLeft() + self.host.panel.menu.getOffsetWidth()
1a5dc08c2749 browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents: 291
diff changeset
109 left = self.host.panel._contacts.getAbsoluteLeft() + self.host.panel._contacts.getOffsetWidth()
1a5dc08c2749 browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents: 291
diff changeset
110 ideal_width = right - left - 40
1a5dc08c2749 browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents: 291
diff changeset
111 self.host.richtext.setWidth("%spx" % ideal_width)
1a5dc08c2749 browser_side: set the ideal width for the rich text dialog when displayed in the unibox panel
souliane <souliane@mailoo.org>
parents: 291
diff changeset
112
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
113
310
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
114 class MessageBox(TextArea):
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
115 """A basic text area for entering messages"""
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
116
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
117 def __init__(self, host):
73
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
118 TextArea.__init__(self)
310
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
119 self.host = host
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
120 self.__size = (0, 0)
310
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
121 self.setStyleName('messageBox')
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
122 self.addKeyboardListener(self)
186
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
123 MouseHandler.__init__(self)
72bb1d845b6a browser side: global resize on UniBox resize
Goffi <goffi@goffi.org>
parents: 185
diff changeset
124 self.addMouseListener(self)
193
f2ae8e170c49 browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents: 192
diff changeset
125 self._selected_cache = None
310
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
126
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
127 def onBrowserEvent(self, event):
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
128 # XXX: woraroung a pyjamas bug: self.currentEvent is not set
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
129 # so the TextBox's cancelKey doens't work. This is a workaround
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
130 # FIXME: fix the bug upstream
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
131 self.currentEvent = event
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
132 TextArea.onBrowserEvent(self, event)
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
133
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
134 def onKeyPress(self, sender, keycode, modifiers):
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
135 _txt = self.getText()
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
136
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
137 def history_cb(text):
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
138 self.setText(text)
422
20c508f9b32a browser side: fixed bad use of Timer
Goffi <goffi@goffi.org>
parents: 414
diff changeset
139 Timer(5, lambda timer: self.setCursorPos(len(text)))
310
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
140
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
141 if keycode == KEY_ENTER:
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
142 if _txt:
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
143 self._selected_cache.onTextEntered(_txt)
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
144 self.host._updateInputHistory(_txt)
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
145 self.setText('')
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
146 sender.cancelKey()
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
147 elif keycode == KEY_UP:
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
148 self.host._updateInputHistory(_txt, -1, history_cb)
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
149 elif keycode == KEY_DOWN:
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
150 self.host._updateInputHistory(_txt, +1, history_cb)
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
151 else:
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
152 self.__onComposing()
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
153
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
154 def __onComposing(self):
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
155 """Callback when the user is composing a text."""
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
156 if hasattr(self._selected_cache, "target"):
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
157 self._selected_cache.state_machine._onEvent("composing")
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
158
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
159 def onMouseUp(self, sender, x, y):
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
160 size = (self.getOffsetWidth(), self.getOffsetHeight())
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
161 if size != self.__size:
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
162 self.__size = size
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
163 self.host.resize()
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
164
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
165 def onSelectedChange(self, selected):
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
166 self._selected_cache = selected
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
167
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
168
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
169 class UniBox(MessageBox, MouseHandler): #AutoCompleteTextBox):
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
170 """This text box is used as a main typing point, for message, microblog, etc"""
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
171
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
172 def __init__(self, host):
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
173 MessageBox.__init__(self, host)
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
174 #AutoCompleteTextBox.__init__(self)
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
175 self.setStyleName('uniBox')
193
f2ae8e170c49 browser side: selected widget caching in UniBox, to avoid to ask the getter at each key pressed, which make the box very slow.
Goffi <goffi@goffi.org>
parents: 192
diff changeset
176 host.addSelectedListener(self.onSelectedChange)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
177
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
178 def addKey(self, key):
73
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
179 return
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
180 #self.getCompletionItems().completions.append(key)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
181
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
182 def removeKey(self, key):
255
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
183 return
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
184 # TODO: investigate why AutoCompleteTextBox doesn't work here,
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
185 # maybe it can work on a TextBox but no TextArea. Remove addKey
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
186 # and removeKey methods if they don't serve anymore.
55
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
187 try:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
188 self.getCompletionItems().completions.remove(key)
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
189 except KeyError:
d5266c41ca24 Roster list update, contact deletion + some refactoring
Goffi <goffi@goffi.org>
parents: 54
diff changeset
190 print "WARNING: trying to remove an unknown key"
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
191
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
192 def _getTarget(self, txt):
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
193 """ Say who will receive the messsage
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
194 @return: a tuple (selected, target_type, target info) with:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
195 - target_hook: None if we use the selected widget, (msg, data) if we have a hook (e.g. "@@: " for a public blog), where msg is the parsed message (i.e. without the "hook key: "@@: bla" become ("bla", None))
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
196 - target_type: one of PUBLIC, GROUP, ONE2ONE, STATUS, MISC
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
197 - msg: HTML message which will appear in the privacy warning banner """
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
198 target = self._selected_cache
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
199
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
200 def getSelectedOrStatus():
294
a6b3715f0bd6 browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents: 293
diff changeset
201 if target and target.isSelectable():
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
202 _type, msg = target.getWarningData()
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
203 target_hook = None # we use the selected widget, not a hook
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
204 else:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
205 _type, msg = "STATUS", "This will be your new status message"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
206 target_hook = (txt, None)
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
207 return (target_hook, _type, msg)
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
208
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
209 if not txt.startswith('@'):
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
210 target_hook, _type, msg = getSelectedOrStatus()
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
211 elif txt.startswith('@@: '):
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
212 _type = "PUBLIC"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
213 msg = MicroblogPanel.warning_msg_public
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
214 target_hook = (txt[4:], None)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
215 elif txt.startswith('@'):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
216 _end = txt.find(': ')
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
217 if _end == -1:
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
218 target_hook, _type, msg = getSelectedOrStatus()
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
219 else:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
220 group = txt[1:_end] # only one target group is managed for the moment
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
221 if not group or not group in self.host.contact_panel.getGroups():
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
222 # the group doesn't exists, we ignore the key
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
223 group = None
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
224 target_hook, _type, msg = getSelectedOrStatus()
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
225 else:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
226 _type = "GROUP"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
227 msg = MicroblogPanel.warning_msg_group % group
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
228 target_hook = (txt[_end + 2:], group)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
229 else:
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
230 print "ERROR: Unknown target"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
231 target_hook, _type, msg = getSelectedOrStatus()
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
232
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
233 return (target_hook, _type, msg)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
234
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
235 def onKeyPress(self, sender, keycode, modifiers):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
236 _txt = self.getText()
361
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
237 target_hook, type_, msg = self._getTarget(_txt)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
238
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
239 if keycode == KEY_ENTER:
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
240 if _txt:
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
241 if target_hook:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
242 parsed_txt, data = target_hook
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
243 self.host.send([(type_, data)], parsed_txt)
310
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
244 self.host._updateInputHistory(_txt)
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
245 self.setText('')
361
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
246 self.host.showWarning(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
247 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
248 self.host.showWarning(type_, msg)
310
5d11ec1f2c22 browser_side: make UniBox inherit from a more basic MessageBox class
souliane <souliane@mailoo.org>
parents: 309
diff changeset
249 MessageBox.onKeyPress(self, sender, keycode, modifiers)
214
7b26be266ab1 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 213
diff changeset
250
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
251 def getTargetAndData(self):
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
252 """For external use, to get information about the (hypothetical) message
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
253 that would be sent if we press Enter right now in the unibox.
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
254 @return a tuple (target, data) with:
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
255 - data: what would be the content of the message (body)
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
256 - target: JID, group with the prefix "@" or the public entity "@@"
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
257 """
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
258 _txt = self.getText()
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
259 target_hook, _type, _msg = self._getTarget(_txt)
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
260 if target_hook:
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
261 data, target = target_hook
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
262 if target is None:
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
263 return target_hook
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
264 return (data, "@%s" % (target if target != "" else "@"))
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
265 if isinstance(self._selected_cache, MicroblogPanel):
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
266 groups = self._selected_cache.accepted_groups
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
267 target = "@%s" % (groups[0] if len(groups) > 0 else "@")
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
268 if len(groups) > 1:
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
269 Window.alert("Sole the first group of the selected panel is taken in consideration: '%s'" % groups[0])
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
270 elif isinstance(self._selected_cache, ChatPanel):
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
271 target = self._selected_cache.target
294
a6b3715f0bd6 browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents: 293
diff changeset
272 else:
a6b3715f0bd6 browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents: 293
diff changeset
273 target = None
231
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
274 return (_txt, target)
fab7aa366576 browser_side: dialogs take **kwargs arguments + unibox helper method
souliane <souliane@mailoo.org>
parents: 230
diff changeset
275
294
a6b3715f0bd6 browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents: 293
diff changeset
276 def onWidgetClosed(self, lib_wid):
a6b3715f0bd6 browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents: 293
diff changeset
277 """Called when a libervia widget is closed"""
a6b3715f0bd6 browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents: 293
diff changeset
278 if self._selected_cache == lib_wid:
a6b3715f0bd6 browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents: 293
diff changeset
279 self.onSelectedChange(None)
a6b3715f0bd6 browser_side: bug fixes for switching between unibox and rich text editor:
souliane <souliane@mailoo.org>
parents: 293
diff changeset
280
73
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
281 """def complete(self):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
282
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
283 #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
284 #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this
73
447dc8ac181b Adrien's uniBox design integration + lastPopup style
Goffi <goffi@goffi.org>
parents: 71
diff changeset
285 return AutoCompleteTextBox.complete(self)"""
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
286
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
287
361
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
288 class WarningPopup():
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
289
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
290 def __init__(self):
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
291 self._popup = None
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
292 self._timer = Timer(notify=self._timeCb)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
293
394
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 383
diff changeset
294 def showWarning(self, type_=None, msg=None, duration=2000):
361
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
295 """Display a popup information message, e.g. to notify the recipient of a message being composed.
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
296 If type_ is None, a popup being currently displayed will be hidden.
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
297 @type_: a type determining the CSS style to be applied (see __showWarning)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
298 @msg: message to be displayed
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
299 """
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
300 if type_ is None:
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
301 self.__removeWarning()
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
302 return
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
303 if not self._popup:
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
304 self.__showWarning(type_, msg)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
305 elif (type_, msg) != self._popup.target_data:
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
306 self._timeCb(None) # we remove the popup
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
307 self.__showWarning(type_, msg)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
308
394
ee61b0765d6c browser_side: radiocol supports MP3
souliane <souliane@mailoo.org>
parents: 383
diff changeset
309 self._timer.schedule(duration)
361
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
310
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
311 def __showWarning(self, type_, msg):
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
312 """Display a popup information message, e.g. to notify the recipient of a message being composed.
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
313 @type_: a type determining the CSS style to be applied. For now the defined styles are
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
314 "NONE" (will do nothing), "PUBLIC", "GROUP", "STATUS" and "ONE2ONE".
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
315 @msg: message to be displayed
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
316 """
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
317 if type_ == "NONE":
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
318 return
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
319 if not msg:
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
320 print "WARNING: no msg set uniBox warning"
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
321 return
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
322 if type_ == "PUBLIC":
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
323 style = "targetPublic"
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
324 elif type_ == "GROUP":
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
325 style = "targetGroup"
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
326 elif type_ == "STATUS":
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
327 style = "targetStatus"
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
328 elif type_ == "ONE2ONE":
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
329 style = "targetOne2One"
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
330 else:
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
331 print "ERROR: unknown message type"
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
332 return
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
333 contents = HTML(msg)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
334
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
335 self._popup = dialog.PopupPanelWrapper(autoHide=False, modal=False)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
336 self._popup.target_data = (type_, msg)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
337 self._popup.add(contents)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
338 self._popup.setStyleName("warningPopup")
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
339 if style:
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
340 self._popup.addStyleName(style)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
341
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
342 left = 0
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
343 top = 0 # max(0, self.getAbsoluteTop() - contents.getOffsetHeight() - 2)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
344 self._popup.setPopupPosition(left, top)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
345 self._popup.show()
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
346
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
347 def _timeCb(self, timer):
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
348 if self._popup:
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
349 self._popup.hide()
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
350 del self._popup
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
351 self._popup = None
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
352
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
353 def __removeWarning(self):
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
354 """Remove the popup"""
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
355 self._timeCb(None)
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
356
f4efffb9627c browser_side: the popup notifying the message's recipient is no more dependent to the unibox.
souliane <souliane@mailoo.org>
parents: 351
diff changeset
357
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
358 class MicroblogItem():
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
359 # 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
360
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
361 def __init__(self, data):
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
362 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
363 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
364 self.empty = data.get('new', False)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
365 self.title = data.get('title', '')
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
366 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
367 self.content = data.get('content', '')
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
368 self.content_xhtml = data.get('content_xhtml', '')
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
369 self.author = data['author']
307
44b46db7dfef browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents: 306
diff changeset
370 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
371 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
372 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
373 self.node = data.get('node', '')
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
374 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
375 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
376 self.comments_node = data.get('comments_node', '')
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
377
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
378
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
379 class MicroblogEntry(SimplePanel, ClickHandler, FocusHandler, KeyboardHandler):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
380
350
f1b9ec412769 browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents: 349
diff changeset
381 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
382 """
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
383 @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
384 @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
385 """
350
f1b9ec412769 browser_side: MicroblogEntry defines properties to access MicroblogItem attributes (instead of overwriting __getattr__)
souliane <souliane@mailoo.org>
parents: 349
diff changeset
386 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
387 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
388 '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
389 '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
390 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
391 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
392 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
393
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
394 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
395 self._blog_panel = blog_panel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
396
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
397 self.panel = FlowPanel()
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
398 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
399
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
400 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
401 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
402
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
403 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
404 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
405 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
406
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
407 entry_avatar = SimplePanel()
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
408 entry_avatar.setStyleName('mb_entry_avatar')
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
409 self.avatar = Image(self._blog_panel.host.getAvatar(self.author))
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
410 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
411 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
412
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
413 self.entry_dialog = HorizontalPanel()
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
414 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
415 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
416
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
417 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
418 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
419 self.addClickListener(self)
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
420
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
421 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
422 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
423
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
424 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
425 """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
426 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
427 self.bubble = self._current_comment = None
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
428 self.__setHeader()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
429 self.__setBubble()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
430 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
431
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
432 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
433 """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
434 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
435 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
436 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
437 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
438 <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
439 <span class='mb_entry_timestamp'>%(published)s</span>%(updated)s
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
440 </div>""" % {'author': html_sanitize(self.author),
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
441 '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
442 '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
443 }
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
444 )
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
445
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
446 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
447 """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
448 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
449 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
450
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
451 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
452 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
453 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
454 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
455 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
456 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
457
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
458 is_publisher = self.author == self._blog_panel.host.whoami.bare
39ae5bf92786 browser_side: allow one blogger to moderate the comments made on his own blog messages.
souliane <souliane@mailoo.org>
parents: 365
diff changeset
459 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
460 self.delete_label = addIcon(u"✗", "Delete 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
461 if is_publisher:
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
462 self.update_label = addIcon(u"✍", "Edit this message")
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
463 if self.comments:
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
464 self.comment_label = addIcon(u"↶", "Comment this message")
291
89818bca1a33 browser_side: set the ideal width for the blog post update dialog
souliane <souliane@mailoo.org>
parents: 289
diff changeset
465
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
466 def updateAvatar(self, new_avatar):
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
467 """Change the avatar of the entry
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
468 @param new_avatar: path to the new image"""
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
469 self.avatar.setUrl(new_avatar)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
470
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
471 def onClick(self, sender):
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
472 if sender == self:
414
ae598511850d browser_side: set microblog editor minimal width + fix the scrolling to comment
souliane <souliane@mailoo.org>
parents: 408
diff changeset
473 try: # prevent re-selection of the main entry after a comment has been focused
ae598511850d browser_side: set microblog editor minimal width + fix the scrolling to comment
souliane <souliane@mailoo.org>
parents: 408
diff changeset
474 if self.__ignoreNextEvent:
ae598511850d browser_side: set microblog editor minimal width + fix the scrolling to comment
souliane <souliane@mailoo.org>
parents: 408
diff changeset
475 self.__ignoreNextEvent = False
ae598511850d browser_side: set microblog editor minimal width + fix the scrolling to comment
souliane <souliane@mailoo.org>
parents: 408
diff changeset
476 return
ae598511850d browser_side: set microblog editor minimal width + fix the scrolling to comment
souliane <souliane@mailoo.org>
parents: 408
diff changeset
477 except AttributeError:
ae598511850d browser_side: set microblog editor minimal width + fix the scrolling to comment
souliane <souliane@mailoo.org>
parents: 408
diff changeset
478 pass
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
479 self._blog_panel.setSelectedEntry(self)
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
480 elif sender == self.delete_label:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
481 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
482 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
483 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
484 elif sender == self.comment_label:
414
ae598511850d browser_side: set microblog editor minimal width + fix the scrolling to comment
souliane <souliane@mailoo.org>
parents: 408
diff changeset
485 self.__ignoreNextEvent = 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
486 self._comment()
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
487
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
488 def __modifiedCb(self, content):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
489 """Send the new content to the backend
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
490 @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
491 """
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
492 if not content['text']: # previous content has been emptied
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
493 self._delete(True)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
494 return False
307
44b46db7dfef browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents: 306
diff changeset
495 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
496 if isinstance(self.bubble, richtext.RichTextEditor):
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
497 # 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
498 # 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
499 # 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
500 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
501 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
502 if self.type == 'main_item':
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
503 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
504 else:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
505 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
506 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
507 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
508 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
509
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
510 def __afterEditCb(self, content):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
511 """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
512 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
513 if self.empty:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
514 self._blog_panel.removeEntry(self.type, self.id)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
515 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
516 self._blog_panel.refresh()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
517 else: # allow to create a new comment
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
518 self._parent_entry._current_comment = None
425
19bd203daa27 browser_side: set microblog editor width to 80%
souliane <souliane@mailoo.org>
parents: 422
diff changeset
519 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
520 try:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
521 self.toggle_syntax_button.removeFromParent()
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
522 except TypeError:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
523 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
524
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
525 def __setBubble(self, edit=False):
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
526 """Set the bubble displaying the initial content."""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
527 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
528 '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
529 if self.content_xhtml:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
530 content.update({'syntax': Const.SYNTAX_XHTML})
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
531 if self.author != self._blog_panel.host.whoami.bare:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
532 options = ['read_only']
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
533 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
534 options = [] if self.empty else ['update_msg']
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
535 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
536 else: # assume raw text message have no title
404
c393e7dc9ae6 browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents: 402
diff changeset
537 self.bubble = 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
538 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
539 try:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
540 self.toggle_syntax_button.removeFromParent()
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
541 except TypeError:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
542 pass
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
543 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
544 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
545 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
546
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
547 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
548 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
549 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
550 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
551 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
552
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
553 def _delete(self, empty=False):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
554 """Ask confirmation for deletion.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
555 @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
556 def confirm_cb(answer):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
557 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
558 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
559 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
560 self.bubble.setContent(self.bubble._original_content)
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
561
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
562 if self.empty:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
563 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
564 dialog.InfoDialog(_("Information"), text).show()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
565 return
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
566 text = ""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
567 if empty:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
568 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
569 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
570 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
571 dialog.ConfirmDialog(confirm_cb, text=text).show()
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
572
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
573 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
574 """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
575 if self._current_comment:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 350
diff changeset
576 self._current_comment.bubble.setFocus(True)
414
ae598511850d browser_side: set microblog editor minimal width + fix the scrolling to comment
souliane <souliane@mailoo.org>
parents: 408
diff changeset
577 self._blog_panel.setSelectedEntry(self._current_comment)
315
09205b410a53 browser_side: handle successive click on blog post "edit" and "comment" icons
souliane <souliane@mailoo.org>
parents: 314
diff changeset
578 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
579 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
580 '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
581 'type': '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
582 'author': 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
583 '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
584 '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
585 }
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
586 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
587 if entry is None:
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
588 print "The entry of id %s can not be commented" % self.id
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
589 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
590 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
591 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
592 self.edit(True, entry)
414
ae598511850d browser_side: set microblog editor minimal width + fix the scrolling to comment
souliane <souliane@mailoo.org>
parents: 408
diff changeset
593 self._blog_panel.setSelectedEntry(entry)
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
594
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
595 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
596 """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
597 @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
598 @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
599 """
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
600 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
601 entry = self
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
602 try:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
603 entry.toggle_syntax_button.removeFromParent()
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
604 except TypeError:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
605 pass
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
606 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
607 if edit:
425
19bd203daa27 browser_side: set microblog editor width to 80%
souliane <souliane@mailoo.org>
parents: 422
diff changeset
608 entry.entry_dialog.setWidth('80%')
395
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
609 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
610 image = '<a class="richTextIcon">A</a>'
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
611 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
612 else:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
613 image = '<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>'
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
614 title = _('Switch to rich text edition')
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
615 entry.toggle_syntax_button = Button(image, entry.toggleContentSyntax)
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
616 entry.toggle_syntax_button.setTitle(title)
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
617 entry.entry_dialog.add(entry.toggle_syntax_button)
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
618
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
619 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
620 """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
621 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
622 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
623 if rich:
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 397
diff changeset
624 original_content['syntax'] = Const.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
625
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
626 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
627 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
628 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
629 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
630 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
631 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
632 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
633 if rich:
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 397
diff changeset
634 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
635
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
636 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
637 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
638 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
639 return
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
640 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
641 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
642 if answer:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
643 self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, Const.SYNTAX_CURRENT, Const.SYNTAX_TEXT)
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
644 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
645 else:
98cd5387d291 browser_side: new microblogs are not using the rich text editor by default:
souliane <souliane@mailoo.org>
parents: 394
diff changeset
646 self._blog_panel.host.bridge.call('syntaxConvert', setBubble, text, Const.SYNTAX_TEXT, Const.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
647
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
648
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
649 class MicroblogPanel(base_widget.LiberviaWidget):
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
650 warning_msg_public = "This message will be PUBLIC and everybody will be able to see it, even people you don't know"
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
651 warning_msg_group = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>"
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
652
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
653 def __init__(self, host, accepted_groups):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
654 """Panel used to show microblog
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
655 @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
656 """
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
657 base_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups), selectable=True)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
658 self.setAcceptedGroup(accepted_groups)
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
659 self.host = host
58
4fa3d57f72f8 browser side: microblog entries caching
Goffi <goffi@goffi.org>
parents: 57
diff changeset
660 self.entries = {}
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
661 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
662 self.selected_entry = None
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
663 self.vpanel = VerticalPanel()
83
68d360caeecb New widget system: first draft
Goffi <goffi@goffi.org>
parents: 78
diff changeset
664 self.vpanel.setStyleName('microblogPanel')
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
665 self.setWidget(self.vpanel)
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
666
326
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
667 def refresh(self):
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
668 """Refresh the display of this widget. If the unibox is disabled,
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
669 display the 'New message' button on top of the panel"""
326
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
670 enable_button = 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
671 if hasattr(self, 'new_button'):
326
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
672 self.new_button.setVisible(enable_button)
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
673 return
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
674 if enable_button:
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
675 def addBox():
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
676 self.new_button.setVisible(False)
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
677 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
678 '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
679 'author': self.host.whoami.bare,
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
680 }
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
681 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
682 entry.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
683 self.new_button = Button("New message", listener=addBox)
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
684 self.new_button.setStyleName("microblogNewButton")
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
685 self.vpanel.insert(self.new_button, 0)
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
686
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
687 @classmethod
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
688 def registerClass(cls):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
689 base_widget.LiberviaWidget.addDropKey("GROUP", cls.createPanel)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
690 base_widget.LiberviaWidget.addDropKey("CONTACT_TITLE", cls.createMetaPanel)
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
691
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
692 @classmethod
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
693 def createPanel(cls, host, item):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
694 """Generic panel creation for one, several or all groups (meta).
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
695 @parem host: the SatWebFrontend instance
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
696 @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
697 (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
698 @return: the created MicroblogPanel
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
699 """
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
700 _items = item if isinstance(item, list) else ([] if item is None else [item])
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
701 _type = 'ALL' if _items == [] else 'GROUP'
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
702 # XXX: pyjamas doesn't support use of cls directly
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
703 _new_panel = MicroblogPanel(host, _items)
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
704 host.FillMicroblogPanel(_new_panel)
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
705 host.bridge.call('getMassiveLastMblogs', _new_panel.massiveInsert, _type, _items, 10)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
706 host.setSelected(_new_panel)
383
b90744ec426e browser_side: refresh the ChatPanel and MicroblogPanel when they are opened from a drag and drop
souliane <souliane@mailoo.org>
parents: 380
diff changeset
707 _new_panel.refresh()
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
708 return _new_panel
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
709
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
710 @classmethod
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
711 def createMetaPanel(cls, host, item):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
712 """Needed for the drop keys to not be mixed between meta panel and panel for "Contacts" group"""
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
713 return MicroblogPanel.createPanel(host, None)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
714
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
715 @property
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
716 def accepted_groups(self):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
717 return self._accepted_groups
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
718
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
719 def matchEntity(self, entity):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
720 """
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
721 @param entity: 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
722 (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
723 @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
724 """
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
725 entity = entity if isinstance(entity, list) else ([] if entity is None else [entity])
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
726 entity.sort() # sort() do not return the sorted list: do it here, not on the "return" line
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
727 return self.accepted_groups == entity
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
728
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
729 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
730 """
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
731 @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
732 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
733 @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
734 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
735 if self.selected_entry and not self.selected_entry.comments:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
736 print ("ERROR: an item without comment is selected")
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
737 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
738 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
739 if comment:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
740 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
741 elif not self._accepted_groups:
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
742 # we have a meta MicroblogPanel, we publish publicly
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
743 return ("PUBLIC", self.warning_msg_public)
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
744 else:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
745 # we only accept one group at the moment
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
746 # FIXME: manage several groups
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
747 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
748
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
749 def onTextEntered(self, text):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
750 if self.selected_entry:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
751 # 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
752 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
753 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
754 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
755 target = ("COMMENT", comments_url)
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
756 elif not self._accepted_groups:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
757 # we are entering a public microblog
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
758 target = ("PUBLIC", None)
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
759 else:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
760 # 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
761 # FIXME: manage several groups
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
762 target = ("GROUP", self._accepted_groups[0])
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
763 self.host.send([target], text)
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
764
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
765 def accept_all(self):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
766 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
767
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
768 def getEntries(self):
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
769 """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
770 and fill the panel"""
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
771
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
772 def massiveInsert(self, mblogs):
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
773 """Insert several microblogs at once
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
774 @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
775 """
242
a25aa882e09a browser_side: add context menu for contact:
souliane <souliane@mailoo.org>
parents: 241
diff changeset
776 print "Massive insertion of %d microblogs" % len(mblogs)
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
777 for publisher in mblogs:
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
778 print "adding blogs for [%s]" % publisher
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
779 for mblog in mblogs[publisher]:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
780 if not "content" in mblog:
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
781 print ("WARNING: No content found in microblog [%s]", mblog)
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
782 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
783 self.addEntry(mblog)
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
784
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
785 def mblogsInsert(self, mblogs):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
786 """ Insert several microblogs at once
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
787 @param mblogs: list of microblogs
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
788 """
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
789 for mblog in mblogs:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
790 if not "content" in mblog:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
791 print ("WARNING: No content found in microblog [%s]", mblog)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
792 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
793 self.addEntry(mblog)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
794
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
795 def _chronoInsert(self, vpanel, entry, reverse=True):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
796 """ Insert an entry in chronological order
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
797 @param vpanel: VerticalPanel instance
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
798 @param entry: MicroblogEntry
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
799 @param reverse: more recent entry on top if True, chronological order else"""
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
800 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
801 entry.published = time()
135
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
802 # we look for the right index to insert our entry:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
803 # 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
804 # in the past
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
805 idx = 0
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
806
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
807 for child in vpanel.children:
135
ceef355156de server + browser side: groupblog subscription + fixed blog insertion order
Goffi <goffi@goffi.org>
parents: 132
diff changeset
808 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
809 idx += 1
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
810 continue
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
811 if reverse:
307
44b46db7dfef browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents: 306
diff changeset
812 if child.published < entry.published:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
813 break
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
814 else:
307
44b46db7dfef browser_side (groupblog): order items using "published" instead of "updated"
souliane <souliane@mailoo.org>
parents: 306
diff changeset
815 if child.published > entry.published:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
816 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
817 idx += 1
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
818
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
819 vpanel.insert(entry, idx)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
820
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
821 def addEntry(self, data):
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
822 """Add an entry to 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
823 @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
824 @return: the added entry, or None
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
825 """
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
826 _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
827 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
828 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
829 if not comments_hash in self.comments:
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
830 # 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
831 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
832 parent = self.comments[comments_hash]
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
833 parent_idx = self.vpanel.getWidgetIndex(parent)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
834 # 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
835 try:
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
836 sub_panel = self.vpanel.getWidget(parent_idx + 1)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
837 except IndexError:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
838 sub_panel = None
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
839 if not sub_panel or not isinstance(sub_panel, VerticalPanel):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
840 sub_panel = VerticalPanel()
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
841 sub_panel.setStyleName('microblogPanel')
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
842 sub_panel.addStyleName('subPanel')
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
843 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
844 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
845 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
846 if comment.id == _entry.id:
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
847 # update an existing comment
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
848 sub_panel.remove(comment)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
849 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
850 return _entry
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
851 # we want comments to be inserted in chronological order
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
852 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
853 return _entry
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
854
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
855 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
856 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
857 self.vpanel.remove(self.entries[_entry.id])
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
858 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
859 else: # new entry
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
860 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
861 self.entries[_entry.id] = _entry
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
862
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
863 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
864 # 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
865 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
866 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
867 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
868
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
869 return _entry
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
870
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
871 def removeEntry(self, type_, id_):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
872 """Remove an entry from the panel
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
873 @param type_: entry type ('main_item' or 'comment')
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
874 @param id_: entry id
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
875 """
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
876 for child in self.vpanel.getChildren():
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
877 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
878 if child.id == id_:
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
879 main_idx = self.vpanel.getWidgetIndex(child)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
880 try:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
881 sub_panel = self.vpanel.getWidget(main_idx + 1)
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
882 if isinstance(sub_panel, VerticalPanel):
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
883 sub_panel.removeFromParent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
884 except IndexError:
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
885 pass
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
886 child.removeFromParent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
887 self.selected_entry = None
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
888 break
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
889 elif isinstance(child, VerticalPanel) and type_ == 'comment':
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
890 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
891 if comment.id == id_:
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
892 comment.removeFromParent()
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
893 self.selected_entry = None
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
894 break
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
895
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
896 def setSelectedEntry(self, 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
897 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
898 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
899 except AttributeError:
334
9c6be29c714a browser side: removed logging imports: it's not working correctly with pyjamas
Goffi <goffi@goffi.org>
parents: 326
diff changeset
900 print "FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!"
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
901 removeStyle = lambda entry: entry.removeStyleName('selected_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
902 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
903 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
904 clicked_entry = entry # entry may be None when the timer is done
422
20c508f9b32a browser side: fixed bad use of Timer
Goffi <goffi@goffi.org>
parents: 414
diff changeset
905 Timer(500, lambda timer: removeStyle(clicked_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
906 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
907 return # unibox is disabled
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
908 # 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
909 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
910 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
911 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
912 if self.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
913 removeStyle(self.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
914 if entry:
282
ae3ec654836d browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents: 279
diff changeset
915 print "microblog entry selected (author=%s)" % 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
916 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
917 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
918
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
919 def updateValue(self, type_, jid, value):
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
920 """Update a jid value in entries
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
921 @param type_: one of 'avatar', 'nick'
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
922 @param jid: jid concerned
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
923 @param value: new value"""
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
924 def updateVPanel(vpanel):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
925 for child in vpanel.children:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
926 if isinstance(child, MicroblogEntry) and child.author == jid:
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
927 child.updateAvatar(value)
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
928 elif isinstance(child, VerticalPanel):
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
929 updateVPanel(child)
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
930 if type_ == 'avatar':
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
931 updateVPanel(self.vpanel)
119
a8d11fdea090 microblog avatar update
Goffi <goffi@goffi.org>
parents: 114
diff changeset
932
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
933 def setAcceptedGroup(self, group):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
934 """Add one or more group(s) which can be displayed in this panel.
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
935 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
936 @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
937 """
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
938 if not hasattr(self, "_accepted_groups"):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
939 self._accepted_groups = []
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
940 groups = group if isinstance(group, list) else [group]
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
941 for _group in groups:
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
942 if _group not in self._accepted_groups:
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
943 self._accepted_groups.append(_group)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
944 self._accepted_groups.sort()
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
945
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
946 def isJidAccepted(self, jid):
163
b887186e8fc8 browser side: get entity's microblogs for newly added contacts
Goffi <goffi@goffi.org>
parents: 148
diff changeset
947 """Tell if a jid is actepted and shown in this panel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
948 @param jid: jid
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
949 @return: True if the jid is accepted"""
132
30d8e328559b server & browser side: microblogging refactoring first draft
Goffi <goffi@goffi.org>
parents: 131
diff changeset
950 if self.accept_all():
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
951 return True
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
952 for group in self._accepted_groups:
27
d89982865c57 browser side: ContactsChooser is now used to ask for 3 others players when tarot game is launched + names refactoring
Goffi <goffi@goffi.org>
parents: 23
diff changeset
953 if self.host.contact_panel.isContactInGroup(group, jid):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
954 return True
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
955 return False
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
956
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
957
402
d7e78cb78dfc browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents: 401
diff changeset
958 class StatusPanel(HTMLTextEditor):
314
70ac3067d641 browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents: 313
diff changeset
959
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
960 EMPTY_STATUS = '&lt;click to set a status&gt;'
314
70ac3067d641 browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents: 313
diff changeset
961
20
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
962 def __init__(self, host, status=''):
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
963 self.host = host
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
964 modifiedCb = lambda content: self.host.bridge.call('setStatus', None, self.host.status_panel.presence, content['text']) or True
404
c393e7dc9ae6 browser_side: refactorize SimpleTextEditor init parameters
souliane <souliane@mailoo.org>
parents: 402
diff changeset
965 HTMLTextEditor.__init__(self, {'text': status}, modifiedCb, options={'no_xhtml': True, 'listen_focus': True, 'listen_click': True})
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
966 self.edit(False)
20
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
967 self.setStyleName('statusPanel')
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
968
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
969 @property
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
970 def status(self):
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
971 return self._original_content['text']
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
972
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
973 def __cleanContent(self, content):
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
974 status = content['text']
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
975 if status == self.EMPTY_STATUS or status in Const.PRESENCE.values():
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
976 content['text'] = ''
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
977 return content
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
978
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
979 def getContent(self):
401
ea03f898067f browser_side: LightTextEditor renamed to HTMLTextEditor, new class LightTextEditor based on TextArea
souliane <souliane@mailoo.org>
parents: 400
diff changeset
980 return self.__cleanContent(HTMLTextEditor.getContent(self))
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
981
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
982 def setContent(self, content):
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
983 content = self.__cleanContent(content)
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
984 BaseTextEditor.setContent(self, content)
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
985
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
986 def setDisplayContent(self):
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
987 status = self._original_content['text']
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
988 try:
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
989 presence = self.host.status_panel.presence
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
990 except AttributeError: # during initialization
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
991 presence = None
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
992 if not status:
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
993 if presence and presence in Const.PRESENCE:
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
994 status = Const.PRESENCE[presence]
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
995 else:
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
996 status = self.EMPTY_STATUS
402
d7e78cb78dfc browser_side: HTMLTextEditor and LightTextEditor factorization
souliane <souliane@mailoo.org>
parents: 401
diff changeset
997 self.display.setHTML(addURLToText(status))
314
70ac3067d641 browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents: 313
diff changeset
998
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
999
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1000 class PresenceStatusPanel(HorizontalPanel, ClickHandler):
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1001
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1002 def __init__(self, host, presence="", status=""):
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1003 self.host = host
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1004 HorizontalPanel.__init__(self, Width='100%')
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1005 self.presence_button = Label(u"◉")
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1006 self.presence_button.setStyleName("presence-button")
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1007 self.status_panel = StatusPanel(host, status=status)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1008 self.setPresence(presence)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1009 entries = {}
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
1010 for value in Const.PRESENCE.keys():
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 322
diff changeset
1011 entries.update({Const.PRESENCE[value]: {"value": value}})
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1012
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1013 def callback(sender, key):
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1014 self.setPresence(entries[key]["value"]) # order matters
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1015 self.host.send([("STATUS", None)], self.status_panel.status)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1016
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1017 self.presence_list = PopupMenuPanel(entries, callback=callback, style={"menu": "gwt-ListBox"})
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1018 self.presence_list.registerClickSender(self.presence_button)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1019
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1020 panel = HorizontalPanel()
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1021 panel.add(self.presence_button)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1022 panel.add(self.status_panel)
314
70ac3067d641 browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents: 313
diff changeset
1023 panel.setCellVerticalAlignment(self.presence_button, 'baseline')
70ac3067d641 browser_side: status can be edited with a click on it
souliane <souliane@mailoo.org>
parents: 313
diff changeset
1024 panel.setCellVerticalAlignment(self.status_panel, 'baseline')
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1025 panel.setStyleName("marginAuto")
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1026 self.add(panel)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1027
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1028 self.status_panel.edit(False)
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1029
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1030 ClickHandler.__init__(self)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1031 self.addClickListener(self)
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1032
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1033 @property
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1034 def presence(self):
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1035 return self._presence
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1036
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1037 @property
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1038 def status(self):
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1039 return self.status_panel._original_content['text']
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1040
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1041 def setPresence(self, presence):
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1042 self._presence = presence
370
30d03d9f07e4 browser_side: refactorization of the file tools.py:
souliane <souliane@mailoo.org>
parents: 366
diff changeset
1043 contact.setPresenceStyle(self.presence_button, self._presence)
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1044
349
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1045 def setStatus(self, status):
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1046 self.status_panel.setContent({'text': status})
f488692c4903 browser_side: LightTextEditor inheritates from BaseTextEditor + display URL in the status
souliane <souliane@mailoo.org>
parents: 347
diff changeset
1047 self.status_panel.setDisplayContent()
279
2d6bd975a72d browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents: 276
diff changeset
1048
62
12e889a683ce server side: misc stuff:
Goffi <goffi@goffi.org>
parents: 58
diff changeset
1049 def onClick(self, sender):
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1050 # As status is the default target of uniBar, we don't want to select anything if click on it
192
cf5c83e7d515 browser side: per tab selected widget management
Goffi <goffi@goffi.org>
parents: 191
diff changeset
1051 self.host.setSelected(None)
20
8f4b1a8914c3 - User status is now updated
Goffi <goffi@goffi.org>
parents: 19
diff changeset
1052
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
1053
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1054 class ChatPanel(base_widget.LiberviaWidget):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1055
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
1056 def __init__(self, host, target, type_='one2one'):
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1057 """Panel used for conversation (one 2 one or group chat)
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1058 @param host: SatWebFrontend instance
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1059 @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room)
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1060 @param type: one2one for simple conversation, group for MUC"""
407
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1061 base_widget.LiberviaWidget.__init__(self, host, title=target.bare, selectable=True)
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
1062 self.vpanel = VerticalPanel()
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
1063 self.vpanel.setSize('100%', '100%')
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
1064 self.type = type_
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1065 self.nick = None
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1066 if not target:
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1067 print "ERROR: Empty target !"
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1068 return
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1069 self.target = target
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
1070 self.__body = AbsolutePanel()
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
1071 self.__body.setStyleName('chatPanel_body')
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1072 chat_area = HorizontalPanel()
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1073 chat_area.setStyleName('chatArea')
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
1074 if type_ == 'group':
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1075 self.occupants_list = OccupantsList()
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1076 chat_area.add(self.occupants_list)
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
1077 self.__body.add(chat_area)
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1078 self.content = AbsolutePanel()
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1079 self.content.setStyleName('chatContent')
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1080 self.content_scroll = base_widget.ScrollPanelWrapper(self.content)
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
1081 chat_area.add(self.content_scroll)
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
1082 chat_area.setCellWidth(self.content_scroll, '100%')
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
1083 self.vpanel.add(self.__body)
311
3135ff840b8e browser_side: message box below the ChatPanel when unibox is disabled
souliane <souliane@mailoo.org>
parents: 310
diff changeset
1084 self.vpanel.setCellHeight(self.__body, '100%')
84
8f35e9970e7f browser side: new widget handling:
Goffi <goffi@goffi.org>
parents: 83
diff changeset
1085 self.addStyleName('chatPanel')
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
1086 self.setWidget(self.vpanel)
223
624a87377412 browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents: 218
diff changeset
1087 self.state_machine = ChatStateMachine(self.host, str(self.target))
407
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1088 self._state = None
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1089
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1090 @classmethod
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1091 def registerClass(cls):
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1092 base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createPanel)
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1093
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1094 @classmethod
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1095 def createPanel(cls, host, item):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1096 _contact = item if isinstance(item, JID) else JID(item)
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1097 host.contact_panel.setContactMessageWaiting(_contact.bare, False)
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1098 _new_panel = ChatPanel(host, _contact) # XXX: pyjamas doesn't seems to support creating with cls directly
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1099 _new_panel.historyPrint()
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1100 host.setSelected(_new_panel)
383
b90744ec426e browser_side: refresh the ChatPanel and MicroblogPanel when they are opened from a drag and drop
souliane <souliane@mailoo.org>
parents: 380
diff changeset
1101 _new_panel.refresh()
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1102 return _new_panel
38
7bea2ae0c4fb Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents: 37
diff changeset
1103
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1104 def refresh(self):
326
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1105 """Refresh the display of this widget. If the unibox is disabled,
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1106 add a message box at the bottom of the panel"""
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1107 self.host.contact_panel.setContactMessageWaiting(self.target.bare, False)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1108 self.content_scroll.scrollToBottom()
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1109
326
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1110 enable_box = self.host.uni_box is None
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1111 if hasattr(self, 'message_box'):
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1112 self.message_box.setVisible(enable_box)
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1113 return
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1114 if enable_box:
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1115 self.message_box = MessageBox(self.host)
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1116 self.message_box.onSelectedChange(self)
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1117 self.vpanel.add(self.message_box)
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1118
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1119 def matchEntity(self, entity):
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1120 """
267
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
1121 @param entity: target jid as a string or JID instance.
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
1122 Could also be a couple with a type in the second element.
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1123 @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
1124 """
267
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
1125 if isinstance(entity, tuple):
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
1126 entity, type_ = entity if len(entity) > 1 else (entity[0], self.type)
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
1127 else:
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
1128 type_ = self.type
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1129 entity = entity if isinstance(entity, JID) else JID(entity)
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1130 try:
267
a76243c02074 browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents: 264
diff changeset
1131 return self.target.bare == entity.bare and self.type == type_
230
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1132 except AttributeError as e:
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1133 e.include_traceback()
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1134 return False
266e9678eec0 browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents: 226
diff changeset
1135
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1136 def getWarningData(self):
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1137 if self.type not in ["one2one", "group"]:
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1138 raise Exception("Unmanaged type !")
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1139 if self.type == "one2one":
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1140 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % self.target
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1141 elif self.type == "group":
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1142 msg = "This message will be sent to all the participants of the multi-user room <span class='warningTarget'>%s</span>" % self.target
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1143 return ("ONE2ONE" if self.type == "one2one" else "GROUP", msg)
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1144
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1145 def onTextEntered(self, text):
269
9eb9c7d41bdc browser_side: added generic method "send" in SatWebFrontend
souliane <souliane@mailoo.org>
parents: 267
diff changeset
1146 self.host.send([("groupchat" if self.type == 'group' else "chat", str(self.target))], text)
223
624a87377412 browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents: 218
diff changeset
1147 self.state_machine._onEvent("active")
201
aa76793da353 server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents: 200
diff changeset
1148
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
1149 def onQuit(self):
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1150 base_widget.LiberviaWidget.onQuit(self)
179
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
1151 if self.type == 'group':
8475a29d7214 closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents: 178
diff changeset
1152 self.host.bridge.call('mucLeave', None, self.target.bare)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1153
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1154 def setUserNick(self, nick):
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1155 """Set the nick of the user, usefull for e.g. change the color of the user"""
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1156 self.nick = nick
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1157
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1158 def setPresents(self, nicks):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1159 """Set the users presents in this room
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1160 @param occupants: list of nicks (string)"""
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1161 self.occupants_list.clear()
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1162 for nick in nicks:
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1163 self.occupants_list.addOccupant(nick)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1164
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1165 def userJoined(self, nick, data):
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1166 self.occupants_list.addOccupant(nick)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1167 self.printInfo("=> %s has joined the room" % nick)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1168
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1169 def userLeft(self, nick, data):
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1170 self.occupants_list.removeOccupant(nick)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1171 self.printInfo("<= %s has left the room" % nick)
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1172
408
ee8ebfe23e16 browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents: 407
diff changeset
1173 def changeUserNick(self, old_nick, new_nick):
ee8ebfe23e16 browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents: 407
diff changeset
1174 assert(self.type == "group")
ee8ebfe23e16 browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents: 407
diff changeset
1175 self.occupants_list.removeOccupant(old_nick)
ee8ebfe23e16 browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents: 407
diff changeset
1176 self.occupants_list.addOccupant(new_nick)
ee8ebfe23e16 browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents: 407
diff changeset
1177 self.printInfo(_("%(old_nick)s is now known as %(new_nick)s") % {'old_nick': old_nick, 'new_nick': new_nick})
ee8ebfe23e16 browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents: 407
diff changeset
1178
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1179 def historyPrint(self, size=20):
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1180 """Print the initial history"""
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1181 def getHistoryCB(history):
213
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
1182 # display day change
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
1183 day_format = "%A, %d %b %Y"
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
1184 previous_day = datetime.now().strftime(day_format)
123
5cb852d9757e use of async history
Goffi <goffi@goffi.org>
parents: 120
diff changeset
1185 for line in history:
235
b304cdf13a3b browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents: 232
diff changeset
1186 timestamp, from_jid, to_jid, message, mess_type, extra = line
213
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
1187 message_day = datetime.fromtimestamp(float(timestamp or time())).strftime(day_format)
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
1188 if previous_day != message_day:
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
1189 self.printInfo("* " + message_day)
8bbac49765d6 browser side: display the day change in chat window
souliane <souliane@mailoo.org>
parents: 210
diff changeset
1190 previous_day = message_day
235
b304cdf13a3b browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents: 232
diff changeset
1191 self.printMessage(from_jid, message, extra, timestamp)
123
5cb852d9757e use of async history
Goffi <goffi@goffi.org>
parents: 120
diff changeset
1192 self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1193
397
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1194 def printInfo(self, msg, type_='normal', link_cb=None):
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1195 """Print general info
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1196 @param msg: message to print
397
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1197 @param type_: one of:
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1198 "normal": general info like "toto has joined the room"
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1199 "link": general info that is clickable like "click here to join the main room"
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1200 "me": "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1201 @param link_cb: method to call when the info is clicked, ignored if type_ is not 'link'
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1202 """
397
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1203 _wid = HTML(msg) if type_ == 'link' else Label(msg)
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1204 if type_ == 'normal':
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1205 _wid.setStyleName('chatTextInfo')
397
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1206 elif type_ == 'link':
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1207 _wid.setStyleName('chatTextInfo-link')
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1208 if link_cb:
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1209 _wid.addClickListener(link_cb)
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1210 elif type_ == 'me':
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1211 _wid.setStyleName('chatTextMe')
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1212 else:
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1213 _wid.setStyleName('chatTextInfo')
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1214 self.content.add(_wid)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1215
235
b304cdf13a3b browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents: 232
diff changeset
1216 def printMessage(self, from_jid, msg, extra, timestamp=None):
19
e8e3704eb97f Added basic chat panel
Goffi <goffi@goffi.org>
parents: 18
diff changeset
1217 """Print message in chat window. Must be implemented by child class"""
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
1218 _jid = JID(from_jid)
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
1219 nick = _jid.node if self.type == 'one2one' else _jid.resource
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1220 mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare # mymess = True if message comes from local user
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1221 if msg.startswith('/me '):
397
6148e9063069 browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents: 395
diff changeset
1222 self.printInfo('* %s %s' % (nick, msg[4:]), type_='me')
35
d43d6e4b9dc8 room user joining/leaving
Goffi <goffi@goffi.org>
parents: 34
diff changeset
1223 return
235
b304cdf13a3b browser and server side: XHTML handling, first draft:
Goffi <goffi@goffi.org>
parents: 232
diff changeset
1224 self.content.add(ChatText(timestamp, nick, mymess, msg, extra.get('xhtml')))
34
ed935f763cc8 browser side: misc css/layout fixes
Goffi <goffi@goffi.org>
parents: 33
diff changeset
1225 self.content_scroll.scrollToBottom()
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1226
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 282
diff changeset
1227 def startGame(self, game_type, waiting, referee, players, *args):
36
1d406077b49b Tarot Game: first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
1228 """Configure the chat window to start a game"""
275
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1229 classes = {"Tarot": CardPanel, "RadioCol": RadioColPanel}
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1230 if game_type not in classes.keys():
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1231 return # unknown game
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1232 attr = game_type.lower()
342
44491e963eee browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents: 340
diff changeset
1233 self.occupants_list.updateSpecials(players, SYMBOLS[attr])
275
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1234 if waiting or not self.nick in players:
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1235 return # waiting for player or not playing
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1236 attr = "%s_panel" % attr
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1237 if hasattr(self, attr):
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1238 return
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1239 print ("%s Game Started \o/" % game_type)
285
4f0c2fea358a browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents: 282
diff changeset
1240 panel = classes[game_type](self, referee, self.nick, players, *args)
275
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1241 setattr(self, attr, panel)
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1242 self.vpanel.insert(panel, 0)
a763b2ac5d41 bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents: 273
diff changeset
1243 self.vpanel.setCellHeight(panel, panel.getHeight())
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1244
37
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
1245 def getGame(self, game_type):
b306aa090438 Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents: 36
diff changeset
1246 """Return class managing the game type"""
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1247 # TODO: check that the game is launched, and manage errors
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
1248 if game_type == "Tarot":
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1249 return self.tarot_panel
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
1250 elif game_type == "RadioCol":
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1251 return self.radiocol_panel
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1252
407
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1253 def setState(self, state, nick=None):
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1254 """Set the chat state (XEP-0085) of the contact. Leave nick to None
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1255 to set the state for a one2one conversation, or give a nickname or
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1256 Const.ALL_OCCUPANTS to set the state of a participant within a MUC.
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1257 @param state: the new chat state
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1258 @param nick: None for one2one, the MUC user nick or ALL_OCCUPANTS
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1259 """
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1260 if nick:
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1261 assert(self.type == 'group')
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1262 occupants = self.occupants_list.occupants_list.keys() if nick == Const.ALL_OCCUPANTS else [nick]
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1263 for occupant in occupants:
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1264 self.occupants_list.occupants_list[occupant].setState(state)
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1265 else:
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1266 assert(self.type == 'one2one')
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1267 self._state = state
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1268 self.refreshTitle()
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1269 self.state_machine.started = not not state # start to send "composing" state from now
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1270
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1271 def refreshTitle(self):
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1272 """Refresh the title of this ChatPanel dialog"""
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1273 if self._state:
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1274 self.setTitle(self.target.bare + " (" + self._state + ")")
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1275 else:
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1276 self.setTitle(self.target.bare)
6a6551de4414 browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 404
diff changeset
1277
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
1278
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1279 class WebPanel(base_widget.LiberviaWidget):
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1280 """ (mini)browser like widget """
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1281
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1282 def __init__(self, host, url=None):
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1283 """
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1284 @param host: SatWebFrontend instance
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1285 """
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1286 base_widget.LiberviaWidget.__init__(self, host)
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1287 self._vpanel = VerticalPanel()
188
39936b83da9d Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents: 187
diff changeset
1288 self._vpanel.setSize('100%', '100%')
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
1289 self._url = dialog.ExtTextBox(enter_cb=self.onUrlClick)
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1290 self._url.setText(url or "")
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1291 self._url.setWidth('100%')
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1292 hpanel = HorizontalPanel()
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1293 hpanel.add(self._url)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1294 btn = Button("Go", self.onUrlClick)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1295 hpanel.setCellWidth(self._url, "100%")
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1296 #self.setCellWidth(btn, "10%")
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1297 hpanel.add(self._url)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1298 hpanel.add(btn)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1299 self._vpanel.add(hpanel)
188
39936b83da9d Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents: 187
diff changeset
1300 self._vpanel.setCellHeight(hpanel, '20px')
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1301 self._frame = Frame(url or "")
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1302 self._frame.setSize('100%', '100%')
188
39936b83da9d Browser Side: Web Panel widget position/size fix
Goffi <goffi@goffi.org>
parents: 187
diff changeset
1303 DOM.setStyleAttribute(self._frame.getElement(), "position", "relative")
181
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1304 self._vpanel.add(self._frame)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1305 self.setWidget(self._vpanel)
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1306
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1307 def onUrlClick(self, sender):
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1308 self._frame.setUrl(self._url.getText())
c0b78a3af06d browser side: web widget first draft
Goffi <goffi@goffi.org>
parents: 179
diff changeset
1309
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
1310
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1311 class MainPanel(AbsolutePanel):
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1312
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1313 def __init__(self, host):
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
1314 self.host = host
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1315 AbsolutePanel.__init__(self)
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1316
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1317 # menu
218
4e6467efd6bf browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents: 217
diff changeset
1318 self.menu = Menu(host)
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1319
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1320 # unibox
309
05e264e96a1c browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents: 307
diff changeset
1321 self.unibox_panel = UniBoxPanel(host)
313
5ad70625867a browser_side: save the unibox panel space when unibox is disabled
souliane <souliane@mailoo.org>
parents: 312
diff changeset
1322 self.unibox_panel.setVisible(False)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1323
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1324 # contacts
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1325 self._contacts = HorizontalPanel()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1326 self._contacts.addStyleName('globalLeftArea')
255
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1327 self.contacts_switch = Button(u'«', self._contactsSwitch)
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1328 self.contacts_switch.addStyleName('contactsSwitch')
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1329 self._contacts.add(self.contacts_switch)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1330 self._contacts.add(self.host.contact_panel)
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1331
226
744426c2b699 browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents: 223
diff changeset
1332 # tabs
195
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1333 self.tab_panel = base_widget.MainTabPanel(host)
dd27072d8ae0 browser side: widgets refactoring:
Goffi <goffi@goffi.org>
parents: 194
diff changeset
1334 self.discuss_panel = base_widget.WidgetsPanel(self.host, locked=True)
23
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
1335 self.tab_panel.add(self.discuss_panel, "Discussions")
0ce2a57b34ca added tab panel
Goffi <goffi@goffi.org>
parents: 22
diff changeset
1336 self.tab_panel.selectTab(0)
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1337
426
77d8f55fc5f0 browser_side: hide the presence/status panel until the connection is made
souliane <souliane@mailoo.org>
parents: 425
diff changeset
1338 self.header = AbsolutePanel()
77d8f55fc5f0 browser_side: hide the presence/status panel until the connection is made
souliane <souliane@mailoo.org>
parents: 425
diff changeset
1339 self.header.add(self.menu)
77d8f55fc5f0 browser_side: hide the presence/status panel until the connection is made
souliane <souliane@mailoo.org>
parents: 425
diff changeset
1340 self.header.add(self.unibox_panel)
77d8f55fc5f0 browser_side: hide the presence/status panel until the connection is made
souliane <souliane@mailoo.org>
parents: 425
diff changeset
1341 self.header.add(self.host.status_panel)
77d8f55fc5f0 browser_side: hide the presence/status panel until the connection is made
souliane <souliane@mailoo.org>
parents: 425
diff changeset
1342 self.header.setStyleName('header')
77d8f55fc5f0 browser_side: hide the presence/status panel until the connection is made
souliane <souliane@mailoo.org>
parents: 425
diff changeset
1343 self.add(self.header)
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1344
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1345 self._hpanel = HorizontalPanel()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1346 self._hpanel.add(self._contacts)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1347 self._hpanel.add(self.tab_panel)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1348 self.add(self._hpanel)
202
2bc6cf004e61 browser, server: comments handling:
Goffi <goffi@goffi.org>
parents: 201
diff changeset
1349
18
795d144fc1d2 moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff changeset
1350 self.setWidth("100%")
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1351 Window.addWindowResizeListener(self)
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1352
255
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1353 def _contactsSwitch(self, btn=None):
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1354 """ (Un)hide contacts panel """
255
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1355 if btn is None:
da0487f0a2e7 browser_side: small changes to prepare the contact group manager:
souliane <souliane@mailoo.org>
parents: 249
diff changeset
1356 btn = self.contacts_switch
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1357 cpanel = self.host.contact_panel
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1358 cpanel.setVisible(not cpanel.getVisible())
206
4d7054542751 browser side: contactBox doesn't use left margin anymore (avoid scrollbar issues) + some cosmetic changes to contact panel switch button
Goffi <goffi@goffi.org>
parents: 202
diff changeset
1359 btn.setText(u"«" if cpanel.getVisible() else u"»")
184
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1360 self.host.resize()
97d5e9de1106 browser side: contacts panel switch:
Goffi <goffi@goffi.org>
parents: 181
diff changeset
1361
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1362 def _contactsMove(self, parent):
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1363 """Move the contacts container (containing the contact list and
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1364 the "hide/show" button) to another parent, but always as the
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1365 first child position (insert at index 0).
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1366 """
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1367 if self._contacts.getParent():
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1368 if self._contacts.getParent() == parent:
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1369 return
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1370 self._contacts.removeFromParent()
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1371 parent.insert(self._contacts, 0)
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents: 231
diff changeset
1372
33
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1373 def onWindowResized(self, width, height):
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1374 _elts = doc().getElementsByClassName('gwt-TabBar')
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1375 if not _elts.length:
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1376 tab_bar_h = 0
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1377 else:
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1378 tab_bar_h = _elts.item(0).offsetHeight
e70521e6d803 browser side, misc stuffs
Goffi <goffi@goffi.org>
parents: 27
diff changeset
1379 ideal_height = Window.getClientHeight() - tab_bar_h
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
1380 self.setHeight("%s%s" % (ideal_height, "px"))
241
86055ccf69c3 browser_side: added class PopupMenuPanel to manage more complex context menu
souliane <souliane@mailoo.org>
parents: 239
diff changeset
1381
326
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1382 def refresh(self):
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1383 """Refresh the main panel"""
36927be51481 browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents: 323
diff changeset
1384 self.unibox_panel.refresh()