[PATCH 3 of 3 saem_ref v3] Use existing popovers in ConceptScheme jquery tree view

Frank Bessou frank.bessou at logilab.fr
Fri Sep 28 16:33:06 CEST 2018


# HG changeset patch
# User Frank Bessou <frank.bessou at logilab.fr>
# Date 1538141724 -7200
#      Fri Sep 28 15:35:24 2018 +0200
# Node ID 3d438fea78d581729af9ae7177eb52c807e64841
# Parent  f38adb440019343932d45288aeaa7d90d5cdb428
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 3d438fea78d5
Use existing popovers in ConceptScheme jquery tree view

To make popovers work in the dynamically loaded tree, we add a script
that adds popovers on all elements with a "data-toggle='popover'"
attribute (this is done in a new PopoverJQTreeView).
We adapt the ConceptPopoverView to make it work within a JQTree and we
add the "data-toggle" attribute on the label anchors.

diff --git a/cubicweb_saem_ref/views/skos.py b/cubicweb_saem_ref/views/skos.py
--- a/cubicweb_saem_ref/views/skos.py
+++ b/cubicweb_saem_ref/views/skos.py
@@ -17,12 +17,12 @@
 
 
 from cubicweb import tags, _
-from cubicweb.view import AnyRsetView
+from cubicweb.view import EntityView
 from cubicweb.predicates import is_instance
 from cubicweb.uilib import js
 from cubicweb.view import EntityAdapter
 from cubicweb.web import formwidgets as fw
-from cubicweb.web.views import baseviews, treeview, uicfg
+from cubicweb.web.views import baseviews, uicfg
 
 from cubicweb_seda.entities.itree import IContainedToITreeBase
 import cubicweb_seda.views.jqtree as jqtree
@@ -88,20 +88,21 @@ class ConceptSchemeSameETypeListView(bas
             href=href, title=title))
 
 
-class ConceptTreeView(treeview.TreeView):
-    """`treeview` for Concept entities."""
-    __select__ = treeview.TreeView.__select__ & is_instance('Concept')
-    subvid = 'skos.concept-popover'
+class PopoverJQTreeView(jqtree.JQTreeView):
+
+    __select__ = jqtree.JQTreeView.__select__ & is_instance('ConceptScheme')
+
+    def entity_call(self, entity):
+        super(PopoverJQTreeView, self).entity_call(entity)
+        self._cw.add_onload("$(document).popover({selector:'[data-toggle=\"popover\"]'});")
 
 
-class ConceptPopoverView(AnyRsetView):
-    """Popover view for Concept, to be displayed within treeview"""
-    __regid__ = 'skos.concept-popover'
+class ConceptPopoverView(EntityView):
+    """Popover view for Concept, to be displayed within a jqtree"""
+    __regid__ = 'jqtree.label'
     __select__ = is_instance('Concept')
 
-    def cell_call(self, row, col, **kwargs):
-        entity = self.cw_rset.get_entity(row, col)
-        self._cw.add_onload("$('#{eid}').popover();".format(eid=entity.eid))
+    def entity_call(self, entity):
         title = entity.dc_title()
         content = u'<dl>'
         for attr in ('definition', 'example'):
@@ -112,6 +113,7 @@ class ConceptPopoverView(AnyRsetView):
         content += u'</dl>'
         content += tags.a(self._cw._('view'), href=entity.absolute_url())
         data = {'data-title': title,
+                'data-toggle': 'popover',
                 'data-content': content,
                 'data-html': 'true',
                 'data-trigger': 'focus'}



More information about the saem-devel mailing list