Revert AJAX configuration in header and footer edit forms
authorThierry Florac <thierry.florac@onf.fr>
Fri, 08 Jun 2018 16:21:52 +0200
changeset 595 f6ecc99e4745
parent 594 9386c04e9dec
child 596 0d1df0c8f195
Revert AJAX configuration in header and footer edit forms
src/pyams_content/features/footer/zmi/__init__.py
src/pyams_content/features/header/zmi/__init__.py
--- a/src/pyams_content/features/footer/zmi/__init__.py	Fri Jun 08 16:20:31 2018 +0200
+++ b/src/pyams_content/features/footer/zmi/__init__.py	Fri Jun 08 16:21:52 2018 +0200
@@ -29,10 +29,10 @@
 from z3c.form.interfaces import INPUT_MODE
 
 # import packages
-from pyams_form.form import ajax_config
+from pyams_form.form import AJAXEditForm
 from pyams_form.group import NamedWidgetsGroup
 from pyams_pagelet.pagelet import pagelet_config
-from pyams_skin.viewlet.menu import MenuItem
+from pyams_skin.viewlet.menu import MenuItem, MenuDivider
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.url import absolute_url
@@ -63,8 +63,6 @@
 
 @pagelet_config(name='footer-settings.html', context=IFooterTarget, layer=IPyAMSLayer,
                 permission=MANAGE_TEMPLATE_PERMISSION)
-@ajax_config(name='footer-settings.json', context=IFooterTarget, layer=IPyAMSLayer,
-             permission=MANAGE_TEMPLATE_PERMISSION)
 @implementer(IWidgetForm, IInnerPage)
 class FooterSettingsEditForm(AdminEditForm):
     """Footer settings edit form"""
@@ -94,6 +92,8 @@
         else:
             return button.Buttons(Interface)
 
+    ajax_handler = 'footer-settings.json'
+
     def updateGroups(self):
         if self.getContent().can_inherit:
             group = NamedWidgetsGroup(self, 'footer', self.widgets,
@@ -110,8 +110,14 @@
         self.add_group(group)
         super(FooterSettingsEditForm, self).updateGroups()
 
+
+@view_config(name='footer-settings.json', context=IFooterTarget, request_type=IPyAMSLayer,
+             permission=MANAGE_TEMPLATE_PERMISSION, renderer='json', xhr=True)
+class FooterSettingsAJAXEditForm(AJAXEditForm, FooterSettingsEditForm):
+    """Footer settings edit form, JSON renderer"""
+
     def get_ajax_output(self, changes):
-        output = super(self.__class__, self).get_ajax_output(changes) or {}
+        output = super(FooterSettingsAJAXEditForm, self).get_ajax_output(changes) or {}
         if 'no_inherit' in changes.get(IInheritInfo, ()):
             output['status'] = 'reload'
         return output
@@ -158,7 +164,7 @@
                 context=(IFooterRendererSettings, IPyAMSLayer, FooterSettingsRendererEditSubform),
                 provides=IInnerSubForm)
 @adapter_config(name='footer-renderer-settings-form',
-                context=(IFooterTarget, IPyAMSLayer, FooterSettingsEditForm),
+                context=(IFooterTarget, IPyAMSLayer, FooterSettingsAJAXEditForm),
                 provides=IInnerSubForm)
 class FooterSettingsRendererSettingsEditForm(InnerAdminEditForm):
     """Footer settings renderer settings edit form"""
--- a/src/pyams_content/features/header/zmi/__init__.py	Fri Jun 08 16:20:31 2018 +0200
+++ b/src/pyams_content/features/header/zmi/__init__.py	Fri Jun 08 16:21:52 2018 +0200
@@ -29,7 +29,7 @@
 from z3c.form.interfaces import INPUT_MODE
 
 # import packages
-from pyams_form.form import ajax_config
+from pyams_form.form import AJAXEditForm
 from pyams_form.group import NamedWidgetsGroup
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.viewlet.menu import MenuItem, MenuDivider
@@ -69,8 +69,6 @@
 
 @pagelet_config(name='header-settings.html', context=IHeaderTarget, layer=IPyAMSLayer,
                 permission=MANAGE_TEMPLATE_PERMISSION)
-@ajax_config(name='header-settings.json', context=IHeaderTarget, layer=IPyAMSLayer,
-             permission=MANAGE_TEMPLATE_PERMISSION)
 @implementer(IWidgetForm, IInnerPage)
 class HeaderSettingsEditForm(AdminEditForm):
     """Header settings edit form"""
@@ -100,6 +98,8 @@
         else:
             return button.Buttons(Interface)
 
+    ajax_handler = 'header-settings.json'
+
     def updateGroups(self):
         if self.getContent().can_inherit:
             group = NamedWidgetsGroup(self, 'header', self.widgets,
@@ -116,8 +116,14 @@
         self.add_group(group)
         super(HeaderSettingsEditForm, self).updateGroups()
 
+
+@view_config(name='header-settings.json', context=IHeaderTarget, request_type=IPyAMSLayer,
+             permission=MANAGE_TEMPLATE_PERMISSION, renderer='json', xhr=True)
+class HeaderSettingsAJAXEditForm(AJAXEditForm, HeaderSettingsEditForm):
+    """Header settings edit form, JSON renderer"""
+
     def get_ajax_output(self, changes):
-        output = super(self.__class__, self).get_ajax_output(changes) or {}
+        output = super(HeaderSettingsAJAXEditForm, self).get_ajax_output(changes) or {}
         if 'no_inherit' in changes.get(IInheritInfo, ()):
             output['status'] = 'reload'
         return output
@@ -164,7 +170,7 @@
                 context=(IHeaderRendererSettings, IPyAMSLayer, HeaderSettingsRendererEditSubform),
                 provides=IInnerSubForm)
 @adapter_config(name='header-renderer-settings-form',
-                context=(IHeaderTarget, IPyAMSLayer, HeaderSettingsEditForm),
+                context=(IHeaderTarget, IPyAMSLayer, HeaderSettingsAJAXEditForm),
                 provides=IInnerSubForm)
 class HeaderSettingsRendererSettingsEditForm(InnerAdminEditForm):
     """Header settings renderer settings edit form"""