author | sylvain.thenault@logilab.fr |
Wed, 15 Apr 2009 17:30:03 +0200 | |
branch | tls-sprint |
changeset 1373 | 5e6abf61636d |
parent 1285 | d5ce82d65c2b |
child 1450 | 8edb0806dde4 |
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 |
|
1214
25480a710422
removing any_rset selector to enable 'download schema owl action' to layout
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
1113
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 |
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
|
41 |
|
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] |
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1151
diff
changeset
|
56 |
if not cls.rmode.rtag(rschema, role, X, Y): |
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' |
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1151
diff
changeset
|
67 |
cls.rmode.set_rtag(mode, rschema, role, X, Y) |
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 |
""" |
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1151
diff
changeset
|
74 |
return cls.rmode.rtag(rtype, role, etype, targettype) |
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
|
75 |
|
0 | 76 |
|
1247
3332c92d950c
give view when selecting actions
sylvain.thenault@logilab.fr
parents:
1242
diff
changeset
|
77 |
def call(self, view=None, **kwargs): |
0 | 78 |
_ = self.req._ |
79 |
title = _(self.title) |
|
80 |
if self.rset: |
|
81 |
etypes = self.rset.column_types(0) |
|
82 |
if len(etypes) == 1: |
|
83 |
plural = self.rset.rowcount > 1 and 'plural' or '' |
|
84 |
etypelabel = display_name(self.req, iter(etypes).next(), plural) |
|
85 |
title = u'%s - %s' % (title, etypelabel.lower()) |
|
86 |
box = BoxWidget(title, self.id, _class="greyBoxFrame") |
|
87 |
# build list of actions |
|
1247
3332c92d950c
give view when selecting actions
sylvain.thenault@logilab.fr
parents:
1242
diff
changeset
|
88 |
actions = self.vreg.possible_actions(self.req, self.rset, view=view) |
0 | 89 |
add_menu = BoxMenu(_('add')) # 'addrelated' category |
90 |
other_menu = BoxMenu(_('more actions')) # 'moreactions' category |
|
91 |
searchstate = self.req.search_state[0] |
|
92 |
for category, menu in (('mainactions', box), |
|
93 |
('addrelated', add_menu), |
|
94 |
('moreactions', other_menu)): |
|
95 |
for action in actions.get(category, ()): |
|
96 |
menu.append(self.box_action(action)) |
|
97 |
if self.rset and self.rset.rowcount == 1 and \ |
|
98 |
not self.schema[self.rset.description[0][0]].is_final() and \ |
|
99 |
searchstate == 'normal': |
|
100 |
entity = self.rset.get_entity(0, 0) |
|
101 |
#entity.complete() |
|
102 |
if add_menu.items: |
|
103 |
self.info('explicit actions defined, ignoring potential rtags for %s', |
|
104 |
entity.e_schema) |
|
105 |
else: |
|
106 |
# some addrelated actions may be specified but no one is selectable |
|
107 |
# in which case we should not fallback to schema_actions. The proper |
|
108 |
# way to avoid this is to override add_related_schemas() on the |
|
109 |
# entity class to return an empty list |
|
110 |
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
|
111 |
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
|
112 |
self.workflow_actions(entity, box) |
0 | 113 |
if box.is_empty() and not other_menu.is_empty(): |
114 |
box.items = other_menu.items |
|
115 |
other_menu.items = [] |
|
116 |
self.add_submenu(box, add_menu, _('add')) |
|
117 |
self.add_submenu(box, other_menu) |
|
118 |
if not box.is_empty(): |
|
119 |
box.render(self.w) |
|
1214
25480a710422
removing any_rset selector to enable 'download schema owl action' to layout
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
1113
diff
changeset
|
120 |
|
0 | 121 |
def add_submenu(self, box, submenu, label_prefix=None): |
122 |
if len(submenu.items) == 1: |
|
123 |
boxlink = submenu.items[0] |
|
124 |
if label_prefix: |
|
125 |
boxlink.label = u'%s %s' % (label_prefix, boxlink.label) |
|
126 |
box.append(boxlink) |
|
127 |
elif submenu.items: |
|
128 |
box.append(submenu) |
|
129 |
||
130 |
def schema_actions(self, entity): |
|
131 |
user = self.req.user |
|
132 |
actions = [] |
|
133 |
_ = self.req._ |
|
134 |
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
|
135 |
for rschema, teschema, x in self.add_related_schemas(entity): |
0 | 136 |
if x == 'subject': |
137 |
label = 'add %s %s %s %s' % (eschema, rschema, teschema, x) |
|
138 |
url = self.linkto_url(entity, rschema, teschema, 'object') |
|
139 |
else: |
|
140 |
label = 'add %s %s %s %s' % (teschema, rschema, eschema, x) |
|
141 |
url = self.linkto_url(entity, rschema, teschema, 'subject') |
|
142 |
actions.append(self.mk_action(_(label), url)) |
|
143 |
return actions |
|
144 |
||
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
|
145 |
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
|
146 |
"""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
|
147 |
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
|
148 |
|
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 |
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
|
150 |
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
|
151 |
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
|
152 |
""" |
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 |
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
|
154 |
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
|
155 |
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
|
156 |
('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
|
157 |
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
|
158 |
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
|
159 |
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
|
160 |
# 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
|
161 |
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
|
162 |
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
|
163 |
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
|
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 |
# 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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
|
0 | 172 |
|
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
173 |
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
|
174 |
if 'in_state' in entity.e_schema.subject_relations() and entity.in_state: |
399 | 175 |
_ = self.req._ |
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
176 |
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
|
177 |
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
|
178 |
if transitions: |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
179 |
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
|
180 |
menu_items = [] |
1113
5608c79c789b
[boxes] that looked like a redundant call (needs review)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
859
diff
changeset
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
# 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
|
186 |
# 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
|
187 |
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
|
188 |
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
|
189 |
_('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
|
190 |
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
|
191 |
return None |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
192 |
|
0 | 193 |
def linkto_url(self, entity, rtype, etype, target): |
194 |
return self.build_url(vid='creation', etype=etype, |
|
195 |
__linkto='%s:%s:%s' % (rtype, entity.eid, target), |
|
196 |
__redirectpath=entity.rest_path(), # should not be url quoted! |
|
197 |
__redirectvid=self.req.form.get('vid', '')) |
|
198 |
||
199 |
||
200 |
class SearchBox(BoxTemplate): |
|
201 |
"""display a box with a simple search form""" |
|
202 |
id = 'search_box' |
|
809 | 203 |
|
0 | 204 |
visible = True # enabled by default |
205 |
title = _('search') |
|
206 |
order = 0 |
|
207 |
formdef = u"""<form action="%s"> |
|
208 |
<table id="tsearch"><tr><td> |
|
209 |
<input id="norql" type="text" accesskey="q" tabindex="%s" title="search text" value="%s" name="rql" /> |
|
210 |
<input type="hidden" name="__fromsearchbox" value="1" /> |
|
211 |
<input type="hidden" name="subvid" value="tsearch" /> |
|
212 |
</td><td> |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
536
diff
changeset
|
213 |
<input tabindex="%s" type="submit" id="rqlboxsubmit" class="rqlsubmit" value="" /> |
0 | 214 |
</td></tr></table> |
215 |
</form>""" |
|
216 |
||
217 |
def call(self, view=None, **kwargs): |
|
218 |
req = self.req |
|
219 |
if req.form.pop('__fromsearchbox', None): |
|
220 |
rql = req.form.get('rql', '') |
|
221 |
else: |
|
222 |
rql = '' |
|
223 |
form = self.formdef % (req.build_url('view'), req.next_tabindex(), |
|
224 |
html_escape(rql), req.next_tabindex()) |
|
225 |
title = u"""<span onclick="javascript: toggleVisibility('rqlinput')">%s</span>""" % req._(self.title) |
|
226 |
box = BoxWidget(title, self.id, _class="searchBoxFrame", islist=False, escape=False) |
|
227 |
box.append(BoxHtml(form)) |
|
228 |
box.render(self.w) |
|
229 |
||
230 |
||
231 |
# boxes disabled by default ################################################### |
|
232 |
||
233 |
class PossibleViewsBox(BoxTemplate): |
|
234 |
"""display a box containing links to all possible views""" |
|
235 |
id = 'possible_views_box' |
|
809 | 236 |
__select__ = BoxTemplate.__select__ & match_user_groups('users', 'managers') |
0 | 237 |
|
809 | 238 |
visible = False |
0 | 239 |
title = _('possible views') |
240 |
order = 10 |
|
241 |
||
242 |
def call(self, **kwargs): |
|
243 |
box = BoxWidget(self.req._(self.title), self.id) |
|
613 | 244 |
views = [v for v in self.vreg.possible_views(self.req, self.rset) |
245 |
if v.category != 'startupview'] |
|
246 |
for category, views in self.sort_actions(views): |
|
0 | 247 |
menu = BoxMenu(category) |
613 | 248 |
for view in views: |
249 |
menu.append(self.box_action(view)) |
|
0 | 250 |
box.append(menu) |
251 |
if not box.is_empty(): |
|
252 |
box.render(self.w) |
|
253 |
||
125
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
107
diff
changeset
|
254 |
|
0 | 255 |
class StartupViewsBox(BoxTemplate): |
256 |
"""display a box containing links to all startup views""" |
|
257 |
id = 'startup_views_box' |
|
258 |
visible = False # disabled by default |
|
259 |
title = _('startup views') |
|
260 |
order = 70 |
|
261 |
||
262 |
def call(self, **kwargs): |
|
263 |
box = BoxWidget(self.req._(self.title), self.id) |
|
264 |
for view in self.vreg.possible_views(self.req, None): |
|
265 |
if view.category == 'startupview': |
|
266 |
box.append(self.box_action(view)) |
|
267 |
||
268 |
if not box.is_empty(): |
|
269 |
box.render(self.w) |
|
270 |
||
1263 | 271 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
272 |
# helper classes ############################################################## |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
273 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
274 |
class SideBoxView(EntityView): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
275 |
"""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
|
276 |
id = 'sidebox' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
277 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
278 |
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
|
279 |
"""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
|
280 |
if title: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
281 |
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
|
282 |
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
|
283 |
# 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
|
284 |
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
|
285 |
if self.rset.rowcount <= maxrelated: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
286 |
if len(self.rset) == 1: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
287 |
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
|
288 |
elif 1 < len(self.rset) < 5: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
289 |
self.wview('csv', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
290 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
291 |
self.wview('simplelist', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
292 |
# 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
|
293 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
294 |
self.rset.limit(maxrelated) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
295 |
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
|
296 |
self.wview('simplelist', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
297 |
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
|
298 |
self.req._('see them all'))) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
299 |
self.w(u'</div>\n</div>\n') |