Mercurial > libervia-web
changeset 667:166f3b624816 frontends_multi_profiles
browser_side (blog): clean the MicroblogPanel:
- remove internal constants TOGGLE_EDITION_USE_ICON and NEW_MESSAGE_USE_BUTTON
- ignore the unibox and, as a consequence, remove the 'selected_entry' attribute
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 06 Mar 2015 14:29:37 +0100 |
parents | 1bf645e73fe8 |
children | cbb3662818c8 |
files | src/browser/libervia_main.py src/browser/sat_browser/blog.py |
diffstat | 2 files changed, 32 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- a/src/browser/libervia_main.py Thu Mar 05 13:27:41 2015 +0100 +++ b/src/browser/libervia_main.py Fri Mar 06 14:29:37 2015 +0100 @@ -306,8 +306,6 @@ self.bridge.getNewAccountDomain(callback=domain_cb, errback=domain_eb) self.plug_profiles([C.PROF_KEY_NONE]) # XXX: None was used intitially, but pyjamas bug when using variable arguments and None is the only arg. - microblog_widget = self.displayWidget(blog.MicroblogPanel, ()) - self.setSelected(microblog_widget) # self.discuss_panel.addWidget(panel.MicroblogPanel(self, [])) # # get cached params and refresh the display @@ -322,6 +320,10 @@ def profilePlugged(self, dummy): # FIXME: to be called as a "profilePlugged" listener? QuickApp.profilePlugged(self, dummy) + + microblog_widget = self.displayWidget(blog.MicroblogPanel, ()) + self.setSelected(microblog_widget) + # we fill the panels already here for wid in self.widgets.getWidgets(blog.MicroblogPanel): if wid.accept_all(): @@ -451,7 +453,7 @@ # FIXME self.initialised = True # initialisation phase is finished here for event_data in self.init_cache: # so we have to send all the cached events - self._personalEventCb(*event_data) + self.personalEventHandler(*event_data) del self.init_cache def _getProfileJidCB(self, jid_s): @@ -482,7 +484,8 @@ ## Signals callbacks ## - def _personalEventCb(self, sender, event_type, data): + def personalEventHandler(self, sender, event_type, data): + # FIXME: move some code from here to QuickApp if not self.initialised: self.init_cache.append((sender, event_type, data)) return
--- a/src/browser/sat_browser/blog.py Thu Mar 05 13:27:41 2015 +0100 +++ b/src/browser/sat_browser/blog.py Fri Mar 06 14:29:37 2015 +0100 @@ -49,9 +49,6 @@ from sat_frontends.quick_frontend import quick_widgets from sat_frontends.tools import jid -# TODO: at some point we should decide which behaviors to keep and remove these two constants -TOGGLE_EDITION_USE_ICON = False # set to True to use an icon inside the "toggle syntax" button -NEW_MESSAGE_USE_BUTTON = False # set to True to display the "New message" button instead of an empty entry unicode = str # XXX: pyjamas doesn't manage unicode @@ -112,10 +109,7 @@ entry_avatar.add(self.avatar) self.panel.add(entry_avatar) - if TOGGLE_EDITION_USE_ICON: - self.entry_dialog = HorizontalPanel() - else: - self.entry_dialog = VerticalPanel() + self.entry_dialog = VerticalPanel() self.entry_dialog.setStyleName('mb_entry_dialog') self.panel.add(self.entry_dialog) @@ -212,7 +206,7 @@ if self.empty: self._blog_panel.removeEntry(self.type, self.id) if self.type == 'main_item': # restore the "New message" button - self._blog_panel.refresh() + self._blog_panel.addNewMessageEntry() else: # allow to create a new comment self._parent_entry._current_comment = None self.entry_dialog.setWidth('auto') @@ -312,18 +306,12 @@ 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') - if TOGGLE_EDITION_USE_ICON: - entry.entry_dialog.setWidth('80%') - entry.toggle_syntax_button = Button(image, entry.toggleContentSyntax) - entry.toggle_syntax_button.setTitle(title) - entry.entry_dialog.add(entry.toggle_syntax_button) - else: - entry.toggle_syntax_button = HTML(html) - entry.toggle_syntax_button.addClickListener(entry.toggleContentSyntax) - entry.toggle_syntax_button.addStyleName('mb_entry_toggle_syntax') - entry.entry_dialog.add(entry.toggle_syntax_button) - entry.toggle_syntax_button.setStyleAttribute('top', '-20px') # XXX: need to force CSS - entry.toggle_syntax_button.setStyleAttribute('left', '-20px') + entry.toggle_syntax_button = HTML(html) + entry.toggle_syntax_button.addClickListener(entry.toggleContentSyntax) + entry.toggle_syntax_button.addStyleName('mb_entry_toggle_syntax') + entry.entry_dialog.add(entry.toggle_syntax_button) + entry.toggle_syntax_button.setStyleAttribute('top', '-20px') # XXX: need to force CSS + entry.toggle_syntax_button.setStyleAttribute('left', '-20px') def toggleContentSyntax(self): """Toggle the editor between raw and rich text""" @@ -371,10 +359,10 @@ libervia_widget.LiberviaWidget.__init__(self, host, ", ".join(self.accepted_groups), selectable=True) self.entries = {} self.comments = {} - self.selected_entry = None self.vpanel = VerticalPanel() self.vpanel.setStyleName('microblogPanel') self.setWidget(self.vpanel) + self.addNewMessageEntry() # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) self.avatarListener = self.onAvatarUpdate @@ -398,28 +386,16 @@ if self.isJidAccepted(jid_) or jid_.bare == whoami.bare: self.updateValue('avatar', jid_, hash_) - def refresh(self): - """Refresh the display of this widget. If the unibox is disabled, - display the 'New message' button or an empty bubble on top of the panel""" - if hasattr(self, 'new_button'): - self.new_button.setVisible(self.host.uni_box is None) - return - if self.host.uni_box is None: - def addBox(): - if hasattr(self, 'new_button'): - self.new_button.setVisible(False) - data = {'id': unicode(time()), - 'new': True, - 'author': unicode(self.host.whoami.bare), - } - entry = self.addEntry(data) - entry.edit(True) - if NEW_MESSAGE_USE_BUTTON: - self.new_button = Button("New message", listener=addBox) - self.new_button.setStyleName("microblogNewButton") - self.vpanel.insert(self.new_button, 0) - elif not self.getNewMainEntry(): - addBox() + def addNewMessageEntry(self): + """Add an empty entry for writing a new message if needed.""" + if self.getNewMainEntry(): + return # there's already one + data = {'id': unicode(time()), + 'new': True, + 'author': unicode(self.host.whoami.bare), + } + entry = self.addEntry(data) + entry.edit(True) def getNewMainEntry(self): """Get the new entry being edited, or None if it doesn't exists. @@ -446,7 +422,6 @@ widget = host.displayWidget(MicroblogPanel, targets, dropped=True) host.FillMicroblogPanel(widget) host.bridge.getMassiveLastMblogs(type_, targets, 10, profile=C.PROF_KEY_NONE, callback=widget.massiveInsert) - widget.refresh() # FIXME: needed ? return widget @property @@ -454,16 +429,10 @@ """Return a set of the accepted groups""" return set().union(*self.targets) - def getWarningData(self, comment=None): + def getWarningData(self, comment): """ - @param comment: True if the composed message is a comment. If None, consider we are - composing from the unibox and guess the message type from self.selected_entry + @param comment: set to True if the composed message is a comment @return: a couple (type, msg) for calling self.host.showWarning""" - if comment is None: # composing from the unibox - if self.selected_entry and not self.selected_entry.comments: - log.error("an item without comment is selected") - return ("NONE", None) - comment = self.selected_entry is not None if comment: return ("PUBLIC", "This is a <span class='warningTarget'>comment</span> and keep the initial post visibility, so it is potentialy public") elif not self.accepted_groups: @@ -474,14 +443,7 @@ return ("GROUP", self.warning_msg_group % ' '.join(self.accepted_groups)) def onTextEntered(self, text): - if self.selected_entry: - # we are entering a comment - comments_url = self.selected_entry.comments - if not comments_url: - raise Exception("ERROR: the comments URL is empty") - self.bridge.call("sendMblogComment", None, comments_url, text, {}) - target = ("COMMENT", comments_url) - elif not self.accepted_groups: + if not self.accepted_groups: # we are entering a public microblog self.bridge.call("sendMblog", None, "PUBLIC", (), text, {}) else: @@ -542,7 +504,6 @@ vpanel.insert(entry, idx) - def addEntryIfAccepted(self, sender, groups, mblog_entry): """Check if an entry can go in MicroblogPanel and add to it @@ -624,13 +585,11 @@ except IndexError: pass child.removeFromParent() - self.selected_entry = None break elif isinstance(child, VerticalPanel) and type_ == 'comment': for comment in child.getChildren(): if comment.id == id_: comment.removeFromParent() - self.selected_entry = None break def ensureVisible(self, entry): @@ -652,23 +611,9 @@ if ensure_visible: self.ensureVisible(entry) - if not self.host.uni_box or not entry.comments: - entry.addStyleName('selected_entry') # blink the clicked entry - clicked_entry = entry # entry may be None when the timer is done - Timer(500, lambda timer: clicked_entry.removeStyleName('selected_entry')) - if not self.host.uni_box: - return # unibox is disabled - - # from here the previous behavior (toggle main item selection) is conserved - entry = entry if entry.comments else None - if self.selected_entry == entry: - entry = None - if self.selected_entry: - self.selected_entry.removeStyleName('selected_entry') - if entry: - log.debug("microblog entry selected (author=%s)" % unicode(entry.author)) - entry.addStyleName('selected_entry') - self.selected_entry = entry + entry.addStyleName('selected_entry') # blink the clicked entry + clicked_entry = entry # entry may be None when the timer is done + Timer(500, lambda timer: clicked_entry.removeStyleName('selected_entry')) def updateValue(self, type_, jid_, value): """Update a jid value in entries