web/views/basecomponents.py
author Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 07 Oct 2010 17:25:24 +0200
branchstable
changeset 6406 39663630ca3c
parent 5854 b49f58a320e6
child 6140 65a619eb31c4
permissions -rw-r--r--
xml-escape <script> tags generated by HTMLHead
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
"""Bases HTML components:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
* the rql input form
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
* the logged user link
5854
b49f58a320e6 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5819
diff changeset
    22
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
__docformat__ = "restructuredtext en"
1937
fc702ea02b25 cosmetic
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1739
diff changeset
    25
_ = unicode
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
2313
2940c2341ae4 fix import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2312
diff changeset
    27
from logilab.mtconverter import xml_escape
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
from rql import parse
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
5148
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
    30
from cubicweb.selectors import (yes, multi_etypes_rset, match_form_params,
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
    31
                                anonymous_user, authenticated_user)
1699
f61402624f7b import cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    32
from cubicweb.schema import display_name
4023
eae23c40627a drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4004
diff changeset
    33
from cubicweb.uilib import toggle_action
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1721
diff changeset
    34
from cubicweb.web import component
1699
f61402624f7b import cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    35
from cubicweb.web.htmlwidgets import (MenuWidget, PopupBoxMenu, BoxSeparator,
f61402624f7b import cleanup
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    36
                                      BoxLink)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    38
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
    39
    _('visible'):  dict(type='Boolean', default=True,
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    40
                        help=_('display the component or not')),
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    41
    }
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1514
diff changeset
    43
class RQLInputForm(component.Component):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
    """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
    45
    __regid__ = 'rqlinput'
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    46
    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
    47
    visible = False
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2120
diff changeset
    48
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
    def call(self, view=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
        if hasattr(view, 'filter_box_context_info'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
            rset = view.filter_box_context_info()[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
        else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
    53
            rset = self.cw_rset
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        # 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
    55
        rql = rset is not None and rset.printable_rql(encoded=False) or self._cw.form.get('rql', '')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
        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
    57
        req = self._cw
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
        self.w(u'''<div id="rqlinput" class="%s">
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
          <form action="%s">
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
<fieldset>
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
<input type="text" id="rql" name="rql" value="%s"  title="%s" tabindex="%s" accesskey="q" class="searchField" />
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
</fieldset>
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2799
diff changeset
    63
''' % (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
    64
       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
    65
        if self._cw.search_state[0] != 'normal':
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
            self.w(u'<input type="hidden" name="__mode" value="%s"/>'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
                   % ':'.join(req.search_state[1]))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
        self.w(u'</form></div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1514
diff changeset
    71
class ApplLogo(component.Component):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2381
diff changeset
    72
    """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
    73
    __regid__ = 'logo'
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    74
    cw_property_defs = VISIBLE_PROP_DEF
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    75
    # 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
    76
    site_wide = True
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    77
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    def call(self):
5478
c52124b7a00e [css] progressively fixing rhythm
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5467
diff changeset
    79
        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
    80
               % (self._cw.base_url(), self._cw.uiprops['LOGO']))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1514
diff changeset
    83
class ApplHelp(component.Component):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    """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
    85
    __regid__ = 'help'
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    86
    cw_property_defs = VISIBLE_PROP_DEF
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
    def call(self):
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2650
diff changeset
    88
        self.w(u'<a href="%s" class="help" title="%s">&#160;</a>'
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
    89
               % (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
    90
                  self._cw._(u'help'),))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
5148
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
    93
class _UserLink(component.Component):
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
    94
    """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
    95
    with user'action (preference, logout, etc...)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
    """
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
    97
    cw_property_defs = VISIBLE_PROP_DEF
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    98
    # 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
    99
    site_wide = True
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
   100
    __regid__ = 'loggeduserlink'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
5148
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   102
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   103
class AnonUserLink(_UserLink):
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   104
    __select__ = _UserLink.__select__ & anonymous_user()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    def call(self):
3659
993997b4b41d 3.6 update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3451
diff changeset
   106
        if self._cw.vreg.config['auth-mode'] == 'cookie':
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
   107
            self.w(self._cw._('anonymous'))
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2650
diff changeset
   108
            self.w(u'''&#160;[<a class="logout" href="javascript: popupLoginBox();">%s</a>]'''
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
   109
                   % (self._cw._('i18n_login_popup')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
        else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
   111
            self.w(self._cw._('anonymous'))
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2650
diff changeset
   112
            self.w(u'&#160;[<a class="logout" href="%s">%s</a>]'
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
   113
                   % (self._cw.build_url('login'), self._cw._('login')))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
5148
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   116
class UserLink(_UserLink):
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   117
    __select__ = _UserLink.__select__ & authenticated_user()
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   118
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   119
    def call(self):
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   120
        # display useractions and siteactions
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   121
        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
   122
        box = MenuWidget('', 'userActionsBox', _class='', islist=False)
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   123
        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
   124
        box.append(menu)
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   125
        for action in actions.get('useractions', ()):
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   126
            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
   127
                                action.html_class()))
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   128
        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
   129
            menu.append(BoxSeparator())
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   130
        for action in actions.get('siteactions', ()):
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   131
            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
   132
                                action.html_class()))
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   133
        box.render(w=self.w)
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   134
ec0ea7366066 [web components] refactor as book recommends :$
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4935
diff changeset
   135
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1514
diff changeset
   136
class ApplicationMessage(component.Component):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2381
diff changeset
   137
    """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
   138
    section
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
    """
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 692
diff changeset
   140
    __select__ = yes()
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
   141
    __regid__ = 'applmessages'
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
   142
    # 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
   143
    cw_property_defs = {}
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
    def call(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
   146
        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
   147
                                self._cw.message) if msg]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
        self.w(u'<div id="appMsg" onclick="%s" class="%s">\n' %
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
               (toggle_action('appMsg'), (msgs and ' ' or 'hidden')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
        for msg in msgs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
            self.w(u'<div class="message" id="%s">%s</div>' % (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
                self.div_id(), msg))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
        self.w(u'</div>')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1514
diff changeset
   156
class ApplicationName(component.Component):
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2381
diff changeset
   157
    """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
   158
    __regid__ = 'appliname'
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   159
    cw_property_defs = VISIBLE_PROP_DEF
1739
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1721
diff changeset
   160
    # don't want user to hide this component using an cwproperty
78b0819162a8 final rtag api
sylvain.thenault@logilab.fr
parents: 1721
diff changeset
   161
    site_wide = True
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
    def call(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
   164
        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
   165
        if title:
dc1eedd06766 deal with empty site-title
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   166
            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
   167
                self._cw.base_url(), xml_escape(title)))
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
   168
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1514
diff changeset
   170
class SeeAlsoVComponent(component.RelatedObjectsVComponent):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
    """display any entity's see also"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
   172
    __regid__ = 'seealso'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   173
    context = 'navcontentbottom'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   174
    rtype = 'see_also'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1514
diff changeset
   175
    role = 'subject'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   176
    order = 40
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   177
    # register msg not generated since no entity use see_also in cubicweb itself
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   178
    title = _('contentnavigation_seealso')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
    help = _('contentnavigation_seealso_description')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
   181
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1514
diff changeset
   182
class EtypeRestrictionComponent(component.Component):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   183
    """displays the list of entity types contained in the resultset
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
    to be able to filter accordingly.
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
    """
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3185
diff changeset
   186
    __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
   187
    __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
   188
                                                       '__restrrql')
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   189
    cw_property_defs = VISIBLE_PROP_DEF
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
   190
    # 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
   191
    site_wide = True
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   192
    visible = False # disabled by default
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
   193
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   194
    def call(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
   195
        _ = self._cw._
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   196
        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
   197
        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
   198
        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
   199
        restrrql = self._cw.form.get('__restrrql')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   200
        if not restrrql:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
   201
            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
   202
            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
   203
            restrtypes = self.cw_rset.column_types(0)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   204
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   205
            rqlst = parse(restrrql)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
        html = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
        on_etype = False
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
   208
        etypes = sorted((display_name(self._cw, etype).capitalize(), etype)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   209
                        for etype in restrtypes)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   210
        for elabel, etype in etypes:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   211
            if etype == restrtype:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   212
                html.append(u'<span class="selected">%s</span>' % elabel)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
                on_etype = True
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
                rqlst.save_state()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
                for select in rqlst.children:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
                    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
   218
                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
   219
                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
   220
                                         __restrtype=etype, __restrtypes=','.join(restrtypes))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
                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
   222
                        xml_escape(url), elabel))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
                rqlst.recover()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   224
        if on_etype:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3407
diff changeset
   225
            url = self._cw.build_url(rql=restrrql)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   226
            html.insert(0, u'<span><a href="%s">%s</a></span>' % (
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
                    url, _('Any')))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   228
        else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   229
            html.insert(0, u'<span class="selected">%s</span>' % _('Any'))
2996
866a2c135c33 B #345282 xhtml requires to use &#160; instead of &nbsp;
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2650
diff changeset
   230
        self.w(u'&#160;|&#160;'.join(html))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   231
        self.w(u'</div>')
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
   232
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
   233
3844
c2625c512085 stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3840
diff changeset
   234
class MetaDataComponent(component.EntityVComponent):
4004
c52619c738a5 api renaming update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 3890
diff changeset
   235
    __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
   236
    context = 'navbottom'
c2625c512085 stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3840
diff changeset
   237
    order = 1
c2625c512085 stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3840
diff changeset
   238
c2625c512085 stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3840
diff changeset
   239
    def cell_call(self, row, col, view=None):
4047
2989a7d50b28 cw 3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4023
diff changeset
   240
        self.wview('metadata', self.cw_rset, row=row, col=col)
3844
c2625c512085 stop calling render_entity_metadata in primary view, provides a
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3840
diff changeset
   241
3848
adc706f312a2 cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3844
diff changeset
   242
796
62253c7fe5ba require explicit registration control
sylvain.thenault@logilab.fr
parents: 758
diff changeset
   243
def registration_callback(vreg):
62253c7fe5ba require explicit registration control
sylvain.thenault@logilab.fr
parents: 758
diff changeset
   244
    vreg.register_all(globals().values(), __name__, (SeeAlsoVComponent,))
62253c7fe5ba require explicit registration control
sylvain.thenault@logilab.fr
parents: 758
diff changeset
   245
    if 'see_also' in vreg.schema:
62253c7fe5ba require explicit registration control
sylvain.thenault@logilab.fr
parents: 758
diff changeset
   246
        vreg.register(SeeAlsoVComponent)