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