comparison src/browser/sat_browser/richtext.py @ 759:34f066ed3b23

browser_side: replaced mbdata2tags and tags2mbdata by sat.tools.common.dict2iter and iter2dict
author Goffi <goffi@goffi.org>
date Tue, 24 Nov 2015 23:26:55 +0100
parents d123e27fc386
children 7390cba0bb44
comparison
equal deleted inserted replaced
758:f725cc49e996 759:34f066ed3b23
19 19
20 from sat_frontends.tools import composition 20 from sat_frontends.tools import composition
21 from sat.core.i18n import _ 21 from sat.core.i18n import _
22 from sat.core.log import getLogger 22 from sat.core.log import getLogger
23 log = getLogger(__name__) 23 log = getLogger(__name__)
24 from sat.tools import common
24 25
25 from pyjamas.ui.TextArea import TextArea 26 from pyjamas.ui.TextArea import TextArea
26 from pyjamas.ui.Button import Button 27 from pyjamas.ui.Button import Button
27 from pyjamas.ui.CheckBox import CheckBox 28 from pyjamas.ui.CheckBox import CheckBox
28 from pyjamas.ui.Label import Label 29 from pyjamas.ui.Label import Label
37 import base_panel 38 import base_panel
38 import editor_widget 39 import editor_widget
39 import html_tools 40 import html_tools
40 import list_manager 41 import list_manager
41 42
42 from sat_frontends.quick_frontend import quick_blog
43
44 43
45 class RichTextEditor(editor_widget.BaseTextEditor, FlexTable): 44 class RichTextEditor(editor_widget.BaseTextEditor, FlexTable):
46 """Panel for the rich text editor.""" 45 """Panel for the rich text editor."""
47 46
48 STYLE = {'main': 'richTextEditor', 47 STYLE = {'main': 'richTextEditor',
98 97
99 if not hasattr(self, 'display'): 98 if not hasattr(self, 'display'):
100 self.display = editor_widget.HTMLTextEditor(options={'enhance_display': False, 'listen_keyboard': False}) # for display mode 99 self.display = editor_widget.HTMLTextEditor(options={'enhance_display': False, 'listen_keyboard': False}) # for display mode
101 for listener in self.edit_listeners: 100 for listener in self.edit_listeners:
102 self.display.addEditListener(listener) 101 self.display.addEditListener(listener)
103 102
104 if not self.read_only and not hasattr(self, 'textarea'): 103 if not self.read_only and not hasattr(self, 'textarea'):
105 self.textarea = EditTextArea(self) # for edition mode 104 self.textarea = EditTextArea(self) # for edition mode
106 self.textarea.addStyleName(self.STYLE['textarea']) 105 self.textarea.addStyleName(self.STYLE['textarea'])
107 106
108 self.getFlexCellFormatter().setColSpan(self.content_offset, 0, 2) 107 self.getFlexCellFormatter().setColSpan(self.content_offset, 0, 2)
264 else: 263 else:
265 content = {'text': self.strproc(self.textarea.getText()), 'syntax': self.toolbar.syntax} 264 content = {'text': self.strproc(self.textarea.getText()), 'syntax': self.toolbar.syntax}
266 if hasattr(self, 'title_panel'): 265 if hasattr(self, 'title_panel'):
267 content.update({'title': self.strproc(self.title_panel.getText())}) 266 content.update({'title': self.strproc(self.title_panel.getText())})
268 if hasattr(self, 'tags_panel'): 267 if hasattr(self, 'tags_panel'):
269 content.update(quick_blog.tags2mbdata(self.tags_panel.getTags())) 268 common.iter2dict('tag', self.tags_panel.getTags(), content)
270 return content 269 return content
271 270
272 def edit(self, edit=False, abort=False, sync=False): 271 def edit(self, edit=False, abort=False, sync=False):
273 """ 272 """
274 Remark: the editor must be visible before you call this method. 273 Remark: the editor must be visible before you call this method.
295 if text is not None: 294 if text is not None:
296 # Important: this also update self._original_content 295 # Important: this also update self._original_content
297 content.update({'text': text}) 296 content.update({'text': text})
298 content.update({'syntax': syntax}) 297 content.update({'syntax': syntax})
299 self.textarea.setText(content['text']) 298 self.textarea.setText(content['text'])
300 299
301 if hasattr(self, 'title_panel') and 'title' in content: 300 if hasattr(self, 'title_panel') and 'title' in content:
302 self.title_panel.setText(content['title']) 301 self.title_panel.setText(content['title'])
303 self.title_panel.setStackVisible(0, content['title'] != '') 302 self.title_panel.setStackVisible(0, content['title'] != '')
304 303
305 if hasattr(self, 'tags_panel'): 304 if hasattr(self, 'tags_panel'):
306 tags = quick_blog.mbdata2tags(content) 305 tags = list(common.dict2iter('tag', content))
307 self.tags_panel.setTags(tags) 306 self.tags_panel.setTags(tags)
308 self.tags_panel.setStackVisible(0, len(tags) > 0) 307 self.tags_panel.setStackVisible(0, len(tags) > 0)
309 308
310 self.setToolBar(syntax) 309 self.setToolBar(syntax)
311 if content['text'] and content['syntax'] != syntax: 310 if content['text'] and content['syntax'] != syntax:
323 """Set the content of the editor_widget.HTMLTextEditor which is used for display/wysiwyg""" 322 """Set the content of the editor_widget.HTMLTextEditor which is used for display/wysiwyg"""
324 content = self._original_content 323 content = self._original_content
325 text = content['text'] 324 text = content['text']
326 if 'title' in content and content['title']: 325 if 'title' in content and content['title']:
327 text = '<h1>%s</h1>%s' % (html_tools.html_sanitize(content['title']), text) 326 text = '<h1>%s</h1>%s' % (html_tools.html_sanitize(content['title']), text)
328 tags = quick_blog.mbdata2tags(content) 327 tags = list(common.dict2iter('tag', content))
329 if tags: # FIXME: display it more beautiful 328 if tags: # FIXME: display it more beautiful
330 text = '%s<h3>%s %s</h3>' % (text, _("Tags:"), html_tools.html_sanitize(", ".join(tags))) 329 text = '%s<h3>%s %s</h3>' % (text, _("Tags:"), html_tools.html_sanitize(", ".join(tags)))
331 self.display.setContent({'text': text}) 330 self.display.setContent({'text': text})
332 331
333 def setFocus(self, focus): 332 def setFocus(self, focus):