[PATCH 4 of 4 seda] [views] Display tooltip over primary view label with XSD element name and documentation

Sylvain Thenault sylvain.thenault at logilab.fr
Wed Oct 11 11:01:49 CEST 2017

# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1507561479 -7200
#      Mon Oct 09 17:04:39 2017 +0200
# Node ID 58751ca2039e662229da6e4214361ae03752ffe3
# Parent  66ad8d3da2f51ee8b1a1437d9a5b058a5143dfc8
# Available At https://hg.logilab.org/review/cubes/seda
#              hg pull https://hg.logilab.org/review/cubes/seda -r 58751ca2039e
[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

diff --git a/cubicweb_seda/data/cubes.seda.css b/cubicweb_seda/data/cubes.seda.css
--- a/cubicweb_seda/data/cubes.seda.css
+++ b/cubicweb_seda/data/cubes.seda.css
@@ -35,6 +35,10 @@ div.btn-group {
   color: #AE8332;
 .cw-table-primary-entity td {
   width: 67%;
+.popOverLabel {
+  cursor: help;
\ No newline at end of file
diff --git a/cubicweb_seda/views/__init__.py b/cubicweb_seda/views/__init__.py
--- a/cubicweb_seda/views/__init__.py
+++ b/cubicweb_seda/views/__init__.py
@@ -16,21 +16,25 @@
 from copy import deepcopy
 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
 # XXX trigger monkey patches necessary to import this module, until we use a recent version of
 # lgc.registry supporting instantiation of rtags with explicit __module__ argument
 from .. import site_cubicweb  # noqa
 from ..xsd import XSDM_MAPPING
 from ..xsd2uicfg import FIRST_LEVEL_ETYPES
+from .uicfg import ETYPE_ATTR_DOC
 from .widgets import SEDAMetaField
 CONTENT_ETYPE = 'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement'
@@ -189,5 +193,25 @@ def dropdown_button(text, links):
     for link in links:
     return data.getvalue()
+orig_rel_label = primary.PrimaryView._rel_label
+ at 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))

More information about the saem-devel mailing list