provide state icon with link to state transition form for comments
This commit is contained in:
parent
61cfff0f91
commit
a47b6a02a0
4 changed files with 59 additions and 12 deletions
|
@ -22,6 +22,7 @@ Base classes for comments/discussions.
|
|||
|
||||
from zope.component import adapts
|
||||
from zope.interface import implementer, implements
|
||||
from zope.traversing.api import getParent
|
||||
|
||||
from cybertools.stateful.definition import StatesDefinition
|
||||
from cybertools.stateful.definition import State, Transition
|
||||
|
@ -38,7 +39,7 @@ def commentStates():
|
|||
return StatesDefinition('commentStates',
|
||||
State('new', 'new', ('accept', 'reject'), color='red'),
|
||||
State('public', 'public', ('retract', 'reject'), color='green'),
|
||||
State('rejected', 'rejected', ('accept'), color='grey'),
|
||||
State('rejected', 'rejected', ('accept',), color='grey'),
|
||||
Transition('accept', 'accept', 'public'),
|
||||
Transition('reject', 'reject', 'rejected'),
|
||||
Transition('retract', 'retract', 'new'),
|
||||
|
@ -61,3 +62,11 @@ class Comment(Stateful, Track):
|
|||
super(Comment, self).__init__(taskId, runId, userName, data)
|
||||
self.state = self.getState() # make initial state persistent
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
return self.data['subject']
|
||||
|
||||
def doTransition(self, action):
|
||||
super(Comment, self).doTransition(action)
|
||||
getParent(self).indexTrack(None, self, 'state')
|
||||
|
||||
|
|
|
@ -88,9 +88,17 @@ class CommentsView(NodeView):
|
|||
def getActionsFor(self, comment):
|
||||
if not checkPermission('loops.ViewRestricted', self.context):
|
||||
return []
|
||||
trackUid = util.getUidForObject(comment.track)
|
||||
url = '%s/.%s/change_state.html' % (
|
||||
self.page.virtualTargetUrl, trackUid)
|
||||
onClick = ("objectDialog('change_state', "
|
||||
"'%s?dialog=change_state"
|
||||
"&target_uid=%s'); return false;" % (url, trackUid))
|
||||
stateAct = StateAction(self,
|
||||
definition='organize.commentStates',
|
||||
stateful=comment.track)
|
||||
stateful=comment.track,
|
||||
url=url,
|
||||
onClick=onClick)
|
||||
return [stateAct]
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
|
||||
# Copyright (c) 2014 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -36,6 +36,7 @@ from loops.browser.form import ObjectForm, EditObject
|
|||
from loops.expert.query import And, Or, State, Type, getObjects
|
||||
from loops.expert.browser.search import search_template
|
||||
from loops.security.common import checkPermission
|
||||
from loops import util
|
||||
from loops.util import _
|
||||
|
||||
|
||||
|
@ -97,8 +98,10 @@ class ChangeStateBase(object):
|
|||
|
||||
@Lazy
|
||||
def stateful(self):
|
||||
return component.getAdapter(self.view.virtualTargetObject, IStateful,
|
||||
name=self.definition)
|
||||
target = self.view.virtualTargetObject
|
||||
if IStateful.providedBy(target):
|
||||
return target
|
||||
return component.getAdapter(target, IStateful, name=self.definition)
|
||||
|
||||
@Lazy
|
||||
def definition(self):
|
||||
|
@ -110,7 +113,8 @@ class ChangeStateBase(object):
|
|||
|
||||
@Lazy
|
||||
def transition(self):
|
||||
return self.stateful.getStatesDefinition().transitions[self.action]
|
||||
if self.action:
|
||||
return self.stateful.getStatesDefinition().transitions[self.action]
|
||||
|
||||
@Lazy
|
||||
def stateObject(self):
|
||||
|
@ -143,8 +147,17 @@ class ChangeStateForm(ChangeStateBase, ObjectForm):
|
|||
|
||||
class ChangeState(ChangeStateBase, EditObject):
|
||||
|
||||
@Lazy
|
||||
def stateful(self):
|
||||
target = self.target
|
||||
if IStateful.providedBy(target):
|
||||
return target
|
||||
return component.getAdapter(target, IStateful, name=self.definition)
|
||||
|
||||
def update(self):
|
||||
formData = self.request.form
|
||||
if 'target_uid' in formData:
|
||||
self.target = util.getObjectForUid(formData['target_uid'])
|
||||
# store data in target object (unless field.nostore)
|
||||
self.object = self.target
|
||||
formState = self.instance.applyTemplate(data=formData)
|
||||
|
@ -159,7 +172,7 @@ class ChangeState(ChangeStateBase, EditObject):
|
|||
rawValue = fi.getRawValue(formData, name, u'')
|
||||
trackData[name] = fi.unmarshall(rawValue)
|
||||
self.stateful.doTransition(self.action)
|
||||
notify(ObjectModifiedEvent(self.view.virtualTargetObject, trackData))
|
||||
notify(ObjectModifiedEvent(self.target, trackData))
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
@ -114,16 +114,33 @@
|
|||
tal:define="stateObject view/stateful/getStateObject"
|
||||
tal:content="stateObject/title" /> -
|
||||
<span i18n:translate="">Transition</span>:
|
||||
<span i18n:translate=""
|
||||
tal:content="view/transition/title" />
|
||||
<tal:transition condition="view/transition">
|
||||
<span i18n:translate=""
|
||||
tal:content="view/transition/title" />
|
||||
<input type="hidden" name="action"
|
||||
tal:attributes="value request/form/action|nothing">
|
||||
</tal:transition>
|
||||
<tal:transition condition="not:view/transition">
|
||||
<tal:trans repeat="trans view/stateful/getAvailableTransitions">
|
||||
<label i18n:translate=""
|
||||
tal:attributes="for string:transition.${trans/name}"
|
||||
tal:content="trans/title" />
|
||||
<input type="radio" name="action"
|
||||
tal:attributes="value trans/name;
|
||||
id string:transition.${trans/name}" />
|
||||
</tal:trans>
|
||||
</tal:transition>
|
||||
</div>
|
||||
<input type="hidden" name="form.action" value="change_state">
|
||||
<input type="hidden" name="stdef"
|
||||
tal:attributes="value request/form/stdef|nothing">
|
||||
<input type="hidden" name="action"
|
||||
tal:attributes="value request/form/action|nothing">
|
||||
<input type="hidden" name="target_uid"
|
||||
tal:define="uid request/target_uid|nothing"
|
||||
tal:condition="uid"
|
||||
tal:attributes="value uid" />
|
||||
</div>
|
||||
<div dojoType="dijit.layout.ContentPane" region="center">
|
||||
<div dojoType="dijit.layout.ContentPane" region="center"
|
||||
tal:condition="view/transition">
|
||||
<table cellpadding="3" class="form">
|
||||
<tbody><tr><td colspan="5" style="padding-right: 15px">
|
||||
<div id="form.fields">
|
||||
|
|
Loading…
Add table
Reference in a new issue