30 jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) { |
30 jQuery('#lazy-%(vid)s').bind('%(event)s', function(event) { |
31 load_now('#lazy-%(vid)s', '#%(vid)s-hole', %(reloadable)s); |
31 load_now('#lazy-%(vid)s', '#%(vid)s-hole', %(reloadable)s); |
32 });""" % {'event': 'load_%s' % vid, 'vid': vid, |
32 });""" % {'event': 'load_%s' % vid, 'vid': vid, |
33 'reloadable' : str(reloadable).lower()}) |
33 'reloadable' : str(reloadable).lower()}) |
34 |
34 |
35 def lazyview(self, vid, rql=None, eid=None, rset=None, static=False, |
35 def lazyview(self, vid, eid=None, reloadable=False, show_spinbox=True, w=None): |
36 reloadable=False, show_spinbox=True, w=None): |
|
37 """a lazy version of wview |
36 """a lazy version of wview |
38 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 |
39 """ |
38 """ |
40 assert rql or eid or rset or static, \ |
|
41 'lazyview wants at least : rql, or an eid, or an rset -- or call it with static=True' |
|
42 w = w or self.w |
39 w = w or self.w |
43 self.req.add_js('cubicweb.lazy.js') |
40 self.req.add_js('cubicweb.lazy.js') |
44 urlparams = {'vid' : vid, 'mode' : 'html'} |
41 urlparams = {'vid' : vid, 'mode' : 'html'} |
45 if rql: |
42 if eid: |
46 urlparams['rql'] = rql |
|
47 elif eid: |
|
48 urlparams['rql'] = uilib.rql_for_eid(eid) |
43 urlparams['rql'] = uilib.rql_for_eid(eid) |
49 elif rset: |
|
50 urlparams['rql'] = rset.printable_rql() |
|
51 w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % ( |
44 w(u'<div id="lazy-%s" cubicweb:loadurl="%s">' % ( |
52 vid, html_escape(self.build_url('json', **urlparams)))) |
45 vid, html_escape(self.build_url('json', **urlparams)))) |
53 if show_spinbox: |
46 if show_spinbox: |
54 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"/>' |
55 % (vid, self.req._('loading'))) |
48 % (vid, self.req._('loading'))) |
69 @property |
62 @property |
70 def cookie_name(self): |
63 def cookie_name(self): |
71 return str('%s_active_tab' % self.config.appid) |
64 return str('%s_active_tab' % self.config.appid) |
72 |
65 |
73 def active_tab(self, tabs, default): |
66 def active_tab(self, tabs, default): |
74 cookies = self.req.get_cookie() |
67 cookie = self.req.get_cookie() |
75 cookiename = self.cookie_name |
68 cookiename = self.cookie_name |
76 activetab = cookies.get(cookiename) |
69 activetab = cookie.get(cookiename) |
77 if activetab is None: |
70 if activetab is None: |
78 cookies[cookiename] = default |
71 cookie[cookiename] = default |
79 self.req.set_cookie(cookies, cookiename) |
72 self.req.set_cookie(cookie, cookiename) |
80 tab = default |
73 tab = default |
81 else: |
74 else: |
82 tab = activetab.value |
75 tab = activetab.value |
83 return tab in tabs and tab or default |
76 return tab in tabs and tab or default |
84 |
77 |
100 tabs = self.prune_tabs(tabs) |
93 tabs = self.prune_tabs(tabs) |
101 # select a tab |
94 # select a tab |
102 active_tab = self.active_tab(tabs, default) |
95 active_tab = self.active_tab(tabs, default) |
103 # build the html structure |
96 # build the html structure |
104 w = self.w |
97 w = self.w |
105 w(u'<div id="entity-tabs-%s">' % entity.eid) |
98 w(u'<div id="entity-tabs">') |
106 w(u'<ul>') |
99 w(u'<ul>') |
107 for tab in tabs: |
100 for tab in tabs: |
108 w(u'<li>') |
101 w(u'<li>') |
109 w(u'<a href="#as-%s">' % tab) |
102 w(u'<a href="#as-%s">' % tab) |
110 w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tab, self.cookie_name)) |
103 w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tab, self.cookie_name)) |
114 w(u'</li>') |
107 w(u'</li>') |
115 w(u'</ul>') |
108 w(u'</ul>') |
116 w(u'</div>') |
109 w(u'</div>') |
117 for tab in tabs: |
110 for tab in tabs: |
118 w(u'<div id="as-%s">' % tab) |
111 w(u'<div id="as-%s">' % tab) |
119 self.lazyview(tab, eid=entity.eid) |
112 self.lazyview(tab, entity.eid) |
120 w(u'</div>') |
113 w(u'</div>') |
121 # call the set_tab() JS function *after* each tab is generated |
114 # call the set_tab() JS function *after* each tab is generated |
122 # because the callback binding needs to be done before |
115 # because the callback binding needs to be done before |
123 self.req.html_headers.add_onload(u""" |
116 self.req.html_headers.add_onload(u""" |
124 jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s }); |
117 jQuery('#entity-tabs > ul').tabs( { selected: %(tabindex)s }); |
125 set_tab('%(vid)s', '%(cookiename)s'); |
118 set_tab('%(vid)s', '%(cookiename)s'); |
126 """ % {'tabindex' : tabs.index(active_tab), |
119 """ % {'tabindex' : tabs.index(active_tab), |
127 'vid' : active_tab, |
120 'vid' : active_tab, |
128 'eeid' : entity.eid, |
|
129 'cookiename' : self.cookie_name}) |
121 'cookiename' : self.cookie_name}) |
130 |
122 |
131 |
123 |
132 class EntityRelationView(EntityView): |
124 class EntityRelationView(EntityView): |
133 """view displaying entity related stuff. |
125 """view displaying entity related stuff. |