24 can also be used to lazy-load arbitrary views |
24 can also be used to lazy-load arbitrary views |
25 caveat : lazyview is not recursive, i.e : you can't (successfully) |
25 caveat : lazyview is not recursive, i.e : you can't (successfully) |
26 lazyload a view that in turns does the same |
26 lazyload a view that in turns does the same |
27 """ |
27 """ |
28 |
28 |
29 def lazyview(self, vid, eid=None, show_spinbox=True, w=None): |
29 def _prepare_bindings(self, vid, reloadable): |
|
30 self.req.html_headers.add_onload(u""" |
|
31 jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) { |
|
32 load_now('#lazy-%(vid)s', '#%(vid)s-hole', %(reloadable)s); |
|
33 });""" % {'event': 'load_%s' % vid, 'vid': vid, |
|
34 'reloadable' : str(reloadable).lower()}) |
|
35 |
|
36 def lazyview(self, vid, eid=None, reloadable=False, show_spinbox=True, w=None): |
30 """a lazy version of wview |
37 """a lazy version of wview |
31 first version only support lazy viewing for an entity at a time |
38 first version only support lazy viewing for an entity at a time |
32 """ |
39 """ |
33 w = w or self.w |
40 w = w or self.w |
34 self.req.add_js('cubicweb.lazy.js') |
41 self.req.add_js('cubicweb.lazy.js') |
35 urlparams = {'vid' : vid, 'mode' : 'html'} |
42 urlparams = {'vid' : vid, 'mode' : 'html'} |
36 if eid: |
43 if eid: |
37 urlparams['rql'] = rql_for_eid(eid) |
44 urlparams['rql'] = rql_for_eid(eid) |
38 # w(u'<div id="lazy-%s" cubicweb:loadurl="%s-%s">' % (vid, vid, eid)) |
|
39 w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % ( |
45 w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % ( |
40 vid, html_escape(self.build_url('json', **urlparams)))) |
46 vid, html_escape(self.build_url('json', **urlparams)))) |
41 if show_spinbox: |
47 if show_spinbox: |
42 w(u'<img src="data/loading.gif" id="%s-hole" alt="%s"/>' |
48 w(u'<img src="data/loading.gif" id="%s-hole" alt="%s"/>' |
43 % (vid, self.req._('loading'))) |
49 % (vid, self.req._('loading'))) |
44 w(u'</div>') |
50 w(u'</div>') |
45 self.req.html_headers.add_onload(u""" |
51 self._prepare_bindings(vid, reloadable) |
46 jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) { |
|
47 load_now('#lazy-%(vid)s', '#%(vid)s-hole'); |
|
48 });""" % {'event': 'load_%s' % vid, 'vid': vid}) |
|
49 |
52 |
50 def forceview(self, vid): |
53 def forceview(self, vid): |
51 """trigger an event that will force immediate loading of the view |
54 """trigger an event that will force immediate loading of the view |
52 on dom readyness |
55 on dom readyness |
53 """ |
56 """ |
54 self.req.add_js('.lazy.js') |
57 self.req.add_js('cubicweb.lazy.js') |
55 self.req.html_headers.add_onload("trigger_load('%s');" % vid) |
58 self.req.html_headers.add_onload("trigger_load('%s');" % vid) |
56 |
59 |
57 |
60 |
58 class TabsMixin(LazyViewMixin): |
61 class TabsMixin(LazyViewMixin): |
59 |
62 |