author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Fri, 19 Jun 2009 20:38:32 +0200 | |
branch | stable |
changeset 2172 | cf8f9180e63e |
parent 2120 | ed1cd652b343 |
child 2181 | 94ca417b9b07 |
child 2218 | b5d00053a7fe |
permissions | -rw-r--r-- |
0 | 1 |
"""Bases HTML components: |
2 |
||
3 |
* the rql input form |
|
4 |
* the logged user link |
|
5 |
||
6 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1968
diff
changeset
|
7 |
:copyright: 2001-2009 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 |
|
14 |
from rql import parse |
|
15 |
||
1132 | 16 |
from cubicweb.selectors import yes, two_etypes_rset, match_form_params |
1699 | 17 |
from cubicweb.schema import display_name |
0 | 18 |
from cubicweb.common.uilib import html_escape, toggle_action |
1739 | 19 |
from cubicweb.web import component |
1699 | 20 |
from cubicweb.web.htmlwidgets import (MenuWidget, PopupBoxMenu, BoxSeparator, |
21 |
BoxLink) |
|
0 | 22 |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
23 |
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
|
24 |
_('visible'): dict(type='Boolean', default=True, |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
25 |
help=_('display the component or not')), |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
26 |
} |
0 | 27 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
28 |
class RQLInputForm(component.Component): |
0 | 29 |
"""build the rql input form, usually displayed in the header""" |
30 |
id = 'rqlinput' |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
31 |
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
|
32 |
visible = False |
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2120
diff
changeset
|
33 |
|
0 | 34 |
def call(self, view=None): |
35 |
if hasattr(view, 'filter_box_context_info'): |
|
36 |
rset = view.filter_box_context_info()[0] |
|
37 |
else: |
|
38 |
rset = self.rset |
|
39 |
# display multilines query as one line |
|
40 |
rql = rset is not None and rset.printable_rql(encoded=False) or self.req.form.get('rql', '') |
|
41 |
rql = rql.replace(u"\n", u" ") |
|
42 |
req = self.req |
|
43 |
self.w(u'''<div id="rqlinput" class="%s"> |
|
44 |
<form action="%s"> |
|
45 |
<fieldset> |
|
46 |
<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
|
47 |
<input type="submit" value="" class="rqlsubmit" tabindex="%s" /> |
0 | 48 |
</fieldset> |
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2120
diff
changeset
|
49 |
''' % (not self.propval('visible') and 'hidden' or '', |
0 | 50 |
self.build_url('view'), html_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
|
51 |
req.next_tabindex())) |
0 | 52 |
if self.req.search_state[0] != 'normal': |
53 |
self.w(u'<input type="hidden" name="__mode" value="%s"/>' |
|
54 |
% ':'.join(req.search_state[1])) |
|
55 |
self.w(u'</form></div>') |
|
56 |
||
57 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
58 |
class ApplLogo(component.Component): |
0 | 59 |
"""build the application logo, usually displayed in the header""" |
60 |
id = 'logo' |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
61 |
property_defs = VISIBLE_PROP_DEF |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
62 |
# 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
|
63 |
site_wide = True |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
64 |
|
0 | 65 |
def call(self): |
66 |
self.w(u'<a href="%s"><img class="logo" src="%s" alt="logo"/></a>' |
|
67 |
% (self.req.base_url(), self.req.external_resource('LOGO'))) |
|
68 |
||
69 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
70 |
class ApplHelp(component.Component): |
0 | 71 |
"""build the help button, usually displayed in the header""" |
72 |
id = 'help' |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
73 |
property_defs = VISIBLE_PROP_DEF |
0 | 74 |
def call(self): |
75 |
self.w(u'<a href="%s" class="help" title="%s"> </a>' |
|
76 |
% (self.build_url(_restpath='doc/main'), |
|
77 |
self.req._(u'help'),)) |
|
78 |
||
79 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
80 |
class UserLink(component.Component): |
0 | 81 |
"""if the user is the anonymous user, build a link to login |
82 |
else a link to the connected user object with a loggout link |
|
83 |
""" |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
84 |
property_defs = VISIBLE_PROP_DEF |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
85 |
# 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
|
86 |
site_wide = True |
0 | 87 |
id = 'loggeduserlink' |
88 |
||
89 |
def call(self): |
|
90 |
if not self.req.cnx.anonymous_connection: |
|
91 |
# display useractions and siteactions |
|
92 |
actions = self.vreg.possible_actions(self.req, self.rset) |
|
93 |
box = MenuWidget('', 'userActionsBox', _class='', islist=False) |
|
94 |
menu = PopupBoxMenu(self.req.user.login, isitem=False) |
|
95 |
box.append(menu) |
|
96 |
for action in actions.get('useractions', ()): |
|
97 |
menu.append(BoxLink(action.url(), self.req._(action.title), |
|
98 |
action.html_class())) |
|
99 |
if actions.get('useractions') and actions.get('siteactions'): |
|
100 |
menu.append(BoxSeparator()) |
|
101 |
for action in actions.get('siteactions', ()): |
|
102 |
menu.append(BoxLink(action.url(), self.req._(action.title), |
|
103 |
action.html_class())) |
|
104 |
box.render(w=self.w) |
|
105 |
else: |
|
106 |
self.anon_user_link() |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
107 |
|
0 | 108 |
def anon_user_link(self): |
109 |
if self.config['auth-mode'] == 'cookie': |
|
110 |
self.w(self.req._('anonymous')) |
|
29
7d14f1eadded
fix focus problems on login inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
111 |
self.w(u''' [<a class="logout" href="javascript: popupLoginBox();">%s</a>]''' |
0 | 112 |
% (self.req._('i18n_login_popup'))) |
638 | 113 |
# FIXME maybe have an other option to explicitely authorise registration |
947
01f5001304b2
[registration] comment out until there is more meat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
939
diff
changeset
|
114 |
# also provide a working register view |
01f5001304b2
[registration] comment out until there is more meat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
939
diff
changeset
|
115 |
# if self.config['anonymous-user']: |
01f5001304b2
[registration] comment out until there is more meat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
939
diff
changeset
|
116 |
# self.w(u''' [<a class="logout" href="?vid=register">%s</a>]''' |
01f5001304b2
[registration] comment out until there is more meat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
939
diff
changeset
|
117 |
# % (self.req._('i18n_register_user'))) |
0 | 118 |
else: |
119 |
self.w(self.req._('anonymous')) |
|
120 |
self.w(u' [<a class="logout" href="%s">%s</a>]' |
|
121 |
% (self.build_url('login'), self.req._('login'))) |
|
122 |
||
123 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
124 |
class ApplicationMessage(component.Component): |
0 | 125 |
"""display application's messages given using the __message parameter |
126 |
into a special div section |
|
127 |
""" |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
128 |
__select__ = yes() |
0 | 129 |
id = 'applmessages' |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
130 |
# don't want user to hide this component using an cwproperty |
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
|
131 |
property_defs = {} |
0 | 132 |
|
133 |
def call(self): |
|
134 |
msgs = [msg for msg in (self.req.get_shared_data('sources_error', pop=True), |
|
135 |
self.req.message) if msg] |
|
136 |
self.w(u'<div id="appMsg" onclick="%s" class="%s">\n' % |
|
137 |
(toggle_action('appMsg'), (msgs and ' ' or 'hidden'))) |
|
138 |
for msg in msgs: |
|
139 |
self.w(u'<div class="message" id="%s">%s</div>' % ( |
|
140 |
self.div_id(), msg)) |
|
141 |
self.w(u'</div>') |
|
142 |
||
143 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
144 |
class ApplicationName(component.Component): |
0 | 145 |
"""display the application name""" |
146 |
id = 'appliname' |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
147 |
property_defs = VISIBLE_PROP_DEF |
1739 | 148 |
# don't want user to hide this component using an cwproperty |
149 |
site_wide = True |
|
0 | 150 |
|
151 |
def call(self): |
|
2119
dc1eedd06766
deal with empty site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
152 |
title = self.req.property_value('ui.site-title') |
dc1eedd06766
deal with empty site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
153 |
if title: |
dc1eedd06766
deal with empty site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
154 |
self.w(u'<span id="appliName"><a href="%s">%s</a></span>' % ( |
dc1eedd06766
deal with empty site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
155 |
self.req.base_url(), title)) |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
156 |
|
0 | 157 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
158 |
class SeeAlsoVComponent(component.RelatedObjectsVComponent): |
0 | 159 |
"""display any entity's see also""" |
160 |
id = 'seealso' |
|
161 |
context = 'navcontentbottom' |
|
162 |
rtype = 'see_also' |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
163 |
role = 'subject' |
0 | 164 |
order = 40 |
165 |
# register msg not generated since no entity use see_also in cubicweb itself |
|
166 |
title = _('contentnavigation_seealso') |
|
167 |
help = _('contentnavigation_seealso_description') |
|
168 |
||
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
169 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
170 |
class EtypeRestrictionComponent(component.Component): |
0 | 171 |
"""displays the list of entity types contained in the resultset |
172 |
to be able to filter accordingly. |
|
173 |
""" |
|
174 |
id = 'etypenavigation' |
|
758
0c0dfd33a76d
instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
742
diff
changeset
|
175 |
__select__ = two_etypes_rset() | match_form_params('__restrtype', '__restrtypes', |
0c0dfd33a76d
instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
742
diff
changeset
|
176 |
'__restrrql') |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
177 |
property_defs = VISIBLE_PROP_DEF |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
178 |
# 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
|
179 |
site_wide = True |
0 | 180 |
visible = False # disabled by default |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
181 |
|
0 | 182 |
def call(self): |
183 |
_ = self.req._ |
|
184 |
self.w(u'<div id="etyperestriction">') |
|
185 |
restrtype = self.req.form.get('__restrtype') |
|
186 |
restrtypes = self.req.form.get('__restrtypes', '').split(',') |
|
187 |
restrrql = self.req.form.get('__restrrql') |
|
188 |
if not restrrql: |
|
189 |
rqlst = self.rset.syntax_tree() |
|
190 |
restrrql = rqlst.as_string(self.req.encoding, self.rset.args) |
|
191 |
restrtypes = self.rset.column_types(0) |
|
192 |
else: |
|
193 |
rqlst = parse(restrrql) |
|
194 |
html = [] |
|
195 |
on_etype = False |
|
196 |
etypes = sorted((display_name(self.req, etype).capitalize(), etype) |
|
197 |
for etype in restrtypes) |
|
198 |
for elabel, etype in etypes: |
|
199 |
if etype == restrtype: |
|
200 |
html.append(u'<span class="selected">%s</span>' % elabel) |
|
201 |
on_etype = True |
|
202 |
else: |
|
203 |
rqlst.save_state() |
|
204 |
for select in rqlst.children: |
|
205 |
select.add_type_restriction(select.selection[0], etype) |
|
206 |
newrql = rqlst.as_string(self.req.encoding, self.rset.args) |
|
207 |
url = self.build_url(rql=newrql, __restrrql=restrrql, |
|
208 |
__restrtype=etype, __restrtypes=','.join(restrtypes)) |
|
209 |
html.append(u'<span><a href="%s">%s</a></span>' % ( |
|
210 |
html_escape(url), elabel)) |
|
211 |
rqlst.recover() |
|
212 |
if on_etype: |
|
213 |
url = self.build_url(rql=restrrql) |
|
214 |
html.insert(0, u'<span><a href="%s">%s</a></span>' % ( |
|
215 |
url, _('Any'))) |
|
216 |
else: |
|
217 |
html.insert(0, u'<span class="selected">%s</span>' % _('Any')) |
|
218 |
self.w(u' | '.join(html)) |
|
219 |
self.w(u'</div>') |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
220 |
|
143
c4f11f70b75e
adding two different rss feed component
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
142
diff
changeset
|
221 |
|
796
62253c7fe5ba
require explicit registration control
sylvain.thenault@logilab.fr
parents:
758
diff
changeset
|
222 |
def registration_callback(vreg): |
62253c7fe5ba
require explicit registration control
sylvain.thenault@logilab.fr
parents:
758
diff
changeset
|
223 |
vreg.register_all(globals().values(), __name__, (SeeAlsoVComponent,)) |
62253c7fe5ba
require explicit registration control
sylvain.thenault@logilab.fr
parents:
758
diff
changeset
|
224 |
if 'see_also' in vreg.schema: |
62253c7fe5ba
require explicit registration control
sylvain.thenault@logilab.fr
parents:
758
diff
changeset
|
225 |
vreg.register(SeeAlsoVComponent) |