[gen] Buttons for workfow conditions are now smaller when shown in lists of objects; added the possibility to define a specific icon for every workflow transition.

This commit is contained in:
Gaetan Delannay 2014-04-21 17:19:27 +02:00
parent f0c1f69573
commit e1b6b1b951
5 changed files with 27 additions and 19 deletions

View file

@ -106,9 +106,6 @@ class Ref(Field):
src=":url('arrowDown')" title=":_('move_down')" src=":url('arrowDown')" title=":_('move_down')"
onclick=":ajaxBaseCall.replace('**v**', 'down')"/> onclick=":ajaxBaseCall.replace('**v**', 'down')"/>
</td> </td>
<!-- Workflow transitions -->
<td if="tied.o.showTransitions('result')"
var2="targetObj=tied.o">:tied.pxTransitions</td>
<!-- Edit --> <!-- Edit -->
<td if="not field.noForm and tied.o.mayEdit()"> <td if="not field.noForm and tied.o.mayEdit()">
<a var="navInfo='ref.%s.%s:%s.%d.%d' % (zobj.id, field.name, \ <a var="navInfo='ref.%s.%s:%s.%d.%d' % (zobj.id, field.name, \
@ -136,6 +133,9 @@ class Ref(Field):
onclick=":'onLink(%s,%s,%s,%s)' % (q(action), q(zobj.id), \ onclick=":'onLink(%s,%s,%s,%s)' % (q(action), q(zobj.id), \
q(field.name), q(tiedUid))"/> q(field.name), q(tiedUid))"/>
</td> </td>
<!-- Workflow transitions -->
<td if="tied.o.showTransitions('result')"
var2="targetObj=tied.o; buttonsMode='small'">:tied.pxTransitions</td>
</tr> </tr>
</table>''') </table>''')

View file

@ -166,7 +166,7 @@ class State:
class Transition: class Transition:
'''Represents a workflow transition.''' '''Represents a workflow transition.'''
def __init__(self, states, condition=True, action=None, notify=None, def __init__(self, states, condition=True, action=None, notify=None,
show=True, confirm=False, group=None): show=True, confirm=False, group=None, icon=None):
# In its simpler form, "states" is a list of 2 states: # In its simpler form, "states" is a list of 2 states:
# (fromState, toState). But it can also be a list of several # (fromState, toState). But it can also be a list of several
# (fromState, toState) sub-lists. This way, you may define only 1 # (fromState, toState) sub-lists. This way, you may define only 1
@ -184,6 +184,8 @@ class Transition:
# the transition. It will only be possible by code. # the transition. It will only be possible by code.
self.confirm = confirm # If True, a confirm popup will show up. self.confirm = confirm # If True, a confirm popup will show up.
self.group = Group.get(group) self.group = Group.get(group)
# The user may specify a specific icon to show for this transition.
self.icon = icon or 'transition'
def standardiseStates(self, states): def standardiseStates(self, states):
'''Get p_states as a list or a list of lists. Indeed, the user may also '''Get p_states as a list or a list of lists. Indeed, the user may also
@ -331,7 +333,8 @@ class Transition:
return msg return msg
def trigger(self, transitionName, obj, wf, comment, doAction=True, def trigger(self, transitionName, obj, wf, comment, doAction=True,
doNotify=True, doHistory=True, doSay=True, reindex=True): doNotify=True, doHistory=True, doSay=True, reindex=True,
noSecurity=False):
'''This method triggers this transition on p_obj. The transition is '''This method triggers this transition on p_obj. The transition is
supposed to be triggerable (call to self.isTriggerable must have been supposed to be triggerable (call to self.isTriggerable must have been
performed before calling this method). If p_doAction is False, the performed before calling this method). If p_doAction is False, the
@ -344,6 +347,9 @@ class Transition:
trigger programmatically, and no message is returned to the user. trigger programmatically, and no message is returned to the user.
If p_reindex is False, object reindexing will be performed by the If p_reindex is False, object reindexing will be performed by the
calling method.''' calling method.'''
# Security check
if not noSecurity and not self.isTriggerable(obj, wf):
raise Exception('Transition "%s" can\'t be triggered.' % name)
# Create the workflow_history dict if it does not exist. # Create the workflow_history dict if it does not exist.
if not hasattr(obj.aq_base, 'workflow_history'): if not hasattr(obj.aq_base, 'workflow_history'):
from persistent.mapping import PersistentMapping from persistent.mapping import PersistentMapping
@ -387,9 +393,6 @@ class Transition:
def onUiRequest(self, obj, wf, name, rq): def onUiRequest(self, obj, wf, name, rq):
'''Executed when a user wants to trigger this transition from the UI.''' '''Executed when a user wants to trigger this transition from the UI.'''
tool = obj.getTool() tool = obj.getTool()
# Is this transition triggerable?
if not self.isTriggerable(obj, wf):
raise Exception('Transition "%s" can\'t be triggered.' % name)
# Trigger the transition # Trigger the transition
self.trigger(name, obj, wf, rq.get('comment', ''), reindex=False) self.trigger(name, obj, wf, rq.get('comment', ''), reindex=False)
# Reindex obj if required. # Reindex obj if required.
@ -398,11 +401,12 @@ class Transition:
class UiTransition: class UiTransition:
'''Represents a widget that displays a transition.''' '''Represents a widget that displays a transition.'''
pxView = Px(''' pxView = Px('''<x var="buttonCss = (buttonsMode == 'small') and \
'buttonSmall button' or 'button'">
<!-- Real button --> <!-- Real button -->
<input if="transition.mayTrigger" type="button" class="button" <input if="transition.mayTrigger" type="button" class=":buttonCss"
var2="label=transition.title" var2="label=transition.title"
style=":'%s; %s' % (url('transition', bg=True), \ style=":'%s; %s' % (url(transition.icon, bg=True), \
ztool.getButtonWidth(label))" ztool.getButtonWidth(label))"
value=":label" value=":label"
onclick=":'triggerTransition(%s,%s,%s)' % (q(formId), \ onclick=":'triggerTransition(%s,%s,%s)' % (q(formId), \
@ -410,15 +414,16 @@ class UiTransition:
<!-- Fake button, explaining why the transition can't be triggered --> <!-- Fake button, explaining why the transition can't be triggered -->
<input if="not transition.mayTrigger" type="button" <input if="not transition.mayTrigger" type="button"
class="fake button" var2="label=transition.title" class=":'fake ' + buttonCss" var2="label=transition.title"
style=":'%s; %s' % (url('fake', bg=True), style=":'%s; %s' % (url('fake', bg=True),
ztool.getButtonWidth(label))" ztool.getButtonWidth(label))"
value=":label" title=":transition.reason"/>''') value=":label" title=":transition.reason"/></x>''')
def __init__(self, name, transition, obj, mayTrigger, ): def __init__(self, name, transition, obj, mayTrigger, ):
self.name = name self.name = name
self.transition = transition self.transition = transition
self.type = 'transition' self.type = 'transition'
self.icon = transition.icon
label = obj.getWorkflowLabel(name) label = obj.getWorkflowLabel(name)
self.title = obj.translate(label) self.title = obj.translate(label)
if transition.confirm: if transition.confirm:

View file

@ -67,9 +67,11 @@ img { border: 0; vertical-align: middle }
.navigate td { padding: 4px 9px } .navigate td { padding: 4px 9px }
.login { margin: 3px; color: black } .login { margin: 3px; color: black }
input.button { color: #666666; height: 20px; width: 130px; input.button { color: #666666; height: 20px; width: 130px;
cursor:pointer; font-size: 90%; padding-left: 10px; cursor:pointer; font-size: 90%; padding: 1px 0 0 10px;
background-color: white; background-repeat: no-repeat; background-color: white; background-repeat: no-repeat;
background-position: 5% 25%; box-shadow: 2px 2px 2px #888888} background-position: 5% 25%; box-shadow: 2px 2px 2px #888888}
input.buttonSmall { width: 100px !important; font-size: 85%; height: 18px;
margin-bottom: 3px}
.fake { background-color: #e6e6e6 !important ; cursor:help !important } .fake { background-color: #e6e6e6 !important ; cursor:help !important }
.buttons { margin-left: 4px } .buttons { margin-left: 4px }
.message { position: absolute; top: -40px; left: 50%; font-size: 90%; .message { position: absolute; top: -40px; left: 50%; font-size: 90%;

View file

@ -190,7 +190,7 @@ class ToolWrapper(AbstractWrapper):
<x var="mayCreate=ztool.userMayCreate(rootClass); <x var="mayCreate=ztool.userMayCreate(rootClass);
createMeans=ztool.getCreateMeans(rootClass)"> createMeans=ztool.getCreateMeans(rootClass)">
<!-- Create a new object from a web form. --> <!-- Create a new object from a web form. -->
<input type="button" class="button" <input type="button" class="buttonSmall button"
if="mayCreate and ('form' in createMeans)" if="mayCreate and ('form' in createMeans)"
var2="label=_('query_create')" value=":label" var2="label=_('query_create')" value=":label"
style=":'%s; %s' % (url('add', bg=True), \ style=":'%s; %s' % (url('add', bg=True), \
@ -323,7 +323,7 @@ class ToolWrapper(AbstractWrapper):
<!-- Actions --> <!-- Actions -->
<table class="noStyle" if="zobj.mayAct()"> <table class="noStyle" if="zobj.mayAct()">
<tr valign="top"> <tr>
<!-- Edit --> <!-- Edit -->
<td if="zobj.mayEdit()"> <td if="zobj.mayEdit()">
<a var="navInfo='search.%s.%s.%d.%d' % \ <a var="navInfo='search.%s.%s.%d.%d' % \
@ -340,7 +340,8 @@ class ToolWrapper(AbstractWrapper):
</td> </td>
<!-- Workflow transitions --> <!-- Workflow transitions -->
<td if="zobj.showTransitions('result')" <td if="zobj.showTransitions('result')"
var2="targetObj=zobj">:targetObj.appy().pxTransitions</td> var2="targetObj=zobj;
buttonsMode='small'">:targetObj.appy().pxTransitions</td>
</tr> </tr>
</table> </table>
</x> </x>

View file

@ -363,7 +363,7 @@ class AbstractWrapper(object):
pxTransitions = Px(''' pxTransitions = Px('''
<form var="transitions=targetObj.getTransitions()" if="transitions" <form var="transitions=targetObj.getTransitions()" if="transitions"
var2="formId='trigger_%s' % targetObj.UID()" method="post" var2="formId='trigger_%s' % targetObj.id" method="post"
id=":formId" action=":targetObj.absolute_url() + '/do'"> id=":formId" action=":targetObj.absolute_url() + '/do'">
<input type="hidden" name="action" value="Trigger"/> <input type="hidden" name="action" value="Trigger"/>
<input type="hidden" name="transition"/> <input type="hidden" name="transition"/>
@ -524,7 +524,7 @@ class AbstractWrapper(object):
</td> </td>
<!-- Workflow transitions --> <!-- Workflow transitions -->
<td var="targetObj=zobj" <td var="targetObj=zobj; buttonsMode='normal'"
if="targetObj.showTransitions(layoutType)">:obj.pxTransitions</td> if="targetObj.showTransitions(layoutType)">:obj.pxTransitions</td>
<!-- Refresh --> <!-- Refresh -->