66 # some addrelated actions may be specified but no one is selectable |
66 # some addrelated actions may be specified but no one is selectable |
67 # in which case we should not fallback to schema_actions. The proper |
67 # in which case we should not fallback to schema_actions. The proper |
68 # way to avoid this is to override add_related_schemas() on the |
68 # way to avoid this is to override add_related_schemas() on the |
69 # entity class to return an empty list |
69 # entity class to return an empty list |
70 for action in self.schema_actions(entity): |
70 for action in self.schema_actions(entity): |
71 add_menu.append(action) |
71 add_menu.append(action) |
72 if 'in_state' in entity.e_schema.subject_relations() and entity.in_state: |
72 self.workflow_actions(entity, box) |
73 state = entity.in_state[0] |
|
74 transitions = list(state.transitions(entity)) |
|
75 if transitions: |
|
76 menu_title = u'%s: %s' % (_('state'), state.view('text')) |
|
77 menu_items = [] |
|
78 for tr in state.transitions(entity): |
|
79 url = entity.absolute_url(vid='statuschange', treid=tr.eid) |
|
80 menu_items.append(self.mk_action(_(tr.name), url)) |
|
81 state_menu = BoxMenu(menu_title, menu_items) |
|
82 box.append(state_menu) |
|
83 # when there are no possible transition, put state if the menu if |
|
84 # there are some other actions |
|
85 elif not box.is_empty(): |
|
86 menu_title = u'<a title="%s">%s: <i>%s</i></a>' % ( |
|
87 _('no possible transition'), _('state'), state.view('text')) |
|
88 box.append(RawBoxItem(menu_title, 'boxMainactions')) |
|
89 if box.is_empty() and not other_menu.is_empty(): |
73 if box.is_empty() and not other_menu.is_empty(): |
90 box.items = other_menu.items |
74 box.items = other_menu.items |
91 other_menu.items = [] |
75 other_menu.items = [] |
92 self.add_submenu(box, add_menu, _('add')) |
76 self.add_submenu(box, add_menu, _('add')) |
93 self.add_submenu(box, other_menu) |
77 self.add_submenu(box, other_menu) |
117 url = self.linkto_url(entity, rschema, teschema, 'subject') |
101 url = self.linkto_url(entity, rschema, teschema, 'subject') |
118 actions.append(self.mk_action(_(label), url)) |
102 actions.append(self.mk_action(_(label), url)) |
119 return actions |
103 return actions |
120 |
104 |
121 |
105 |
|
106 def workflow_actions(self, entity, box): |
|
107 if 'in_state' in entity.e_schema.subject_relations() and entity.in_state: |
|
108 state = entity.in_state[0] |
|
109 transitions = list(state.transitions(entity)) |
|
110 if transitions: |
|
111 menu_title = u'%s: %s' % (_('state'), state.view('text')) |
|
112 menu_items = [] |
|
113 for tr in state.transitions(entity): |
|
114 url = entity.absolute_url(vid='statuschange', treid=tr.eid) |
|
115 menu_items.append(self.mk_action(_(tr.name), url)) |
|
116 box.append(BoxMenu(menu_title, menu_items)) |
|
117 # when there are no possible transition, put state if the menu if |
|
118 # there are some other actions |
|
119 elif not box.is_empty(): |
|
120 menu_title = u'<a title="%s">%s: <i>%s</i></a>' % ( |
|
121 _('no possible transition'), _('state'), state.view('text')) |
|
122 box.append(RawBoxItem(menu_title, 'boxMainactions')) |
|
123 return None |
|
124 |
122 def linkto_url(self, entity, rtype, etype, target): |
125 def linkto_url(self, entity, rtype, etype, target): |
123 |
|
124 return self.build_url(vid='creation', etype=etype, |
126 return self.build_url(vid='creation', etype=etype, |
125 __linkto='%s:%s:%s' % (rtype, entity.eid, target), |
127 __linkto='%s:%s:%s' % (rtype, entity.eid, target), |
126 __redirectpath=entity.rest_path(), # should not be url quoted! |
128 __redirectpath=entity.rest_path(), # should not be url quoted! |
127 __redirectvid=self.req.form.get('vid', '')) |
129 __redirectvid=self.req.form.get('vid', '')) |
128 |
130 |