src/pyams_content/shared/form/zmi/field.py
changeset 591 b694d5667d17
parent 527 5dd1aa8bedd9
child 789 7c0f6dfc6387
--- a/src/pyams_content/shared/form/zmi/field.py	Wed Jun 06 13:32:14 2018 +0200
+++ b/src/pyams_content/shared/form/zmi/field.py	Fri Jun 08 10:33:23 2018 +0200
@@ -35,7 +35,7 @@
 # import packages
 from pyams_content.shared.common.zmi import WfModifiedContentColumnMixin
 from pyams_content.shared.form.field import FormField
-from pyams_form.form import AJAXAddForm, AJAXEditForm
+from pyams_form.form import AJAXAddForm, ajax_config
 from pyams_form.security import ProtectedFormObjectMixin
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.container import switch_element_visibility
@@ -231,6 +231,8 @@
 
 @pagelet_config(name='add-form-field.html', context=IFormFieldContainerTarget, layer=IPyAMSLayer,
                 permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='add-form-field.json', context=IFormFieldContainerTarget, layer=IPyAMSLayer,
+             base=AJAXAddForm)
 class FormFieldAddForm(AdminDialogAddForm):
     """Form field add form"""
 
@@ -238,7 +240,6 @@
     icon_css_class = 'fa fa-fw fa-pencil-square-o'
 
     fields = field.Fields(IFormField).omit('__parent__', '__name__', 'visible')
-    ajax_handler = 'add-form-field.json'
     edit_permission = MANAGE_CONTENT_PERMISSION
 
     def updateWidgets(self, prefix=None):
@@ -252,6 +253,9 @@
     def add(self, object):
         IFormFieldContainer(self.context)[object.name] = object
 
+    def nextURL(self):
+        return '#form-fields.html'
+
 
 @subscriber(IDataExtractedEvent, form_selector=FormFieldAddForm)
 def handle_new_form_field_data_extraction(event):
@@ -262,16 +266,8 @@
         event.form.widgets.errors += (Invalid(_("Specified name is already used!")),)
 
 
-@view_config(name='add-form-field.json', context=IFormFieldContainerTarget, request_type=IPyAMSLayer,
-             permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-class FormFieldAJAXAddForm(AJAXAddForm, FormFieldAddForm):
-    """Form field add form, JSON renderer"""
-
-    def nextURL(self):
-        return '#form-fields.html'
-
-
 @pagelet_config(name='properties.html', context=IFormField, layer=IPyAMSLayer, permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='properties.json', context=IFormField, layer=IPyAMSLayer)
 class FormFieldPropertiesEditForm(AdminDialogEditForm):
     """Form field properties edit form"""
 
@@ -286,7 +282,6 @@
     icon_class = 'fa fa-fw fa-pencil-square-o'
 
     fields = field.Fields(IFormField).omit('__parent__', '__name__', 'visible')
-    ajax_handler = 'properties.json'
     edit_permission = MANAGE_CONTENT_PERMISSION
 
     def updateWidgets(self, prefix=None):
@@ -296,14 +291,8 @@
         if 'description' in self.widgets:
             self.widgets['description'].widget_css_class = 'textarea'
 
-
-@view_config(name='properties.json', context=IFormField, request_type=IPyAMSLayer,
-             permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-class FormFieldPropertiesAJAXEditForm(AJAXEditForm, FormFieldPropertiesEditForm):
-    """Form field properties edit form, JSON renderer"""
-
     def get_ajax_output(self, changes):
-        output = super(FormFieldPropertiesAJAXEditForm, self).get_ajax_output(changes)
+        output = super(self.__class__, self).get_ajax_output(changes)
         if 'label' in changes.get(IFormField, ()):
             output.setdefault('events', []).append({
                 'event': 'myams.refresh',