From 4a393e76aff12fbce098b9002a4ebb98caa69061 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Mon, 10 Nov 2014 13:34:52 +0100 Subject: [PATCH] [gen] Allow an ajax request to return a message, carried as a custom HTTP header and retrieved by appy.js to display a message. --- fields/action.py | 13 +++++++------ gen/mixins/ToolMixin.py | 7 ++++--- gen/ui/appy.js | 12 ++++++++++++ gen/wrappers/ToolWrapper.py | 10 ++++++---- gen/wrappers/__init__.py | 6 ++++-- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/fields/action.py b/fields/action.py index 1170e15..14e64f1 100644 --- a/fields/action.py +++ b/fields/action.py @@ -52,12 +52,13 @@ class Action(Field): pxEdit = pxSearch = '' def __init__(self, validator=None, multiplicity=(1,1), default=None, - show=True, page='main', group=None, layouts=None, move=0, - indexed=False, searchable=False, specificReadPermission=False, - specificWritePermission=False, width=None, height=None, - maxChars=None, colspan=1, action=None, result='computation', - confirm=False, master=None, masterValue=None, focus=False, - historized=False, mapping=None, label=None): + show=('view', 'result'), page='main', group=None, layouts=None, + move=0, indexed=False, searchable=False, + specificReadPermission=False, specificWritePermission=False, + width=None, height=None, maxChars=None, colspan=1, action=None, + result='computation', confirm=False, master=None, + masterValue=None, focus=False, historized=False, mapping=None, + label=None): # Can be a single method or a list/tuple of methods self.action = action # For the 'result' param: diff --git a/gen/mixins/ToolMixin.py b/gen/mixins/ToolMixin.py index 4f09a98..f581c83 100644 --- a/gen/mixins/ToolMixin.py +++ b/gen/mixins/ToolMixin.py @@ -1284,9 +1284,10 @@ class ToolMixin(BaseMixin): chunk. This method executes this action.''' if action.startswith(':'): # The action corresponds to a method on Appy p_obj. - getattr(obj, action[1:])() + msg = getattr(obj, action[1:])() else: # The action must be executed on p_field if present, on obj.o else. - if field: getattr(field, action)(obj.o) - else: getattr(obj.o, action)() + if field: msg = getattr(field, action)(obj.o) + else: msg = getattr(obj.o, action)() + return msg # ------------------------------------------------------------------------------ diff --git a/gen/ui/appy.js b/gen/ui/appy.js index c17eca4..b44edee 100644 --- a/gen/ui/appy.js +++ b/gen/ui/appy.js @@ -148,6 +148,9 @@ function getAjaxChunk(pos) { for (var i=0; i + ''') +
+ + ''') # The page footer. pxFooter = Px(''' diff --git a/gen/wrappers/__init__.py b/gen/wrappers/__init__.py index 1c726c1..443fd53 100644 --- a/gen/wrappers/__init__.py +++ b/gen/wrappers/__init__.py @@ -632,10 +632,12 @@ class AbstractWrapper(object): x=resp.setHeader('Content-type', ztool.xhtmlEncoding); x=resp.setHeader('Expires', 'Thu, 11 Dec 1975 12:05:00 GMT+2'); x=resp.setHeader('Content-Language', lang); - x=resp.setHeader('CacheControl', 'no-cache')"> + x=resp.setHeader('Cache-Control', 'no-cache')"> - + :getattr(obj, px[0])