annotate src/browser/sat_browser/panels.py @ 495:587fe75d1b16

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