web/component.py
author Rémi Cardona <remi.cardona@logilab.fr>
Wed, 16 Sep 2015 16:02:04 +0200
changeset 10692 14e7ddb0f670
parent 10688 fa29f3628a1b
child 10702 f94c812c3669
permissions -rw-r--r--
[py3k] unicode → six.text_type
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
10688
fa29f3628a1b [py3k] use six.add_metaclass
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
    27
from six import add_metaclass
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
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   220
    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
   221
        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
   222
10044
5907c2b0acd7 [component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10040
diff changeset
   223
    def __repr__(self):
5907c2b0acd7 [component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10040
diff changeset
   224
        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
   225
                                              self.href, self.label, self.attrs)
5907c2b0acd7 [component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 10040
diff changeset
   226
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   227
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   228
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
   229
    """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
   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
    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
   232
    """
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   233
    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
   234
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   235
    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
   236
        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
   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
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   239
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
   240
    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
   241
        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
   242
            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
   243
                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
   244
                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
   245
                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
   246
            else:
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   247
                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
   248
                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
   249
                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
   250
        else:
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) # 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
   252
    else:
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   253
        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
   254
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   255
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   256
class Layout(Component):
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   257
    __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
   258
    __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
   259
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   260
    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
   261
        """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
   262
        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
   263
        """
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   264
        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
   265
        try:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   266
            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
   267
        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
   268
            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
   269
            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
   270
        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
   271
            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
   272
        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
   273
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   274
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   275
class LayoutableMixIn(object):
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   276
    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
   277
    layout_args = {}
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   278
10006
8391bf718485 remove most 3.10 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9915
diff changeset
   279
    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
   280
        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
   281
        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
   282
        layout.render(w)
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   283
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   284
    def layout_select_args(self):
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   285
        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
   286
                     view=self)
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   287
        args.update(self.layout_args)
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   288
        return args
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   289
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   290
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   291
class CtxComponent(LayoutableMixIn, AppObject):
6580
798200432f50 some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6553
diff changeset
   292
    """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
   293
    predefined:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   294
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   295
    * 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
   296
    * 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
   297
    * 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
   298
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   299
    The 'incontext', 'navcontenttop', 'navcontentbottom' and 'ctxtoolbar'
6580
798200432f50 some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6553
diff changeset
   300
    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
   301
    template.
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   302
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   303
    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
   304
    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
   305
    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
   306
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   307
    .. 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
   308
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   309
      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
   310
          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
   311
                                          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
   312
          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
   313
6580
798200432f50 some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6553
diff changeset
   314
    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
   315
    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
   316
    """
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   317
    __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
   318
    __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
   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
    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
   321
    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
   322
        _('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
   323
                           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
   324
        _('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
   325
                           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
   326
        _('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
   327
                           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
   328
                                       _('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
   329
                                       _('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
   330
                                       _('ctxtoolbar')),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   331
                           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
   332
        }
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
   333
    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
   334
    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
   335
    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
   336
    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
   337
    title = None
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   338
    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
   339
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   340
    def render(self, w, **kwargs):
10006
8391bf718485 remove most 3.10 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9915
diff changeset
   341
        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
   342
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
   343
    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
   344
        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
   345
        try:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   346
            # 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
   347
            # ajax
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   348
            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
   349
        except KeyError:
7991
dcc5a4d48122 [web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7990
diff changeset
   350
            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
   351
        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
   352
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   353
    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
   354
        """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
   355
        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
   356
        :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
   357
10510
51321946da37 Spelling fixes in comments and docstrings
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10075
diff changeset
   358
        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
   359
        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
   360
        """
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   361
        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
   362
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   363
    @property
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   364
    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
   365
        """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
   366
        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
   367
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   368
    @property
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   369
    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
   370
        """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
   371
        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
   372
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   373
    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
   374
        """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
   375
        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
   376
            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
   377
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   378
    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
   379
        """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
   380
        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
   381
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   382
    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
   383
        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
   384
            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
   385
        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
   386
        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
   387
        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
   388
            _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
   389
        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
   390
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   391
    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
   392
        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
   393
6800
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   394
    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
   395
        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
   396
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 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
   398
        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
   399
            try:
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   400
                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
   401
            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
   402
                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
   403
        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
   404
3f3d576b87d9 [web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6777
diff changeset
   405
    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
   406
        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
   407
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   408
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   409
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
   410
    """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
   411
    __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
   412
    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
   413
    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
   414
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   415
    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
   416
        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
   417
        try:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   418
            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
   419
        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
   420
            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
   421
        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
   422
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
   423
    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
   424
        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
   425
        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
   426
        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
   427
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   428
    @property
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   429
    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
   430
        return domid(self.__regid__) + unicode(self.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
   431
6924
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   432
    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
   433
        """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
   434
        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
   435
        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
   436
        """
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   437
        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
   438
        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
   439
        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
   440
        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
   441
        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
   442
        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
   443
        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
   444
            eid = entity.eid
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   445
        else:
b88221afe491 [js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6907
diff changeset
   446
            eid = None
8900
010a59e12d89 use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8732
diff changeset
   447
            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
   448
            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
   449
        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
   450
        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
   451
            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
   452
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   453
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   454
# 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
   455
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   456
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
   457
    """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
   458
    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
   459
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   460
    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
   461
    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
   462
    `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
   463
    """
6777
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   464
    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
   465
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   466
    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
   467
        """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
   468
        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
   469
        """
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   470
        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
   471
        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
   472
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   473
    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
   474
        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
   475
        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
   476
        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
   477
            raise EmptyComponent()
6777
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   478
1d423b7aa6c9 [ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 6743
diff changeset
   479
    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
   480
        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
   481
        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
   482
            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
   483
            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
   484
                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
   485
                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
   486
        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
   487
            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
   488
                     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
   489
        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
   490
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   491
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   492
class EditRelationMixIn(ReloadableMixIn):
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   493
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   494
    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
   495
        """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
   496
        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
   497
        # 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
   498
        jscall = js.cw.utils.callAjaxFuncThenReload(fname,
020d2e453e6f [web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents: 9914
diff changeset
   499
                                                    self.rtype,
020d2e453e6f [web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents: 9914
diff changeset
   500
                                                    args['subject'],
020d2e453e6f [web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents: 9914
diff changeset
   501
                                                    args['object'])
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   502
        return u'[<a href="javascript: %s" class="action">%s</a>] %s' % (
9915
020d2e453e6f [web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents: 9914
diff changeset
   503
            xml_escape(unicode(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
   504
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   505
    def related_boxitems(self, entity):
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   506
        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
   507
                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
   508
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   509
    def related_entities(self, entity):
6151
f910c60b84ff [new components] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   510
        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
   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 unrelated_boxitems(self, entity):
9784
790956c311ef EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents: 9700
diff changeset
   513
        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
   514
                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
   515
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   516
    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
   517
        """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
   518
        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
   519
        """
6151
f910c60b84ff [new components] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6141
diff changeset
   520
        skip = set(unicode(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
   521
                                                          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
   522
        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
   523
        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
   524
        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
   525
        entities = []
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   526
        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
   527
                                             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
   528
                                             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
   529
        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
   530
        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
   531
            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
   532
                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
   533
                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
   534
                    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
   535
        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
   536
6553
2be8ff05fd20 add note
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6550
diff changeset
   537
# 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
   538
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
   539
    """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
   540
    relation
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   541
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   542
    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
   543
    """
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
   544
    # 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
   545
    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
   546
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   547
    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
   548
        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
   549
                       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
   550
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   551
    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
   552
        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
   553
        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
   554
        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
   555
        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
   556
        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
   557
            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
   558
        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
   559
        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
   560
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   561
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   562
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
   563
    __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
   564
        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
   565
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   566
    # 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
   567
    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
   568
    # 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
   569
    separator = ','
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   570
    # 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
   571
    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
   572
    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
   573
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
   574
    # 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
   575
    rtype = role = target_etype = 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
   576
    # class attributes below *must* be set in concrete classes (additionaly 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
   577
    # 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
   578
    # 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
   579
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   580
    # 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
   581
    # -> 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
   582
    #    vocabulary
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   583
    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
   584
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   585
    # 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
   586
    # -> 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
   587
    # 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
   588
    # 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
   589
    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
   590
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   591
    # 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
   592
    # -> 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
   593
    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
   594
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   595
    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
   596
        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
   597
        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
   598
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   599
    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
   600
        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
   601
                                       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
   602
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   603
    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
   604
        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
   605
        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
   606
        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
   607
        return True
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   608
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   609
    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
   610
        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
   611
        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
   612
        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
   613
        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
   614
            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
   615
        else:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   616
            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
   617
        js_css_added = False
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   618
        if mayadd:
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   619
            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
   620
        _ = req._
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   621
        if related:
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   622
            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
   623
            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
   624
            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
   625
                if maydel is None:
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   626
                    # 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
   627
                    if self.role == 'subject':
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   628
                        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
   629
                    else:
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   630
                        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
   631
                    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
   632
                            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
   633
                # 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
   634
                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
   635
                if maydel:
10075
136b5f995f8e Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 10044
diff changeset
   636
                    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
   637
                        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
   638
                    jscall = unicode(js.ajaxBoxRemoveLinkedEntity(
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   639
                        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
   640
                        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
   641
                        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
   642
                    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
   643
                      '<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
   644
                                                            subview))
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   645
                else:
6452
6b6a2fa28069 [ui] nicer ajax edit relation table (tags box for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6448
diff changeset
   646
                    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
   647
            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
   648
        else:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   649
            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
   650
        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
   651
            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
   652
            w(u'<table><tr><td>')
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   653
            jscall = unicode(js.ajaxBoxShowSelector(
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   654
                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
   655
                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
   656
                _(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
   657
                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
   658
            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
   659
                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
   660
                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
   661
            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
   662
            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
   663
            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
   664
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   665
6461
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   666
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
   667
    """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
   668
    __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
   669
    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
   670
    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
   671
    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
   672
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   673
    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
   674
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   675
    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
   676
        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
   677
        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
   678
b546296227ff [ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6452
diff changeset
   679
6141
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   680
# 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
   681
10688
fa29f3628a1b [py3k] use six.add_metaclass
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10666
diff changeset
   682
@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
   683
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
   684
    """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
   685
    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
   686
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   687
    * 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
   688
    * 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
   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
    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
   691
    .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
   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
    __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
   694
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   695
    __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
   696
    __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
   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
    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
   699
        _('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
   700
                            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
   701
        _('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
   702
                            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
   703
        _('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
   704
                            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
   705
                                        _('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
   706
                                        _('ctxtoolbar')),
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   707
                            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
   708
    }
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   709
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   710
    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
   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
    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
   713
        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
   714
            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
   715
        else:
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   716
            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
   717
b8287e54b528 [web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6140
diff changeset
   718
    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
   719
        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
   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 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
   722
        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
   723
10040
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   724
class RelatedObjectsVComponent(EntityVComponent):
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   725
    """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
   726
    __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
   727
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   728
    vid = 'list'
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   729
    # 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
   730
    rtype = title = None
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   731
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   732
    def rql(self):
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   733
        """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
   734
        return None
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   735
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   736
    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
   737
        rql = self.rql()
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   738
        if rql is None:
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   739
            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
   740
            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
   741
        else:
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   742
            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
   743
            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
   744
        if not rset.rowcount:
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   745
            return
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   746
        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
   747
        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
   748
        self.wview(self.vid, rset)
2ddeece84808 [web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents: 10006
diff changeset
   749
        self.w(u'</div>')