5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 |
7 |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 |
9 |
|
10 from logilab.common.decorators import monkeypatch |
10 from logilab.mtconverter import html_escape |
11 from logilab.mtconverter import html_escape |
11 |
12 |
12 from cubicweb import NoSelectableObject, role |
13 from cubicweb import NoSelectableObject, role |
13 from cubicweb.common.view import EntityView |
14 from cubicweb.common.view import EntityView |
14 from cubicweb.common.selectors import has_related_entities |
15 from cubicweb.common.selectors import has_related_entities |
|
16 from cubicweb.common.utils import HTMLHead |
|
17 from cubicweb.common.uilib import rql_for_eid |
15 |
18 |
16 from cubicweb.common.utils import HTMLHead |
19 from cubicweb.web.views.basecontrollers import JSonController |
17 |
20 |
18 # the prepend hack only work for 1-level lazy views |
21 # the prepend hack only work for 1-level lazy views |
19 # a whole lot different thing must be done otherwise |
22 # a whole lot different thing must be done otherwise |
|
23 @monkeypatch(HTMLHead) |
20 def prepend_post_inline_script(self, content): |
24 def prepend_post_inline_script(self, content): |
21 self.post_inlined_scripts.insert(0, content) |
25 self.post_inlined_scripts.insert(0, content) |
22 HTMLHead.prepend_post_inline_script = prepend_post_inline_script |
26 |
23 |
27 |
24 class LazyViewMixin(object): |
28 class LazyViewMixin(object): |
25 """provides two convenience methods for the tab machinery |
29 """provides two convenience methods for the tab machinery |
26 can also be used to lazy-load arbitrary views |
30 can also be used to lazy-load arbitrary views |
27 caveat : lazyview is not recursive, i.e : you can't (successfully) |
31 caveat : lazyview is not recursive, i.e : you can't (successfully) |
114 w(u'<div id="as-%s">' % tab) |
118 w(u'<div id="as-%s">' % tab) |
115 self.lazyview(tab, entity.eid) |
119 self.lazyview(tab, entity.eid) |
116 w(u'</div>') |
120 w(u'</div>') |
117 |
121 |
118 |
122 |
119 from cubicweb.web.views.basecontrollers import JSonController |
123 @monkeypatch(JSonController) |
120 |
|
121 def js_remember_active_tab(self, tabname): |
124 def js_remember_active_tab(self, tabname): |
122 cookie = self.req.get_cookie() |
125 cookie = self.req.get_cookie() |
123 cookiename = '%s_active_tab' % self.config.appid |
126 cookiename = '%s_active_tab' % self.config.appid |
124 cookie[cookiename] = tabname |
127 cookie[cookiename] = tabname |
125 self.req.set_cookie(cookie, cookiename) |
128 self.req.set_cookie(cookie, cookiename) |
126 |
129 |
|
130 @monkeypatch(JSonController) |
127 def js_lazily(self, vid_eid): |
131 def js_lazily(self, vid_eid): |
128 vid, eid = vid_eid.split('-') |
132 vid, eid = vid_eid.split('-') |
129 rset = eid and self.req.eid_rset(eid) or None |
133 rset = eid and self.req.eid_rset(eid) or None |
130 view = self.vreg.select_view(vid, self.req, rset) |
134 view = self.vreg.select_view(vid, self.req, rset) |
131 return self._set_content_type(view, view.dispatch()) |
135 return self._set_content_type(view, view.dispatch()) |
132 |
136 |
133 JSonController.js_remember_active_tab = js_remember_active_tab |
|
134 JSonController.js_lazily = js_lazily |
|
135 |
137 |
136 class EntityRelatedTab(EntityView): |
138 class EntityRelatedTab(EntityView): |
137 """A view you should inherit from leftmost, |
139 """A view you should inherit from leftmost, |
138 to wrap another actual view displaying entity related stuff. |
140 to wrap another actual view displaying entity related stuff. |
139 Such a view _must_ provide the rtype, target and vid attributes : |
141 Such a view _must_ provide the rtype, target and vid attributes : |
140 |
142 |
141 Example : |
143 Example : |
142 |
144 |
143 class ProjectScreenshotsView(EntityRelationView): |
145 class ProjectScreenshotsView(EntityRelationView): |
144 "display project's screenshots" |
146 '''display project's screenshots''' |
145 id = title = _('projectscreenshots') |
147 id = title = _('projectscreenshots') |
146 accepts = ('Project',) |
148 accepts = ('Project',) |
147 rtype = 'screenshot' |
149 rtype = 'screenshot' |
148 target = 'object' |
150 target = 'object' |
149 vid = 'gallery' |
151 vid = 'gallery' |
158 """ |
160 """ |
159 __selectors__ = EntityView.__selectors__ + (has_related_entities,) |
161 __selectors__ = EntityView.__selectors__ + (has_related_entities,) |
160 vid = 'list' |
162 vid = 'list' |
161 |
163 |
162 def cell_call(self, row, col): |
164 def cell_call(self, row, col): |
163 rset = self.rset.get_entity(row, col).related(self.rtype, role(self)) |
165 rset = self.entity(row, col).related(self.rtype, role(self)) |
164 self.w(u'<div class="mainInfo">') |
166 self.w(u'<div class="mainInfo">') |
165 self.wview(self.vid, rset, 'noresult') |
167 self.wview(self.vid, rset, 'noresult') |
166 self.w(u'</div>') |
168 self.w(u'</div>') |