13 |
13 |
14 from logilab.mtconverter import xml_escape |
14 from logilab.mtconverter import xml_escape |
15 from logilab.common.graph import escape, GraphGenerator, DotBackend |
15 from logilab.common.graph import escape, GraphGenerator, DotBackend |
16 |
16 |
17 from cubicweb import Unauthorized, view |
17 from cubicweb import Unauthorized, view |
18 from cubicweb.selectors import (implements, has_related_entities, |
18 from cubicweb.selectors import (implements, has_related_entities, one_line_rset, |
19 relation_possible, match_form_params) |
19 relation_possible, match_form_params) |
20 from cubicweb.interfaces import IWorkflowable |
20 from cubicweb.interfaces import IWorkflowable |
21 from cubicweb.view import EntityView |
21 from cubicweb.view import EntityView |
22 from cubicweb.schema import display_name |
22 from cubicweb.schema import display_name |
23 from cubicweb.web import stdmsgs, action, component, form, action |
23 from cubicweb.web import stdmsgs, action, component, form, action |
108 title = _('Workflow history') |
108 title = _('Workflow history') |
109 |
109 |
110 def cell_call(self, row, col, view=None): |
110 def cell_call(self, row, col, view=None): |
111 self.wview('wfhistory', self.rset, row=row, col=col, view=view) |
111 self.wview('wfhistory', self.rset, row=row, col=col, view=view) |
112 |
112 |
113 # workflow entity types views ################################################# |
113 |
|
114 # workflow actions ############################################################# |
|
115 |
|
116 class WorkflowActions(action.Action): |
|
117 """fill 'workflow' sub-menu of the actions box""" |
|
118 id = 'workflow' |
|
119 __select__ = (action.Action.__select__ & one_line_rset() & |
|
120 relation_possible('in_state')) |
|
121 |
|
122 submenu = _('workflow') |
|
123 order = 10 |
|
124 |
|
125 def fill_menu(self, box, menu): |
|
126 req = self.req |
|
127 entity = self.rset.get_entity(self.row or 0, self.col or 0) |
|
128 menu.label = u'%s: %s' % (req._('state'), entity.printable_state) |
|
129 menu.append_anyway = True |
|
130 for tr in entity.possible_transitions(): |
|
131 url = entity.absolute_url(vid='statuschange', treid=tr.eid) |
|
132 menu.append(box.mk_action(req._(tr.name), url)) |
|
133 # don't propose to see wf if user can't pass any transition |
|
134 if menu.items: |
|
135 wfurl = entity.current_workflow.absolute_url() |
|
136 menu.append(box.mk_action(req._('view workflow'), wfurl)) |
|
137 if entity.workflow_history: |
|
138 wfurl = entity.absolute_url(vid='wfhistory') |
|
139 menu.append(box.mk_action(req._('view history'), wfurl)) |
|
140 |
|
141 |
|
142 # workflow entity types views ################################################## |
114 |
143 |
115 class CellView(view.EntityView): |
144 class CellView(view.EntityView): |
116 id = 'cell' |
145 id = 'cell' |
117 __select__ = implements('TrInfo') |
146 __select__ = implements('TrInfo') |
118 |
147 |
129 self.w(xml_escape(self.view('textincontext', self.rset, |
158 self.w(xml_escape(self.view('textincontext', self.rset, |
130 row=row, col=col))) |
159 row=row, col=col))) |
131 |
160 |
132 |
161 |
133 class WorkflowPrimaryView(primary.PrimaryView): |
162 class WorkflowPrimaryView(primary.PrimaryView): |
134 id = 'workflow' |
|
135 __select__ = implements('Workflow') |
163 __select__ = implements('Workflow') |
136 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
164 cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
137 |
165 |
138 def render_entity_attributes(self, entity): |
166 def render_entity_attributes(self, entity): |
139 self.w(u'<img src="%s" alt="%s"/>' % ( |
167 self.w(u'<img src="%s" alt="%s"/>' % ( |