src/pyams_content/component/paragraph/zmi/verbatim.py
changeset 591 b694d5667d17
parent 555 8e8a14452567
child 842 7f0d72e427b1
--- a/src/pyams_content/component/paragraph/zmi/verbatim.py	Wed Jun 06 13:32:14 2018 +0200
+++ b/src/pyams_content/component/paragraph/zmi/verbatim.py	Fri Jun 08 10:33:23 2018 +0200
@@ -32,12 +32,12 @@
 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, IParagraphEditFormButtons
 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
+from pyams_form.form import ajax_config
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.event import get_json_widget_refresh_event
 from pyams_utils.adapter import adapter_config
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogAddForm
-from pyramid.view import view_config
 from z3c.form import field, button
 from zope.interface import implementer
 
@@ -61,6 +61,8 @@
 
 @pagelet_config(name='add-verbatim-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
                 permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='add-verbatim-paragraph.json', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+             base=BaseParagraphAJAXAddForm)
 class VerbatimParagraphAddForm(AdminDialogAddForm):
     """Verbatim paragraph add form"""
 
@@ -68,7 +70,6 @@
     icon_css_class = 'fa fa-fw fa-quote-right'
 
     fields = field.Fields(IVerbatimParagraph).omit('__parent__', '__name__', 'visible')
-    ajax_handler = 'add-verbatim-paragraph.json'
     edit_permission = MANAGE_CONTENT_PERMISSION
 
     def updateWidgets(self, prefix=None):
@@ -83,14 +84,10 @@
         IParagraphContainer(self.context).append(object)
 
 
-@view_config(name='add-verbatim-paragraph.json', context=IParagraphContainerTarget, request_type=IPyAMSLayer,
-             permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-class VerbatimParagraphAJAXAddForm(BaseParagraphAJAXAddForm, VerbatimParagraphAddForm):
-    """Verbatim paragraph add form, JSON renderer"""
-
-
 @pagelet_config(name='properties.html', context=IVerbatimParagraph, layer=IPyAMSLayer,
                 permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='properties.json', context=IVerbatimParagraph, layer=IPyAMSLayer,
+             base=BaseParagraphAJAXEditForm)
 class VerbatimParagraphPropertiesEditForm(BaseParagraphPropertiesEditForm):
     """Verbatim paragraph properties edit form"""
 
@@ -102,7 +99,6 @@
     fields = field.Fields(IVerbatimParagraph).omit('__parent__', '__name__', 'visible')
     fields['renderer'].widgetFactory = RendererFieldWidget
 
-    ajax_handler = 'properties.json'
     edit_permission = MANAGE_CONTENT_PERMISSION
 
     def updateWidgets(self, prefix=None):
@@ -111,19 +107,14 @@
             self.widgets['quote'].widget_css_class = 'textarea'
 
 
-@view_config(name='properties.json', context=IVerbatimParagraph, request_type=IPyAMSLayer,
-             permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-class VerbatimParagraphPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, VerbatimParagraphPropertiesEditForm):
-    """Verbatim paragraph properties edit form, JSON renderer"""
-
-
 @adapter_config(context=(IVerbatimParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
+@ajax_config(name='inner-properties.json', context=IVerbatimParagraph, layer=IPyAMSLayer,
+             base=BaseParagraphAJAXEditForm)
 @implementer(IInnerForm, IPropertiesEditForm, IAssociationsParentForm)
 class VerbatimParagraphInnerEditForm(VerbatimParagraphPropertiesEditForm):
     """Verbatim paragraph inner edit form"""
 
     legend = None
-    ajax_handler = 'inner-properties.json'
 
     @property
     def buttons(self):
@@ -132,14 +123,8 @@
         else:
             return button.Buttons()
 
-
-@view_config(name='inner-properties.json', context=IVerbatimParagraph, request_type=IPyAMSLayer,
-             permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-class VerbatimParagraphInnerAJAXEditForm(BaseParagraphAJAXEditForm, VerbatimParagraphInnerEditForm):
-    """Verbatim paragraph inner edit form, JSON renderer"""
-
     def get_ajax_output(self, changes):
-        output = super(VerbatimParagraphInnerAJAXEditForm, self).get_ajax_output(changes)
+        output = super(self.__class__, self).get_ajax_output(changes)
         updated = changes.get(IVerbatimParagraph, ())
         if 'renderer' in updated:
             output.setdefault('events', []).append(