[views] Display tooltip over primary view label with XSD element name and documentation draft obsolete
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 09 Oct 2017 17:04:39 +0200
changeset 2706 5f5ed5ee3056
obsolete rewritten as 71c3d7cf079a by Philippe Pepiot <philippe.pepiot@logilab.fr>, Sylvain Thénault <sylvain.thenault@logilab.fr> between Tue, 10 Oct 2017 14:34:12 +0200 and Wed, 11 Oct 2017 14:24:10 +0200
parent 2705 5b4e8f85c0f2
child 2707 57ff8e828e83
[views] Display tooltip over primary view label with XSD element name and documentation Introduce a bootstrap tooltip whose presence is indicated through a question mark on hover. Notice the comment change above aliasing cw's uicfg: this have to be there because of the relative import from our own uicfg module, though it's still unclear to me why this screw up the module's local namespace. Closes #17106808
cubicweb_seda/data/cubes.seda.css
cubicweb_seda/views/__init__.py
--- a/cubicweb_seda/data/cubes.seda.css	Mon Oct 09 17:01:59 2017 +0200
+++ b/cubicweb_seda/data/cubes.seda.css	Mon Oct 09 17:04:39 2017 +0200
@@ -37,4 +37,8 @@
 
 .cw-table-primary-entity td {
   width: 67%;
+}
+
+.popOverLabel {
+  cursor: help;
 }
\ No newline at end of file
--- a/cubicweb_seda/views/__init__.py	Mon Oct 09 17:01:59 2017 +0200
+++ b/cubicweb_seda/views/__init__.py	Mon Oct 09 17:04:39 2017 +0200
@@ -16,14 +16,18 @@
 
 from yams import BASE_TYPES
 
+from logilab.common.decorators import monkeypatch
+from logilab.mtconverter import xml_escape
+
 from cubicweb import tags, neg_role
 from cubicweb.utils import UStringIO
 from cubicweb.web import formfields as ff
-# XXX alias to avoid side effect: uicfg will become our uicfg submodule. Not necessary with 3.23?
-from cubicweb.web.views import uicfg as cwuicfg
+# XXX alias to avoid weird side effect: uicfg will become our uicfg submodule
+from cubicweb.web.views import primary, uicfg as cwuicfg
 
 from ..xsd import XSDM_MAPPING
 from ..xsd2uicfg import FIRST_LEVEL_ETYPES
+from .uicfg import ETYPE_ATTR_DOC
 from .widgets import SEDAMetaField
 
 
@@ -175,3 +179,23 @@
     w(u'</ul>')
     w(u'</div>')
     return data.getvalue()
+
+
+orig_rel_label = primary.PrimaryView._rel_label
+
+
+@monkeypatch(primary.PrimaryView)
+def _rel_label(self, entity, rschema, role, dispctrl):
+    label = orig_rel_label(self, entity, rschema, role, dispctrl)
+    try:
+        element_name, desc = ETYPE_ATTR_DOC[(entity.cw_etype, rschema.type, role)]
+    except KeyError:
+        print('nodoc for', entity.cw_etype, rschema.type, role)
+        return label
+    description = xml_escape(desc[0]) if desc else u''
+    title = xml_escape(element_name)
+    self._cw.add_onload("$('.popOverLabel').popover();")
+    return (u'<div class="popOverLabel" '
+            'data-toggle="popover" data-placement="top" '
+            'title="{}" data-content="{}">{}</div>'.format(
+                title, description, label))