web/component.py
author Rémi Cardona <remi.cardona@logilab.fr>, Julien Cristau <julien.cristau@logilab.fr>
Thu, 26 Nov 2015 11:30:54 +0100
changeset 10935 049209b9e9d6
parent 10903 da30851f9706
child 11082 0cdd92261c4a
permissions -rw-r--r--
[qunit] stop dealing with filesystem paths qunit tests need a few things served by cubicweb: - qunit itself, which is now handled by CWDevtoolsStaticController (serving files in cubicweb/devtools/data) - standard cubicweb or cubes data files, handled by the DataController - the tests themselves and their dependencies. These can live in <apphome>/data or <apphome>/static and be served by one of the STATIC_CONTROLLERS This avoids having to guess in CWSoftwareRootStaticController where to serve things from (some files may be installed, others are in the source tree), and should hopefully make it possible to have these tests pass when using tox, and to write qunit tests for cubes, outside of cubicweb itself. This requires modifying the tests to only declare URL paths instead of filesystem paths, and moving support files below test/data/static.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
     1
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
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: 5389
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5715
2c3e83817a8e [view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5624
diff changeset
    18
"""abstract component class and base components definition for CubicWeb web
2c3e83817a8e [view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5624
diff changeset
    19
client
2c3e83817a8e [view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5624
diff changeset
    20
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
__docformat__ = "restructuredtext en"
10666
7f6b5f023884 [py3k] replace '_ = unicode' in global scope (closes #7589459)
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10510
diff changeset
    23
from cubicweb import _
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
6423
c560f8d9faee [pre 3.10 compat] if CtxComponent as a call() method, emit a deprecation warning but use it. Also ensure default value on class for visible and order, and define wview for bw compat as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    25
from warnings import warn
c560f8d9faee [pre 3.10 compat] if CtxComponent as a call() method, emit a deprecation warning but use it. Also ensure default value on class for visible and order, and define wview for bw compat as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
    26
10713
ec0f96cd7a18 [py3k] __unicode__ and __str__
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10702
diff changeset
    27
from six import PY3, add_metaclass, text_type
10688
fa29f3628a1b [py3k] use six.add_metaclass
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
    28
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
    29
from logilab.common.deprecation import class_deprecated, class_renamed, deprecated
2312
af4d8f75c5db use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2259
diff changeset
    30
from logilab.mtconverter import xml_escape
661
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
    31
6490
34359fbde6ef [components] add missing imports for code copied/pasted. Forgot to run pylint afterward...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6489
diff changeset
    32
from cubicweb import Unauthorized, role, target, tags
34359fbde6ef [components] add missing imports for code copied/pasted. Forgot to run pylint afterward...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6489
diff changeset
    33
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
    34
from cubicweb.uilib import js, domid
7998
9ef285eb20f4 [utils] add a ``js_href`` function to generated proper javascript href
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 7991
diff changeset
    35
from cubicweb.utils import json_dumps, js_href
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    36
from cubicweb.view import ReloadableMixIn, Component
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8102
diff changeset
    37
from cubicweb.predicates import (no_cnx, paginated_rset, one_line_rset,
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    38
                                non_final_entity, partial_relation_possible,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    39
                                partial_has_related_entities)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    40
from cubicweb.appobject import AppObject
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
    41
from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
    44
# abstract base class for navigation components ################################
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    45
661
4f61eb8a96b7 properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents: 659
diff changeset
    46
class NavigationComponent(Component):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
    """abstract base class for navigation components"""
3408
c92170fca813 [api] use __regid__ instead of deprecated id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3023
diff changeset
    48
    __regid__ = 'navigation'
742
99115e029dca replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 687
diff changeset
    49
    __select__ = paginated_rset()
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    50
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2381
diff changeset
    51
    cw_property_defs = {
1511
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1433
diff changeset
    52
        _('visible'):  dict(type='Boolean', default=True,
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1433
diff changeset
    53
                            help=_('display the component or not')),
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1433
diff changeset
    54
        }
514e4e53a3c7 do not set visible property by default
sylvain.thenault@logilab.fr
parents: 1433
diff changeset
    55
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
    page_size_property = 'navigation.page-size'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
    start_param = '__start'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
    stop_param = '__stop'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    page_link_templ = u'<span class="slice"><a href="%s" title="%s">%s</a></span>'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
    selected_page_link_templ = u'<span class="selectedSlice"><a href="%s" title="%s">%s</a></span>'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
    previous_page_link_templ = next_page_link_templ = page_link_templ
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    62
1339
f74674c042ed should take extra kwargs
sylvain.thenault@logilab.fr
parents: 1132
diff changeset
    63
    def __init__(self, req, rset, **kwargs):
2890
fdcb8a2bb6eb fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2819
diff changeset
    64
        super(NavigationComponent, self).__init__(req, rset=rset, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
        self.starting_from = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
        self.total = rset.rowcount
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
    def get_page_size(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
            return self._page_size
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
        except AttributeError:
3468
b02fa4db2868 [tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3457
diff changeset
    72
            page_size = self.cw_extra_kwargs.get('page_size')
822
e3d8db01f3f5 test_views fixes
sylvain.thenault@logilab.fr
parents: 817
diff changeset
    73
            if page_size is None:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
    74
                if 'page_size' in self._cw.form:
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
    75
                    page_size = int(self._cw.form['page_size'])
822
e3d8db01f3f5 test_views fixes
sylvain.thenault@logilab.fr
parents: 817
diff changeset
    76
                else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
    77
                    page_size = self._cw.property_value(self.page_size_property)
799
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    78
            self._page_size = page_size
ad129d374ee2 fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents: 747
diff changeset
    79
            return page_size
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
    def set_page_size(self, page_size):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
        self._page_size = page_size
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    83
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    page_size = property(get_page_size, set_page_size)
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    85
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
    def page_boundaries(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
        try:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
    88
            stop = int(self._cw.form[self.stop_param]) + 1
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3408
diff changeset
    89
            start = int(self._cw.form[self.start_param])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
        except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
            start, stop = 0, self.page_size
4089
ff92c7d692bf typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3890
diff changeset
    92
        if start >= len(self.cw_rset):
3607
a7c5e62c7e00 don't crash if specified page size is greater than rset size
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3014
diff changeset
    93
            start, stop = 0, self.page_size
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
        self.starting_from = start
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
        return start, stop
1433
091ac3ba5d51 remove trailing white spaces
sylvain.thenault@logilab.fr
parents: 1432
diff changeset
    96
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
    def clean_params(self, params):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
        if self.start_param in params:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
            del params[self.start_param]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
        if self.stop_param in params:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
            del params[self.stop_param]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
5910
432c657ebfec [facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5715
diff changeset
   103
    def page_url(self, path, params, start=None, stop=None):
4882
4a42d700c52d [web] stop using deprecated merge_dicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   104
        params = dict(params)
8102
619d41a4c770 [navigation] provide a link back from the full view to the paginated one
Julien Cristau <julien.cristau@logilab.fr>
parents: 8054
diff changeset
   105
        params['__fromnavigation'] = 1
5910
432c657ebfec [facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5715
diff changeset
   106
        if start is not None:
432c657ebfec [facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5715
diff changeset
   107
            params[self.start_param] = start
432c657ebfec [facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5715
diff changeset
   108
        if stop is not None:
432c657ebfec [facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 5715
diff changeset
   109
            params[self.stop_param] = stop
5616
859225caf375 [navigation] view may implements page_navigation_url to handle them self url generated for pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   110
        view = self.cw_extra_kwargs.get('view')
859225caf375 [navigation] view may implements page_navigation_url to handle them self url generated for pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   111
        if view is not None and hasattr(view, 'page_navigation_url'):
859225caf375 [navigation] view may implements page_navigation_url to handle them self url generated for pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   112
            url = view.page_navigation_url(self, path, params)
9587
0f0199948f93 Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents: 9536
diff changeset
   113
        elif path in ('json', 'ajax'):
0f0199948f93 Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents: 9536
diff changeset
   114
            # 'ajax' is the new correct controller, but the old 'json'
0f0199948f93 Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents: 9536
diff changeset
   115
            # controller should still be supported
0f0199948f93 Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents: 9536
diff changeset
   116
            url = self.ajax_page_url(**params)
9530
170e1437948d [web/navigation] use add_onload instead of inline javascript href
Julien Cristau <julien.cristau@logilab.fr>
parents: 8900
diff changeset
   117
        else:
9587
0f0199948f93 Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents: 9536
diff changeset
   118
            url = self._cw.build_url(path, **params)
6280
e220f8b85f88 [navigation] move hack from page_link to page_url so '#1251858: Can't see all the elements when a limited list is shown' if fixed as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6265
diff changeset
   119
        # XXX hack to avoid opening a new page containing the evaluation of the
e220f8b85f88 [navigation] move hack from page_link to page_url so '#1251858: Can't see all the elements when a limited list is shown' if fixed as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6265
diff changeset
   120
        # js expression on ajax call
e220f8b85f88 [navigation] move hack from page_link to page_url so '#1251858: Can't see all the elements when a limited list is shown' if fixed as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6265
diff changeset
   121
        if url.startswith('javascript:'):
6543
66145280a7e6 [js] remove deprecation warnings by using $.noop instead of noop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6490
diff changeset
   122
            url += '; $.noop();'
3013
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   123
        return url
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   124
6248
3f89bf00e8ce [navigation] refactor base navigation component: replace deprecated replacePageChunk js call by loadxhtml, using the magic js object
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   125
    def ajax_page_url(self, **params):
3f89bf00e8ce [navigation] refactor base navigation component: replace deprecated replacePageChunk js call by loadxhtml, using the magic js object
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   126
        divid = params.setdefault('divid', 'pageContent')
6265
27417b8b94ed [navigation] for rql to the one of the rset being paginated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6248
diff changeset
   127
        params['rql'] = self.cw_rset.printable_rql()
9587
0f0199948f93 Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents: 9536
diff changeset
   128
        return js_href("$(%s).loadxhtml(AJAX_PREFIX_URL, %s, 'get', 'swap')" % (
0f0199948f93 Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents: 9536
diff changeset
   129
            json_dumps('#'+divid), js.ajaxFuncArgs('view', params)))
6248
3f89bf00e8ce [navigation] refactor base navigation component: replace deprecated replacePageChunk js call by loadxhtml, using the magic js object
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5940
diff changeset
   130
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
    def page_link(self, path, params, start, stop, content):
3013
6a40a9a72957 [page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3012
diff changeset
   132
        url = xml_escape(self.page_url(path, params, start, stop))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
        if start == self.starting_from:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
            return self.selected_page_link_templ % (url, content, content)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        return self.page_link_templ % (url, content, content)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
7323
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   137
    @property
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   138
    def prev_icon_url(self):
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   139
        return xml_escape(self._cw.data_url('go_prev.png'))
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   140
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   141
    @property
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   142
    def next_icon_url(self):
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   143
        return xml_escape(self._cw.data_url('go_next.png'))
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   144
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   145
    @property
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   146
    def no_previous_page_link(self):
7326
6c603d0fb2c7 [component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7323
diff changeset
   147
        return (u'<img src="%s" alt="%s" class="prevnext_nogo"/>' %
6c603d0fb2c7 [component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7323
diff changeset
   148
                (self.prev_icon_url, self._cw._('there is no previous page')))
7323
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   149
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   150
    @property
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   151
    def no_next_page_link(self):
7326
6c603d0fb2c7 [component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7323
diff changeset
   152
        return (u'<img src="%s" alt="%s" class="prevnext_nogo"/>' %
6c603d0fb2c7 [component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7323
diff changeset
   153
                (self.next_icon_url, self._cw._('there is no next page')))
7323
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   154
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   155
    @property
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   156
    def no_content_prev_link(self):
7326
6c603d0fb2c7 [component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7323
diff changeset
   157
        return (u'<img src="%s" alt="%s" class="prevnext"/>' % (
6c603d0fb2c7 [component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7323
diff changeset
   158
                (self.prev_icon_url, self._cw._('no content prev link'))))
7323
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   159
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   160
    @property
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   161
    def no_content_next_link(self):
7326
6c603d0fb2c7 [component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7323
diff changeset
   162
        return (u'<img src="%s" alt="%s" class="prevnext"/>' %
6c603d0fb2c7 [component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 7323
diff changeset
   163
                (self.next_icon_url, self._cw._('no content next link')))
7323
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   164
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   165
    def previous_link(self, path, params, content=None, title=_('previous_results')):
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   166
        if not content:
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   167
            content = self.no_content_prev_link
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   168
        start = self.starting_from
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   169
        if not start :
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   170
            return self.no_previous_page_link
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   171
        start = max(0, start - self.page_size)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   172
        stop = start + self.page_size - 1
3014
62ce5a139b52 [page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3013
diff changeset
   173
        url = xml_escape(self.page_url(path, params, start, stop))
8052
fbeb82fe45a4 [prev/next] properly translate previous/next links' title, closes #2072158
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7879
diff changeset
   174
        return self.previous_page_link_templ % (url, self._cw._(title), content)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   175
7323
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   176
    def next_link(self, path, params, content=None, title=_('next_results')):
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   177
        if not content:
53f38d39287f [nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6987
diff changeset
   178
            content = self.no_content_next_link
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   179
        start = self.starting_from + self.page_size
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   180
        if start >= self.total:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   181
            return self.no_next_page_link
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   182
        stop = start + self.page_size - 1
3014
62ce5a139b52 [page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3013
diff changeset
   183
        url = xml_escape(self.page_url(path, params, start, stop))
8052
fbeb82fe45a4 [prev/next] properly translate previous/next links' title, closes #2072158
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7879
diff changeset
   184
        return self.next_page_link_templ % (url, self._cw._(title), content)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   186
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   187
# new contextual components system #############################################
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   188
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   189
def override_ctx(cls, **kwargs):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   190
    cwpdefs = cls.cw_property_defs.copy()
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   191
    cwpdefs['context']  = cwpdefs['context'].copy()
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   192
    cwpdefs['context'].update(kwargs)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   193
    return cwpdefs
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   194
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   195
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   196
class EmptyComponent(Exception):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   197
    """some selectable component has actually no content and should not be
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   198
    rendered
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   199
    """
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   200
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   201
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   202
class Link(object):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   203
    """a link to a view or action in the ui.
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   204
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   205
    Use this rather than `cw.web.htmlwidgets.BoxLink`.
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   206
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   207
    Note this class could probably be avoided with a proper DOM on the server
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   208
    side.
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   209
    """
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   210
    newstyle = True
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   211
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   212
    def __init__(self, href, label, **attrs):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   213
        self.href = href
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   214
        self.label = label
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   215
        self.attrs = attrs
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   216
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   217
    def __unicode__(self):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   218
        return tags.a(self.label, href=self.href, **self.attrs)
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   219
10713
ec0f96cd7a18 [py3k] __unicode__ and __str__
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10702
diff changeset
   220
    if PY3:
ec0f96cd7a18 [py3k] __unicode__ and __str__
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10702
diff changeset
   221
        __str__ = __unicode__
ec0f96cd7a18 [py3k] __unicode__ and __str__
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10702
diff changeset
   222
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   223
    def render(self, w):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   224
        w(tags.a(self.label, href=self.href, **self.attrs))
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   225
10044
5907c2b0acd7 [component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10040
diff changeset
   226
    def __repr__(self):
5907c2b0acd7 [component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10040
diff changeset
   227
        return '<%s: href=%r label=%r %r>' % (self.__class__.__name__,
5907c2b0acd7 [component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10040
diff changeset
   228
                                              self.href, self.label, self.attrs)
5907c2b0acd7 [component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10040
diff changeset
   229
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   230
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   231
class Separator(object):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   232
    """a menu separator.
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   233
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   234
    Use this rather than `cw.web.htmlwidgets.BoxSeparator`.
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   235
    """
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   236
    newstyle = True
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   237
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   238
    def render(self, w):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   239
        w(u'<hr class="boxSeparator"/>')
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   240
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   241
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   242
def _bwcompatible_render_item(w, item):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   243
    if hasattr(item, 'render'):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   244
        if getattr(item, 'newstyle', False):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   245
            if isinstance(item, Separator):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   246
                w(u'</ul>')
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   247
                item.render(w)
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   248
                w(u'<ul>')
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   249
            else:
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   250
                w(u'<li>')
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   251
                item.render(w)
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   252
                w(u'</li>')
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   253
        else:
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   254
            item.render(w) # XXX displays <li> by itself
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   255
    else:
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   256
        w(u'<li>%s</li>' % item)
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   257
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   258
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   259
class Layout(Component):
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   260
    __regid__ = 'component_layout'
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   261
    __abstract__ = True
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 init_rendering(self):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   264
        """init view for rendering. Return true if we should go on, false
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   265
        if we should stop now.
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   266
        """
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 = 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
   268
        try:
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.init_rendering()
8695
358d8bed9626 [toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8190
diff changeset
   270
        except Unauthorized as ex:
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   271
            self.warning("can't render %s: %s", view, ex)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   272
            return False
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   273
        except EmptyComponent:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   274
            return False
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   275
        return True
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   276
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   277
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   278
class LayoutableMixIn(object):
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   279
    layout_id = None # to be defined in concret class
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   280
    layout_args = {}
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   281
10006
8391bf718485 remove most 3.10 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9915
diff changeset
   282
    def layout_render(self, w, **kwargs):
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   283
        getlayout = self._cw.vreg['components'].select
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   284
        layout = getlayout(self.layout_id, self._cw, **self.layout_select_args())
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   285
        layout.render(w)
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   286
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   287
    def layout_select_args(self):
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   288
        args  = dict(rset=self.cw_rset, row=self.cw_row, col=self.cw_col,
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   289
                     view=self)
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   290
        args.update(self.layout_args)
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   291
        return args
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   292
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   293
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   294
class CtxComponent(LayoutableMixIn, AppObject):
6580
798200432f50 some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6553
diff changeset
   295
    """base class for contextual components. The following contexts are
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   296
    predefined:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   297
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   298
    * boxes: 'left', 'incontext', 'right'
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   299
    * section: 'navcontenttop', 'navcontentbottom', '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
   300
    * other: 'ctxtoolbar'
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   301
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   302
    The 'incontext', 'navcontenttop', 'navcontentbottom' and 'ctxtoolbar'
6580
798200432f50 some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6553
diff changeset
   303
    contexts are handled by the default primary view, others by the default main
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   304
    template.
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   305
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   306
    All subclasses may not support all those contexts (for instance if it can't
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   307
    be displayed as box, or as a toolbar icon). You may restrict allowed context
6580
798200432f50 some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6553
diff changeset
   308
    as follows:
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   309
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   310
    .. sourcecode:: python
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   311
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   312
      class MyComponent(CtxComponent):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   313
          cw_property_defs = override_ctx(CtxComponent,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   314
                                          vocabulary=[list of contexts])
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   315
          context = 'my default context'
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   316
6580
798200432f50 some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6553
diff changeset
   317
    You can configure a component's default context by simply giving an
798200432f50 some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6553
diff changeset
   318
    appropriate value to the `context` class attribute, as seen above.
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   319
    """
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   320
    __registry__ = 'ctxcomponents'
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   321
    __select__ = ~no_cnx()
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   322
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   323
    categories_in_order = ()
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   324
    cw_property_defs = {
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   325
        _('visible'): dict(type='Boolean', default=True,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   326
                           help=_('display the box or not')),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   327
        _('order'):   dict(type='Int', default=99,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   328
                           help=_('display order of the box')),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   329
        _('context'): dict(type='String', default='left',
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   330
                           vocabulary=(_('left'), _('incontext'), _('right'),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   331
                                       _('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
   332
                                       _('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
   333
                                       _('ctxtoolbar')),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   334
                           help=_('context where this component should be displayed')),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   335
        }
6423
c560f8d9faee [pre 3.10 compat] if CtxComponent as a call() method, emit a deprecation warning but use it. Also ensure default value on class for visible and order, and define wview for bw compat as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   336
    visible = True
c560f8d9faee [pre 3.10 compat] if CtxComponent as a call() method, emit a deprecation warning but use it. Also ensure default value on class for visible and order, and define wview for bw compat as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6333
diff changeset
   337
    order = 0
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   338
    context = 'left'
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   339
    contextual = False
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   340
    title = None
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   341
    layout_id = 'component_layout'
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   342
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   343
    def render(self, w, **kwargs):
10006
8391bf718485 remove most 3.10 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9915
diff changeset
   344
        self.layout_render(w, **kwargs)
6907
449e5b46ed3d [component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6800
diff changeset
   345
449e5b46ed3d [component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6800
diff changeset
   346
    def layout_select_args(self):
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   347
        args = super(CtxComponent, self).layout_select_args()
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   348
        try:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   349
            # XXX ensure context is given when the component is reloaded through
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   350
            # ajax
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   351
            args['context'] = self.cw_extra_kwargs['context']
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   352
        except KeyError:
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   353
            args['context'] = self.cw_propval('context')
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   354
        return args
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   355
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   356
    def init_rendering(self):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   357
        """init rendering callback: that's the good time to check your component
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   358
        has some content to display. If not, you can still raise
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   359
        :exc:`EmptyComponent` to inform it should be skipped.
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   360
10510
51321946da37 Spelling fixes in comments and docstrings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10075
diff changeset
   361
        Also, :exc:`Unauthorized` will be caught, logged, then the component
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   362
        will be skipped.
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   363
        """
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   364
        self.items = []
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   365
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   366
    @property
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   367
    def domid(self):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   368
        """return the HTML DOM identifier for this component"""
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   369
        return domid(self.__regid__)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   370
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   371
    @property
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   372
    def cssclass(self):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   373
        """return the CSS class name for this component"""
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   374
        return domid(self.__regid__)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   375
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   376
    def render_title(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
   377
        """return the title for this component"""
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   378
        if self.title:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   379
            w(self._cw._(self.title))
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   380
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   381
    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
   382
        """return the body (content) for this component"""
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   383
        raise NotImplementedError()
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   384
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   385
    def render_items(self, w, items=None, klass=u'boxListing'):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   386
        if items is None:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   387
            items = self.items
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   388
        assert items
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   389
        w(u'<ul class="%s">' % klass)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   390
        for item in items:
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   391
            _bwcompatible_render_item(w, item)
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   392
        w(u'</ul>')
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   393
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   394
    def append(self, item):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   395
        self.items.append(item)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   396
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   397
    def action_link(self, action):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   398
        return self.link(self._cw._(action.title), action.url())
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   399
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   400
    def link(self, title, url, **kwargs):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   401
        if self._cw.selected(url):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   402
            try:
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   403
                kwargs['klass'] += ' selected'
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   404
            except KeyError:
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   405
                kwargs['klass'] = 'selected'
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   406
        return Link(url, title, **kwargs)
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   407
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   408
    def separator(self):
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   409
        return Separator()
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   410
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   411
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   412
class EntityCtxComponent(CtxComponent):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   413
    """base class for boxes related to a single entity"""
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   414
    __select__ = CtxComponent.__select__ & non_final_entity() & one_line_rset()
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   415
    context = 'incontext'
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   416
    contextual = True
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   417
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   418
    def __init__(self, *args, **kwargs):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   419
        super(EntityCtxComponent, self).__init__(*args, **kwargs)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   420
        try:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   421
            entity = kwargs['entity']
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   422
        except KeyError:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   423
            entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   424
        self.entity = entity
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   425
6907
449e5b46ed3d [component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6800
diff changeset
   426
    def layout_select_args(self):
449e5b46ed3d [component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6800
diff changeset
   427
        args = super(EntityCtxComponent, self).layout_select_args()
449e5b46ed3d [component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6800
diff changeset
   428
        args['entity'] = self.entity
449e5b46ed3d [component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6800
diff changeset
   429
        return args
449e5b46ed3d [component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6800
diff changeset
   430
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   431
    @property
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   432
    def domid(self):
10702
f94c812c3669 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10688
diff changeset
   433
        return domid(self.__regid__) + text_type(self.entity.eid)
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   434
6924
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   435
    def lazy_view_holder(self, w, entity, oid, registry='views'):
9700
da7d341cca76 an URL -> a URL
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9587
diff changeset
   436
        """add a holder and return a URL that may be used to replace this
6924
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   437
        holder by the html generate by the view specified by registry and
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   438
        identifier. Registry defaults to 'views'.
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   439
        """
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   440
        holderid = '%sHolder' % self.domid
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   441
        w(u'<div id="%s"></div>' % holderid)
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   442
        params = self.cw_extra_kwargs.copy()
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   443
        params.pop('view', None)
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   444
        params.pop('entity', None)
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   445
        form = params.pop('formparams', {})
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   446
        if entity.has_eid():
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   447
            eid = entity.eid
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   448
        else:
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   449
            eid = None
8900
010a59e12d89 use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8732
diff changeset
   450
            form['etype'] = entity.cw_etype
6924
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   451
            form['tempEid'] = entity.eid
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   452
        args = [json_dumps(x) for x in (registry, oid, eid, params)]
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   453
        return self._cw.ajax_replace_url(
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   454
            holderid, fname='render', arg=args, **form)
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   455
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   456
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   457
# high level abstract classes ##################################################
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   458
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   459
class RQLCtxComponent(CtxComponent):
6777
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   460
    """abstract box for boxes displaying the content of a rql query not related
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   461
    to the current result set.
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   462
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   463
    Notice that this class's init_rendering implemention is overwriting context
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   464
    result set (eg `cw_rset`) with the result set returned by execution of
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   465
    `to_display_rql()`.
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   466
    """
6777
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   467
    rql = None
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   468
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   469
    def to_display_rql(self):
6777
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   470
        """return arguments to give to self._cw.execute, as a tuple, to build
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   471
        the result set to be displayed by this box.
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   472
        """
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   473
        assert self.rql is not None, self.__regid__
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   474
        return (self.rql,)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   475
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   476
    def init_rendering(self):
6777
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   477
        super(RQLCtxComponent, self).init_rendering()
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   478
        self.cw_rset = self._cw.execute(*self.to_display_rql())
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   479
        if not self.cw_rset:
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   480
            raise EmptyComponent()
6777
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   481
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   482
    def render_body(self, w):
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   483
        rset = self.cw_rset
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   484
        if len(rset[0]) == 2:
6777
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   485
            items = []
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   486
            for i, (eid, label) in enumerate(rset):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   487
                entity = rset.get_entity(i, 0)
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   488
                items.append(self.link(label, entity.absolute_url()))
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   489
        else:
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   490
            items = [self.link(e.dc_title(), e.absolute_url())
6777
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   491
                     for e in rset.entities()]
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   492
        self.render_items(w, items)
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   493
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   494
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   495
class EditRelationMixIn(ReloadableMixIn):
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   496
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   497
    def box_item(self, entity, etarget, fname, label):
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   498
        """builds HTML link to edit relation between `entity` and `etarget`"""
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   499
        args = {role(self) : entity.eid, target(self): etarget.eid}
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   500
        # for each target, provide a link to edit the relation
9915
020d2e453e6f [web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents: 9914
diff changeset
   501
        jscall = js.cw.utils.callAjaxFuncThenReload(fname,
020d2e453e6f [web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents: 9914
diff changeset
   502
                                                    self.rtype,
020d2e453e6f [web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents: 9914
diff changeset
   503
                                                    args['subject'],
020d2e453e6f [web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents: 9914
diff changeset
   504
                                                    args['object'])
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   505
        return u'[<a href="javascript: %s" class="action">%s</a>] %s' % (
10702
f94c812c3669 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10688
diff changeset
   506
            xml_escape(text_type(jscall)), label, etarget.view('incontext'))
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   507
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   508
    def related_boxitems(self, entity):
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   509
        return [self.box_item(entity, etarget, 'delete_relation', u'-')
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   510
                for etarget in self.related_entities(entity)]
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   511
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   512
    def related_entities(self, entity):
6151
f910c60b84ff [new components] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   513
        return entity.related(self.rtype, role(self), entities=True)
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   514
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   515
    def unrelated_boxitems(self, entity):
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   516
        return [self.box_item(entity, etarget, 'add_relation', u'+')
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   517
                for etarget in self.unrelated_entities(entity)]
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   518
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   519
    def unrelated_entities(self, entity):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   520
        """returns the list of unrelated entities, using the entity's
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   521
        appropriate vocabulary function
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   522
        """
10702
f94c812c3669 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10688
diff changeset
   523
        skip = set(text_type(e.eid) for e in entity.related(self.rtype, role(self),
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   524
                                                          entities=True))
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   525
        skip.add(None)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   526
        skip.add(INTERNAL_FIELD_VALUE)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   527
        filteretype = getattr(self, 'etype', None)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   528
        entities = []
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   529
        form = self._cw.vreg['forms'].select('edition', self._cw,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   530
                                             rset=self.cw_rset,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   531
                                             row=self.cw_row or 0)
6151
f910c60b84ff [new components] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   532
        field = form.field_by_name(self.rtype, role(self), entity.e_schema)
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   533
        for _, eid in field.vocabulary(form):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   534
            if eid not in skip:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   535
                entity = self._cw.entity_from_eid(eid)
8900
010a59e12d89 use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8732
diff changeset
   536
                if filteretype is None or entity.cw_etype == filteretype:
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   537
                    entities.append(entity)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   538
        return entities
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   539
6553
2be8ff05fd20 add note
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6550
diff changeset
   540
# XXX should be a view usable using uicfg
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   541
class EditRelationCtxComponent(EditRelationMixIn, EntityCtxComponent):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   542
    """base class for boxes which let add or remove entities linked by a given
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   543
    relation
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   544
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   545
    subclasses should define at least id, rtype and target class attributes.
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   546
    """
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7536
diff changeset
   547
    # to be defined in concrete classes
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7536
diff changeset
   548
    rtype = None
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7536
diff changeset
   549
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   550
    def render_title(self, w):
6547
6be127941760 [new components] render_title must write title, not return it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6543
diff changeset
   551
        w(display_name(self._cw, self.rtype, role(self),
8900
010a59e12d89 use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8732
diff changeset
   552
                       context=self.entity.cw_etype))
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   553
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   554
    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
   555
        self._cw.add_js('cubicweb.ajax.js')
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   556
        related = self.related_boxitems(self.entity)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   557
        unrelated = self.unrelated_boxitems(self.entity)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   558
        self.items.extend(related)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   559
        if related and unrelated:
6550
8c6a0f6bba3b [boxes] use a new separator instead of clumsy htmlwidget's one which close and reopen the <ul> (loosing any list class on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6548
diff changeset
   560
            self.items.append(u'<hr class="boxSeparator"/>')
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   561
        self.items.extend(unrelated)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   562
        self.render_items(w)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   563
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   564
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   565
class AjaxEditRelationCtxComponent(EntityCtxComponent):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   566
    __select__ = EntityCtxComponent.__select__ & (
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   567
        partial_relation_possible(action='add') | partial_has_related_entities())
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   568
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   569
    # view used to display related entties
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   570
    item_vid = 'incontext'
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   571
    # values separator when multiple values are allowed
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   572
    separator = ','
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   573
    # msgid of the message to display when some new relation has been added/removed
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   574
    added_msg = None
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   575
    removed_msg = None
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   576
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7536
diff changeset
   577
    # to be defined in concrete classes
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7536
diff changeset
   578
    rtype = role = target_etype = None
10903
da30851f9706 spelling: *aly → *ally
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10713
diff changeset
   579
    # class attributes below *must* be set in concrete classes (additionally to
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   580
    # rtype / role [/ target_etype]. They should correspond to js_* methods on
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   581
    # the json controller
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   582
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   583
    # function(eid)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   584
    # -> expected to return a list of values to display as input selector
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   585
    #    vocabulary
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   586
    fname_vocabulary = None
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   587
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   588
    # function(eid, value)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   589
    # -> handle the selector's input (eg create necessary entities and/or
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   590
    # relations). If the relation is multiple, you'll get a list of value, else
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   591
    # a single string value.
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   592
    fname_validate = None
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   593
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   594
    # function(eid, linked entity eid)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   595
    # -> remove the relation
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   596
    fname_remove = None
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   597
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   598
    def __init__(self, *args, **kwargs):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   599
        super(AjaxEditRelationCtxComponent, self).__init__(*args, **kwargs)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   600
        self.rdef = self.entity.e_schema.rdef(self.rtype, self.role, self.target_etype)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   601
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   602
    def render_title(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
   603
        w(self.rdef.rtype.display_name(self._cw, self.role,
8900
010a59e12d89 use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8732
diff changeset
   604
                                       context=self.entity.cw_etype))
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   605
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   606
    def add_js_css(self):
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   607
        self._cw.add_js(('jquery.ui.js', 'cubicweb.widgets.js'))
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   608
        self._cw.add_js(('cubicweb.ajax.js', 'cubicweb.ajax.box.js'))
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   609
        self._cw.add_css('jquery.ui.css')
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   610
        return True
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   611
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   612
    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
   613
        req = self._cw
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   614
        entity = self.entity
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   615
        related = entity.related(self.rtype, self.role)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   616
        if self.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
   617
            mayadd = self.rdef.has_perm(req, 'add', fromeid=entity.eid)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   618
        else:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   619
            mayadd = self.rdef.has_perm(req, 'add', toeid=entity.eid)
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   620
        js_css_added = False
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   621
        if mayadd:
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   622
            js_css_added = self.add_js_css()
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   623
        _ = req._
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   624
        if related:
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   625
            maydel = None
6452
6b6a2fa28069 [ui] nicer ajax edit relation table (tags box for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6448
diff changeset
   626
            w(u'<table class="ajaxEditRelationTable">')
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   627
            for rentity in related.entities():
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   628
                if maydel is None:
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   629
                    # Only check permission for the first related.
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   630
                    if self.role == 'subject':
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   631
                        fromeid, toeid = entity.eid, rentity.eid
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   632
                    else:
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   633
                        fromeid, toeid = rentity.eid, entity.eid
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   634
                    maydel = self.rdef.has_perm(
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   635
                            req, 'delete', fromeid=fromeid, toeid=toeid)
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   636
                # for each related entity, provide a link to remove the relation
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   637
                subview = rentity.view(self.item_vid)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   638
                if maydel:
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   639
                    if not js_css_added:
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   640
                        js_css_added = self.add_js_css()
10702
f94c812c3669 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10688
diff changeset
   641
                    jscall = text_type(js.ajaxBoxRemoveLinkedEntity(
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   642
                        self.__regid__, entity.eid, rentity.eid,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   643
                        self.fname_remove,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   644
                        self.removed_msg and _(self.removed_msg)))
6452
6b6a2fa28069 [ui] nicer ajax edit relation table (tags box for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6448
diff changeset
   645
                    w(u'<tr><td class="dellink">[<a href="javascript: %s">-</a>]</td>'
6b6a2fa28069 [ui] nicer ajax edit relation table (tags box for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6448
diff changeset
   646
                      '<td class="entity"> %s</td></tr>' % (xml_escape(jscall),
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   647
                                                            subview))
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   648
                else:
6452
6b6a2fa28069 [ui] nicer ajax edit relation table (tags box for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6448
diff changeset
   649
                    w(u'<tr><td class="entity">%s</td></tr>' % (subview))
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   650
            w(u'</table>')
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   651
        else:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   652
            w(_('no related entity'))
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   653
        if mayadd:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   654
            multiple = self.rdef.role_cardinality(self.role) in '*+'
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   655
            w(u'<table><tr><td>')
10702
f94c812c3669 [py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10688
diff changeset
   656
            jscall = text_type(js.ajaxBoxShowSelector(
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   657
                self.__regid__, entity.eid, self.fname_vocabulary,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   658
                self.fname_validate, self.added_msg and _(self.added_msg),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   659
                _(stdmsgs.BUTTON_OK[0]), _(stdmsgs.BUTTON_CANCEL[0]),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   660
                multiple and self.separator))
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   661
            w('<a class="button sglink" href="javascript: %s">%s</a>' % (
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   662
                xml_escape(jscall),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   663
                multiple and _('add_relation') or _('update_relation')))
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   664
            w(u'</td><td>')
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   665
            w(u'<div id="%sHolder"></div>' % self.domid)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   666
            w(u'</td></tr></table>')
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   667
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   668
6461
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   669
class RelatedObjectsCtxComponent(EntityCtxComponent):
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   670
    """a contextual component to display entities related to another"""
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   671
    __select__ = EntityCtxComponent.__select__ & partial_has_related_entities()
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   672
    context = 'navcontentbottom'
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   673
    rtype = None
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   674
    role = 'subject'
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   675
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   676
    vid = 'list'
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   677
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   678
    def render_body(self, w):
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   679
        rset = self.entity.related(self.rtype, role(self))
6468
40033d536ed8 [ctx component] has no wview method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6461
diff changeset
   680
        self._cw.view(self.vid, rset, w=w)
6461
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   681
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   682
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   683
# old contextual components, deprecated ########################################
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   684
10688
fa29f3628a1b [py3k] use six.add_metaclass
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
   685
@add_metaclass(class_deprecated)
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   686
class EntityVComponent(Component):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   687
    """abstract base class for additinal components displayed in content
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   688
    headers and footer according to:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   689
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   690
    * the displayed entity's type
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   691
    * a context (currently 'header' or 'footer')
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   692
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   693
    it should be configured using .accepts, .etype, .rtype, .target and
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   694
    .context class attributes
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   695
    """
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   696
    __deprecation_warning__ = '[3.10] *VComponent classes are deprecated, use *CtxComponent instead (%(cls)s)'
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   697
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   698
    __registry__ = 'ctxcomponents'
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   699
    __select__ = one_line_rset()
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   700
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   701
    cw_property_defs = {
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   702
        _('visible'):  dict(type='Boolean', default=True,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   703
                            help=_('display the component or not')),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   704
        _('order'):    dict(type='Int', default=99,
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   705
                            help=_('display order of the component')),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   706
        _('context'):  dict(type='String', default='navtop',
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   707
                            vocabulary=(_('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
   708
                                        _('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
   709
                                        _('ctxtoolbar')),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   710
                            help=_('context where this component should be displayed')),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   711
    }
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   712
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   713
    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
   714
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   715
    def call(self, view=None):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   716
        if self.cw_rset is None:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   717
            self.entity_call(self.cw_extra_kwargs.pop('entity'))
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   718
        else:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   719
            self.cell_call(0, 0, view=view)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   720
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   721
    def cell_call(self, row, col, view=None):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   722
        self.entity_call(self.cw_rset.get_entity(row, col), view=view)
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   723
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   724
    def entity_call(self, entity, view=None):
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   725
        raise NotImplementedError()
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   726
10040
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   727
class RelatedObjectsVComponent(EntityVComponent):
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   728
    """a section to display some related entities"""
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   729
    __select__ = EntityVComponent.__select__ & partial_has_related_entities()
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   730
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   731
    vid = 'list'
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   732
    # to be defined in concrete classes
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   733
    rtype = title = None
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   734
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   735
    def rql(self):
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   736
        """override this method if you want to use a custom rql query"""
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   737
        return None
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   738
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   739
    def cell_call(self, row, col, view=None):
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   740
        rql = self.rql()
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   741
        if rql is None:
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   742
            entity = self.cw_rset.get_entity(row, col)
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   743
            rset = entity.related(self.rtype, role(self))
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   744
        else:
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   745
            eid = self.cw_rset[row][col]
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   746
            rset = self._cw.execute(self.rql(), {'x': eid})
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   747
        if not rset.rowcount:
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   748
            return
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   749
        self.w(u'<div class="%s">' % self.cssclass)
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   750
        self.w(u'<h4>%s</h4>\n' % self._cw._(self.title).capitalize())
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   751
        self.wview(self.vid, rset)
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   752
        self.w(u'</div>')