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