changeset 770:e67d8c13ba22

browser_side (blog): fixes switching between display/edit modes and raw/rich text
author souliane <souliane@mailoo.org>
date Thu, 26 Nov 2015 13:51:06 +0100 (2015-11-26)
parents 5b28bca05d23
children 102050e489fa
files src/browser/sat_browser/blog.py
diffstat 1 files changed, 22 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/sat_browser/blog.py	Wed Nov 25 18:40:37 2015 +0100
+++ b/src/browser/sat_browser/blog.py	Thu Nov 26 13:51:06 2015 +0100
@@ -150,10 +150,9 @@
         else:
             log.error("Bad entry mode: %s" % self.mode)
         self.bubble.addStyleName("bubble")
-        self._showSyntaxSwitchButton(False)
         self.entry_dialog.add(self.bubble)
         self.bubble.addEditListener(self._showWarning) # FIXME: remove edit listeners
-        self._setEditable()
+        self.setEditable(self.editable)
 
     def _setIcons(self):
         """Set the entry icons (delete, update, comment)"""
@@ -188,61 +187,34 @@
             self.comments_panel.addStyleName('subPanel')
             self.add(self.comments_panel)
 
-    def _setEditable(self):
-        self.bubble.edit(self.editable)
-        if self.editable:
-            self._showSyntaxSwitchButton()
-
     def setEditable(self, editable=True):
+        """Toggle the bubble between display and edit mode.
+        
+        @param editable (bool)
+        """
         self.editable = editable
-        self._setEditable()
+        self.bubble.edit(self.editable)
+        self.updateSyntaxSwitchButton()
 
-    def _showSyntaxSwitchButton(self, show=True):
-        if show:
+    def updateSyntaxSwitchButton(self):
+        """Set the visibility of the button to switch between blog and microblog."""
+        try:
+            self.toggle_syntax_button.removeFromParent()
+        except (AttributeError, TypeError):
+            pass
+        if self.editable:
             if self.mode == C.ENTRY_MODE_TEXT:
-                html = '<a style="color: blue;">rich text</a>'
+                html = _(u'<a style="color: blue;">switch to blog</a>')
+                title = _(u'compose a rich text message with a title - suitable for writing articles')
             else:
-                html = '<a style="color: blue;">raw text</a>'
-            self.toggle_syntax_button = HTML(html)
+                html = _(u'<a style="color: blue;">switch to microblog</a>')
+                title = _(u'compose a short message without title - suitable for sharing news')
+            self.toggle_syntax_button = HTML(html, Title=title)
             self.toggle_syntax_button.addClickListener(self.toggleContentSyntax)
             self.toggle_syntax_button.addStyleName('mb_entry_toggle_syntax')
             self.entry_dialog.add(self.toggle_syntax_button)
             self.toggle_syntax_button.setStyleAttribute('top', '-20px')  # XXX: need to force CSS
             self.toggle_syntax_button.setStyleAttribute('left', '-20px')
-        else:
-            try:
-                self.toggle_syntax_button.removeFromParent()
-            except (AttributeError, TypeError):
-                pass
-
-
-    def edit(self, edit=True):
-        """Toggle the bubble between display and edit mode"""
-        try:
-            self.toggle_syntax_button.removeFromParent()
-        except (AttributeError, TypeError):
-            pass
-        self.bubble.edit(edit)
-        if edit:
-            if self.mode in ENTRY_RICH:
-                # image = '<a class="richTextIcon">A</a>'
-                html = '<a style="color: blue;">raw text</a>'
-                # title = _('Switch to raw text edition')
-            else:
-                # image = '<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>'
-                html = '<a style="color: blue;">rich text</a>'
-                # title = _('Switch to rich text edition')
-            self.toggle_syntax_button = HTML(html)
-            self.toggle_syntax_button.addClickListener(self.toggleContentSyntax)
-            self.toggle_syntax_button.addStyleName('mb_entry_toggle_syntax')
-            self.entry_dialog.add(self.toggle_syntax_button)
-            self.toggle_syntax_button.setStyleAttribute('top', '-20px')  # XXX: need to force CSS
-            self.toggle_syntax_button.setStyleAttribute('left', '-20px')
-
-    # def updateAvatar(self, new_avatar):
-    #     """Change the avatar of the entry
-    #     @param new_avatar: path to the new image"""
-    #     self.avatar.setUrl(new_avatar)
 
     def onClick(self, sender):
         if sender == self:
@@ -250,7 +222,7 @@
         elif sender == self.delete_label:
             self._onRetractClick()
         elif sender == self.update_label:
-            self.edit(True)
+            self.setEditable(True)
         elif sender == self.comment_label:
             self._onCommentClick()
         # elif sender == self.show_comments_link:
@@ -300,7 +272,8 @@
                 # we don't keep edit entries for comments
                 self.delete()
         else:
-            self._showSyntaxSwitchButton(False)
+            self.editable = False
+            self.updateSyntaxSwitchButton()
 
     def _showWarning(self, sender, keycode, modifiers):
         if keycode == keyb.KEY_ENTER & keyb.MODIFIER_SHIFT: # FIXME: fix edit_listeners, it's dirty (we have to check keycode/modifiers twice !)