[gen] [gen] Action field: param confirm can be 'text': in this case, the confirm popup contains a textarea whose content is passed as param to the method speficied in param 'action'. Action fields can now be defined in a new layout 'buttons' (show='buttons') in order to appear, on the view layout, besides the extsting series of buttons (edit, next/previous pages...).
This commit is contained in:
parent
960a4c6a46
commit
ccf7e44eef
6 changed files with 157 additions and 114 deletions
|
@ -350,7 +350,7 @@ class Field:
|
|||
for r in res:
|
||||
if r == layoutType: return True
|
||||
return
|
||||
elif res in ('view', 'edit', 'result'):
|
||||
elif res in ('view', 'edit', 'result', 'buttons'):
|
||||
return res == layoutType
|
||||
return bool(res)
|
||||
|
||||
|
|
|
@ -29,18 +29,22 @@ class Action(Field):
|
|||
pxView = pxCell = Px('''
|
||||
<form var="formId='%s_%s_form' % (zobj.id, name);
|
||||
label=_(field.labelId);
|
||||
descr=field.descrId and _(field.descrId) or None;
|
||||
buttonWidth=ztool.getButtonWidth(label)"
|
||||
id=":formId" action=":ztool.absolute_url() + '/do'">
|
||||
<input type="hidden" name="action" value="ExecuteAction"/>
|
||||
<input type="hidden" name="objectUid" value=":zobj.id"/>
|
||||
<input type="hidden" name="fieldName" value=":name"/>
|
||||
<input if="field.confirm" type="button" class="button"
|
||||
var="labelConfirm=_(field.labelId + '_confirm')" value=":label"
|
||||
<input type="hidden" name="comment" value=""/>
|
||||
<input if="field.confirm" type="button" class="button" title=":descr"
|
||||
var="labelConfirm=_(field.labelId + '_confirm');
|
||||
commentParam=(field.confirm == 'text') and 'true' or 'false'"
|
||||
value=":label"
|
||||
style=":'%s; %s' % (url('action', bg=True), buttonWidth)"
|
||||
onclick=":'askConfirm(%s,%s,%s)' % (q('form'), q(formId), \
|
||||
q(labelConfirm))"/>
|
||||
onclick=":'askConfirm(%s,%s,%s,%s)' % (q('form'), q(formId), \
|
||||
q(labelConfirm), commentParam)"/>
|
||||
<input if="not field.confirm" type="submit" class="button" name="do"
|
||||
value=":label"
|
||||
value=":label" title=":descr"
|
||||
style=":'%s; %s' % (url('action', bg=True), buttonWidth)"/>
|
||||
</form>''')
|
||||
|
||||
|
@ -78,13 +82,24 @@ class Action(Field):
|
|||
|
||||
def getDefaultLayouts(self): return {'view': 'l-f', 'edit': 'lrv-f'}
|
||||
|
||||
def callAction(self, obj, method, hasParam, param):
|
||||
'''Calls p_method on p_obj. m_method can be the single action as defined
|
||||
in self.action or one of them is self.action contains several
|
||||
methods. Calling m_method can be done with a p_param (when p_hasParam
|
||||
is True), ie, when self.confirm is "text".'''
|
||||
if hasParam: return method(obj, param)
|
||||
else: return method(obj)
|
||||
|
||||
def __call__(self, 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)
|
||||
if type(self.action) in sutils.sequenceTypes:
|
||||
# There are multiple Python methods
|
||||
res = [True, '']
|
||||
for act in self.action:
|
||||
actRes = act(obj)
|
||||
actRes = self.callAction(obj, act, hasParam, param)
|
||||
if type(actRes) in sutils.sequenceTypes:
|
||||
res[0] = res[0] and actRes[0]
|
||||
if self.result.startswith('file'):
|
||||
|
@ -95,7 +110,7 @@ class Action(Field):
|
|||
res[0] = res[0] and actRes
|
||||
else:
|
||||
# There is only one Python method
|
||||
actRes = self.action(obj)
|
||||
actRes = self.callAction(obj, self.action, hasParam, param)
|
||||
if type(actRes) in sutils.sequenceTypes:
|
||||
res = list(actRes)
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue