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