[gen] Bugfix: name clash when a transition is named 'comment'. [gen] Added AbstractWrapper::getHistoryComments allowing to collect comments of all history events of some type.

This commit is contained in:
Gaetan Delannay 2015-03-15 22:08:41 +01:00
parent cf0309cb26
commit 424c0521de
4 changed files with 22 additions and 10 deletions

View file

@ -36,7 +36,7 @@ class Action(Field):
id=":formId" action=":zobj.absolute_url() + '/onExecuteAction'"
style="display:inline">
<input type="hidden" name="fieldName" value=":name"/>
<input type="hidden" name="comment" value=""/>
<input type="hidden" name="popupComment" value=""/>
<input type="button" class=":css" title=":descr"
var="textConfirm=field.confirm and _(field.labelId+'_confirm') or '';
showComment=(field.confirm == 'text') and 'true' or 'false'"
@ -91,10 +91,10 @@ class Action(Field):
else: return method(obj)
def __call__(self, obj):
'''Calls the action on p_obj.'''
'''Calls the action on p_obj'''
# Must we call the method(s) with a param ?
hasParam = self.confirm == 'text'
param = hasParam and obj.request.get('comment', None)
param = hasParam and obj.request.get('popupComment', None)
if type(self.action) in sutils.sequenceTypes:
# There are multiple Python methods
res = [True, '']

View file

@ -425,7 +425,8 @@ class Transition:
'''Executed when a user wants to trigger this transition from the UI.'''
tool = obj.getTool()
# Trigger the transition
msg = self.trigger(name, obj, wf, rq.get('comment', ''), reindex=False)
msg = self.trigger(name, obj, wf, rq.get('popupComment', ''),
reindex=False)
# Reindex obj if required
if not obj.isTemporary(): obj.reindex()
# If we are called from an Ajax request, simply return msg

View file

@ -989,11 +989,11 @@ function askConfirm(actionType, action, msg, showComment) {
// Transfer comment from the confirm form to some other form
function transferComment(confirmForm, targetForm) {
if ((confirmForm.comment.style.display != 'none') &&
(confirmForm.comment.value)) {
targetForm.comment.value = confirmForm.comment.value;
if ((confirmForm.popupComment.style.display != 'none') &&
(confirmForm.popupComment.value)) {
targetForm.popupComment.value = confirmForm.popupComment.value;
// Clean the confirm form
confirmForm.comment.value = '';
confirmForm.popupComment.value = '';
}
}

View file

@ -105,7 +105,7 @@ class AbstractWrapper(object):
<input type="hidden" name="action"/>
<div id="commentArea" align=":dleft"><br/>
<span class="discreet">:_('workflow_comment')</span>
<textarea name="comment" cols="30" rows="3"></textarea>
<textarea name="popupComment" cols="30" rows="3"></textarea>
<br/>
</div><br/>
<input type="button" onclick="doConfirm()" value=":_('yes')"/>
@ -379,7 +379,7 @@ class AbstractWrapper(object):
style="display: inline" method="post">
<input type="hidden" name="transition"/>
<!-- Input field for storing the comment coming from the popup -->
<textarea id="comment" name="comment" cols="30" rows="3"
<textarea id="popupComment" name="popupComment" cols="30" rows="3"
style="display:none"></textarea>
<x for="transition in transitions">
<!-- Render a transition or a group of transitions. -->
@ -1291,6 +1291,17 @@ class AbstractWrapper(object):
if condition: return event
i -= 1
def getHistoryComments(self, transition, xhtml=False):
'''Gets the concatenation of all comments for all transitions of type
p_transition in the object history.'''
res = []
for event in self.history:
if event['action'] != transition: continue
if not event['comments']: continue
res.append(event['comments'])
br = xhtml and '<br/>' or '\n'
return br.join(res)
def removeEvent(self, event):
'''Removes p_event from this object's history'''
res = []