37 first version only support lazy viewing for an entity at a time |
37 first version only support lazy viewing for an entity at a time |
38 """ |
38 """ |
39 w = w or self.w |
39 w = w or self.w |
40 self.req.add_js('cubicweb.lazy.js') |
40 self.req.add_js('cubicweb.lazy.js') |
41 eid = eid or '' |
41 eid = eid or '' |
42 w(u'<div id="lazy-%s" cubicweb:lazyloadurl="%s-%s">' % (vid, vid, eid)) |
42 # w(u'<div id="lazy-%s" cubicweb:loadurl="%s-%s">' % (vid, vid, eid)) |
|
43 w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % ( |
|
44 vid, html_escape(self.build_url('json', rql=rql_for_eid(eid), vid=vid, |
|
45 mode='html')))) |
43 if show_spinbox: |
46 if show_spinbox: |
44 w(u'<img src="data/loading.gif" id="%s-hole" alt="%s"/>' |
47 w(u'<img src="data/loading.gif" id="%s-hole" alt="%s"/>' |
45 % (vid, self.req._('loading'))) |
48 % (vid, self.req._('loading'))) |
46 w(u'</div>') |
49 w(u'</div>') |
47 self.req.html_headers.prepend_post_inline_script(u""" |
50 self.req.html_headers.add_onload(u""" |
48 jQuery(document).ready(function () { |
51 jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) { |
49 $('#lazy-%(vid)s').bind('%(event)s', function(event) { |
|
50 load_now('#lazy-%(vid)s', '#%(vid)s-hole'); |
52 load_now('#lazy-%(vid)s', '#%(vid)s-hole'); |
51 });});""" % {'event' : 'load_%s' % vid, |
53 });""" % {'event': 'load_%s' % vid, 'vid': vid}) |
52 'vid' : vid}) |
|
53 |
54 |
54 def forceview(self, vid): |
55 def forceview(self, vid): |
55 """trigger an event that will force immediate loading of the view |
56 """trigger an event that will force immediate loading of the view |
56 on dom readyness |
57 on dom readyness |
57 """ |
58 """ |
58 self.req.add_js('.lazy.js') |
59 self.req.add_js('.lazy.js') |
59 self.req.html_headers.add_post_inline_script(u""" |
60 self.req.html_headers.add_onload("trigger_load('%s');})" % vid) |
60 jQuery(document).ready(function() { |
61 |
61 trigger_load('%(vid)s');}) |
|
62 """ % {'vid' : vid}) |
|
63 |
62 |
64 class TabsMixin(LazyViewMixin): |
63 class TabsMixin(LazyViewMixin): |
65 |
64 |
66 def active_tab(self, tabs, default): |
65 def active_tab(self, tabs, default): |
67 cookie = self.req.get_cookie() |
66 cookie = self.req.get_cookie() |
91 'cubicweb.ajax.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js')) |
90 'cubicweb.ajax.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js')) |
92 # prune tabs : not all are to be shown |
91 # prune tabs : not all are to be shown |
93 tabs = self.prune_tabs(tabs) |
92 tabs = self.prune_tabs(tabs) |
94 # select a tab |
93 # select a tab |
95 active_tab = self.active_tab(tabs, default) |
94 active_tab = self.active_tab(tabs, default) |
96 self.req.html_headers.add_post_inline_script(u""" |
|
97 jQuery(document).ready(function() { |
|
98 jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s }); |
|
99 set_tab('%(vid)s'); |
|
100 }); |
|
101 """ % {'tabindex' : tabs.index(active_tab), |
|
102 'vid' : active_tab}) |
|
103 # build the html structure |
95 # build the html structure |
104 w = self.w |
96 w = self.w |
105 w(u'<div id="entity-tabs">') |
97 w(u'<div id="entity-tabs">') |
106 w(u'<ul>') |
98 w(u'<ul>') |
107 for tab in tabs: |
99 for tab in tabs: |
116 w(u'</div>') |
108 w(u'</div>') |
117 for tab in tabs: |
109 for tab in tabs: |
118 w(u'<div id="as-%s">' % tab) |
110 w(u'<div id="as-%s">' % tab) |
119 self.lazyview(tab, entity.eid) |
111 self.lazyview(tab, entity.eid) |
120 w(u'</div>') |
112 w(u'</div>') |
|
113 # call the set_tab() JS function *after* each tab is generated |
|
114 # because the callback binding needs to be done before |
|
115 self.req.html_headers.add_onload(u""" |
|
116 jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s }); |
|
117 set_tab('%(vid)s'); |
|
118 """ % {'tabindex' : tabs.index(active_tab), |
|
119 'vid' : active_tab}) |
121 |
120 |
122 |
121 |
123 @monkeypatch(JSonController) |
122 @monkeypatch(JSonController) |
124 def js_remember_active_tab(self, tabname): |
123 def js_remember_active_tab(self, tabname): |
125 cookie = self.req.get_cookie() |
124 cookie = self.req.get_cookie() |