[PATCH saem] [views] Override seda popup to hide element name

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Oct 13 07:12:12 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1507819942 -7200
#      Thu Oct 12 16:52:22 2017 +0200
# Node ID 05ffb07d8ea1d5561f324dedf36a14bb0f732bca
# Parent  3ff35553f659dd0d7f83008e97237e4ccc979cfc
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 05ffb07d8ea1
[views] Override seda popup to hide element name

this might be confusing in this SEDA 0.2 only platform to see SEDA 2 element
names.

diff --git a/cubicweb_saem_ref/views/__init__.py b/cubicweb_saem_ref/views/__init__.py
--- a/cubicweb_saem_ref/views/__init__.py
+++ b/cubicweb_saem_ref/views/__init__.py
@@ -31,10 +31,11 @@ from cubicweb.predicates import (has_per
 from cubicweb.web import component, formwidgets as fw
 from cubicweb.web.views import basecomponents, uicfg, urlrewrite, tabs, primary
 
 from cubes.squareui.views.basetemplates import basetemplates
 from cubicweb_seda.views import dropdown_button, has_rel_perm, widgets as sedawidgets
+from cubicweb_seda.views.uicfg import ETYPE_ATTR_DOC
 
 from .. import cwuri_url
 
 
 pvs = uicfg.primaryview_section
@@ -426,10 +427,27 @@ class URLAttributeView(primary.URLAttrib
             url = entity.printable_value(rtype)
         if url:
             self.w(u'<a href="%s">%s</a>' % (url, url))
 
 
+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:
+        return label
+    description = xml_escape(desc[0]) if desc else u''
+    self._cw.add_onload("$('.popOverLabel').popover();")
+    return (u'<div class="popOverLabel" '
+            'data-toggle="popover" data-placement="top" '
+            'data-content="{}">{}</div>'.format(description, label))
+
+
 def registration_callback(vreg):
     from cubicweb.web.views import actions, cwuser, tableview, undohistory
     vreg.register_all(globals().values(), __name__, (URLAttributeView, SAEMHTMLPageFooter,))
     vreg.register_and_replace(URLAttributeView, primary.URLAttributeView)
     vreg.register_and_replace(SAEMHTMLPageFooter, basetemplates.HTMLPageFooter)
diff --git a/dev-requirements.txt b/dev-requirements.txt
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,4 +1,4 @@
 mock
 pytest
 webtest
-http://hg.logilab.org/review/cubes/seda/archive/d547500012b2.tar.bz2#egg=cubicweb-seda
+http://hg.logilab.org/master/cubes/seda/archive/tip.tar.bz2#egg=cubicweb-seda


More information about the saem-devel mailing list