author | Rémi Cardona <remi.cardona@logilab.fr> |
Tue, 15 Sep 2015 15:08:04 +0200 | |
changeset 10673 | 9924fd69bcba |
parent 10666 | 7f6b5f023884 |
child 10688 | fa29f3628a1b |
permissions | -rw-r--r-- |
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 | 21 |
|
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 | 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 |
|
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
27 |
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
|
28 |
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
|
29 |
|
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
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs |
0 | 40 |
|
41 |
||
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
42 |
# abstract base class for navigation components ################################ |
1433 | 43 |
|
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
659
diff
changeset
|
44 |
class NavigationComponent(Component): |
0 | 45 |
"""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
|
46 |
__regid__ = 'navigation' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
687
diff
changeset
|
47 |
__select__ = paginated_rset() |
1433 | 48 |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
49 |
cw_property_defs = { |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
50 |
_('visible'): dict(type='Boolean', default=True, |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
51 |
help=_('display the component or not')), |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
52 |
} |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
53 |
|
0 | 54 |
page_size_property = 'navigation.page-size' |
55 |
start_param = '__start' |
|
56 |
stop_param = '__stop' |
|
57 |
page_link_templ = u'<span class="slice"><a href="%s" title="%s">%s</a></span>' |
|
58 |
selected_page_link_templ = u'<span class="selectedSlice"><a href="%s" title="%s">%s</a></span>' |
|
59 |
previous_page_link_templ = next_page_link_templ = page_link_templ |
|
1433 | 60 |
|
1339 | 61 |
def __init__(self, req, rset, **kwargs): |
2890
fdcb8a2bb6eb
fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2819
diff
changeset
|
62 |
super(NavigationComponent, self).__init__(req, rset=rset, **kwargs) |
0 | 63 |
self.starting_from = 0 |
64 |
self.total = rset.rowcount |
|
65 |
||
66 |
def get_page_size(self): |
|
67 |
try: |
|
68 |
return self._page_size |
|
69 |
except AttributeError: |
|
3468
b02fa4db2868
[tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
70 |
page_size = self.cw_extra_kwargs.get('page_size') |
822 | 71 |
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
|
72 |
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
|
73 |
page_size = int(self._cw.form['page_size']) |
822 | 74 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
75 |
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
|
76 |
self._page_size = page_size |
ad129d374ee2
fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents:
747
diff
changeset
|
77 |
return page_size |
0 | 78 |
|
79 |
def set_page_size(self, page_size): |
|
80 |
self._page_size = page_size |
|
1433 | 81 |
|
0 | 82 |
page_size = property(get_page_size, set_page_size) |
1433 | 83 |
|
0 | 84 |
def page_boundaries(self): |
85 |
try: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
86 |
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
|
87 |
start = int(self._cw.form[self.start_param]) |
0 | 88 |
except KeyError: |
89 |
start, stop = 0, self.page_size |
|
4089
ff92c7d692bf
typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
90 |
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
|
91 |
start, stop = 0, self.page_size |
0 | 92 |
self.starting_from = start |
93 |
return start, stop |
|
1433 | 94 |
|
0 | 95 |
def clean_params(self, params): |
96 |
if self.start_param in params: |
|
97 |
del params[self.start_param] |
|
98 |
if self.stop_param in params: |
|
99 |
del params[self.stop_param] |
|
100 |
||
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
# '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
|
113 |
# 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
|
114 |
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
|
115 |
else: |
9587
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._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
|
117 |
# 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
|
118 |
# 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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
|
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
|
0 | 129 |
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
|
130 |
url = xml_escape(self.page_url(path, params, start, stop)) |
0 | 131 |
if start == self.starting_from: |
132 |
return self.selected_page_link_templ % (url, content, content) |
|
133 |
return self.page_link_templ % (url, content, content) |
|
134 |
||
7323
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
135 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
139 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
143 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
(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
|
147 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
148 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
149 |
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
|
150 |
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
|
151 |
(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
|
152 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
153 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
154 |
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
|
155 |
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
|
156 |
(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
|
157 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
158 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
(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
|
162 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
163 |
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
|
164 |
if not content: |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
165 |
content = self.no_content_prev_link |
0 | 166 |
start = self.starting_from |
167 |
if not start : |
|
168 |
return self.no_previous_page_link |
|
169 |
start = max(0, start - self.page_size) |
|
170 |
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
|
171 |
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
|
172 |
return self.previous_page_link_templ % (url, self._cw._(title), content) |
0 | 173 |
|
7323
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
174 |
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
|
175 |
if not content: |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
176 |
content = self.no_content_next_link |
0 | 177 |
start = self.starting_from + self.page_size |
178 |
if start >= self.total: |
|
179 |
return self.no_next_page_link |
|
180 |
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
|
181 |
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
|
182 |
return self.next_page_link_templ % (url, self._cw._(title), content) |
0 | 183 |
|
184 |
||
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
185 |
# 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
|
186 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
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
|
191 |
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
|
192 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
193 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
194 |
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
|
195 |
"""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
|
196 |
rendered |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
197 |
""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
198 |
|
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
199 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
200 |
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
|
201 |
"""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
|
202 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
203 |
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
|
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 |
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
|
206 |
side. |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
207 |
""" |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
208 |
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
|
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 |
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
|
211 |
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
|
212 |
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
|
213 |
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
|
214 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
215 |
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
|
216 |
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
|
217 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
218 |
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
|
219 |
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
|
220 |
|
10044
5907c2b0acd7
[component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10040
diff
changeset
|
221 |
def __repr__(self): |
5907c2b0acd7
[component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10040
diff
changeset
|
222 |
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
|
223 |
self.href, self.label, self.attrs) |
5907c2b0acd7
[component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10040
diff
changeset
|
224 |
|
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
225 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
226 |
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
|
227 |
"""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
|
228 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
229 |
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
|
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 |
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
|
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 |
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
|
234 |
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
|
235 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
236 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
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
|
242 |
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
|
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 |
else: |
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'<li>') |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
246 |
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
|
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 |
else: |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
249 |
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
|
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 |
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
|
252 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
253 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
254 |
class Layout(Component): |
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
255 |
__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
|
256 |
__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
|
257 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
258 |
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
|
259 |
"""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
|
260 |
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
|
261 |
""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
262 |
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
|
263 |
try: |
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.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
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
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
|
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 |
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
|
271 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
272 |
|
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
273 |
class LayoutableMixIn(object): |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
274 |
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
|
275 |
layout_args = {} |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
276 |
|
10006
8391bf718485
remove most 3.10 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9915
diff
changeset
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
layout.render(w) |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
281 |
|
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
282 |
def layout_select_args(self): |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
283 |
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
|
284 |
view=self) |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
285 |
args.update(self.layout_args) |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
286 |
return args |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
287 |
|
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
288 |
|
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
289 |
class CtxComponent(LayoutableMixIn, AppObject): |
6580
798200432f50
some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6553
diff
changeset
|
290 |
"""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
|
291 |
predefined: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
292 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
293 |
* 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
|
294 |
* 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
|
295 |
* 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
|
296 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
297 |
The 'incontext', 'navcontenttop', 'navcontentbottom' and 'ctxtoolbar' |
6580
798200432f50
some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6553
diff
changeset
|
298 |
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
|
299 |
template. |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
300 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
301 |
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
|
302 |
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
|
303 |
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
|
304 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
305 |
.. 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
|
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 |
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
|
6580
798200432f50
some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6553
diff
changeset
|
312 |
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
|
313 |
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
|
314 |
""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
315 |
__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
|
316 |
__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
|
317 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
318 |
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
|
319 |
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
|
320 |
_('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
|
321 |
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
|
322 |
_('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
|
323 |
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
|
324 |
_('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
|
325 |
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
|
326 |
_('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
|
327 |
_('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
|
328 |
_('ctxtoolbar')), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
329 |
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
|
330 |
} |
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
|
331 |
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
|
332 |
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
|
333 |
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
|
334 |
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
|
335 |
title = None |
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
336 |
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
|
337 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
338 |
def render(self, w, **kwargs): |
10006
8391bf718485
remove most 3.10 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9915
diff
changeset
|
339 |
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
|
340 |
|
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
|
341 |
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
|
342 |
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
|
343 |
try: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
344 |
# 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
|
345 |
# ajax |
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
346 |
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
|
347 |
except KeyError: |
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_propval('context') |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
349 |
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
|
350 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
351 |
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
|
352 |
"""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
|
353 |
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
|
354 |
: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
|
355 |
|
10510
51321946da37
Spelling fixes in comments and docstrings
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10075
diff
changeset
|
356 |
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
|
357 |
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
|
358 |
""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
359 |
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
|
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 |
@property |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
362 |
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
|
363 |
"""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
|
364 |
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
|
365 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
366 |
@property |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
367 |
def 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
|
368 |
"""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
|
369 |
return domid(self.__regid__) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
370 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
371 |
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
|
372 |
"""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
|
373 |
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
|
374 |
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
|
375 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
376 |
def render_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
|
377 |
"""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
|
378 |
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
|
379 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
380 |
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
|
381 |
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
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
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
|
386 |
_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
|
387 |
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
|
388 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
389 |
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
|
390 |
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
|
391 |
|
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
392 |
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
|
393 |
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
|
394 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
395 |
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
|
396 |
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
|
397 |
try: |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
398 |
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
|
399 |
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
|
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 |
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
|
402 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
403 |
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
|
404 |
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
|
405 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
406 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
407 |
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
|
408 |
"""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
|
409 |
__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
|
410 |
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
|
411 |
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
|
412 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
413 |
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
|
414 |
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
|
415 |
try: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
416 |
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
|
417 |
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
|
418 |
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
|
419 |
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
|
420 |
|
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
|
421 |
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
|
422 |
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
|
423 |
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
|
424 |
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
|
425 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
426 |
@property |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
427 |
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
|
428 |
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
|
429 |
|
6924
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
430 |
def lazy_view_holder(self, w, entity, oid, registry='views'): |
9700 | 431 |
"""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
|
432 |
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
|
433 |
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
|
434 |
""" |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
435 |
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
|
436 |
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
|
437 |
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
|
438 |
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
|
439 |
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
|
440 |
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
|
441 |
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
|
442 |
eid = entity.eid |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
443 |
else: |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
444 |
eid = None |
8900
010a59e12d89
use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8732
diff
changeset
|
445 |
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
|
446 |
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
|
447 |
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
|
448 |
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
|
449 |
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
|
450 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
451 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
452 |
# 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
|
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 |
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
|
455 |
"""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
|
456 |
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
|
457 |
|
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
458 |
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
|
459 |
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
|
460 |
`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
|
461 |
""" |
6777
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
462 |
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
|
463 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
464 |
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
|
465 |
"""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
|
466 |
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
|
467 |
""" |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
468 |
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
|
469 |
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
|
470 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
471 |
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
|
472 |
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
|
473 |
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
|
474 |
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
|
475 |
raise EmptyComponent() |
6777
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
476 |
|
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
477 |
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
|
478 |
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
|
479 |
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
|
480 |
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
|
481 |
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
|
482 |
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
|
483 |
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
|
484 |
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
|
485 |
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
|
486 |
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
|
487 |
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
|
488 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
489 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
490 |
class EditRelationMixIn(ReloadableMixIn): |
9784
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
491 |
|
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
492 |
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
|
493 |
"""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
|
494 |
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
|
495 |
# 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
|
496 |
jscall = js.cw.utils.callAjaxFuncThenReload(fname, |
020d2e453e6f
[web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents:
9914
diff
changeset
|
497 |
self.rtype, |
020d2e453e6f
[web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents:
9914
diff
changeset
|
498 |
args['subject'], |
020d2e453e6f
[web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents:
9914
diff
changeset
|
499 |
args['object']) |
9784
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
500 |
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
|
501 |
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
|
502 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
503 |
def related_boxitems(self, entity): |
9784
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
504 |
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
|
505 |
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
|
506 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
507 |
def related_entities(self, entity): |
6151
f910c60b84ff
[new components] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
508 |
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
|
509 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
510 |
def unrelated_boxitems(self, entity): |
9784
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
511 |
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
|
512 |
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
|
513 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
514 |
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
|
515 |
"""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
|
516 |
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
|
517 |
""" |
6151
f910c60b84ff
[new components] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
518 |
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
|
519 |
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
|
520 |
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
|
521 |
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
|
522 |
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
|
523 |
entities = [] |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
524 |
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
|
525 |
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
|
526 |
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
|
527 |
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
|
528 |
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
|
529 |
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
|
530 |
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
|
531 |
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
|
532 |
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
|
533 |
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
|
534 |
|
6553 | 535 |
# 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
|
536 |
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
|
537 |
"""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
|
538 |
relation |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
539 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
540 |
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
|
541 |
""" |
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
|
542 |
# 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
|
543 |
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
|
544 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
545 |
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
|
546 |
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
|
547 |
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
|
548 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
549 |
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
|
550 |
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
|
551 |
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
|
552 |
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
|
553 |
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
|
554 |
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
|
555 |
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
|
556 |
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
|
557 |
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
|
558 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
559 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
560 |
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
|
561 |
__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
|
562 |
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
|
563 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
564 |
# 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
|
565 |
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
|
566 |
# 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
|
567 |
separator = ',' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
568 |
# 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
|
569 |
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
|
570 |
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
|
571 |
|
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
|
572 |
# 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
|
573 |
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
|
574 |
# 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
|
575 |
# 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
|
576 |
# 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
|
577 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
578 |
# 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
|
579 |
# -> 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
|
580 |
# vocabulary |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
581 |
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
|
582 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
583 |
# function(eid, value) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
584 |
# -> 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
|
585 |
# 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
|
586 |
# 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
|
587 |
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
|
588 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
589 |
# 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
|
590 |
# -> 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
|
591 |
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
|
592 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
593 |
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
|
594 |
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
|
595 |
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
|
596 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
597 |
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
|
598 |
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
|
599 |
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
|
600 |
|
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
601 |
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
|
602 |
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
|
603 |
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
|
604 |
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
|
605 |
return True |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
606 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
607 |
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
|
608 |
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
|
609 |
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
|
610 |
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
|
611 |
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
|
612 |
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
|
613 |
else: |
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', toeid=entity.eid) |
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
615 |
js_css_added = False |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
616 |
if mayadd: |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
617 |
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
|
618 |
_ = req._ |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
619 |
if related: |
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
620 |
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
|
621 |
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
|
622 |
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
|
623 |
if maydel is None: |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
624 |
# 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
|
625 |
if self.role == 'subject': |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
626 |
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
|
627 |
else: |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
628 |
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
|
629 |
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
|
630 |
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
|
631 |
# 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
|
632 |
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
|
633 |
if maydel: |
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
634 |
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
|
635 |
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
|
636 |
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
|
637 |
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
|
638 |
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
|
639 |
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
|
640 |
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
|
641 |
'<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
|
642 |
subview)) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
643 |
else: |
6452
6b6a2fa28069
[ui] nicer ajax edit relation table (tags box for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6448
diff
changeset
|
644 |
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
|
645 |
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
|
646 |
else: |
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(_('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
|
648 |
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
|
649 |
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
|
650 |
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
|
651 |
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
|
652 |
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
|
653 |
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
|
654 |
_(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
|
655 |
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
|
656 |
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
|
657 |
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
|
658 |
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
|
659 |
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
|
660 |
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
|
661 |
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
|
662 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
663 |
|
6461
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
664 |
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
|
665 |
"""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
|
666 |
__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
|
667 |
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
|
668 |
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
|
669 |
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
|
670 |
|
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
671 |
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
|
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 |
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
|
674 |
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
|
675 |
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
|
676 |
|
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
677 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
678 |
# 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
|
679 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
680 |
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
|
681 |
"""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
|
682 |
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
|
683 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
684 |
* 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
|
685 |
* 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
|
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 |
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
|
688 |
.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
|
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 |
__metaclass__ = class_deprecated |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
691 |
__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
|
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 |
__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
|
694 |
__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
|
695 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
696 |
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
|
697 |
_('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
|
698 |
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
|
699 |
_('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
|
700 |
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
|
701 |
_('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
|
702 |
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
|
703 |
_('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
|
704 |
_('ctxtoolbar')), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
705 |
help=_('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
|
706 |
} |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
707 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
708 |
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
|
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 |
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
|
711 |
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
|
712 |
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
|
713 |
else: |
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.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
|
715 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
716 |
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
|
717 |
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
|
718 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
719 |
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
|
720 |
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
|
721 |
|
10040
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
722 |
class RelatedObjectsVComponent(EntityVComponent): |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
723 |
"""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
|
724 |
__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
|
725 |
|
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
726 |
vid = 'list' |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
727 |
# 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
|
728 |
rtype = title = None |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
729 |
|
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
730 |
def rql(self): |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
731 |
"""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
|
732 |
return None |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
733 |
|
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
734 |
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
|
735 |
rql = self.rql() |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
736 |
if rql is None: |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
737 |
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
|
738 |
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
|
739 |
else: |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
740 |
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
|
741 |
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
|
742 |
if not rset.rowcount: |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
743 |
return |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
744 |
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
|
745 |
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
|
746 |
self.wview(self.vid, rset) |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
747 |
self.w(u'</div>') |