author | Stephanie Marcu <stephanie.marcu@logilab.fr> |
Fri, 22 Oct 2010 14:54:24 +0200 | |
changeset 6592 | 4dad0ec0a44f |
parent 6499 | c4123c741c66 |
child 7879 | 9aae456abab5 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5927
diff
changeset
|
18 |
"""abstract box classes for CubicWeb web client""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
2159 | 21 |
_ = unicode |
0 | 22 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2159
diff
changeset
|
23 |
from logilab.mtconverter import xml_escape |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
24 |
from logilab.common.deprecation import class_deprecated, class_renamed |
0 | 25 |
|
6490
34359fbde6ef
[components] add missing imports for code copied/pasted. Forgot to run pylint afterward...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
26 |
from cubicweb import Unauthorized, role as get_role |
2710
40789c3044f3
[web.box] remove deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
27 |
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
|
28 |
from cubicweb.selectors import no_cnx, 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
|
29 |
from cubicweb.view import View |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5927
diff
changeset
|
30 |
from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs |
0 | 31 |
from cubicweb.web.htmlwidgets import (BoxLink, BoxWidget, SideBoxWidget, |
250
7fd7a0d387d7
new RelatedEntityBoxTemplate base class
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
237
diff
changeset
|
32 |
RawBoxItem, BoxSeparator) |
0 | 33 |
from cubicweb.web.action import UnregisteredAction |
34 |
||
35 |
||
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
36 |
def sort_by_category(actions, categories_in_order=None): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
37 |
"""return a list of (category, actions_sorted_by_title)""" |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
38 |
result = [] |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
39 |
actions_by_cat = {} |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
40 |
for action in actions: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
41 |
actions_by_cat.setdefault(action.category, []).append( |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
42 |
(action.title, action) ) |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
43 |
for key, values in actions_by_cat.items(): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
44 |
actions_by_cat[key] = [act for title, act in sorted(values)] |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
45 |
if categories_in_order: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
46 |
for cat in categories_in_order: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
47 |
if cat in actions_by_cat: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
48 |
result.append( (cat, actions_by_cat[cat]) ) |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
49 |
for item in sorted(actions_by_cat.items()): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
50 |
result.append(item) |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
51 |
return result |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
52 |
|
1493 | 53 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
54 |
# old box system, deprecated ################################################### |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
55 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
56 |
class BoxTemplate(View): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
57 |
"""base template for boxes, usually a (contextual) list of possible |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
58 |
actions. Various classes attributes may be used to control the box |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
59 |
rendering. |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
60 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
61 |
You may override one of the formatting callbacks if this is not necessary |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
62 |
for your custom box. |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
63 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
64 |
Classes inheriting from this class usually only have to override call |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
65 |
to fetch desired actions, and then to do something like :: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
66 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
67 |
box.render(self.w) |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
68 |
""" |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
69 |
__metaclass__ = class_deprecated |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
70 |
__deprecation_warning__ = '[3.10] *BoxTemplate classes are deprecated, use *CtxComponent instead (%(cls)s)' |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
71 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
72 |
__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
|
73 |
__select__ = ~no_cnx() |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
74 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
75 |
categories_in_order = () |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
76 |
cw_property_defs = { |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
77 |
_('visible'): dict(type='Boolean', default=True, |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
78 |
help=_('display the box or not')), |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
79 |
_('order'): dict(type='Int', default=99, |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
80 |
help=_('display order of the box')), |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
81 |
# XXX 'incontext' boxes are handled by the default primary view |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
82 |
_('context'): dict(type='String', default='left', |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
83 |
vocabulary=(_('left'), _('incontext'), _('right')), |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
84 |
help=_('context where this box should be displayed')), |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
85 |
} |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
86 |
context = 'left' |
0 | 87 |
|
88 |
def sort_actions(self, actions): |
|
89 |
"""return a list of (category, actions_sorted_by_title)""" |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
90 |
return sort_by_category(actions, self.categories_in_order) |
0 | 91 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
92 |
def mk_action(self, title, url, escape=True, **kwargs): |
0 | 93 |
"""factory function to create dummy actions compatible with the |
94 |
.format_actions method |
|
95 |
""" |
|
96 |
if escape: |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2159
diff
changeset
|
97 |
title = xml_escape(title) |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
98 |
return self.box_action(self._action(title, url, **kwargs)) |
1493 | 99 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
100 |
def _action(self, title, url, **kwargs): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
101 |
return UnregisteredAction(self._cw, title, url, **kwargs) |
0 | 102 |
|
103 |
# formating callbacks |
|
104 |
||
105 |
def boxitem_link_tooltip(self, action): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
106 |
if action.__regid__: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
107 |
return u'keyword: %s' % action.__regid__ |
0 | 108 |
return u'' |
109 |
||
110 |
def box_action(self, action): |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
111 |
klass = getattr(action, 'html_class', lambda: None)() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
112 |
return BoxLink(action.url(), self._cw._(action.title), |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
113 |
klass, self.boxitem_link_tooltip(action)) |
1493 | 114 |
|
0 | 115 |
|
116 |
class RQLBoxTemplate(BoxTemplate): |
|
117 |
"""abstract box for boxes displaying the content of a rql query not |
|
118 |
related to the current result set. |
|
119 |
""" |
|
120 |
||
121 |
rql = None |
|
1493 | 122 |
|
0 | 123 |
def to_display_rql(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
124 |
assert self.rql is not None, self.__regid__ |
0 | 125 |
return (self.rql,) |
1493 | 126 |
|
0 | 127 |
def call(self, **kwargs): |
128 |
try: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
129 |
rset = self._cw.execute(*self.to_display_rql()) |
0 | 130 |
except Unauthorized: |
131 |
# can't access to something in the query, forget this box |
|
132 |
return |
|
133 |
if len(rset) == 0: |
|
134 |
return |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
135 |
box = BoxWidget(self._cw._(self.title), self.__regid__) |
0 | 136 |
for i, (teid, tname) in enumerate(rset): |
137 |
entity = rset.get_entity(i, 0) |
|
138 |
box.append(self.mk_action(tname, entity.absolute_url())) |
|
139 |
box.render(w=self.w) |
|
140 |
||
1493 | 141 |
|
0 | 142 |
class UserRQLBoxTemplate(RQLBoxTemplate): |
143 |
"""same as rql box template but the rql is build using the eid of the |
|
144 |
request's user |
|
145 |
""" |
|
146 |
||
147 |
def to_display_rql(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
148 |
assert self.rql is not None, self.__regid__ |
5979
561b6c2eb288
[web] eid key is deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5952
diff
changeset
|
149 |
return (self.rql, {'x': self._cw.user.eid}) |
1493 | 150 |
|
0 | 151 |
|
152 |
class EntityBoxTemplate(BoxTemplate): |
|
153 |
"""base class for boxes related to a single entity""" |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
154 |
__select__ = BoxTemplate.__select__ & one_line_rset() |
0 | 155 |
context = 'incontext' |
1493 | 156 |
|
0 | 157 |
def call(self, row=0, col=0, **kwargs): |
526 | 158 |
"""classes inheriting from EntityBoxTemplate should define cell_call""" |
0 | 159 |
self.cell_call(row, col, **kwargs) |
160 |
||
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
161 |
from cubicweb.web.component import AjaxEditRelationCtxComponent, EditRelationMixIn |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
162 |
|
0 | 163 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
164 |
class EditRelationBoxTemplate(EditRelationMixIn, EntityBoxTemplate): |
0 | 165 |
"""base class for boxes which let add or remove entities linked |
166 |
by a given relation |
|
167 |
||
168 |
subclasses should define at least id, rtype and target |
|
169 |
class attributes. |
|
170 |
""" |
|
1493 | 171 |
|
1624
baf484a182cd
should take arbitrary arguments
sylvain.thenault@logilab.fr
parents:
1493
diff
changeset
|
172 |
def cell_call(self, row, col, view=None, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
173 |
self._cw.add_js('cubicweb.ajax.js') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
174 |
entity = self.cw_rset.get_entity(row, col) |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
175 |
title = display_name(self._cw, self.rtype, get_role(self), |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
176 |
context=entity.__regid__) |
6017
5f6a60ea8544
[relations in ui] provide context information when computing label for a relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5979
diff
changeset
|
177 |
box = SideBoxWidget(title, self.__regid__) |
2757
c8e28e1754f0
B [web.box] fix EditRelationBoxTemplate in case neither related nor unrelated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2710
diff
changeset
|
178 |
related = self.related_boxitems(entity) |
c8e28e1754f0
B [web.box] fix EditRelationBoxTemplate in case neither related nor unrelated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2710
diff
changeset
|
179 |
unrelated = self.unrelated_boxitems(entity) |
c8e28e1754f0
B [web.box] fix EditRelationBoxTemplate in case neither related nor unrelated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2710
diff
changeset
|
180 |
box.extend(related) |
c8e28e1754f0
B [web.box] fix EditRelationBoxTemplate in case neither related nor unrelated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2710
diff
changeset
|
181 |
if related and unrelated: |
0 | 182 |
box.append(BoxSeparator()) |
2757
c8e28e1754f0
B [web.box] fix EditRelationBoxTemplate in case neither related nor unrelated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2710
diff
changeset
|
183 |
box.extend(unrelated) |
0 | 184 |
box.render(self.w) |
185 |
||
186 |
def box_item(self, entity, etarget, rql, label): |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
187 |
label = super(EditRelationBoxTemplate, self).box_item( |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
188 |
entity, etarget, rql, label) |
0 | 189 |
return RawBoxItem(label, liclass=u'invisible') |
1493 | 190 |
|
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5927
diff
changeset
|
191 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
192 |
AjaxEditRelationBoxTemplate = class_renamed( |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
193 |
'AjaxEditRelationBoxTemplate', AjaxEditRelationCtxComponent, |
6499
c4123c741c66
[deprecation] enhanced messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6490
diff
changeset
|
194 |
'[3.10] AjaxEditRelationBoxTemplate has been renamed to AjaxEditRelationCtxComponent (%(cls)s)') |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5927
diff
changeset
|
195 |