author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Mon, 04 Oct 2010 18:56:05 +0200 | |
changeset 6389 | 72ba82a26e05 |
parent 6141 | b8287e54b528 |
child 6396 | a9e4c51fc1c1 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5148
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""Bases HTML components: |
19 |
||
20 |
* the rql input form |
|
21 |
* the logged user link |
|
5854 | 22 |
""" |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
23 |
from __future__ import with_statement |
0 | 24 |
|
25 |
__docformat__ = "restructuredtext en" |
|
1937 | 26 |
_ = unicode |
0 | 27 |
|
2313 | 28 |
from logilab.mtconverter import xml_escape |
0 | 29 |
from rql import parse |
30 |
||
6389
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
31 |
from cubicweb.selectors import (yes, multi_etypes_rset, match_form_params, |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
32 |
match_context, configuration_values, |
5148
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
33 |
anonymous_user, authenticated_user) |
1699 | 34 |
from cubicweb.schema import display_name |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
35 |
from cubicweb.utils import wrap_on_write |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4004
diff
changeset
|
36 |
from cubicweb.uilib import toggle_action |
1739 | 37 |
from cubicweb.web import component |
1699 | 38 |
from cubicweb.web.htmlwidgets import (MenuWidget, PopupBoxMenu, BoxSeparator, |
39 |
BoxLink) |
|
0 | 40 |
|
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
41 |
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
|
42 |
_('visible'): dict(type='Boolean', default=True, |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
43 |
help=_('display the component or not')), |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
44 |
} |
0 | 45 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
46 |
class RQLInputForm(component.Component): |
0 | 47 |
"""build the rql input form, usually displayed in the header""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
48 |
__regid__ = 'rqlinput' |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
49 |
cw_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
|
50 |
visible = False |
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2120
diff
changeset
|
51 |
|
0 | 52 |
def call(self, view=None): |
53 |
if hasattr(view, 'filter_box_context_info'): |
|
54 |
rset = view.filter_box_context_info()[0] |
|
55 |
else: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
56 |
rset = self.cw_rset |
0 | 57 |
# display multilines query as one line |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
58 |
rql = rset is not None and rset.printable_rql(encoded=False) or self._cw.form.get('rql', '') |
0 | 59 |
rql = rql.replace(u"\n", u" ") |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
60 |
req = self._cw |
0 | 61 |
self.w(u'''<div id="rqlinput" class="%s"> |
62 |
<form action="%s"> |
|
63 |
<fieldset> |
|
64 |
<input type="text" id="rql" name="rql" value="%s" title="%s" tabindex="%s" accesskey="q" class="searchField" /> |
|
65 |
</fieldset> |
|
2818
326375561412
propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2799
diff
changeset
|
66 |
''' % (not self.cw_propval('visible') and 'hidden' or '', |
5819
1017163825c7
[css] more css rework, need visual test in compat/new modes
katia
parents:
5478
diff
changeset
|
67 |
self._cw.build_url('view'), xml_escape(rql), req._('full text or RQL query'), req.next_tabindex())) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
68 |
if self._cw.search_state[0] != 'normal': |
0 | 69 |
self.w(u'<input type="hidden" name="__mode" value="%s"/>' |
70 |
% ':'.join(req.search_state[1])) |
|
71 |
self.w(u'</form></div>') |
|
72 |
||
73 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
74 |
class ApplLogo(component.Component): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
75 |
"""build the instance logo, usually displayed in the header""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
76 |
__regid__ = 'logo' |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
77 |
cw_property_defs = VISIBLE_PROP_DEF |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
78 |
# 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
|
79 |
site_wide = True |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
80 |
|
0 | 81 |
def call(self): |
5478
c52124b7a00e
[css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5467
diff
changeset
|
82 |
self.w(u'<a href="%s"><img id="logo" src="%s" alt="logo"/></a>' |
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
83 |
% (self._cw.base_url(), self._cw.uiprops['LOGO'])) |
0 | 84 |
|
85 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
86 |
class ApplHelp(component.Component): |
0 | 87 |
"""build the help button, usually displayed in the header""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
88 |
__regid__ = 'help' |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
89 |
cw_property_defs = VISIBLE_PROP_DEF |
0 | 90 |
def call(self): |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2650
diff
changeset
|
91 |
self.w(u'<a href="%s" class="help" title="%s"> </a>' |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
92 |
% (self._cw.build_url(_restpath='doc/main'), |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
93 |
self._cw._(u'help'),)) |
0 | 94 |
|
95 |
||
5148
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
96 |
class _UserLink(component.Component): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
97 |
"""if the user is the anonymous user, build a link to login else display a menu |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
98 |
with user'action (preference, logout, etc...) |
0 | 99 |
""" |
6389
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
100 |
__abstract__ = True |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
101 |
cw_property_defs = VISIBLE_PROP_DEF |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
102 |
# 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
|
103 |
site_wide = True |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
104 |
__regid__ = 'loggeduserlink' |
0 | 105 |
|
5148
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
106 |
|
6389
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
107 |
class CookieAnonUserLink(_UserLink): |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
108 |
__select__ = _UserLink.__select__ & configuration_values('auth-mode', 'cookie') & anonymous_user() |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
109 |
loginboxid = 'popupLoginBox' |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
110 |
|
0 | 111 |
def call(self): |
6389
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
112 |
w = self.w |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
113 |
w(self._cw._('anonymous')) |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
114 |
w(u"""[<a class="logout" href="javascript: cw.htmlhelpers.popupLoginBox('%s', '__login');">%s</a>]""" |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
115 |
% (self.loginboxid, self._cw._('i18n_login_popup'))) |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
116 |
self.wview('logform', rset=self.cw_rset, id=self.loginboxid, |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
117 |
klass='hidden', title=False, showmessage=False) |
0 | 118 |
|
6389
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
119 |
class HTTPAnonUserLink(_UserLink): |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
120 |
__select__ = _UserLink.__select__ & configuration_values('auth-mode', 'http') & anonymous_user() |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
121 |
loginboxid = 'popupLoginBox' |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
122 |
|
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
123 |
def call(self): |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
124 |
w = self.w |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
125 |
w(self._cw._('anonymous')) |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
126 |
# this redirects to the 'login' controller which in turn |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
127 |
# will raise a 401/Unauthorized |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
128 |
w(u' [<a class="logout" href="%s">%s</a>]' |
72ba82a26e05
refactor login box & form to enable easy pluggability
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6141
diff
changeset
|
129 |
% (self._cw.build_url('login'), self._cw._('login'))) |
0 | 130 |
|
5148
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
131 |
class UserLink(_UserLink): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
132 |
__select__ = _UserLink.__select__ & authenticated_user() |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
133 |
|
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
134 |
def call(self): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
135 |
# display useractions and siteactions |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
136 |
actions = self._cw.vreg['actions'].possible_actions(self._cw, rset=self.cw_rset) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
137 |
box = MenuWidget('', 'userActionsBox', _class='', islist=False) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
138 |
menu = PopupBoxMenu(self._cw.user.login, isitem=False) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
139 |
box.append(menu) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
140 |
for action in actions.get('useractions', ()): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
141 |
menu.append(BoxLink(action.url(), self._cw._(action.title), |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
142 |
action.html_class())) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
143 |
if actions.get('useractions') and actions.get('siteactions'): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
144 |
menu.append(BoxSeparator()) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
145 |
for action in actions.get('siteactions', ()): |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
146 |
menu.append(BoxLink(action.url(), self._cw._(action.title), |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
147 |
action.html_class())) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
148 |
box.render(w=self.w) |
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
149 |
|
ec0ea7366066
[web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4935
diff
changeset
|
150 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
151 |
class ApplicationMessage(component.Component): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
152 |
"""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
|
153 |
section |
0 | 154 |
""" |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
155 |
__select__ = yes() |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
156 |
__regid__ = 'applmessages' |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
157 |
# don't want user to hide this component using an cwproperty |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
158 |
cw_property_defs = {} |
0 | 159 |
|
160 |
def call(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
161 |
msgs = [msg for msg in (self._cw.get_shared_data('sources_error', pop=True), |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
162 |
self._cw.message) if msg] |
0 | 163 |
self.w(u'<div id="appMsg" onclick="%s" class="%s">\n' % |
164 |
(toggle_action('appMsg'), (msgs and ' ' or 'hidden'))) |
|
165 |
for msg in msgs: |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5854
diff
changeset
|
166 |
self.w(u'<div class="message" id="%s">%s</div>' % (self.domid, msg)) |
0 | 167 |
self.w(u'</div>') |
168 |
||
169 |
||
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
170 |
class ApplicationName(component.Component): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
171 |
"""display the instance name""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
172 |
__regid__ = 'appliname' |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
173 |
cw_property_defs = VISIBLE_PROP_DEF |
1739 | 174 |
# don't want user to hide this component using an cwproperty |
175 |
site_wide = True |
|
0 | 176 |
|
177 |
def call(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
178 |
title = self._cw.property_value('ui.site-title') |
2119
dc1eedd06766
deal with empty site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
179 |
if title: |
dc1eedd06766
deal with empty site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
180 |
self.w(u'<span id="appliName"><a href="%s">%s</a></span>' % ( |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
181 |
self._cw.base_url(), xml_escape(title))) |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
182 |
|
0 | 183 |
|
1554
3a3263df6cdd
new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents:
1514
diff
changeset
|
184 |
class EtypeRestrictionComponent(component.Component): |
0 | 185 |
"""displays the list of entity types contained in the resultset |
186 |
to be able to filter accordingly. |
|
187 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
188 |
__regid__ = 'etypenavigation' |
4320
4efd4c306746
closes #345410: two_lines_rset, two_cols_rset, two_etypes_rset are badly named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
189 |
__select__ = multi_etypes_rset() | match_form_params('__restrtype', '__restrtypes', |
758
0c0dfd33a76d
instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
742
diff
changeset
|
190 |
'__restrrql') |
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
191 |
cw_property_defs = VISIBLE_PROP_DEF |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
192 |
# 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
|
193 |
site_wide = True |
0 | 194 |
visible = False # disabled by default |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
195 |
|
0 | 196 |
def call(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
197 |
_ = self._cw._ |
0 | 198 |
self.w(u'<div id="etyperestriction">') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
199 |
restrtype = self._cw.form.get('__restrtype') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
200 |
restrtypes = self._cw.form.get('__restrtypes', '').split(',') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
201 |
restrrql = self._cw.form.get('__restrrql') |
0 | 202 |
if not restrrql: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
203 |
rqlst = self.cw_rset.syntax_tree() |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
204 |
restrrql = rqlst.as_string(self._cw.encoding, self.cw_rset.args) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
205 |
restrtypes = self.cw_rset.column_types(0) |
0 | 206 |
else: |
207 |
rqlst = parse(restrrql) |
|
208 |
html = [] |
|
209 |
on_etype = False |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
210 |
etypes = sorted((display_name(self._cw, etype).capitalize(), etype) |
0 | 211 |
for etype in restrtypes) |
212 |
for elabel, etype in etypes: |
|
213 |
if etype == restrtype: |
|
214 |
html.append(u'<span class="selected">%s</span>' % elabel) |
|
215 |
on_etype = True |
|
216 |
else: |
|
217 |
rqlst.save_state() |
|
218 |
for select in rqlst.children: |
|
219 |
select.add_type_restriction(select.selection[0], etype) |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
220 |
newrql = rqlst.as_string(self._cw.encoding, self.cw_rset.args) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
221 |
url = self._cw.build_url(rql=newrql, __restrrql=restrrql, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
222 |
__restrtype=etype, __restrtypes=','.join(restrtypes)) |
0 | 223 |
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
|
224 |
xml_escape(url), elabel)) |
0 | 225 |
rqlst.recover() |
226 |
if on_etype: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3407
diff
changeset
|
227 |
url = self._cw.build_url(rql=restrrql) |
0 | 228 |
html.insert(0, u'<span><a href="%s">%s</a></span>' % ( |
229 |
url, _('Any'))) |
|
230 |
else: |
|
231 |
html.insert(0, u'<span class="selected">%s</span>' % _('Any')) |
|
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2650
diff
changeset
|
232 |
self.w(u' | '.join(html)) |
0 | 233 |
self.w(u'</div>') |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
234 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
235 |
# contextual components ######################################################## |
3840
2eff4348b1e4
prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3818
diff
changeset
|
236 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
237 |
# class SeeAlsoVComponent(component.RelatedObjectsVComponent): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
238 |
# """display any entity's see also""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
239 |
# __regid__ = 'seealso' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
240 |
# context = 'navcontentbottom' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
241 |
# rtype = 'see_also' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
242 |
# role = 'subject' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
243 |
# order = 40 |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
244 |
# # register msg not generated since no entity use see_also in cubicweb itself |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
245 |
# title = _('ctxcomponents_seealso') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
246 |
# help = _('ctxcomponents_seealso_description') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
247 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
248 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
249 |
class MetaDataComponent(component.EntityCtxComponent): |
4004
c52619c738a5
api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3890
diff
changeset
|
250 |
__regid__ = 'metadata' |
3844
c2625c512085
stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3840
diff
changeset
|
251 |
context = 'navbottom' |
c2625c512085
stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3840
diff
changeset
|
252 |
order = 1 |
c2625c512085
stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3840
diff
changeset
|
253 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
254 |
def render_body(self, w): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
255 |
self.entity.view('metadata', w=w) |
3844
c2625c512085
stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3840
diff
changeset
|
256 |
|
3848 | 257 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
258 |
class SectionLayout(component.Layout): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
259 |
__select__ = match_context('navtop', 'navbottom', |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
260 |
'navcontenttop', 'navcontentbottom') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
261 |
cssclass = 'section' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
262 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
263 |
def render(self, w): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
264 |
if self.init_rendering(): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
265 |
view = self.cw_extra_kwargs['view'] |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
266 |
w(u'<div class="%s %s" id="%s">' % (self.cssclass, view.cssclass, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
267 |
view.domid)) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
268 |
with wrap_on_write(w, '<h4>') as wow: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
269 |
view.render_title(wow) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
270 |
view.render_body(w) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
271 |
w(u'</div>\n') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
272 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
273 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
274 |
# def registration_callback(vreg): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
275 |
# vreg.register_all(globals().values(), __name__, (SeeAlsoVComponent,)) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
276 |
# if 'see_also' in vreg.schema: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
277 |
# vreg.register(SeeAlsoVComponent) |