Updated edit form
authorThierry Florac <thierry.florac@onf.fr>
Wed, 13 Jun 2018 11:30:50 +0200
changeset 636 1d0b1d4b3770
parent 635 ac6c59149f0d
child 637 20e36155fb1c
Updated edit form
src/pyams_content/features/footer/zmi/__init__.py
--- a/src/pyams_content/features/footer/zmi/__init__.py	Wed Jun 13 11:30:18 2018 +0200
+++ b/src/pyams_content/features/footer/zmi/__init__.py	Wed Jun 13 11:30:50 2018 +0200
@@ -132,6 +132,8 @@
     fields = field.Fields(IFooterSettings).select('renderer')
     weight = 1
 
+    _changes = None
+
     def __init__(self, context, request, group):
         context = IFooterSettings(context)
         super(FooterSettingsRendererEditSubform, self).__init__(context, request, group)
@@ -152,13 +154,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(FooterSettingsRendererEditSubform, 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(FooterSettingsRendererEditSubform, self).get_ajax_output(changes)
+
 
 @adapter_config(name='footer-renderer-settings-form',
                 context=(IFooterRendererSettings, IPyAMSLayer, FooterSettingsRendererEditSubform),