Mercurial > libervia-web
annotate browser_side/richtext.py @ 333:c01397d18026
server side: paramsXml2xmlUI is now parasXML2XMLUI + improved lisibility in getParamsUI
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 04 Feb 2014 16:49:20 +0100 |
parents | 6126bd24e7dd |
children | 2067d6241927 |
rev | line source |
---|---|
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 Libervia: a Salut à Toi frontend |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 Copyright (C) 2013 Adrien Cossa <souliane@mailoo.org> |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 GNU Affero General Public License for more details. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 from pyjamas.ui.TextArea import TextArea |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 from pyjamas.ui.Button import Button |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 from pyjamas.ui.DialogBox import DialogBox |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 from pyjamas.ui.Label import Label |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
26 from pyjamas.ui.HTML import HTML |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 from pyjamas.ui.FlexTable import FlexTable |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
29 |
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
30 from dialog import ConfirmDialog, InfoDialog |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
31 from base_panels import ToggleStackPanel |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
32 from list_manager import ListManager |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
319
diff
changeset
|
33 |
276
aebb96bfa8d1
frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents:
270
diff
changeset
|
34 from sat_frontends.tools import composition |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
35 from sat.core.i18n import _ |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
36 |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
37 # used for onCloseCallback |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
38 CANCEL, SYNC_NOT_SAVE, SAVE = xrange(0, 3) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 class RichTextEditor(FlexTable): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 """Panel for the rich text editor.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
44 def __init__(self, host, parent, onCloseCallback=None, options=()): |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
45 """Fill the editor with recipients panel, toolbar, text area... |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
46 @param host: the SatWebFrontend instance |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
47 @param parent: the parent panel |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
48 @param onCloseCallback: method to call when the dialog is closed |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
49 @param options: list of options: 'no_recipient', 'no_command', 'no_style'... |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
50 """ |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
51 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 # TODO: don't forget to comment this before commit |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
53 self._debug = False |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
54 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 # This must be done before FlexTable.__init__ because it is used by setVisible |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 self.host = host |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
58 self.no_title = 'no_title' in options |
327
6126bd24e7dd
browser_side: actually disable the microblog title (not supported yet)
souliane <souliane@mailoo.org>
parents:
324
diff
changeset
|
59 self.no_title = True # XXX: remove this line when titles are managed |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
60 self.no_close = 'no_close' in options |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
61 self.update_msg = 'update_msg' in options |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
62 self.no_recipient = 'no_recipient' in options |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
63 self.no_command = 'no_command' in options |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
64 self.no_sync_unibox = self.no_command or 'no_sync_unibox' in options |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
65 self.no_main_style = 'no_style' in options or 'no_main_style' in options |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
66 self.no_title_style = 'no_style' in options or 'no_title_style' in options |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
67 self.no_textarea_style = 'no_style' in options or 'no_textarea_style' in options |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
68 |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
69 offset1 = 0 if self.no_recipient else (len(composition.RECIPIENT_TYPES) + 1) |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
70 offset2 = 0 if self.no_title else 1 |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
71 offset3 = len(composition.RICH_FORMATS) if self._debug else 1 |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
72 offset4 = 0 if self.no_command else 1 |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
73 FlexTable.__init__(self, offset1 + offset2 + offset3 + 1 + offset4, 2) |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
74 if not self.no_main_style: |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
75 self.addStyleName('richTextEditor') |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 self._parent = parent |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 self._on_close_callback = onCloseCallback |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
282
diff
changeset
|
79 self.original_text = '' |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
80 |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
81 current_offset = offset1 |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
82 if not self.no_recipient: |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
83 # recipient types sub-panels are automatically added by the manager |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
84 self.recipient = RecipientManager(self) |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
85 self.recipient.createWidgets(title_format="%s: ") |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
86 self.getFlexCellFormatter().setColSpan(current_offset - 1, 0, 2) |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
87 spacer = HTML('') |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
88 spacer.setStyleName('recipientSpacer') |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
89 self.setWidget(current_offset - 1, 0, spacer) |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
90 |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
91 current_offset += offset2 |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
92 if not self.no_title: |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
93 self.title_panel = TitlePanel() |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
94 self.title_panel.addStyleName("richTextTitle") |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
95 self.getFlexCellFormatter().setColSpan(current_offset - 1, 0, 2) |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
96 self.setWidget(current_offset - 1, 0, self.title_panel) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
97 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
98 # Rich text tool bar is automatically added by setVisible |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
99 self.offset_toolbar = offset1 + offset2 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
101 current_offset += offset3 + 1 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 self.textarea = TextArea() |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
103 if not self.no_textarea_style: |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
104 self.textarea.addStyleName('richTextArea') |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
105 self.getFlexCellFormatter().setColSpan(current_offset - 1, 0, 2) |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
106 self.setWidget(current_offset - 1, 0, self.textarea) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
107 |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
108 current_offset += offset4 |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
109 if not self.no_command: |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
110 self.command = HorizontalPanel() |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
111 self.command.addStyleName("marginAuto") |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
112 self.command.add(Button("Cancel", listener=self.cancelWithoutSaving)) |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
113 if not self.no_sync_unibox: |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
114 self.command.add(Button("Back to quick box", listener=self.closeAndSave)) |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
115 self.command.add(Button("Update" if self.update_msg else "Send message", |
319
462a0a8894e3
browser_side: display the good text for microblog button regarding the context: "Send message" or "Update"
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
116 listener=self.__close if (self.update_msg or self.no_recipient) else self.sendMessage)) |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
117 self.getFlexCellFormatter().setColSpan(current_offset - 1, 0, 2) |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
118 self.setWidget(current_offset - 1, 0, self.command) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
119 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
120 @classmethod |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
121 def getOrCreate(cls, host, parent=None, onCloseCallback=None): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
122 """Get or create the richtext editor associated to that host. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
123 Add it to parent if parent is not None, otherwise display it |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
124 in a popup dialog. Information are saved for later the widget |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
125 to be also automatically removed from its parent, or the |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
126 popup to be closed. |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 @param host: the host |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
128 @param parent: parent panel (or None to display in a popup). |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
129 @return: the RichTextEditor instance if parent is not None, |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
130 otherwise a popup DialogBox containing the RichTextEditor. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
131 """ |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
132 if not hasattr(host, 'richtext'): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
133 host.richtext = RichTextEditor(host, parent, onCloseCallback) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
135 def add(widget, parent): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
136 if widget.getParent() is not None: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
137 if widget.getParent() != parent: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 widget.removeFromParent() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
139 parent.add(widget) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
140 else: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 parent.add(widget) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
142 widget.setVisible(True) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
143 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
144 if parent is None: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
145 if not hasattr(host.richtext, 'popup'): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 host.richtext.popup = DialogBox(autoHide=False, centered=True) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 host.richtext.popup.setHTML("Compose your message") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 host.richtext.popup.add(host.richtext) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 add(host.richtext, host.richtext.popup) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 host.richtext.popup.center() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
151 else: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 add(host.richtext, parent) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
153 host.richtext.syncFromUniBox() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 return host.richtext.popup if parent is None else host.richtext |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
155 |
270
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
156 def setVisible(self, visible): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 """Called each time the widget is displayed, after creation or after having been hidden.""" |
270
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
158 FlexTable.setVisible(self, visible) |
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
159 if visible: |
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
160 self.host.bridge.call('asyncGetParamA', self.setToolBar, composition.PARAM_NAME_SYNTAX, composition.PARAM_KEY_COMPOSITION) or self.setToolBar(None) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
161 |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
162 def __close(self, result=SAVE): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
163 """Remove the widget from parent or close the popup.""" |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
164 if not self.no_close: |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
165 if self._parent is None: |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
166 self.popup.hide() |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
167 else: |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
168 self.setVisible(False) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
169 if self._on_close_callback is not None: |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
170 self._on_close_callback(result) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
171 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
172 def setToolBar(self, _format): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 """This method is called asynchronously after the parameter |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 holding the rich text format is retrieved. It is called at |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 each opening of the rich text editor because the user may |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
176 have change his setting since the last time.""" |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
177 if _format is None or _format not in composition.RICH_FORMATS.keys(): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
178 _format = composition.RICH_FORMATS.keys()[0] |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 if hasattr(self, "_format") and self._format == _format: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
180 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
181 self._format = _format |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
182 count = 0 |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
183 for _format in composition.RICH_FORMATS.keys() if self._debug else [self._format]: |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
184 toolbar = HorizontalPanel() |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
185 toolbar.addStyleName('richTextToolbar') |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
186 for key in composition.RICH_FORMATS[_format].keys(): |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
187 self.addToolbarButton(toolbar, _format, key) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
188 label = Label("Format: %s" % _format) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
189 label.addStyleName("richTextFormatLabel") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 toolbar.add(label) |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
191 self.getFlexCellFormatter().setColSpan(self.offset_toolbar + count, 0, 2) |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
192 self.setWidget(self.offset_toolbar + count, 0, toolbar) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
193 count += 1 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 |
282
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
281
diff
changeset
|
195 @property |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
281
diff
changeset
|
196 def format(self): |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
281
diff
changeset
|
197 """Get the current text format""" |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
281
diff
changeset
|
198 return self._format if hasattr(self, '_format') else None |
ae3ec654836d
browser_side: added blog item modification/deletion
souliane <souliane@mailoo.org>
parents:
281
diff
changeset
|
199 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
200 def addToolbarButton(self, toolbar, _format, key): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
201 """Add a button with the defined parameters.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
202 button = Button('<img src="%s" class="richTextIcon" />' % |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
203 composition.RICH_BUTTONS[key]["icon"]) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
204 button.setTitle(composition.RICH_BUTTONS[key]["tip"]) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
205 button.addStyleName('richTextToolButton') |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 toolbar.add(button) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
207 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 def button_callback(): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
209 """Generic callback for a toolbar button.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
210 text = self.textarea.getText() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
211 cursor_pos = self.textarea.getCursorPos() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
212 selection_length = self.textarea.getSelectionLength() |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
213 infos = composition.RICH_FORMATS[_format][key] |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
214 if selection_length == 0: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
215 middle_text = infos[1] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
216 else: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 middle_text = text[cursor_pos:cursor_pos + selection_length] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
218 self.textarea.setText(text[:cursor_pos] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
219 + infos[0] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
220 + middle_text |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
221 + infos[2] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
222 + text[cursor_pos + selection_length:]) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
223 self.textarea.setCursorPos(cursor_pos + len(infos[0]) + len(middle_text)) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
224 self.textarea.setFocus(True) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
225 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
226 button.addClickListener(button_callback) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
228 def syncFromUniBox(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
229 """Synchronize from unibox.""" |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
282
diff
changeset
|
230 if not self.host.uni_box: |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
282
diff
changeset
|
231 return |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
232 data, target = self.host.uni_box.getTargetAndData() |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
233 if hasattr(self, 'recipient'): |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
234 self.recipient.setContacts({"To": [target]} if target else {}) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 self.textarea.setText(data if data else "") |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
236 |
270
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
237 def syncToUniBox(self, recipients=None, emptyText=False): |
280
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
238 """Synchronize to unibox if a maximum of one recipient is set. |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
239 @return True if the sync could be done, False otherwise""" |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
240 def setText(): |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
241 self.host.uni_box.setText("" if emptyText else self.textarea.getText()) |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
242 |
309
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
282
diff
changeset
|
243 if not self.host.uni_box: |
05e264e96a1c
browser_side: make unibox optional
souliane <souliane@mailoo.org>
parents:
282
diff
changeset
|
244 return |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
245 if not hasattr(self, 'recipient'): |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
246 setText() |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
247 return True |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
248 if recipients is None: |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
249 recipients = self.recipient.getContacts() |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
250 target = "" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 # we could eventually allow more in the future |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
252 allowed = 1 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
253 for key in recipients: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
254 count = len(recipients[key]) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
255 if count == 0: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
256 continue |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
257 allowed -= count |
280
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
258 if allowed < 0: |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
259 return False |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
260 # TODO: change this if later more then one recipients are allowed |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
261 target = recipients[key][0] |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
262 setText() |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
263 from panels import ChatPanel, MicroblogPanel |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
264 if target == "": |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
265 return True |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
266 if target.startswith("@"): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
267 _class = MicroblogPanel |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
268 target = None if target == "@@" else target[1:] |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
269 else: |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
270 _class = ChatPanel |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
271 self.host.getOrCreateLiberviaWidget(_class, target) |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
272 return True |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
273 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
274 def cancelWithoutSaving(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
275 """Ask for confirmation before closing the dialog.""" |
319
462a0a8894e3
browser_side: display the good text for microblog button regarding the context: "Send message" or "Update"
souliane <souliane@mailoo.org>
parents:
309
diff
changeset
|
276 if self.textarea.getText() == self.original_text: |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
277 self.__close(CANCEL) |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
278 return |
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
279 |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
280 def confirm_cb(answer): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
281 if answer: |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
282 self.__close(CANCEL) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
284 _dialog = ConfirmDialog(confirm_cb, text="Do you really want to %s?" % ("cancel your changes" if self.update_msg else "cancel this message")) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
285 _dialog.show() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
286 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
287 def closeAndSave(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
288 """Synchronize to unibox and close the dialog afterward. Display |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
289 a message and leave the dialog open if the sync was not possible.""" |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
290 if self.syncToUniBox(): |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
291 self.__close(SYNC_NOT_SAVE) |
232
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
292 return |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
293 InfoDialog("Too many recipients", |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
294 "A message with more than one direct recipient (To)," + |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
295 " or with any special recipient (Cc or Bcc), could not be" + |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
296 " stored in the quick box.\n\nPlease finish your composing" + |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
297 " in the rich text editor, and send your message directly" + |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
298 " from here.", Width="400px").center() |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
299 |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
300 def sendMessage(self): |
0ed09cc0566f
browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
301 """Send the message.""" |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
302 recipients = self.recipient.getContacts() |
270
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
303 text = self.textarea.getText() |
280
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
304 targets = [] |
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
305 for addr in recipients: |
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
306 for recipient in recipients[addr]: |
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
307 if recipient.startswith("@"): |
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
308 targets.append(("PUBLIC", None, addr) if recipient == "@@" else ("GROUP", recipient[1:], addr)) |
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
309 else: |
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
310 targets.append(("chat", recipient, addr)) |
270
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
311 # check that we actually have a message target and data |
280
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
312 if text == "" or len(targets) == 0: |
270
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
313 InfoDialog("Missing information", |
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
314 "Some information are missing and the message hasn't been sent.", Width="400px").center() |
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
315 return |
52e60dd2bc43
browser_side: send rich text to all the "To" recipients (groups and one2one)
souliane <souliane@mailoo.org>
parents:
263
diff
changeset
|
316 self.syncToUniBox(recipients, emptyText=True) |
280
1ccdc34cfb60
browser_side: changes related to the implementation of XEP-0033 (addressing)
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
317 self.host.send(targets, text, extra={'rich': text}) |
281
36ce989c73a5
browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents:
280
diff
changeset
|
318 self.__close(SAVE) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
319 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
320 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
321 class RecipientManager(ListManager): |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
322 """A manager for sub-panels to set the recipients for each recipient type.""" |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
323 |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
324 def __init__(self, parent, y_offset=0): |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
325 # TODO: be sure we also display empty groups and disconnected contacts + their groups |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
326 # store the full list of potential recipients (groups and contacts) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
327 list_ = [] |
263
d3c734669577
browser_side: improvements for lists and contact groups manager:
souliane <souliane@mailoo.org>
parents:
254
diff
changeset
|
328 list_.append("@@") |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
329 list_.extend("@%s" % group for group in parent.host.contact_panel.getGroups()) |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
330 list_.extend(contact for contact in parent.host.contact_panel.getContacts()) |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
331 ListManager.__init__(self, parent, composition.RECIPIENT_TYPES, list_, {'y': y_offset}) |
254
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
332 |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
333 self.registerPopupMenuPanel(entries=composition.RECIPIENT_TYPES, |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
334 hide=lambda sender, key: self.__children[key]["panel"].isVisible(), |
28d3315a8003
browser_side: isolate the basic stuff of RecipientManager in a new class ListManager:
souliane <souliane@mailoo.org>
parents:
234
diff
changeset
|
335 callback=self.setContactPanelVisible) |
324
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
336 |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
337 |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
338 class TitlePanel(ToggleStackPanel): |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
339 """A toggle panel to set the message title""" |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
340 def __init__(self): |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
341 ToggleStackPanel.__init__(self, Width="100%") |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
342 self.text_area = TextArea() |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
343 self.add(self.text_area, _("Title")) |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
344 self.addStackChangeListener(self) |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
345 |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
346 def onStackChanged(self, sender, index, visible=None): |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
347 if visible is None: |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
348 visible = sender.getWidget(index).getVisible() |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
349 text = self.text_area.getText() |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
350 suffix = "" if (visible or not text) else (": %s" % text) |
8131d0ccf21b
browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
351 sender.setStackText(index, _("Title") + suffix) |