changeset 740:b6510fd9ae15

browser_side: implements tags UI
author souliane <souliane@mailoo.org>
date Thu, 19 Nov 2015 16:43:18 +0100
parents 4545d48dee60
children c3cb68227cca
files src/browser/public/libervia.css src/browser/sat_browser/list_manager.py src/browser/sat_browser/richtext.py
diffstat 3 files changed, 59 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/public/libervia.css	Thu Nov 19 16:42:39 2015 +0100
+++ b/src/browser/public/libervia.css	Thu Nov 19 16:43:18 2015 +0100
@@ -1436,6 +1436,16 @@
 	margin: 0px 5px;
 }
 
+.tagsPanel-main {
+    margin-bottom: 10px;
+}
+
+.tagsPanel-tags {
+    padding: 0px;
+    display: flex;
+    flex-wrap: wrap;
+}
+
 /* Room and contacts chooser */
 
 .room-contact-chooser {
--- a/src/browser/sat_browser/list_manager.py	Thu Nov 19 16:42:39 2015 +0100
+++ b/src/browser/sat_browser/list_manager.py	Thu Nov 19 16:43:18 2015 +0100
@@ -473,3 +473,40 @@
         self.popup_menu = base_panel.PopupMenuPanel(entries, callback=callback)
         for key in self.lists:  # register click sender for already existing lists
             self.popup_menu.registerClickSender(self.lists[key]["button"])
+
+
+class TagsPanel(base_panel.ToggleStackPanel):
+    """A toggle panel to set the tags"""
+
+    TAGS = _("Tags")
+    
+    STYLE = {"main": "tagsPanel-main",
+             "tags": "tagsPanel-tags"}
+
+    def __init__(self, suggested_tags, tags):
+        """
+        
+        @param suggested_tags (list[unicode]): list of all suggested tags
+        @param tags (list[unicode]): already assigned tags
+        """
+        base_panel.ToggleStackPanel.__init__(self, Width="100%")
+        self.addStyleName(self.STYLE["main"])
+        self.tags = ListPanel(quick_list_manager.QuickTagList(suggested_tags), tags)
+        self.tags.addStyleName(self.STYLE["tags"])
+        self.tags.ACCEPT_NEW_ENTRY = True
+        self.add(self.tags, self.TAGS)
+        self.addStackChangeListener(self)
+
+    def onStackChanged(self, sender, index, visible=None):
+        if visible is None:
+            visible = sender.getWidget(index).getVisible()
+        text = ", ".join(self.getTags())
+        suffix = "" if (visible or not text) else (": %s" % text)
+        sender.setStackText(index, self.TAGS + suffix)
+
+    def getTags(self):
+        return self.tags.getItems()
+
+    def setTags(self, items):
+        self.tags.resetItems(items)
+
--- a/src/browser/sat_browser/richtext.py	Thu Nov 19 16:42:39 2015 +0100
+++ b/src/browser/sat_browser/richtext.py	Thu Nov 19 16:43:18 2015 +0100
@@ -37,6 +37,9 @@
 import base_panel
 import editor_widget
 import html_tools
+import list_manager
+
+from sat_frontends.quick_frontend import quick_list_manager
 
 
 class RichTextEditor(editor_widget.BaseTextEditor, FlexTable):
@@ -63,8 +66,8 @@
         self.read_only = 'read_only' in options
         self.update_msg = 'update_msg' in options
 
-        indices = (-1, -1, 0, -1) if self.read_only else (0, 1, 2, 3)
-        self.title_offset, self.toolbar_offset, self.content_offset, self.command_offset = indices
+        indices = (-1, -1, 0, -1, -1) if self.read_only else (0, 1, 2, 3, 4)
+        self.title_offset, self.toolbar_offset, self.content_offset, self.tags_offset, self.command_offset = indices
         self.addStyleName(self.STYLE['main'])
 
         editor_widget.BaseTextEditor.__init__(self, content, None, modifiedCb, afterEditCb)
@@ -117,6 +120,13 @@
             self.getFlexCellFormatter().setColSpan(self.title_offset, 0, 2)
             self.setWidget(self.title_offset, 0, self.title_panel)
 
+        if not self.read_only and not hasattr(self, 'tags'):
+            suggested_tags = []  # TODO: feed this list with tags suggestion
+            tags = []  # TODO: feed this list with tags already assigned to this message
+            self.tags = list_manager.TagsPanel(suggested_tags, tags)
+            self.getFlexCellFormatter().setColSpan(self.tags_offset, 0, 2)
+            self.setWidget(self.tags_offset, 0, self.tags)
+
         if not self.read_only and not hasattr(self, 'command'):
             self.command = HorizontalPanel()
             self.command.addStyleName("marginAuto")