author | sylvain.thenault@logilab.fr |
Mon, 11 May 2009 17:01:34 +0200 | |
branch | tls-sprint |
changeset 1730 | cec526a96535 |
parent 1726 | 08918409815e |
child 1732 | e812ba9499ac |
permissions | -rw-r--r-- |
0 | 1 |
""" |
2 |
generic boxes for CubicWeb web client: |
|
3 |
||
4 |
* actions box |
|
5 |
* possible views box |
|
6 |
||
7 |
additional (disabled by default) boxes |
|
8 |
* schema box |
|
9 |
* startup views box |
|
10 |
||
11 |
:organization: Logilab |
|
612 | 12 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 13 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
14 |
""" |
|
15 |
__docformat__ = "restructuredtext en" |
|
16 |
||
17 |
from logilab.mtconverter import html_escape |
|
18 |
||
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
19 |
from cubicweb.rtags import RelationTags |
1132 | 20 |
from cubicweb.selectors import match_user_groups, non_final_entity |
0 | 21 |
from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, BoxHtml, RawBoxItem |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
22 |
from cubicweb.view import EntityView |
1285
d5ce82d65c2b
for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
23 |
from cubicweb.web import uicfg |
663 | 24 |
from cubicweb.web.box import BoxTemplate |
0 | 25 |
|
26 |
_ = unicode |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
27 |
|
0 | 28 |
class EditBox(BoxTemplate): |
29 |
""" |
|
30 |
box with all actions impacting the entity displayed: edit, copy, delete |
|
31 |
change state, add related entities |
|
32 |
""" |
|
33 |
id = 'edit_box' |
|
809 | 34 |
__select__ = BoxTemplate.__select__ & non_final_entity() |
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
35 |
|
0 | 36 |
title = _('actions') |
37 |
order = 2 |
|
1285
d5ce82d65c2b
for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
38 |
# class attributes below are actually stored in the uicfg module since we |
d5ce82d65c2b
for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
39 |
# don't want them to be reloaded |
d5ce82d65c2b
for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
40 |
rmode = uicfg.rmode |
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
41 |
|
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
42 |
@classmethod |
1285
d5ce82d65c2b
for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
43 |
def vreg_initialization_completed(cls): |
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
44 |
"""set default category tags for relations where it's not yet defined in |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
45 |
the category relation tags |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
46 |
""" |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
47 |
for eschema in cls.schema.entities(): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
48 |
for rschema, tschemas, role in eschema.relation_definitions(True): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
49 |
for tschema in tschemas: |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
50 |
if role == 'subject': |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
51 |
X, Y = eschema, tschema |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
52 |
card = rschema.rproperty(X, Y, 'cardinality')[0] |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
53 |
else: |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
54 |
X, Y = tschema, eschema |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
55 |
card = rschema.rproperty(X, Y, 'cardinality')[1] |
1726
08918409815e
[rtags] .get api change
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1721
diff
changeset
|
56 |
if not cls.rmode.get(X, rschema, Y, role): |
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
57 |
if card in '?1': |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
58 |
# by default, suppose link mode if cardinality doesn't allow |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
59 |
# more than one relation |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
60 |
mode = 'link' |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
61 |
elif rschema.rproperty(X, Y, 'composite') == role: |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
62 |
# if self is composed of the target type, create mode |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
63 |
mode = 'create' |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
64 |
else: |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
65 |
# link mode by default |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
66 |
mode = 'link' |
1721
694f6a50e138
final rtags api (eventually :$)
sylvain.thenault@logilab.fr
parents:
1672
diff
changeset
|
67 |
cls.rmode.tag_relation(X, rschema, Y, mode, tagged=role) |
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
68 |
|
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
69 |
@classmethod |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
70 |
def relation_mode(cls, rtype, etype, targettype, role='subject'): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
71 |
"""return a string telling if the given relation is usually created |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
72 |
to a new entity ('create' mode) or to an existant entity ('link' mode) |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
73 |
""" |
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
74 |
if role == 'subject': |
1540
996355824825
more rtags api change propagation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1539
diff
changeset
|
75 |
return cls.rmode.get(rtype, role, etype, targettype) |
996355824825
more rtags api change propagation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1539
diff
changeset
|
76 |
return cls.rmode.get(rtype, role, targettype, etype) |
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
77 |
|
0 | 78 |
|
1247
3332c92d950c
give view when selecting actions
sylvain.thenault@logilab.fr
parents:
1242
diff
changeset
|
79 |
def call(self, view=None, **kwargs): |
0 | 80 |
_ = self.req._ |
81 |
title = _(self.title) |
|
82 |
if self.rset: |
|
83 |
etypes = self.rset.column_types(0) |
|
84 |
if len(etypes) == 1: |
|
85 |
plural = self.rset.rowcount > 1 and 'plural' or '' |
|
86 |
etypelabel = display_name(self.req, iter(etypes).next(), plural) |
|
87 |
title = u'%s - %s' % (title, etypelabel.lower()) |
|
88 |
box = BoxWidget(title, self.id, _class="greyBoxFrame") |
|
89 |
# build list of actions |
|
1247
3332c92d950c
give view when selecting actions
sylvain.thenault@logilab.fr
parents:
1242
diff
changeset
|
90 |
actions = self.vreg.possible_actions(self.req, self.rset, view=view) |
0 | 91 |
add_menu = BoxMenu(_('add')) # 'addrelated' category |
92 |
other_menu = BoxMenu(_('more actions')) # 'moreactions' category |
|
93 |
searchstate = self.req.search_state[0] |
|
94 |
for category, menu in (('mainactions', box), |
|
95 |
('addrelated', add_menu), |
|
96 |
('moreactions', other_menu)): |
|
97 |
for action in actions.get(category, ()): |
|
98 |
menu.append(self.box_action(action)) |
|
99 |
if self.rset and self.rset.rowcount == 1 and \ |
|
100 |
not self.schema[self.rset.description[0][0]].is_final() and \ |
|
101 |
searchstate == 'normal': |
|
102 |
entity = self.rset.get_entity(0, 0) |
|
103 |
#entity.complete() |
|
104 |
if add_menu.items: |
|
105 |
self.info('explicit actions defined, ignoring potential rtags for %s', |
|
106 |
entity.e_schema) |
|
107 |
else: |
|
108 |
# some addrelated actions may be specified but no one is selectable |
|
109 |
# in which case we should not fallback to schema_actions. The proper |
|
110 |
# way to avoid this is to override add_related_schemas() on the |
|
111 |
# entity class to return an empty list |
|
112 |
for action in self.schema_actions(entity): |
|
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
113 |
add_menu.append(action) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
114 |
self.workflow_actions(entity, box) |
0 | 115 |
if box.is_empty() and not other_menu.is_empty(): |
116 |
box.items = other_menu.items |
|
117 |
other_menu.items = [] |
|
118 |
self.add_submenu(box, add_menu, _('add')) |
|
119 |
self.add_submenu(box, other_menu) |
|
120 |
if not box.is_empty(): |
|
121 |
box.render(self.w) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
122 |
|
0 | 123 |
def add_submenu(self, box, submenu, label_prefix=None): |
124 |
if len(submenu.items) == 1: |
|
125 |
boxlink = submenu.items[0] |
|
126 |
if label_prefix: |
|
127 |
boxlink.label = u'%s %s' % (label_prefix, boxlink.label) |
|
128 |
box.append(boxlink) |
|
129 |
elif submenu.items: |
|
130 |
box.append(submenu) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
131 |
|
0 | 132 |
def schema_actions(self, entity): |
133 |
user = self.req.user |
|
134 |
actions = [] |
|
135 |
_ = self.req._ |
|
136 |
eschema = entity.e_schema |
|
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
137 |
for rschema, teschema, x in self.add_related_schemas(entity): |
0 | 138 |
if x == 'subject': |
1672
2406667c90d6
'add' is already added before
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1540
diff
changeset
|
139 |
label = '%s %s %s %s' % (eschema, rschema, teschema, x) |
0 | 140 |
url = self.linkto_url(entity, rschema, teschema, 'object') |
141 |
else: |
|
1672
2406667c90d6
'add' is already added before
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1540
diff
changeset
|
142 |
label = '%s %s %s %s' % (teschema, rschema, eschema, x) |
0 | 143 |
url = self.linkto_url(entity, rschema, teschema, 'subject') |
144 |
actions.append(self.mk_action(_(label), url)) |
|
145 |
return actions |
|
146 |
||
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
147 |
def add_related_schemas(self, entity): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
148 |
"""this is actually used ui method to generate 'addrelated' actions from |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
149 |
the schema. |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
150 |
|
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
151 |
If you're using explicit 'addrelated' actions for an entity types, you |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
152 |
should probably overrides this method to return an empty list else you |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
153 |
may get some unexpected actions. |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
154 |
""" |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
155 |
req = self.req |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
156 |
eschema = entity.e_schema |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
157 |
for role, rschemas in (('subject', eschema.subject_relations()), |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
158 |
('object', eschema.object_relations())): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
159 |
for rschema in rschemas: |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
160 |
if rschema.is_final(): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
161 |
continue |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
162 |
# check the relation can be added as well |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
163 |
if role == 'subject'and not rschema.has_perm(req, 'add', fromeid=entity.eid): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
164 |
continue |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
165 |
if role == 'object'and not rschema.has_perm(req, 'add', toeid=entity.eid): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
166 |
continue |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
167 |
# check the target types can be added as well |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
168 |
for teschema in rschema.targets(eschema, role): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
169 |
if not self.relation_mode(rschema, eschema, teschema, role) == 'create': |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
170 |
continue |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
171 |
if teschema.has_local_role('add') or teschema.has_perm(req, 'add'): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
172 |
yield rschema, teschema, role |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
173 |
|
0 | 174 |
|
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
175 |
def workflow_actions(self, entity, box): |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
176 |
if 'in_state' in entity.e_schema.subject_relations() and entity.in_state: |
399 | 177 |
_ = self.req._ |
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
178 |
state = entity.in_state[0] |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
179 |
transitions = list(state.transitions(entity)) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
180 |
if transitions: |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
181 |
menu_title = u'%s: %s' % (_('state'), state.view('text')) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
182 |
menu_items = [] |
1113
5608c79c789b
[boxes] that looked like a redundant call (needs review)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
859
diff
changeset
|
183 |
for tr in transitions: |
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
184 |
url = entity.absolute_url(vid='statuschange', treid=tr.eid) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
185 |
menu_items.append(self.mk_action(_(tr.name), url)) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
186 |
box.append(BoxMenu(menu_title, menu_items)) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
187 |
# when there are no possible transition, put state if the menu if |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
188 |
# there are some other actions |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
189 |
elif not box.is_empty(): |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
190 |
menu_title = u'<a title="%s">%s: <i>%s</i></a>' % ( |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
191 |
_('no possible transition'), _('state'), state.view('text')) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
192 |
box.append(RawBoxItem(menu_title, 'boxMainactions')) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
193 |
return None |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
194 |
|
0 | 195 |
def linkto_url(self, entity, rtype, etype, target): |
196 |
return self.build_url(vid='creation', etype=etype, |
|
197 |
__linkto='%s:%s:%s' % (rtype, entity.eid, target), |
|
198 |
__redirectpath=entity.rest_path(), # should not be url quoted! |
|
199 |
__redirectvid=self.req.form.get('vid', '')) |
|
200 |
||
201 |
||
202 |
class SearchBox(BoxTemplate): |
|
203 |
"""display a box with a simple search form""" |
|
204 |
id = 'search_box' |
|
809 | 205 |
|
0 | 206 |
visible = True # enabled by default |
207 |
title = _('search') |
|
208 |
order = 0 |
|
209 |
formdef = u"""<form action="%s"> |
|
210 |
<table id="tsearch"><tr><td> |
|
211 |
<input id="norql" type="text" accesskey="q" tabindex="%s" title="search text" value="%s" name="rql" /> |
|
212 |
<input type="hidden" name="__fromsearchbox" value="1" /> |
|
213 |
<input type="hidden" name="subvid" value="tsearch" /> |
|
214 |
</td><td> |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
536
diff
changeset
|
215 |
<input tabindex="%s" type="submit" id="rqlboxsubmit" class="rqlsubmit" value="" /> |
0 | 216 |
</td></tr></table> |
217 |
</form>""" |
|
218 |
||
219 |
def call(self, view=None, **kwargs): |
|
220 |
req = self.req |
|
221 |
if req.form.pop('__fromsearchbox', None): |
|
222 |
rql = req.form.get('rql', '') |
|
223 |
else: |
|
224 |
rql = '' |
|
225 |
form = self.formdef % (req.build_url('view'), req.next_tabindex(), |
|
226 |
html_escape(rql), req.next_tabindex()) |
|
227 |
title = u"""<span onclick="javascript: toggleVisibility('rqlinput')">%s</span>""" % req._(self.title) |
|
228 |
box = BoxWidget(title, self.id, _class="searchBoxFrame", islist=False, escape=False) |
|
229 |
box.append(BoxHtml(form)) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
230 |
box.render(self.w) |
0 | 231 |
|
232 |
||
233 |
# boxes disabled by default ################################################### |
|
234 |
||
235 |
class PossibleViewsBox(BoxTemplate): |
|
236 |
"""display a box containing links to all possible views""" |
|
237 |
id = 'possible_views_box' |
|
809 | 238 |
__select__ = BoxTemplate.__select__ & match_user_groups('users', 'managers') |
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
239 |
|
809 | 240 |
visible = False |
0 | 241 |
title = _('possible views') |
242 |
order = 10 |
|
243 |
||
244 |
def call(self, **kwargs): |
|
245 |
box = BoxWidget(self.req._(self.title), self.id) |
|
613 | 246 |
views = [v for v in self.vreg.possible_views(self.req, self.rset) |
247 |
if v.category != 'startupview'] |
|
248 |
for category, views in self.sort_actions(views): |
|
0 | 249 |
menu = BoxMenu(category) |
613 | 250 |
for view in views: |
251 |
menu.append(self.box_action(view)) |
|
0 | 252 |
box.append(menu) |
253 |
if not box.is_empty(): |
|
254 |
box.render(self.w) |
|
255 |
||
125
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
107
diff
changeset
|
256 |
|
0 | 257 |
class StartupViewsBox(BoxTemplate): |
258 |
"""display a box containing links to all startup views""" |
|
259 |
id = 'startup_views_box' |
|
260 |
visible = False # disabled by default |
|
261 |
title = _('startup views') |
|
262 |
order = 70 |
|
263 |
||
264 |
def call(self, **kwargs): |
|
265 |
box = BoxWidget(self.req._(self.title), self.id) |
|
266 |
for view in self.vreg.possible_views(self.req, None): |
|
267 |
if view.category == 'startupview': |
|
268 |
box.append(self.box_action(view)) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
269 |
|
0 | 270 |
if not box.is_empty(): |
271 |
box.render(self.w) |
|
272 |
||
1263 | 273 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
274 |
# helper classes ############################################################## |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
275 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
276 |
class SideBoxView(EntityView): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
277 |
"""helper view class to display some entities in a sidebox""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
278 |
id = 'sidebox' |
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
279 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
280 |
def call(self, boxclass='sideBox', title=u''): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
281 |
"""display a list of entities by calling their <item_vid> view""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
282 |
if title: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
283 |
self.w(u'<div class="sideBoxTitle"><span>%s</span></div>' % title) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
284 |
self.w(u'<div class="%s"><div class="sideBoxBody">' % boxclass) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
285 |
# if not too much entities, show them all in a list |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
286 |
maxrelated = self.req.property_value('navigation.related-limit') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
287 |
if self.rset.rowcount <= maxrelated: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
288 |
if len(self.rset) == 1: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
289 |
self.wview('incontext', self.rset, row=0) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
290 |
elif 1 < len(self.rset) < 5: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
291 |
self.wview('csv', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
292 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
293 |
self.wview('simplelist', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
294 |
# else show links to display related entities |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
295 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
296 |
self.rset.limit(maxrelated) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
297 |
rql = self.rset.printable_rql(encoded=False) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
298 |
self.wview('simplelist', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
299 |
self.w(u'[<a href="%s">%s</a>]' % (self.build_url(rql=rql), |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
300 |
self.req._('see them all'))) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
301 |
self.w(u'</div>\n</div>\n') |