Updated formp AJAX output
authorThierry Florac <thierry.florac@onf.fr>
Wed, 13 Jun 2018 08:47:14 +0200
changeset 628 baf2d9499054
parent 627 e350df2967ea
child 629 760b1b1dff20
Updated formp AJAX output
src/pyams_content/features/header/zmi/__init__.py
--- a/src/pyams_content/features/header/zmi/__init__.py	Tue Jun 12 14:32:37 2018 +0200
+++ b/src/pyams_content/features/header/zmi/__init__.py	Wed Jun 13 08:47:14 2018 +0200
@@ -138,6 +138,8 @@
     fields = field.Fields(IHeaderSettings).select('renderer')
     weight = 1
 
+    _changes = None
+
     def __init__(self, context, request, group):
         context = IHeaderSettings(context)
         super(HeaderSettingsRendererEditSubform, self).__init__(context, request, group)
@@ -158,13 +160,24 @@
             alsoProvides(widget, IObjectData)
 
     def get_forms(self, include_self=True):
-        if include_self and self.request.method == 'POST':
+        if include_self and (self._changes is None) and (self.request.method == 'POST'):
             data, errors = self.extractData()
             if not errors:
-                self.applyChanges(data)
+                self._changes = self.applyChanges(data)
         for form in super(HeaderSettingsRendererEditSubform, self).get_forms(include_self):
             yield form
 
+    def get_ajax_output(self, changes):
+        if not changes:
+            changes = self._changes
+        if changes:
+            return {
+                'status': 'success',
+                'message': self.request.localizer.translate(self.successMessage)
+            }
+        else:
+            return super(HeaderSettingsRendererEditSubform, self).get_ajax_output(changes)
+
 
 @adapter_config(name='header-renderer-settings-form',
                 context=(IHeaderRendererSettings, IPyAMSLayer, HeaderSettingsRendererEditSubform),