annotate browser/sat_browser/richtext.py @ 1203:251eba911d4d

server (websockets): fixed websocket handling on HTTPS connections: Original request used to retrieve a page was stored on dynamic pages, but after the end of it, the channel was deleted, resulting in a isSecure() always returning False, and troubles in chain leading to the the use of the wrong session object. This patch fixes this by reworking the way original request is used, and creating a new wrapping class allowing to keep an API similar to iweb.IRequest, with data coming from both the original request and the websocket request. fix 327
author Goffi <goffi@goffi.org>
date Sun, 14 Jul 2019 14:45:51 +0200
parents 3048bd137aaf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
diff changeset
4 # Libervia: a Salut à Toi frontend
818
f8a7a046ff9c copyright update
Goffi <goffi@goffi.org>
parents: 765
diff changeset
5 # Copyright (C) 2013-2016 Adrien Cossa <souliane@mailoo.org>
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
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: 327
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: 327
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: 327
diff changeset
10 # (at your option) any later version.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
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: 327
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: 327
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: 327
diff changeset
15 # GNU Affero General Public License for more details.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 327
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: 327
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
19
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 433
diff changeset
20 from sat_frontends.tools import composition
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 433
diff changeset
21 from sat.core.i18n import _
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 685
diff changeset
22 from sat.core.log import getLogger
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 685
diff changeset
23 log = getLogger(__name__)
449
981ed669d3b3 /!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents: 433
diff changeset
24
232
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.TextArea import TextArea
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from pyjamas.ui.Button import Button
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
27 from pyjamas.ui.CheckBox import CheckBox
232
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.Label import Label
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
29 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
30 from pyjamas.ui.HorizontalPanel import HorizontalPanel
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
31 from pyjamas.ui.KeyboardListener import KeyboardHandler
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
32 from pyjamas import Window
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
33 from __pyjamas__ import doc
323
0b7934e75e76 misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents: 319
diff changeset
34
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
35 from constants import Const as C
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
36 import dialog
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
37 import base_panel
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
38 import editor_widget
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
39 import html_tools
740
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 738
diff changeset
40 import list_manager
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 738
diff changeset
41
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
42
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
43 class RichTextEditor(editor_widget.BaseTextEditor, FlexTable):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
44 """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
45
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
46 STYLE = {'main': 'richTextEditor',
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
47 'title': 'richTextTitle',
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
48 'toolbar': 'richTextToolbar',
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
49 'textarea': 'richTextArea'
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
50 }
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
51
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
52 def __init__(self, host, content=None, modifiedCb=None, afterEditCb=None, options=None):
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
53 """
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
54
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
55 @param host (SatWebFrontend): host instance
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
56 @param content (dict): dict with at least a 'text' key
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
57 @param modifiedCb (callable): to be called when the text has been modified
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
58 @param afterEditCb (callable): to be called when the edition is done
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
59 @param options (list[unicode]): UI options ("read_only", "update_msg")
281
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
60 """
593
b97c85b8a47e browser side: fixed bad FlexTable __init__ call, need to be checked
Goffi <goffi@goffi.org>
parents: 574
diff changeset
61 FlexTable.__init__(self) # FIXME
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
62 self.host = host
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
63 self.wysiwyg = False
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
64 self.read_only = 'read_only' in options
281
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
65 self.update_msg = 'update_msg' in options
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
66
740
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 738
diff changeset
67 indices = (-1, -1, 0, -1, -1) if self.read_only else (0, 1, 2, 3, 4)
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 738
diff changeset
68 self.title_offset, self.toolbar_offset, self.content_offset, self.tags_offset, self.command_offset = indices
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
69 self.addStyleName(self.STYLE['main'])
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
70
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
71 editor_widget.BaseTextEditor.__init__(self, content, None, modifiedCb, afterEditCb)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
72
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: 359
diff changeset
73 def addEditListener(self, listener):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
74 """Add a method to be called whenever the text is edited.
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
75
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
76 @param listener: method taking two arguments: sender, keycode
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
77 """
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
78 editor_widget.BaseTextEditor.addEditListener(self, listener)
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: 359
diff changeset
79 if hasattr(self, 'display'):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
80 self.display.addEditListener(listener)
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
81
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
82 def refresh(self, edit=None):
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
83 """Refresh the UI for edition/display mode.
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
84
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
85 @param edit: set to True to display the edition mode
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
86 """
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
87 if edit is None:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
88 edit = hasattr(self, 'textarea') and self.textarea.getVisible()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
89
741
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
90 for widget in ['title_panel', 'tags_panel', 'command']:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
91 if hasattr(self, widget):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
92 getattr(self, widget).setVisible(edit)
324
8131d0ccf21b browser_side: prepare user input for microblog titles
souliane <souliane@mailoo.org>
parents: 323
diff changeset
93
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
94 if hasattr(self, 'toolbar'):
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
95 self.toolbar.setVisible(False)
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
96
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
97 if not hasattr(self, 'display'):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
98 self.display = editor_widget.HTMLTextEditor(options={'enhance_display': False, 'listen_keyboard': False}) # for display mode
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: 359
diff changeset
99 for listener in self.edit_listeners:
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
100 self.display.addEditListener(listener)
759
34f066ed3b23 browser_side: replaced mbdata2tags and tags2mbdata by sat.tools.common.dict2iter and iter2dict
Goffi <goffi@goffi.org>
parents: 742
diff changeset
101
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
102 if not self.read_only and not hasattr(self, 'textarea'):
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: 359
diff changeset
103 self.textarea = EditTextArea(self) # for edition mode
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
104 self.textarea.addStyleName(self.STYLE['textarea'])
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
105
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
106 self.getFlexCellFormatter().setColSpan(self.content_offset, 0, 2)
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
107 if edit and not self.wysiwyg:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
108 self.textarea.setWidth('100%') # CSS width doesn't do it, don't know why
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
109 self.setWidget(self.content_offset, 0, self.textarea)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
110 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
111 self.setWidget(self.content_offset, 0, self.display)
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
112 if not edit:
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
113 return
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
114
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
115 if not self.read_only and not hasattr(self, 'title_panel'):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
116 self.title_panel = base_panel.TitlePanel()
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
117 self.title_panel.addStyleName(self.STYLE['title'])
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
118 self.getFlexCellFormatter().setColSpan(self.title_offset, 0, 2)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
119 self.setWidget(self.title_offset, 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
120
741
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
121 if not self.read_only and not hasattr(self, 'tags_panel'):
740
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 738
diff changeset
122 suggested_tags = [] # TODO: feed this list with tags suggestion
741
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
123 self.tags_panel = list_manager.TagsPanel(suggested_tags)
740
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 738
diff changeset
124 self.getFlexCellFormatter().setColSpan(self.tags_offset, 0, 2)
741
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
125 self.setWidget(self.tags_offset, 0, self.tags_panel)
740
b6510fd9ae15 browser_side: implements tags UI
souliane <souliane@mailoo.org>
parents: 738
diff changeset
126
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
127 if not self.read_only and not hasattr(self, 'command'):
281
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
128 self.command = HorizontalPanel()
36ce989c73a5 browser_side: more customizable rich text editor
souliane <souliane@mailoo.org>
parents: 280
diff changeset
129 self.command.addStyleName("marginAuto")
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
130 self.command.add(Button("Cancel", lambda: self.edit(True, True)))
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
131 self.command.add(Button("Update" if self.update_msg else "Send message", lambda: self.edit(False)))
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
132 self.getFlexCellFormatter().setColSpan(self.command_offset, 0, 2)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
133 self.setWidget(self.command_offset, 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
134
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
135 def setToolBar(self, syntax):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
136 """This method is called asynchronously after the parameter
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
137 holding the rich text syntax is retrieved. It is called at
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
138 each call of self.edit(True) because the user may
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
139 have change his setting since the last time."""
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
140 if syntax is None or syntax not in composition.RICH_SYNTAXES.keys():
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
141 syntax = composition.RICH_SYNTAXES.keys()[0]
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
142 if hasattr(self, "toolbar") and self.toolbar.syntax == syntax:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
143 self.toolbar.setVisible(True)
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
144 return
738
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
145 self.toolbar = HorizontalPanel()
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
146 self.toolbar.syntax = syntax
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
147 self.toolbar.addStyleName(self.STYLE['toolbar'])
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
148 for key in composition.RICH_SYNTAXES[syntax].keys():
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
149 self.addToolbarButton(syntax, key)
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
150 self.wysiwyg_button = CheckBox(_('preview'))
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
151 wysiywgCb = lambda sender: self.setWysiwyg(sender.getChecked())
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
152 self.wysiwyg_button.addClickListener(wysiywgCb)
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
153 self.toolbar.add(self.wysiwyg_button)
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
154 self.syntax_label = Label(_("Syntax: %s") % syntax)
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
155 self.syntax_label.addStyleName("richTextSyntaxLabel")
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
156 self.toolbar.add(self.syntax_label)
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
157 self.toolbar.setCellWidth(self.syntax_label, "100%")
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
158 self.getFlexCellFormatter().setColSpan(self.toolbar_offset, 0, 2)
caad07bdb659 browser_side: simplify RichTextEditor initialization
souliane <souliane@mailoo.org>
parents: 737
diff changeset
159 self.setWidget(self.toolbar_offset, 0, self.toolbar)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
160
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
161 def setWysiwyg(self, wysiwyg, init=False):
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
162 """Toggle the edition mode between rich content syntax and wysiwyg.
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
163 @param wysiwyg: boolean value
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
164 @param init: set to True to re-init without switching the widgets."""
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
165 def setWysiwyg():
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
166 self.wysiwyg = wysiwyg
364
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
167 try:
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
168 self.wysiwyg_button.setChecked(wysiwyg)
593
b97c85b8a47e browser side: fixed bad FlexTable __init__ call, need to be checked
Goffi <goffi@goffi.org>
parents: 574
diff changeset
169 except (AttributeError, TypeError):
364
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
170 pass
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
171 try:
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
172 if wysiwyg:
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
173 self.syntax_label.addStyleName('transparent')
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
174 else:
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
175 self.syntax_label.removeStyleName('transparent')
593
b97c85b8a47e browser side: fixed bad FlexTable __init__ call, need to be checked
Goffi <goffi@goffi.org>
parents: 574
diff changeset
176 except (AttributeError, TypeError):
364
4cf735b40304 browser_side: hide the syntax label when wysiwyg edtion is active
souliane <souliane@mailoo.org>
parents: 362
diff changeset
177 pass
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
178 if not wysiwyg:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
179 self.display.removeStyleName('richTextWysiwyg')
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
180
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
181 if init:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
182 setWysiwyg()
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
183 return
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
184
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
185 self.getFlexCellFormatter().setColSpan(self.content_offset, 0, 2)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
186 if wysiwyg:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
187 def syntaxConvertCb(text):
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
188 self.display.setContent({'text': text})
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
189 self.textarea.removeFromParent() # XXX: force as it is not always done...
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
190 self.setWidget(self.content_offset, 0, self.display)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
191 self.display.addStyleName('richTextWysiwyg')
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
192 self.display.edit(True)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
193 content = self.getContent()
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
194 if content['text'] and content['syntax'] != C.SYNTAX_XHTML:
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
195 self.host.bridge.call('syntaxConvert', syntaxConvertCb, content['text'], content['syntax'], C.SYNTAX_XHTML)
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
196 else:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
197 syntaxConvertCb(content['text'])
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
198 else:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
199 syntaxConvertCb = lambda text: self.textarea.setText(text)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
200 text = self.display.getContent()['text']
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
201 if text and self.toolbar.syntax != C.SYNTAX_XHTML:
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
202 self.host.bridge.call('syntaxConvert', syntaxConvertCb, text)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
203 else:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
204 syntaxConvertCb(text)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
205 self.setWidget(self.content_offset, 0, self.textarea)
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
206 self.textarea.setWidth('100%') # CSS width doesn't do it, don't know why
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
207
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
208 setWysiwyg() # do it in the end because it affects self.getContent
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
209
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
210 def addToolbarButton(self, syntax, key):
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
211 """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
212 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
213 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
214 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
215 button.addStyleName('richTextToolButton')
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
216 self.toolbar.add(button)
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
217
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
218 def buttonCb():
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
219 """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
220 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
221 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
222 selection_length = self.textarea.getSelectionLength()
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
223 data = composition.RICH_SYNTAXES[syntax][key]
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
224 if selection_length == 0:
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
225 middle_text = data[1]
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
226 else:
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
227 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
228 self.textarea.setText(text[:cursor_pos]
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
229 + data[0]
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
230 + middle_text
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
231 + data[2]
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
232 + text[cursor_pos + selection_length:])
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
233 self.textarea.setCursorPos(cursor_pos + len(data[0]) + len(middle_text))
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
234 self.textarea.setFocus(True)
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: 359
diff changeset
235 self.textarea.onKeyDown()
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
236
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
237 def wysiwygCb():
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
238 """Callback for a toolbar button while wysiwyg mode is enabled."""
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
239 data = composition.COMMANDS[key]
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
240
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
241 def execCommand(command, arg):
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
242 self.display.setFocus(True)
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
243 doc().execCommand(command, False, arg.strip() if arg else '')
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
244 # use Window.prompt instead of dialog.PromptDialog to not loose the focus
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
245 prompt = lambda command, text: execCommand(command, Window.prompt(text))
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
246 if isinstance(data, tuple) or isinstance(data, list):
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
247 if data[1]:
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
248 prompt(data[0], data[1])
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
249 else:
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
250 execCommand(data[0], data[2])
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
251 else:
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
252 execCommand(data, False, '')
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: 359
diff changeset
253 self.textarea.onKeyDown()
355
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
254
9bb78c09e9fc browser_side: wysiwyg edition handles the toolbar buttons
souliane <souliane@mailoo.org>
parents: 353
diff changeset
255 button.addClickListener(lambda: wysiwygCb() if self.wysiwyg else buttonCb())
232
0ed09cc0566f browser_side: added UIs for rich text editor and addressing to multiple recipients
souliane <souliane@mailoo.org>
parents:
diff changeset
256
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
257 def getContent(self):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
258 assert(hasattr(self, 'textarea'))
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
259 assert(hasattr(self, 'toolbar'))
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
260 if self.wysiwyg:
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
261 content = {'text': self.display.getContent()['text'], 'syntax': C.SYNTAX_XHTML}
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
262 else:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
263 content = {'text': self.strproc(self.textarea.getText()), 'syntax': self.toolbar.syntax}
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
264 if hasattr(self, 'title_panel'):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
265 content.update({'title': self.strproc(self.title_panel.getText())})
741
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
266 if hasattr(self, 'tags_panel'):
1156
3048bd137aaf server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
267 content['tags'] = self.tags_panel.getTags()
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
268 return content
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
269
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
270 def edit(self, edit=False, abort=False, sync=False):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
271 """
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
272 Remark: the editor must be visible before you call this method.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
273 @param edit: set to True to edit the content or False to only display it
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
274 @param abort: set to True to cancel the edition and loose the changes.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
275 If edit and abort are both True, self.abortEdition can be used to ask for a
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
276 confirmation. When edit is False and abort is True, abortion is actually done.
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
277 @param sync: set to True to cancel the edition after the content has been saved somewhere else
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
278 """
357
2b5503392fbd browser_side: small fixes for RichTextEditor
souliane <souliane@mailoo.org>
parents: 356
diff changeset
279 if not (edit and abort):
2b5503392fbd browser_side: small fixes for RichTextEditor
souliane <souliane@mailoo.org>
parents: 356
diff changeset
280 self.refresh(edit) # not when we are asking for a confirmation
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
281 editor_widget.BaseTextEditor.edit(self, edit, abort, sync) # after the UI has been refreshed
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
282 if (edit and abort):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
283 return # self.abortEdition is called by editor_widget.BaseTextEditor.edit
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
284 self.setWysiwyg(False, init=True) # after editor_widget.BaseTextEditor (it affects self.getContent)
353
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
285 if sync:
ddb909ab5cbc browser_side: wysiwyg edtion, first steps (do not use the buttons yet)
souliane <souliane@mailoo.org>
parents: 352
diff changeset
286 return
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
287 # the following must NOT be done at each UI refresh!
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
288 content = self._original_content
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
289 if edit:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
290 def getParamCb(syntax):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
291 # set the editable text in the current user-selected syntax
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
292 def syntaxConvertCb(text=None):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
293 if text is not None:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
294 # Important: this also update self._original_content
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
295 content.update({'text': text})
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
296 content.update({'syntax': syntax})
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
297 self.textarea.setText(content['text'])
759
34f066ed3b23 browser_side: replaced mbdata2tags and tags2mbdata by sat.tools.common.dict2iter and iter2dict
Goffi <goffi@goffi.org>
parents: 742
diff changeset
298
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
299 if hasattr(self, 'title_panel') and 'title' in content:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
300 self.title_panel.setText(content['title'])
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
301 self.title_panel.setStackVisible(0, content['title'] != '')
741
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
302
742
d123e27fc386 browser_side: use methods defined in quick_frontend to retrieve and set the tags from/to microblog data
souliane <souliane@mailoo.org>
parents: 741
diff changeset
303 if hasattr(self, 'tags_panel'):
1156
3048bd137aaf server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
304 tags = content['tags']
741
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
305 self.tags_panel.setTags(tags)
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
306 self.tags_panel.setStackVisible(0, len(tags) > 0)
c3cb68227cca browser_side: read and write tags from microblog data:
souliane <souliane@mailoo.org>
parents: 740
diff changeset
307
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
308 self.setToolBar(syntax)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
309 if content['text'] and content['syntax'] != syntax:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
310 self.host.bridge.call('syntaxConvert', syntaxConvertCb, content['text'], content['syntax'])
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
311 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
312 syntaxConvertCb()
352
2610443b05a2 browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
souliane <souliane@mailoo.org>
parents: 351
diff changeset
313 self.host.bridge.call('asyncGetParamA', getParamCb, composition.PARAM_NAME_SYNTAX, composition.PARAM_KEY_COMPOSITION)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
314 else:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
315 if not self.initialized:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
316 # set the display text in XHTML only during init because a new MicroblogEntry instance is created after each modification
400
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
317 self.setDisplayContent()
357
2b5503392fbd browser_side: small fixes for RichTextEditor
souliane <souliane@mailoo.org>
parents: 356
diff changeset
318 self.display.edit(False)
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
319
400
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
320 def setDisplayContent(self):
648
6d3142b782c3 browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents: 624
diff changeset
321 """Set the content of the editor_widget.HTMLTextEditor which is used for display/wysiwyg"""
400
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
322 content = self._original_content
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
323 text = content['text']
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
324 if 'title' in content and content['title']:
765
a55df9c37d0e browser_side (blog): display title with h2 instead of h1 + add some bottom margin for the tags
souliane <souliane@mailoo.org>
parents: 763
diff changeset
325 title = '<h2>%s</h2>' % html_tools.html_sanitize(content['title'])
876
ca31e4f677e5 browser (richtext): fixes uninitialized variable
souliane <souliane@mailoo.org>
parents: 818
diff changeset
326 else:
ca31e4f677e5 browser (richtext): fixes uninitialized variable
souliane <souliane@mailoo.org>
parents: 818
diff changeset
327 title = ""
763
7390cba0bb44 browser_side: display tags with nice icons like for the static blog
souliane <souliane@mailoo.org>
parents: 759
diff changeset
328
7390cba0bb44 browser_side: display tags with nice icons like for the static blog
souliane <souliane@mailoo.org>
parents: 759
diff changeset
329 tags = ""
1156
3048bd137aaf server, browser: changed blog items serialisation following changes in backend
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
330 for tag in content['tags']:
763
7390cba0bb44 browser_side: display tags with nice icons like for the static blog
souliane <souliane@mailoo.org>
parents: 759
diff changeset
331 tags += "<li><a>%s</a></li>" % html_tools.html_sanitize(tag)
7390cba0bb44 browser_side: display tags with nice icons like for the static blog
souliane <souliane@mailoo.org>
parents: 759
diff changeset
332 if tags:
7390cba0bb44 browser_side: display tags with nice icons like for the static blog
souliane <souliane@mailoo.org>
parents: 759
diff changeset
333 tags = '<ul class="mblog_tags">%s</ul>' % tags
7390cba0bb44 browser_side: display tags with nice icons like for the static blog
souliane <souliane@mailoo.org>
parents: 759
diff changeset
334
7390cba0bb44 browser_side: display tags with nice icons like for the static blog
souliane <souliane@mailoo.org>
parents: 759
diff changeset
335 self.display.setContent({'text': "%s%s%s" % (title, tags, text)})
400
487dd238ab88 browser_side: bug fixes for microblog raw/rich edition toggle
souliane <souliane@mailoo.org>
parents: 395
diff changeset
336
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
337 def setFocus(self, focus):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
338 self.textarea.setFocus(focus)
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
339
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
340 def abortEdition(self, content):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
341 """Ask for confirmation before closing the dialog."""
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
342 def confirm_cb(answer):
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
343 if answer:
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
344 self.edit(False, True)
467
97c72fe4a5f2 browser_side: import fixes:
Goffi <goffi@goffi.org>
parents: 449
diff changeset
345 _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to %s?" % ("cancel your changes" if self.update_msg else "cancel this message"))
357
2b5503392fbd browser_side: small fixes for RichTextEditor
souliane <souliane@mailoo.org>
parents: 356
diff changeset
346 _dialog.cancel_button.setText(_("No"))
351
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
347 _dialog.show()
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
348
c943fd54c90e browser_side: heavy refactorisation for microblogs:
souliane <souliane@mailoo.org>
parents: 346
diff changeset
349
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: 359
diff changeset
350 class EditTextArea(TextArea, KeyboardHandler):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
351 def __init__(self, _parent):
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
352 TextArea.__init__(self)
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
353 self._parent = _parent
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
354 KeyboardHandler.__init__(self)
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
355 self.addKeyboardListener(self)
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
356
019e1e706e74 browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
souliane <souliane@mailoo.org>
parents: 359
diff changeset
357 def onKeyDown(self, sender=None, keycode=None, modifiers=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: 359
diff changeset
358 for listener in self._parent.edit_listeners:
716
3b91225b457a server + browser side: blogging refactoring (draft), huge commit sorry:
Goffi <goffi@goffi.org>
parents: 685
diff changeset
359 listener(self, keycode, modifiers) # FIXME: edit_listeners must either be removed, or send an action instead of keycode/modifiers