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