[gen] Allow to group transitions.

This commit is contained in:
Gaetan Delannay 2013-09-24 12:26:31 +02:00
parent 180b3473e8
commit 91e0bd2240
8 changed files with 166 additions and 95 deletions

View file

@ -761,7 +761,7 @@ class ZopeGenerator(Generator):
# Generate labels for groups of searches
if search.group and not search.group.label:
search.group.generateLabels(self.labels, classDescr, set(),
forSearch=True)
content='searches')
# Generate the resulting Zope class.
self.copyFile('Class.pyt', repls, destName=fileName)

View file

@ -261,8 +261,11 @@ class ZopeInstaller:
indexed=True, searchable=True)
title.init('title', None, 'appy')
setattr(wrapperClass, 'title', title)
# Special field "state" must be added for every class
state = gen.String(show='result')
# Special field "state" must be added for every class. It must be a
# "select" field, because it will be necessary for displaying the
# translated state name.
state = gen.String(validator=gen.Selection('listStates'),
show='result')
state.init('state', None, 'workflow')
setattr(wrapperClass, 'state', state)
names = self.config.attributes[wrapperClass.__name__[:-8]]

View file

@ -738,8 +738,9 @@ class ToolMixin(BaseMixin):
res = []
default = None # Also retrieve the default one here.
groups = {} # The already encountered groups
page = Page('main') # A dummy page required by class UiGroup
page = Page('searches') # A dummy page required by class UiGroup
# Get the searches statically defined on the class
className = self.getPortalType(klass)
searches = ClassDescriptor.getSearches(klass, tool=self.appy())
# Get the dynamically computed searches
if hasattr(klass, 'getDynamicSearches'):
@ -752,8 +753,8 @@ class ToolMixin(BaseMixin):
res.append(uiSearch)
else:
uiGroup = search.group.insertInto(res, groups, page, className,
forSearch=True)
uiGroup.addField(uiSearch)
content='searches')
uiGroup.addElement(uiSearch)
# Is this search the default search?
if search.default: default = uiSearch
return Object(searches=res, default=default)

View file

@ -5,6 +5,7 @@
# ------------------------------------------------------------------------------
import os, os.path, sys, types, urllib, cgi
from appy import Object
from appy.fields.workflow import UiTransition
import appy.gen as gen
from appy.gen.utils import *
from appy.gen.layout import Table, defaultPageLayouts
@ -742,11 +743,10 @@ class BaseMixin:
if not field.group:
res.append(field)
else:
# Insert the UiGroup instance corresponding to field.group at
# the right place.
# Insert the UiGroup instance corresponding to field.group.
uiGroup = field.group.insertInto(res, groups, field.page,
self.meta_type)
uiGroup.addField(field)
uiGroup.addElement(field)
if collectCssJs:
cssJs['css'] = css or ()
cssJs['js'] = js or ()
@ -786,9 +786,10 @@ class BaseMixin:
return klass.styles[elem]
return elem
def getTransitions(self, includeFake=True, includeNotShowable=False):
'''This method returns info about transitions that one can trigger from
the user interface.
def getTransitions(self, includeFake=True, includeNotShowable=False,
grouped=True):
'''This method returns info about transitions (as UiTransition
instances) that one can trigger from the user interface.
* if p_includeFake is True, it retrieves transitions that the user
can't trigger, but for which he needs to know for what reason he
can't trigger it;
@ -797,8 +798,12 @@ class BaseMixin:
and not a security concern, in some cases it has sense to set
includeNotShowable=True, because those transitions are triggerable
from a security point of view.
* If p_grouped is True, transitions are grouped according to their
"group" attribute, in a similar way to fields or searches.
'''
res = []
groups = {} # The already encountered groups of transitions.
wfPage = gen.Page('workflow')
wf = self.getWorkflow()
currentState = self.State(name=False)
# Loop on every transition
@ -818,17 +823,16 @@ class BaseMixin:
if not includeNotShowable:
includeIt = includeIt and transition.isShowable(wf, self)
if not includeIt: continue
# Add transition-info to the result.
label = self.getWorkflowLabel(name)
tInfo = {'name': name, 'title': self.translate(label),
'confirm': '', 'may_trigger': True}
if transition.confirm:
cLabel = '%s_confirm' % label
tInfo['confirm'] = self.translate(cLabel)
if not mayTrigger:
tInfo['may_trigger'] = False
tInfo['reason'] = mayTrigger.msg
res.append(tInfo)
# Create the UiTransition instance.
info = UiTransition(name, transition, self, mayTrigger)
# Add the transition into the result.
if not transition.group or not grouped:
res.append(info)
else:
# Insert the UiGroup instance corresponding to transition.group.
uiGroup = transition.group.insertInto(res, groups, wfPage,
self.__class__.__name__, content='transitions')
uiGroup.addElement(info)
return res
def getAppyPhases(self, currentOnly=False, layoutType='view'):

View file

@ -326,10 +326,7 @@ class ToolWrapper(AbstractWrapper):
<!-- Actions -->
<table class="noStyle" if="zobj.mayAct()">
<tr>
<!-- Workflow transitions -->
<td if="zobj.showTransitions('result')"
var2="targetObj=zobj">:targetObj.appy().pxTransitions</td>
<tr valign="top">
<!-- Edit -->
<td if="zobj.mayEdit()">
<a var="navInfo='search.%s.%s.%d.%d' % \
@ -344,6 +341,9 @@ class ToolWrapper(AbstractWrapper):
title=":_('object_delete')"
onClick=":'onDeleteObject(%s)' % q(zobj.UID())"/>
</td>
<!-- Workflow transitions -->
<td if="zobj.showTransitions('result')"
var2="targetObj=zobj">:targetObj.appy().pxTransitions</td>
</tr>
</table>
</x>

View file

@ -349,34 +349,22 @@ class AbstractWrapper(object):
</table>
</x>''')
# Displays an object's transitions(s).
pxTransitions = Px('''
<form var="transitions=targetObj.getTransitions()" if="transitions"
var2="formId='trigger_%s' % targetObj.UID()" method="post"
id=":formId" action=":targetObj.absolute_url() + '/do'">
<input type="hidden" name="action" value="Trigger"/>
<input type="hidden" name="workflow_action"/>
<!-- Input field for storing the comment coming from the popup -->
<textarea id="comment" name="comment" cols="30" rows="3"
style="display:none"></textarea>
<table>
<tr valign="middle">
<!-- Input field for storing comment -->
<textarea id="comment" name="comment" cols="30" rows="3"
style="display:none"></textarea>
<!-- Buttons for triggering transitions -->
<td align=":dright" for="transition in transitions">
<!-- Real button -->
<input type="button" class="button" if="transition['may_trigger']"
style=":url('buttonTransition', bg=True)"
title=":transition['title']"
value=":ztool.truncateValue(transition['title'])"
onclick=":'triggerTransition(%s,%s,%s)' % (q(formId), \
q(transition['name']), q(transition['confirm']))"/>
<!-- Fake button, explaining why the transition can't be triggered -->
<input type="button" class="button" if="not transition['may_trigger']"
style=":url('buttonFake', bg=True) + ';cursor: help'"
value=":ztool.truncateValue(transition['title'])"
title=":'%s: %s' % (transition['title'], \
transition['reason'])"/>
<!-- Render a transition or a group of transitions. -->
<x if="transition.type == 'transition'">:transition.pxView</x>
<x if="transition.type == 'group'"
var2="uiGroup=transition">:uiGroup.px</x>
</td>
</tr>
</table>
@ -446,7 +434,7 @@ class AbstractWrapper(object):
nextPage=phaseObj.getNextPage(page)[0];
isEdit=layoutType == 'edit';
pageInfo=phaseObj.pagesInfo[page]">
<tr>
<tr valign="top">
<!-- Previous -->
<td if="previousPage and pageInfo.showPrevious">
<!-- Button on the edit page -->
@ -1045,4 +1033,14 @@ class AbstractWrapper(object):
'''Produces a representation of p_text into the desired p_format, which
is 'html' by default.'''
return self.o.formatText(text, format)
def listStates(self):
'''Lists the possible states for this object.'''
res = []
o = self.o
workflow = o.getWorkflow()
for name in dir(workflow):
if getattr(workflow, name).__class__.__name__ != 'State': continue
res.append((name, o.translate(o.getWorkflowLabel(name))))
return res
# ------------------------------------------------------------------------------