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