37 from cubicweb.view import EntityView |
37 from cubicweb.view import EntityView |
38 from cubicweb.schema import display_name |
38 from cubicweb.schema import display_name |
39 from cubicweb.web import uicfg, stdmsgs, action, component, form, action |
39 from cubicweb.web import uicfg, stdmsgs, action, component, form, action |
40 from cubicweb.web import formfields as ff, formwidgets as fwdgs |
40 from cubicweb.web import formfields as ff, formwidgets as fwdgs |
41 from cubicweb.web.views import TmpFileViewMixin |
41 from cubicweb.web.views import TmpFileViewMixin |
42 from cubicweb.web.views import forms, primary, autoform, ibreadcrumbs |
42 from cubicweb.web.views import forms, primary, ibreadcrumbs |
43 from cubicweb.web.views.tabs import TabbedPrimaryView, PrimaryTab |
43 from cubicweb.web.views.tabs import TabbedPrimaryView, PrimaryTab |
44 from cubicweb.web.views.dotgraphview import DotGraphView, DotPropsHandler |
44 from cubicweb.web.views.dotgraphview import DotGraphView, DotPropsHandler |
45 |
45 |
46 _pvs = uicfg.primaryview_section |
46 _pvs = uicfg.primaryview_section |
47 _pvs.tag_subject_of(('Workflow', 'initial_state', '*'), 'hidden') |
47 _pvs.tag_subject_of(('Workflow', 'initial_state', '*'), 'hidden') |
70 _abaa.tag_object_of(('State', 'state_of', 'Workflow'), True) |
70 _abaa.tag_object_of(('State', 'state_of', 'Workflow'), True) |
71 _abaa.tag_object_of(('Transition', 'transition_of', 'Workflow'), True) |
71 _abaa.tag_object_of(('Transition', 'transition_of', 'Workflow'), True) |
72 _abaa.tag_object_of(('WorkflowTransition', 'transition_of', 'Workflow'), True) |
72 _abaa.tag_object_of(('WorkflowTransition', 'transition_of', 'Workflow'), True) |
73 |
73 |
74 _afs = uicfg.autoform_section |
74 _afs = uicfg.autoform_section |
75 _afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'main', 'hidden') |
75 _affk = uicfg.autoform_field_kwargs |
76 _afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'main', 'hidden') |
|
77 _afs.tag_attribute(('TrInfo', 'tr_count'), 'main', 'hidden') |
|
78 _afs.tag_object_of(('State', 'allowed_transition', '*'), 'main', 'attributes') |
|
79 |
|
80 |
76 |
81 # IWorkflowable views ######################################################### |
77 # IWorkflowable views ######################################################### |
82 |
78 |
83 class ChangeStateForm(forms.CompositeEntityForm): |
79 class ChangeStateForm(forms.CompositeEntityForm): |
84 # set dom id to ensure there is no conflict with edition form (see |
80 # set dom id to ensure there is no conflict with edition form (see |
322 in entity.reverse_allowed_transition))) |
318 in entity.reverse_allowed_transition))) |
323 |
319 |
324 |
320 |
325 # workflow entity types edition ################################################ |
321 # workflow entity types edition ################################################ |
326 |
322 |
327 _afs = uicfg.autoform_section |
323 def _wf_items_for_relation(req, wfeid, wfrelation, field): |
|
324 wf = req.entity_from_eid(wfeid) |
|
325 rschema = req.vreg.schema[field.name] |
|
326 param = 'toeid' if field.role == 'subject' else 'fromeid' |
|
327 return sorted((e.view('combobox'), e.eid) |
|
328 for e in getattr(wf, 'reverse_%s' % wfrelation) |
|
329 if rschema.has_perm(req, 'add', **{param: e.eid})) |
|
330 |
|
331 # TrInfo |
328 _afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'main', 'hidden') |
332 _afs.tag_subject_of(('TrInfo', 'to_state', '*'), 'main', 'hidden') |
329 _afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'main', 'hidden') |
333 _afs.tag_subject_of(('TrInfo', 'from_state', '*'), 'main', 'hidden') |
330 _afs.tag_object_of(('State', 'allowed_transition', '*'), 'main', 'attributes') |
334 _afs.tag_attribute(('TrInfo', 'tr_count'), 'main', 'hidden') |
|
335 |
|
336 # BaseTransition |
|
337 # XXX * allowed_transition BaseTransition |
|
338 # XXX BaseTransition destination_state * |
|
339 |
|
340 def transition_states_vocabulary(form, field): |
|
341 entity = form.edited_entity |
|
342 if not entity.has_eid(): |
|
343 eids = entity.linked_to('transition_of', 'subject') |
|
344 if not eids: |
|
345 return [] |
|
346 return _wf_items_for_relation(form._cw, eids[0], 'state_of', field) |
|
347 return ff.relvoc_unrelated(entity, field.name, field.role) |
|
348 |
|
349 _afs.tag_subject_of(('*', 'destination_state', '*'), 'main', 'attributes') |
|
350 _affk.tag_subject_of(('*', 'destination_state', '*'), |
|
351 {'choices': transition_states_vocabulary}) |
|
352 _afs.tag_object_of(('*', 'allowed_transition', '*'), 'main', 'attributes') |
|
353 _affk.tag_object_of(('*', 'allowed_transition', '*'), |
|
354 {'choices': transition_states_vocabulary}) |
|
355 |
|
356 # State |
|
357 |
|
358 def state_transitions_vocabulary(form, field): |
|
359 entity = form.edited_entity |
|
360 if not entity.has_eid(): |
|
361 eids = entity.linked_to('state_of', 'subject') |
|
362 if eids: |
|
363 return _wf_items_for_relation(form._cw, eids[0], 'transition_of', field) |
|
364 return [] |
|
365 return ff.relvoc_unrelated(entity, field.name, field.role) |
|
366 |
331 _afs.tag_subject_of(('State', 'allowed_transition', '*'), 'main', 'attributes') |
367 _afs.tag_subject_of(('State', 'allowed_transition', '*'), 'main', 'attributes') |
332 |
368 _affk.tag_subject_of(('State', 'allowed_transition', '*'), |
333 def workflow_items_for_relation(req, wfeid, wfrelation, targetrelation): |
369 {'choices': state_transitions_vocabulary}) |
334 wf = req.entity_from_eid(wfeid) |
370 |
335 rschema = req.vreg.schema[targetrelation] |
371 |
336 return sorted((e.view('combobox'), e.eid) |
372 # adaptaters ################################################################### |
337 for e in getattr(wf, 'reverse_%s' % wfrelation) |
|
338 if rschema.has_perm(req, 'add', toeid=e.eid)) |
|
339 |
|
340 |
|
341 class TransitionEditionForm(autoform.AutomaticEntityForm): |
|
342 __select__ = is_instance('Transition') |
|
343 |
|
344 def workflow_states_for_relation(self, targetrelation): |
|
345 eids = self.edited_entity.linked_to('transition_of', 'subject') |
|
346 if eids: |
|
347 return workflow_items_for_relation(self._cw, eids[0], 'state_of', |
|
348 targetrelation) |
|
349 return [] |
|
350 |
|
351 def subject_destination_state_vocabulary(self, rtype, limit=None): |
|
352 if not self.edited_entity.has_eid(): |
|
353 return self.workflow_states_for_relation('destination_state') |
|
354 return self.subject_relation_vocabulary(rtype, limit) |
|
355 |
|
356 def object_allowed_transition_vocabulary(self, rtype, limit=None): |
|
357 if not self.edited_entity.has_eid(): |
|
358 return self.workflow_states_for_relation('allowed_transition') |
|
359 return self.object_relation_vocabulary(rtype, limit) |
|
360 |
|
361 |
|
362 class StateEditionForm(autoform.AutomaticEntityForm): |
|
363 __select__ = is_instance('State') |
|
364 |
|
365 def subject_allowed_transition_vocabulary(self, rtype, limit=None): |
|
366 if not self.edited_entity.has_eid(): |
|
367 eids = self.edited_entity.linked_to('state_of', 'subject') |
|
368 if eids: |
|
369 return workflow_items_for_relation(self._cw, eids[0], 'transition_of', |
|
370 'allowed_transition') |
|
371 return [] |
|
372 |
373 |
373 class WorkflowIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter): |
374 class WorkflowIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter): |
374 __select__ = is_instance('Workflow') |
375 __select__ = is_instance('Workflow') |
375 # XXX what if workflow of multiple types? |
376 # XXX what if workflow of multiple types? |
376 def parent_entity(self): |
377 def parent_entity(self): |