[gen] Bugfix: For showing a field on layout buttons, the buttons layout must explicitly be returned by the show method. [gen] Action.py: added param 'icon' allowing to specify a specific icon.

This commit is contained in:
Gaetan Delannay 2014-12-05 11:55:25 +01:00
parent 2ef3cdb006
commit f055ec1754
2 changed files with 11 additions and 7 deletions

View file

@ -353,7 +353,9 @@ class Field:
return return
elif res in ('view', 'edit', 'result', 'buttons'): elif res in ('view', 'edit', 'result', 'buttons'):
return res == layoutType return res == layoutType
return bool(res) # For showing a field on layout "buttons", the "buttons" layout must
# explicitly be returned by the show method.
if layoutType != 'buttons': return bool(res)
def isClientVisible(self, obj): def isClientVisible(self, obj):
'''This method returns True if this field is visible according to '''This method returns True if this field is visible according to

View file

@ -25,7 +25,7 @@ class Action(Field):
'''An action is a Python method that can be triggered by the user on a '''An action is a Python method that can be triggered by the user on a
given gen-class. An action is rendered as a button.''' given gen-class. An action is rendered as a button.'''
# PX for viewing the Action button. # PX for viewing the Action button
pxView = pxCell = Px(''' pxView = pxCell = Px('''
<form var="formId='%s_%s_form' % (zobj.id, name); <form var="formId='%s_%s_form' % (zobj.id, name);
label=_(field.labelId); label=_(field.labelId);
@ -41,15 +41,15 @@ class Action(Field):
var="labelConfirm=_(field.labelId + '_confirm'); var="labelConfirm=_(field.labelId + '_confirm');
commentParam=(field.confirm == 'text') and 'true' or 'false'" commentParam=(field.confirm == 'text') and 'true' or 'false'"
value=":label" value=":label"
style=":'%s; %s' % (url('action', bg=True), buttonWidth)" style=":'%s; %s' % (url(field.icon, bg=True), buttonWidth)"
onclick=":'askConfirm(%s,%s,%s,%s)' % (q('form'), q(formId), \ onclick=":'askConfirm(%s,%s,%s,%s)' % (q('form'), q(formId), \
q(labelConfirm), commentParam)"/> q(labelConfirm), commentParam)"/>
<input if="not field.confirm" type="submit" class="button" name="do" <input if="not field.confirm" type="submit" class="button" name="do"
value=":label" title=":descr" value=":label" title=":descr"
style=":'%s; %s' % (url('action', bg=True), buttonWidth)"/> style=":'%s; %s' % (url(field.icon, bg=True), buttonWidth)"/>
</form>''') </form>''')
# It is not possible to edit an action, not to search it. # It is not possible to edit an action, not to search it
pxEdit = pxSearch = '' pxEdit = pxSearch = ''
def __init__(self, validator=None, multiplicity=(1,1), default=None, def __init__(self, validator=None, multiplicity=(1,1), default=None,
@ -59,7 +59,7 @@ class Action(Field):
width=None, height=None, maxChars=None, colspan=1, action=None, width=None, height=None, maxChars=None, colspan=1, action=None,
result='computation', confirm=False, master=None, result='computation', confirm=False, master=None,
masterValue=None, focus=False, historized=False, mapping=None, masterValue=None, focus=False, historized=False, mapping=None,
label=None): label=None, icon=None):
# Can be a single method or a list/tuple of methods # Can be a single method or a list/tuple of methods
self.action = action self.action = action
# For the 'result' param: # For the 'result' param:
@ -74,13 +74,15 @@ class Action(Field):
# If following field "confirm" is True, a popup will ask the user if # If following field "confirm" is True, a popup will ask the user if
# she is really sure about triggering this action. # she is really sure about triggering this action.
self.confirm = confirm self.confirm = confirm
# If no p_icon is specified, "action.png" will be used
self.icon = icon or 'action'
Field.__init__(self, None, (0,1), default, show, page, group, layouts, Field.__init__(self, None, (0,1), default, show, page, group, layouts,
move, indexed, False, specificReadPermission, move, indexed, False, specificReadPermission,
specificWritePermission, width, height, None, colspan, specificWritePermission, width, height, None, colspan,
master, masterValue, focus, historized, mapping, label, master, masterValue, focus, historized, mapping, label,
None, None, None, None, False) None, None, None, None, False)
self.validable = False self.validable = False
self.renderLabel = False # Label is rendered directly within the button. self.renderLabel = False # Label is rendered directly within the button
def getDefaultLayouts(self): return {'view': 'l-f', 'edit': 'lrv-f'} def getDefaultLayouts(self): return {'view': 'l-f', 'edit': 'lrv-f'}