changeset 352:2610443b05a2

browser_side: misc improvements for RichTextEditor to prepare Wysiwyg edition
author souliane <souliane@mailoo.org>
date Thu, 13 Feb 2014 01:17:07 +0100
parents c943fd54c90e
children ddb909ab5cbc
files browser_side/richtext.py
diffstat 1 files changed, 22 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/richtext.py	Wed Feb 12 15:17:04 2014 +0100
+++ b/browser_side/richtext.py	Thu Feb 13 01:17:07 2014 +0100
@@ -25,6 +25,7 @@
 from pyjamas.ui.FlexTable import FlexTable
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
 
+from constants import Const
 from dialog import ConfirmDialog, InfoDialog
 from base_panels import TitlePanel, BaseTextEditor, LightTextEditor
 from list_manager import ListManager
@@ -47,6 +48,7 @@
         """
         self.host = host
         self._debug = False  # TODO: don't forget to set  it False before commit
+        self.wysiwyg = False
         self.__readOptions(options)
         self.style = {'main': 'richTextEditor',
                       'title': 'richTextTitle',
@@ -87,19 +89,21 @@
             if hasattr(self, widget):
                 getattr(self, widget).setVisible(edit)
 
+        if hasattr(self, 'toolbar'):
+            self.toolbar.setVisible(False)
+        if not hasattr(self, 'display'):
+            self.display = LightTextEditor()  # for display mode
+        if not self.read_only and not hasattr(self, 'textarea'):
+            self.textarea = TextArea()  # for edition mode
+            self.textarea.addStyleName(self.style['textarea'])
+
         self.getFlexCellFormatter().setColSpan(self.content_offset, 0, 2)
-        if edit:
-            if not hasattr(self, 'textarea'):
-                self.textarea = TextArea()  # for edition mode
-                self.textarea.addStyleName(self.style['textarea'])
+        if edit and not self.wysiwyg:
             self.textarea.setWidth('100%')  # CSS width doesn't do it, don't know why
             self.setWidget(self.content_offset, 0, self.textarea)
         else:
-            if hasattr(self, 'toolbar'):
-                self.toolbar.setVisible(False)
-            if not hasattr(self, 'display'):
-                self.display = LightTextEditor()  # for display mode
             self.setWidget(self.content_offset, 0, self.display)
+        if not edit:
             return
 
         if not self.no_title and not hasattr(self, 'title_panel'):
@@ -125,6 +129,7 @@
             syntax = composition.RICH_SYNTAXES.keys()[0]
         if hasattr(self, "toolbar") and self.toolbar.syntax == syntax:
             self.toolbar.setVisible(True)
+            return
         count = 0
         for syntax in composition.RICH_SYNTAXES.keys() if self._debug else [syntax]:
             self.toolbar = HorizontalPanel()
@@ -203,12 +208,12 @@
                     if hasattr(self, 'title_panel') and 'title' in content:
                         self.title_panel.setText(content['title'])
                         self.title_panel.setStackVisible(0, content['title'] != '')
+                    self.setToolBar(syntax)
                 if content['text'] and content['syntax'] != syntax:
                     self.host.bridge.call('syntaxConvert', syntaxConvertCb, content['text'], content['syntax'])
                 else:
                     syntaxConvertCb()
-                self.setToolBar(syntax)
-            self.host.bridge.call('asyncGetParamA', getParamCb, composition.PARAM_NAME_SYNTAX, composition.PARAM_KEY_COMPOSITION) or self.setToolBar(None)
+            self.host.bridge.call('asyncGetParamA', getParamCb, composition.PARAM_NAME_SYNTAX, composition.PARAM_KEY_COMPOSITION)
         else:
             if not self.initialized:
                 # set the display text in XHTML only during init because a new MicroblogEntry instance is created after each modification
@@ -253,7 +258,6 @@
                 else:
                     host.richtext.setVisible(False)
                 callback()
-                host.richtext.initialized = False
             options = ['no_title']
             style = {'main': 'richMessageEditor', 'textarea': 'richMessageArea'}
             host.richtext = RichMessageEditor(host, None, modifiedCb, afterEditCb, options, style)
@@ -266,6 +270,7 @@
             else:
                 parent.add(widget)
             widget.setVisible(True)
+            widget.initialized = False  # fake a new creation
             widget.edit(True)
 
         if parent is None:
@@ -328,7 +333,7 @@
         @return True if the sync could be done, False otherwise"""
         if not self.host.uni_box:
             return
-        setText = lambda: self.host.uni_box.setText("" if emptyText else self.textarea.getText())
+        setText = lambda: self.host.uni_box.setText("" if emptyText else self.getContent()['text'])
         if not hasattr(self, 'recipient'):
             setText()
             return True
@@ -387,16 +392,16 @@
                 else:
                     targets.append(("chat", recipient, addr))
         # check that we actually have a message target and data
-        text = self.textarea.getText()
-        if text == "" or len(targets) == 0:
+        content = self.getContent()
+        if content['text'] == "" or len(targets) == 0:
             InfoDialog("Missing information",
                        "Some information are missing and the message hasn't been sent.", Width="400px").center()
             return None
         self.__syncToUniBox(recipients, emptyText=True)
-        extra = {'content_rich': text}
+        extra = {'content_rich': content['text']}
         if hasattr(self, 'title_panel'):
-            extra.update({'title': self.title_panel.getText()})
-        self.host.send(targets, text, extra=extra)
+            extra.update({'title': content['title']})
+        self.host.send(targets, content['text'], extra=extra)
         return True