[tabs] prepare for reloadability
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 06 Feb 2009 20:23:26 +0100
changeset 559 7cfd3d11edc8
parent 558 a8887dd924f4
child 560 005f78d21fc7
[tabs] prepare for reloadability
web/data/cubicweb.lazy.js
web/views/tabs.py
--- a/web/data/cubicweb.lazy.js	Fri Feb 06 12:03:58 2009 +0100
+++ b/web/data/cubicweb.lazy.js	Fri Feb 06 20:23:26 2009 +0100
@@ -1,8 +1,8 @@
 
-function load_now(eltsel, holesel) {
+function load_now(eltsel, holesel, reloadable) {
     var lazydiv = jQuery(eltsel);
     var hole = lazydiv.children(holesel);
-    if (hole.length == 0) {
+    if ((hole.length == 0) && !reloadable) {
 	/* the hole is already filled */
 	return;
     }
--- a/web/views/tabs.py	Fri Feb 06 12:03:58 2009 +0100
+++ b/web/views/tabs.py	Fri Feb 06 20:23:26 2009 +0100
@@ -26,7 +26,14 @@
     lazyload a view that in turns does the same
     """
 
-    def lazyview(self, vid, eid=None, show_spinbox=True, w=None):
+    def _prepare_bindings(self, vid, reloadable):
+        self.req.html_headers.add_onload(u"""
+  jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) {
+     load_now('#lazy-%(vid)s', '#%(vid)s-hole', %(reloadable)s);
+  });""" % {'event': 'load_%s' % vid, 'vid': vid,
+            'reloadable' : str(reloadable).lower()})
+
+    def lazyview(self, vid, eid=None, reloadable=False, show_spinbox=True, w=None):
         """a lazy version of wview
         first version only support lazy viewing for an entity at a time
         """
@@ -35,23 +42,19 @@
         urlparams = {'vid' : vid, 'mode' : 'html'}
         if eid:
             urlparams['rql'] = rql_for_eid(eid)
-        # w(u'<div id="lazy-%s" cubicweb:loadurl="%s-%s">' % (vid, vid, eid))
         w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % (
             vid, html_escape(self.build_url('json', **urlparams))))
         if show_spinbox:
             w(u'<img src="data/loading.gif" id="%s-hole" alt="%s"/>'
               % (vid, self.req._('loading')))
         w(u'</div>')
-        self.req.html_headers.add_onload(u"""
-  jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) {
-     load_now('#lazy-%(vid)s', '#%(vid)s-hole');
-  });""" % {'event': 'load_%s' % vid, 'vid': vid})
+        self._prepare_bindings(vid, reloadable)
 
     def forceview(self, vid):
         """trigger an event that will force immediate loading of the view
         on dom readyness
         """
-        self.req.add_js('.lazy.js')
+        self.req.add_js('cubicweb.lazy.js')
         self.req.html_headers.add_onload("trigger_load('%s');" % vid)