author | sylvain.thenault@logilab.fr |
Fri, 27 Mar 2009 12:31:42 +0100 | |
branch | tls-sprint |
changeset 1181 | 620ec8e6ae19 |
parent 1151 | b20677336ee6 |
child 1263 | 01152fffd593 |
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 |
663 | 23 |
from cubicweb.web.box import BoxTemplate |
0 | 24 |
|
25 |
_ = unicode |
|
26 |
||
27 |
||
28 |
class EditBox(BoxTemplate): |
|
29 |
""" |
|
30 |
box with all actions impacting the entity displayed: edit, copy, delete |
|
31 |
change state, add related entities |
|
32 |
""" |
|
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
|
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 |
|
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
|
38 |
# 'link' / 'create' relation tags, used to control the "add entity" submenu |
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
|
39 |
rmode = RelationTags() |
1151
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
40 |
rmode.set_rtag('link', 'is', 'subject') |
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
41 |
rmode.set_rtag('link', 'is', 'object') |
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
42 |
rmode.set_rtag('link', 'is_instance_of', 'subject') |
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
43 |
rmode.set_rtag('link', 'is_instance_of', 'object') |
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
44 |
rmode.set_rtag('link', 'identity', 'subject') |
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
45 |
rmode.set_rtag('link', 'identity', 'object') |
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
46 |
rmode.set_rtag('link', 'owned_by', 'subject') |
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
47 |
rmode.set_rtag('link', 'created_by', 'subject') |
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
48 |
rmode.set_rtag('link', 'require_permission', 'subject') |
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
49 |
rmode.set_rtag('link', 'wf_info_for', 'subject') |
b20677336ee6
turn old __rtags__ the new way
sylvain.thenault@logilab.fr
parents:
1150
diff
changeset
|
50 |
rmode.set_rtag('link', 'wf_info_for', 'subject') |
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
|
51 |
|
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 |
@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
|
53 |
def registered(cls, registry): |
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 |
"""build class using descriptor at registration time""" |
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1151
diff
changeset
|
55 |
super(EditBox, cls).registered(registry) |
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
|
56 |
cls.init_rtags_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
|
57 |
return cls |
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 |
|
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 |
@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
|
60 |
def init_rtags_mode(cls): |
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 |
"""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
|
62 |
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
|
63 |
""" |
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 |
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
|
65 |
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
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
card = rschema.rproperty(X, Y, 'cardinality')[1] |
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1151
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
# 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
|
76 |
# 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
|
77 |
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
|
78 |
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
|
79 |
# 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
|
80 |
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
|
81 |
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
|
82 |
# 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
|
83 |
mode = 'link' |
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1151
diff
changeset
|
84 |
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
|
85 |
|
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
|
86 |
@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
|
87 |
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
|
88 |
"""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
|
89 |
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
|
90 |
""" |
1181
620ec8e6ae19
cleanup, various fix to get something working
sylvain.thenault@logilab.fr
parents:
1151
diff
changeset
|
91 |
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
|
92 |
|
0 | 93 |
|
94 |
def call(self, **kwargs): |
|
95 |
_ = self.req._ |
|
96 |
title = _(self.title) |
|
97 |
if self.rset: |
|
98 |
etypes = self.rset.column_types(0) |
|
99 |
if len(etypes) == 1: |
|
100 |
plural = self.rset.rowcount > 1 and 'plural' or '' |
|
101 |
etypelabel = display_name(self.req, iter(etypes).next(), plural) |
|
102 |
title = u'%s - %s' % (title, etypelabel.lower()) |
|
103 |
box = BoxWidget(title, self.id, _class="greyBoxFrame") |
|
104 |
# build list of actions |
|
105 |
actions = self.vreg.possible_actions(self.req, self.rset) |
|
106 |
add_menu = BoxMenu(_('add')) # 'addrelated' category |
|
107 |
other_menu = BoxMenu(_('more actions')) # 'moreactions' category |
|
108 |
searchstate = self.req.search_state[0] |
|
109 |
for category, menu in (('mainactions', box), |
|
110 |
('addrelated', add_menu), |
|
111 |
('moreactions', other_menu)): |
|
112 |
for action in actions.get(category, ()): |
|
113 |
menu.append(self.box_action(action)) |
|
114 |
if self.rset and self.rset.rowcount == 1 and \ |
|
115 |
not self.schema[self.rset.description[0][0]].is_final() and \ |
|
116 |
searchstate == 'normal': |
|
117 |
entity = self.rset.get_entity(0, 0) |
|
118 |
#entity.complete() |
|
119 |
if add_menu.items: |
|
120 |
self.info('explicit actions defined, ignoring potential rtags for %s', |
|
121 |
entity.e_schema) |
|
122 |
else: |
|
123 |
# some addrelated actions may be specified but no one is selectable |
|
124 |
# in which case we should not fallback to schema_actions. The proper |
|
125 |
# way to avoid this is to override add_related_schemas() on the |
|
126 |
# entity class to return an empty list |
|
127 |
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
|
128 |
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
|
129 |
self.workflow_actions(entity, box) |
0 | 130 |
if box.is_empty() and not other_menu.is_empty(): |
131 |
box.items = other_menu.items |
|
132 |
other_menu.items = [] |
|
133 |
self.add_submenu(box, add_menu, _('add')) |
|
134 |
self.add_submenu(box, other_menu) |
|
135 |
if not box.is_empty(): |
|
136 |
box.render(self.w) |
|
137 |
||
138 |
def add_submenu(self, box, submenu, label_prefix=None): |
|
139 |
if len(submenu.items) == 1: |
|
140 |
boxlink = submenu.items[0] |
|
141 |
if label_prefix: |
|
142 |
boxlink.label = u'%s %s' % (label_prefix, boxlink.label) |
|
143 |
box.append(boxlink) |
|
144 |
elif submenu.items: |
|
145 |
box.append(submenu) |
|
146 |
||
147 |
def schema_actions(self, entity): |
|
148 |
user = self.req.user |
|
149 |
actions = [] |
|
150 |
_ = self.req._ |
|
151 |
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
|
152 |
for rschema, teschema, x in self.add_related_schemas(entity): |
0 | 153 |
if x == 'subject': |
154 |
label = 'add %s %s %s %s' % (eschema, rschema, teschema, x) |
|
155 |
url = self.linkto_url(entity, rschema, teschema, 'object') |
|
156 |
else: |
|
157 |
label = 'add %s %s %s %s' % (teschema, rschema, eschema, x) |
|
158 |
url = self.linkto_url(entity, rschema, teschema, 'subject') |
|
159 |
actions.append(self.mk_action(_(label), url)) |
|
160 |
return actions |
|
161 |
||
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
|
162 |
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
|
163 |
"""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
|
164 |
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
|
165 |
|
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 |
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
|
167 |
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
|
168 |
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
|
169 |
""" |
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 |
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
|
171 |
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
|
172 |
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
|
173 |
('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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
# 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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
# 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
|
183 |
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
|
184 |
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
|
185 |
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
|
186 |
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
|
187 |
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
|
188 |
|
0 | 189 |
|
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
190 |
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
|
191 |
if 'in_state' in entity.e_schema.subject_relations() and entity.in_state: |
399 | 192 |
_ = self.req._ |
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
193 |
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
|
194 |
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
|
195 |
if transitions: |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
196 |
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
|
197 |
menu_items = [] |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
198 |
for tr in state.transitions(entity): |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
# 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
|
203 |
# 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
|
204 |
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
|
205 |
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
|
206 |
_('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
|
207 |
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
|
208 |
return None |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
209 |
|
0 | 210 |
def linkto_url(self, entity, rtype, etype, target): |
211 |
return self.build_url(vid='creation', etype=etype, |
|
212 |
__linkto='%s:%s:%s' % (rtype, entity.eid, target), |
|
213 |
__redirectpath=entity.rest_path(), # should not be url quoted! |
|
214 |
__redirectvid=self.req.form.get('vid', '')) |
|
215 |
||
216 |
||
217 |
class SearchBox(BoxTemplate): |
|
218 |
"""display a box with a simple search form""" |
|
219 |
id = 'search_box' |
|
809 | 220 |
|
0 | 221 |
visible = True # enabled by default |
222 |
title = _('search') |
|
223 |
order = 0 |
|
224 |
formdef = u"""<form action="%s"> |
|
225 |
<table id="tsearch"><tr><td> |
|
226 |
<input id="norql" type="text" accesskey="q" tabindex="%s" title="search text" value="%s" name="rql" /> |
|
227 |
<input type="hidden" name="__fromsearchbox" value="1" /> |
|
228 |
<input type="hidden" name="subvid" value="tsearch" /> |
|
229 |
</td><td> |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
536
diff
changeset
|
230 |
<input tabindex="%s" type="submit" id="rqlboxsubmit" class="rqlsubmit" value="" /> |
0 | 231 |
</td></tr></table> |
232 |
</form>""" |
|
233 |
||
234 |
def call(self, view=None, **kwargs): |
|
235 |
req = self.req |
|
236 |
if req.form.pop('__fromsearchbox', None): |
|
237 |
rql = req.form.get('rql', '') |
|
238 |
else: |
|
239 |
rql = '' |
|
240 |
form = self.formdef % (req.build_url('view'), req.next_tabindex(), |
|
241 |
html_escape(rql), req.next_tabindex()) |
|
242 |
title = u"""<span onclick="javascript: toggleVisibility('rqlinput')">%s</span>""" % req._(self.title) |
|
243 |
box = BoxWidget(title, self.id, _class="searchBoxFrame", islist=False, escape=False) |
|
244 |
box.append(BoxHtml(form)) |
|
245 |
box.render(self.w) |
|
246 |
||
247 |
||
248 |
# boxes disabled by default ################################################### |
|
249 |
||
250 |
class PossibleViewsBox(BoxTemplate): |
|
251 |
"""display a box containing links to all possible views""" |
|
252 |
id = 'possible_views_box' |
|
809 | 253 |
__select__ = BoxTemplate.__select__ & match_user_groups('users', 'managers') |
0 | 254 |
|
809 | 255 |
visible = False |
0 | 256 |
title = _('possible views') |
257 |
order = 10 |
|
258 |
||
259 |
def call(self, **kwargs): |
|
260 |
box = BoxWidget(self.req._(self.title), self.id) |
|
613 | 261 |
views = [v for v in self.vreg.possible_views(self.req, self.rset) |
262 |
if v.category != 'startupview'] |
|
263 |
for category, views in self.sort_actions(views): |
|
0 | 264 |
menu = BoxMenu(category) |
613 | 265 |
for view in views: |
266 |
menu.append(self.box_action(view)) |
|
0 | 267 |
box.append(menu) |
268 |
if not box.is_empty(): |
|
269 |
box.render(self.w) |
|
270 |
||
125
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
107
diff
changeset
|
271 |
|
0 | 272 |
class StartupViewsBox(BoxTemplate): |
273 |
"""display a box containing links to all startup views""" |
|
274 |
id = 'startup_views_box' |
|
809 | 275 |
|
0 | 276 |
visible = False # disabled by default |
277 |
title = _('startup views') |
|
278 |
order = 70 |
|
279 |
||
280 |
def call(self, **kwargs): |
|
281 |
box = BoxWidget(self.req._(self.title), self.id) |
|
282 |
for view in self.vreg.possible_views(self.req, None): |
|
283 |
if view.category == 'startupview': |
|
284 |
box.append(self.box_action(view)) |
|
285 |
||
286 |
if not box.is_empty(): |
|
287 |
box.render(self.w) |
|
288 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
289 |
# helper classes ############################################################## |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
290 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
291 |
class SideBoxView(EntityView): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
292 |
"""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
|
293 |
id = 'sidebox' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
294 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
295 |
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
|
296 |
"""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
|
297 |
if title: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
# 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
|
301 |
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
|
302 |
if self.rset.rowcount <= maxrelated: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
303 |
if len(self.rset) == 1: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
304 |
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
|
305 |
elif 1 < len(self.rset) < 5: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
306 |
self.wview('csv', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
307 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
308 |
self.wview('simplelist', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
309 |
# 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
|
310 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
311 |
self.rset.limit(maxrelated) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
312 |
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
|
313 |
self.wview('simplelist', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
314 |
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
|
315 |
self.req._('see them all'))) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
316 |
self.w(u'</div>\n</div>\n') |