author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 06 Apr 2010 10:17:18 +0200 | |
branch | stable |
changeset 5148 | ec0ea7366066 |
parent 4935 | f710770e6e90 |
child 5195 | e8235b2789fc |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
0 | 1 |
"""Bases HTML components: |
2 |
||
3 |
* the rql input form |
|
4 |
* the logged user link |
|
2937
36b11249014e
[pdf] (ugly) pdf icon, component
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2650
diff
changeset
|
5 |
* pdf view link |
0 | 6 |
|
7 |
:organization: Logilab |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3848
diff
changeset
|
8 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 9 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1968
diff
changeset
|
10 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 11 |
""" |
12 |
__docformat__ = "restructuredtext en" |
|
1937 | 13 |
_ = unicode |
0 | 14 |
|
2313 | 15 |
from logilab.mtconverter import xml_escape |
0 | 16 |
from rql import parse |
17 |
||
5148
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
18 |
from cubicweb.selectors import (yes, multi_etypes_rset, match_form_params, |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
19 |
anonymous_user, authenticated_user) |
1699 | 20 |
from cubicweb.schema import display_name |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4004
diff
changeset
|
21 |
from cubicweb.uilib import toggle_action |
1739 | 22 |
from cubicweb.web import component |
1699 | 23 |
from cubicweb.web.htmlwidgets import (MenuWidget, PopupBoxMenu, BoxSeparator, |
24 |
BoxLink) |
|
0 | 25 |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
26 |
VISIBLE_PROP_DEF = { |
1968
d3de0f44b57b
components should be visible by default, applmessages components should not be hideable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1937
diff
changeset
|
27 |
_('visible'): dict(type='Boolean', default=True, |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
28 |
help=_('display the component or not')), |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
29 |
} |
0 | 30 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
31 |
class RQLInputForm(component.Component): |
0 | 32 |
"""build the rql input form, usually displayed in the header""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
33 |
__regid__ = 'rqlinput' |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
34 |
cw_property_defs = VISIBLE_PROP_DEF |
2120
ed1cd652b343
rqlinput should have its default visible property to false
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2119
diff
changeset
|
35 |
visible = False |
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2120
diff
changeset
|
36 |
|
0 | 37 |
def call(self, view=None): |
38 |
if hasattr(view, 'filter_box_context_info'): |
|
39 |
rset = view.filter_box_context_info()[0] |
|
40 |
else: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
41 |
rset = self.cw_rset |
0 | 42 |
# display multilines query as one line |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
43 |
rql = rset is not None and rset.printable_rql(encoded=False) or self._cw.form.get('rql', '') |
0 | 44 |
rql = rql.replace(u"\n", u" ") |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
45 |
req = self._cw |
0 | 46 |
self.w(u'''<div id="rqlinput" class="%s"> |
47 |
<form action="%s"> |
|
48 |
<fieldset> |
|
49 |
<input type="text" id="rql" name="rql" value="%s" title="%s" tabindex="%s" accesskey="q" class="searchField" /> |
|
851
33957ff2b790
use rql button
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
533
diff
changeset
|
50 |
<input type="submit" value="" class="rqlsubmit" tabindex="%s" /> |
0 | 51 |
</fieldset> |
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2799
diff
changeset
|
52 |
''' % (not self.cw_propval('visible') and 'hidden' or '', |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
53 |
self._cw.build_url('view'), xml_escape(rql), req._('full text or RQL query'), req.next_tabindex(), |
851
33957ff2b790
use rql button
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
533
diff
changeset
|
54 |
req.next_tabindex())) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
55 |
if self._cw.search_state[0] != 'normal': |
0 | 56 |
self.w(u'<input type="hidden" name="__mode" value="%s"/>' |
57 |
% ':'.join(req.search_state[1])) |
|
58 |
self.w(u'</form></div>') |
|
59 |
||
60 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
61 |
class ApplLogo(component.Component): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
62 |
"""build the instance logo, usually displayed in the header""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
63 |
__regid__ = 'logo' |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
64 |
cw_property_defs = VISIBLE_PROP_DEF |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
65 |
# don't want user to hide this component using an cwproperty |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
66 |
site_wide = True |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
67 |
|
0 | 68 |
def call(self): |
69 |
self.w(u'<a href="%s"><img class="logo" src="%s" alt="logo"/></a>' |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
70 |
% (self._cw.base_url(), self._cw.external_resource('LOGO'))) |
0 | 71 |
|
72 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
73 |
class ApplHelp(component.Component): |
0 | 74 |
"""build the help button, usually displayed in the header""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
75 |
__regid__ = 'help' |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
76 |
cw_property_defs = VISIBLE_PROP_DEF |
0 | 77 |
def call(self): |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2650
diff
changeset
|
78 |
self.w(u'<a href="%s" class="help" title="%s"> </a>' |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
79 |
% (self._cw.build_url(_restpath='doc/main'), |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
80 |
self._cw._(u'help'),)) |
0 | 81 |
|
82 |
||
5148
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
83 |
class _UserLink(component.Component): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
84 |
"""if the user is the anonymous user, build a link to login else display a menu |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
85 |
with user'action (preference, logout, etc...) |
0 | 86 |
""" |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
87 |
cw_property_defs = VISIBLE_PROP_DEF |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
88 |
# don't want user to hide this component using an cwproperty |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
89 |
site_wide = True |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
90 |
__regid__ = 'loggeduserlink' |
0 | 91 |
|
5148
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
92 |
|
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
93 |
class AnonUserLink(_UserLink): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
94 |
__select__ = _UserLink.__select__ & anonymous_user() |
0 | 95 |
def call(self): |
3659 | 96 |
if self._cw.vreg.config['auth-mode'] == 'cookie': |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
97 |
self.w(self._cw._('anonymous')) |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2650
diff
changeset
|
98 |
self.w(u''' [<a class="logout" href="javascript: popupLoginBox();">%s</a>]''' |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
99 |
% (self._cw._('i18n_login_popup'))) |
0 | 100 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
101 |
self.w(self._cw._('anonymous')) |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2650
diff
changeset
|
102 |
self.w(u' [<a class="logout" href="%s">%s</a>]' |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
103 |
% (self._cw.build_url('login'), self._cw._('login'))) |
0 | 104 |
|
105 |
||
5148
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
106 |
class UserLink(_UserLink): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
107 |
__select__ = _UserLink.__select__ & authenticated_user() |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
108 |
|
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
109 |
def call(self): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
110 |
# display useractions and siteactions |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
111 |
actions = self._cw.vreg['actions'].possible_actions(self._cw, rset=self.cw_rset) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
112 |
box = MenuWidget('', 'userActionsBox', _class='', islist=False) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
113 |
menu = PopupBoxMenu(self._cw.user.login, isitem=False) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
114 |
box.append(menu) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
115 |
for action in actions.get('useractions', ()): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
116 |
menu.append(BoxLink(action.url(), self._cw._(action.title), |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
117 |
action.html_class())) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
118 |
if actions.get('useractions') and actions.get('siteactions'): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
119 |
menu.append(BoxSeparator()) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
120 |
for action in actions.get('siteactions', ()): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
121 |
menu.append(BoxLink(action.url(), self._cw._(action.title), |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
122 |
action.html_class())) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
123 |
box.render(w=self.w) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
124 |
|
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
125 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
126 |
class ApplicationMessage(component.Component): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
127 |
"""display messages given using the __message parameter into a special div |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
128 |
section |
0 | 129 |
""" |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
130 |
__select__ = yes() |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
131 |
__regid__ = 'applmessages' |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
132 |
# don't want user to hide this component using an cwproperty |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
133 |
cw_property_defs = {} |
0 | 134 |
|
135 |
def call(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
136 |
msgs = [msg for msg in (self._cw.get_shared_data('sources_error', pop=True), |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
137 |
self._cw.message) if msg] |
0 | 138 |
self.w(u'<div id="appMsg" onclick="%s" class="%s">\n' % |
139 |
(toggle_action('appMsg'), (msgs and ' ' or 'hidden'))) |
|
140 |
for msg in msgs: |
|
141 |
self.w(u'<div class="message" id="%s">%s</div>' % ( |
|
142 |
self.div_id(), msg)) |
|
143 |
self.w(u'</div>') |
|
144 |
||
145 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
146 |
class ApplicationName(component.Component): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
147 |
"""display the instance name""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
148 |
__regid__ = 'appliname' |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
149 |
cw_property_defs = VISIBLE_PROP_DEF |
1739 | 150 |
# don't want user to hide this component using an cwproperty |
151 |
site_wide = True |
|
0 | 152 |
|
153 |
def call(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
154 |
title = self._cw.property_value('ui.site-title') |
2119
dc1eedd06766
deal with empty site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
155 |
if title: |
dc1eedd06766
deal with empty site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
156 |
self.w(u'<span id="appliName"><a href="%s">%s</a></span>' % ( |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
157 |
self._cw.base_url(), xml_escape(title))) |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
158 |
|
0 | 159 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
160 |
class SeeAlsoVComponent(component.RelatedObjectsVComponent): |
0 | 161 |
"""display any entity's see also""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
162 |
__regid__ = 'seealso' |
0 | 163 |
context = 'navcontentbottom' |
164 |
rtype = 'see_also' |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
165 |
role = 'subject' |
0 | 166 |
order = 40 |
167 |
# register msg not generated since no entity use see_also in cubicweb itself |
|
168 |
title = _('contentnavigation_seealso') |
|
169 |
help = _('contentnavigation_seealso_description') |
|
170 |
||
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
171 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
172 |
class EtypeRestrictionComponent(component.Component): |
0 | 173 |
"""displays the list of entity types contained in the resultset |
174 |
to be able to filter accordingly. |
|
175 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
176 |
__regid__ = 'etypenavigation' |
4320
4efd4c306746
closes #345410: two_lines_rset, two_cols_rset, two_etypes_rset are badly named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
177 |
__select__ = multi_etypes_rset() | match_form_params('__restrtype', '__restrtypes', |
758
0c0dfd33a76d
instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
742
diff
changeset
|
178 |
'__restrrql') |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
179 |
cw_property_defs = VISIBLE_PROP_DEF |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
180 |
# don't want user to hide this component using an cwproperty |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
181 |
site_wide = True |
0 | 182 |
visible = False # disabled by default |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
183 |
|
0 | 184 |
def call(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
185 |
_ = self._cw._ |
0 | 186 |
self.w(u'<div id="etyperestriction">') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
187 |
restrtype = self._cw.form.get('__restrtype') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
188 |
restrtypes = self._cw.form.get('__restrtypes', '').split(',') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
189 |
restrrql = self._cw.form.get('__restrrql') |
0 | 190 |
if not restrrql: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
191 |
rqlst = self.cw_rset.syntax_tree() |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
192 |
restrrql = rqlst.as_string(self._cw.encoding, self.cw_rset.args) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
193 |
restrtypes = self.cw_rset.column_types(0) |
0 | 194 |
else: |
195 |
rqlst = parse(restrrql) |
|
196 |
html = [] |
|
197 |
on_etype = False |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
198 |
etypes = sorted((display_name(self._cw, etype).capitalize(), etype) |
0 | 199 |
for etype in restrtypes) |
200 |
for elabel, etype in etypes: |
|
201 |
if etype == restrtype: |
|
202 |
html.append(u'<span class="selected">%s</span>' % elabel) |
|
203 |
on_etype = True |
|
204 |
else: |
|
205 |
rqlst.save_state() |
|
206 |
for select in rqlst.children: |
|
207 |
select.add_type_restriction(select.selection[0], etype) |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
208 |
newrql = rqlst.as_string(self._cw.encoding, self.cw_rset.args) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
209 |
url = self._cw.build_url(rql=newrql, __restrrql=restrrql, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
210 |
__restrtype=etype, __restrtypes=','.join(restrtypes)) |
0 | 211 |
html.append(u'<span><a href="%s">%s</a></span>' % ( |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2218
diff
changeset
|
212 |
xml_escape(url), elabel)) |
0 | 213 |
rqlst.recover() |
214 |
if on_etype: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
215 |
url = self._cw.build_url(rql=restrrql) |
0 | 216 |
html.insert(0, u'<span><a href="%s">%s</a></span>' % ( |
217 |
url, _('Any'))) |
|
218 |
else: |
|
219 |
html.insert(0, u'<span class="selected">%s</span>' % _('Any')) |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2650
diff
changeset
|
220 |
self.w(u' | '.join(html)) |
0 | 221 |
self.w(u'</div>') |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
222 |
|
3840
2eff4348b1e4
prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3818
diff
changeset
|
223 |
|
3844
c2625c512085
stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3840
diff
changeset
|
224 |
class MetaDataComponent(component.EntityVComponent): |
4004
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3890
diff
changeset
|
225 |
__regid__ = 'metadata' |
3844
c2625c512085
stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3840
diff
changeset
|
226 |
context = 'navbottom' |
c2625c512085
stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3840
diff
changeset
|
227 |
order = 1 |
c2625c512085
stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3840
diff
changeset
|
228 |
|
c2625c512085
stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3840
diff
changeset
|
229 |
def cell_call(self, row, col, view=None): |
4047
2989a7d50b28
cw 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4023
diff
changeset
|
230 |
self.wview('metadata', self.cw_rset, row=row, col=col) |
3844
c2625c512085
stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3840
diff
changeset
|
231 |
|
3848 | 232 |
|
796
62253c7fe5ba
require explicit registration control
sylvain.thenault@logilab.fr
parents:
758
diff
changeset
|
233 |
def registration_callback(vreg): |
62253c7fe5ba
require explicit registration control
sylvain.thenault@logilab.fr
parents:
758
diff
changeset
|
234 |
vreg.register_all(globals().values(), __name__, (SeeAlsoVComponent,)) |
62253c7fe5ba
require explicit registration control
sylvain.thenault@logilab.fr
parents:
758
diff
changeset
|
235 |
if 'see_also' in vreg.schema: |
62253c7fe5ba
require explicit registration control
sylvain.thenault@logilab.fr
parents:
758
diff
changeset
|
236 |
vreg.register(SeeAlsoVComponent) |