comparison src/browser/sat_browser/blog.py @ 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
parents 5b28bca05d23
children 102050e489fa
comparison
equal deleted inserted replaced
769:5b28bca05d23 770:e67d8c13ba22
148 options = ['read_only'] 148 options = ['read_only']
149 self.bubble = richtext.RichTextEditor(self.blog.host, content, modifiedCb=self._modifiedCb, afterEditCb=self._afterEditCb, options=options) 149 self.bubble = richtext.RichTextEditor(self.blog.host, content, modifiedCb=self._modifiedCb, afterEditCb=self._afterEditCb, options=options)
150 else: 150 else:
151 log.error("Bad entry mode: %s" % self.mode) 151 log.error("Bad entry mode: %s" % self.mode)
152 self.bubble.addStyleName("bubble") 152 self.bubble.addStyleName("bubble")
153 self._showSyntaxSwitchButton(False)
154 self.entry_dialog.add(self.bubble) 153 self.entry_dialog.add(self.bubble)
155 self.bubble.addEditListener(self._showWarning) # FIXME: remove edit listeners 154 self.bubble.addEditListener(self._showWarning) # FIXME: remove edit listeners
156 self._setEditable() 155 self.setEditable(self.editable)
157 156
158 def _setIcons(self): 157 def _setIcons(self):
159 """Set the entry icons (delete, update, comment)""" 158 """Set the entry icons (delete, update, comment)"""
160 if self.new: 159 if self.new:
161 return 160 return
186 self.comments_panel = VerticalPanel() 185 self.comments_panel = VerticalPanel()
187 self.comments_panel.setStyleName('microblogPanel') 186 self.comments_panel.setStyleName('microblogPanel')
188 self.comments_panel.addStyleName('subPanel') 187 self.comments_panel.addStyleName('subPanel')
189 self.add(self.comments_panel) 188 self.add(self.comments_panel)
190 189
191 def _setEditable(self): 190 def setEditable(self, editable=True):
191 """Toggle the bubble between display and edit mode.
192
193 @param editable (bool)
194 """
195 self.editable = editable
192 self.bubble.edit(self.editable) 196 self.bubble.edit(self.editable)
197 self.updateSyntaxSwitchButton()
198
199 def updateSyntaxSwitchButton(self):
200 """Set the visibility of the button to switch between blog and microblog."""
201 try:
202 self.toggle_syntax_button.removeFromParent()
203 except (AttributeError, TypeError):
204 pass
193 if self.editable: 205 if self.editable:
194 self._showSyntaxSwitchButton()
195
196 def setEditable(self, editable=True):
197 self.editable = editable
198 self._setEditable()
199
200 def _showSyntaxSwitchButton(self, show=True):
201 if show:
202 if self.mode == C.ENTRY_MODE_TEXT: 206 if self.mode == C.ENTRY_MODE_TEXT:
203 html = '<a style="color: blue;">rich text</a>' 207 html = _(u'<a style="color: blue;">switch to blog</a>')
208 title = _(u'compose a rich text message with a title - suitable for writing articles')
204 else: 209 else:
205 html = '<a style="color: blue;">raw text</a>' 210 html = _(u'<a style="color: blue;">switch to microblog</a>')
206 self.toggle_syntax_button = HTML(html) 211 title = _(u'compose a short message without title - suitable for sharing news')
212 self.toggle_syntax_button = HTML(html, Title=title)
207 self.toggle_syntax_button.addClickListener(self.toggleContentSyntax) 213 self.toggle_syntax_button.addClickListener(self.toggleContentSyntax)
208 self.toggle_syntax_button.addStyleName('mb_entry_toggle_syntax') 214 self.toggle_syntax_button.addStyleName('mb_entry_toggle_syntax')
209 self.entry_dialog.add(self.toggle_syntax_button) 215 self.entry_dialog.add(self.toggle_syntax_button)
210 self.toggle_syntax_button.setStyleAttribute('top', '-20px') # XXX: need to force CSS 216 self.toggle_syntax_button.setStyleAttribute('top', '-20px') # XXX: need to force CSS
211 self.toggle_syntax_button.setStyleAttribute('left', '-20px') 217 self.toggle_syntax_button.setStyleAttribute('left', '-20px')
212 else:
213 try:
214 self.toggle_syntax_button.removeFromParent()
215 except (AttributeError, TypeError):
216 pass
217
218
219 def edit(self, edit=True):
220 """Toggle the bubble between display and edit mode"""
221 try:
222 self.toggle_syntax_button.removeFromParent()
223 except (AttributeError, TypeError):
224 pass
225 self.bubble.edit(edit)
226 if edit:
227 if self.mode in ENTRY_RICH:
228 # image = '<a class="richTextIcon">A</a>'
229 html = '<a style="color: blue;">raw text</a>'
230 # title = _('Switch to raw text edition')
231 else:
232 # image = '<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>'
233 html = '<a style="color: blue;">rich text</a>'
234 # title = _('Switch to rich text edition')
235 self.toggle_syntax_button = HTML(html)
236 self.toggle_syntax_button.addClickListener(self.toggleContentSyntax)
237 self.toggle_syntax_button.addStyleName('mb_entry_toggle_syntax')
238 self.entry_dialog.add(self.toggle_syntax_button)
239 self.toggle_syntax_button.setStyleAttribute('top', '-20px') # XXX: need to force CSS
240 self.toggle_syntax_button.setStyleAttribute('left', '-20px')
241
242 # def updateAvatar(self, new_avatar):
243 # """Change the avatar of the entry
244 # @param new_avatar: path to the new image"""
245 # self.avatar.setUrl(new_avatar)
246 218
247 def onClick(self, sender): 219 def onClick(self, sender):
248 if sender == self: 220 if sender == self:
249 self.blog.setSelectedEntry(self) 221 self.blog.setSelectedEntry(self)
250 elif sender == self.delete_label: 222 elif sender == self.delete_label:
251 self._onRetractClick() 223 self._onRetractClick()
252 elif sender == self.update_label: 224 elif sender == self.update_label:
253 self.edit(True) 225 self.setEditable(True)
254 elif sender == self.comment_label: 226 elif sender == self.comment_label:
255 self._onCommentClick() 227 self._onCommentClick()
256 # elif sender == self.show_comments_link: 228 # elif sender == self.show_comments_link:
257 # self._blog_panel.loadAllCommentsForEntry(self) 229 # self._blog_panel.loadAllCommentsForEntry(self)
258 230
298 self._setBubble() 270 self._setBubble()
299 else: 271 else:
300 # we don't keep edit entries for comments 272 # we don't keep edit entries for comments
301 self.delete() 273 self.delete()
302 else: 274 else:
303 self._showSyntaxSwitchButton(False) 275 self.editable = False
276 self.updateSyntaxSwitchButton()
304 277
305 def _showWarning(self, sender, keycode, modifiers): 278 def _showWarning(self, sender, keycode, modifiers):
306 if keycode == keyb.KEY_ENTER & keyb.MODIFIER_SHIFT: # FIXME: fix edit_listeners, it's dirty (we have to check keycode/modifiers twice !) 279 if keycode == keyb.KEY_ENTER & keyb.MODIFIER_SHIFT: # FIXME: fix edit_listeners, it's dirty (we have to check keycode/modifiers twice !)
307 self.blog.host.showWarning(None, None) 280 self.blog.host.showWarning(None, None)
308 else: 281 else: