107 # (https://www.logilab.net/cwo/ticket/342789) |
107 # (https://www.logilab.net/cwo/ticket/342789) |
108 #rql = self.req.form.get('rql') |
108 #rql = self.req.form.get('rql') |
109 #if rql: |
109 #if rql: |
110 # self.req.execute(rql).get_entity(0,0).view(default, w=self.w) |
110 # self.req.execute(rql).get_entity(0,0).view(default, w=self.w) |
111 # return |
111 # return |
112 self.req.add_css('ui.tabs.css') |
112 self.req.add_css('tabs-no-images.css') |
113 self.req.add_js(('ui.core.js', 'ui.tabs.js', |
113 self.req.add_js(('jquery.tools.min.js', 'cubicweb.htmlhelpers.js', |
114 'cubicweb.ajax.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js')) |
114 'cubicweb.ajax.js', 'cubicweb.tabs.js', 'cubicweb.lazy.js')) |
115 # prune tabs : not all are to be shown |
115 # prune tabs : not all are to be shown |
116 tabs = self.prune_tabs(tabs) |
116 tabs = self.prune_tabs(tabs) |
117 # select a tab |
117 # select a tab |
118 active_tab = self.active_tab(tabs, default) |
118 active_tab = self.active_tab(tabs, default) |
121 if entity: |
121 if entity: |
122 w(u'<div id="entity-tabs-%s">' % entity.eid) |
122 w(u'<div id="entity-tabs-%s">' % entity.eid) |
123 else: |
123 else: |
124 uid = make_uid('tab') |
124 uid = make_uid('tab') |
125 w(u'<div id="entity-tabs-%s">' % uid) |
125 w(u'<div id="entity-tabs-%s">' % uid) |
126 w(u'<ul>') |
126 w(u'<ul class="css-tabs" id="tabs-%s">' % entity.eid) |
127 for tab in tabs: |
127 for tab in tabs: |
128 w(u'<li>') |
128 w(u'<li>') |
129 w(u'<a href="#as-%s">' % tab) |
129 w(u'<a href="#as-%s">' % tab) |
130 w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tab, self.cookie_name)) |
130 w(u'<span onclick="set_tab(\'%s\', \'%s\')">' % (tab, self.cookie_name)) |
131 w(self.req._(tab)) |
131 w(self.req._(tab)) |
132 w(u'</span>') |
132 w(u'</span>') |
133 w(u'</a>') |
133 w(u'</a>') |
134 w(u'</li>') |
134 w(u'</li>') |
135 w(u'</ul>') |
135 w(u'</ul>') |
136 w(u'</div>') |
136 w(u'</div>') |
|
137 w(u'<div id="panes-%s">' % entity.eid) |
137 for tab in tabs: |
138 for tab in tabs: |
138 w(u'<div id="as-%s">' % tab) |
139 w(u'<div>') |
139 if entity: |
140 if entity: |
140 self.lazyview(tab, eid=entity.eid) |
141 self.lazyview(tab, eid=entity.eid) |
141 else: |
142 else: |
142 self.lazyview(tab, static=True) |
143 self.lazyview(tab, static=True) |
143 w(u'</div>') |
144 w(u'</div>') |
|
145 w(u'</div>') |
144 # call the set_tab() JS function *after* each tab is generated |
146 # call the set_tab() JS function *after* each tab is generated |
145 # because the callback binding needs to be done before |
147 # because the callback binding needs to be done before |
146 self.req.html_headers.add_onload(u""" |
148 self.req.html_headers.add_onload(u""" |
147 jQuery('#entity-tabs-%(eeid)s > ul').tabs( { selected: %(tabindex)s }); |
149 jQuery(function() { |
148 set_tab('%(vid)s', '%(cookiename)s'); |
150 jQuery("#tabs-%(eeid)s").tabs("#panes-%(eeid)s > div", {initialIndex: %(tabindex)s}); |
149 """ % {'tabindex' : tabs.index(active_tab), |
151 set_tab('%(vid)s', '%(cookiename)s'); |
150 'vid' : active_tab, |
152 });""" % {'eeid' : entity.eid, |
151 'eeid' : (entity and entity.eid or uid), |
153 'vid' : active_tab, |
152 'cookiename' : self.cookie_name}) |
154 'cookiename' : self.cookie_name, |
|
155 'tabindex' : tabs.index(active_tab)}) |
153 |
156 |
154 |
157 |
155 class EntityRelationView(EntityView): |
158 class EntityRelationView(EntityView): |
156 """view displaying entity related stuff. |
159 """view displaying entity related stuff. |
157 Such a view _must_ provide the rtype, target and vid attributes : |
160 Such a view _must_ provide the rtype, target and vid attributes : |