--- a/src/pyams_content/component/illustration/zmi/paragraph.py Wed Jun 06 13:32:14 2018 +0200
+++ b/src/pyams_content/component/illustration/zmi/paragraph.py Fri Jun 08 10:33:23 2018 +0200
@@ -33,12 +33,12 @@
from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, get_json_paragraph_refresh_event, 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_form_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
@@ -62,6 +62,8 @@
@pagelet_config(name='add-illustration.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='add-illustration.json', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+ base=BaseParagraphAJAXAddForm)
class IllustrationAddForm(AdminDialogAddForm):
"""Illustration add form"""
@@ -71,7 +73,7 @@
fields = field.Fields(IIllustrationParagraph).select('data', 'title', 'alt_title', 'description',
'author', 'renderer')
- ajax_handler = 'add-illustration.json'
+
edit_permission = MANAGE_CONTENT_PERMISSION
def updateWidgets(self, prefix=None):
@@ -86,14 +88,10 @@
IParagraphContainer(self.context).append(object)
-@view_config(name='add-illustration.json', context=IParagraphContainerTarget, request_type=IPyAMSLayer,
- permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-class IllustrationAJAXAddForm(BaseParagraphAJAXAddForm, IllustrationAddForm):
- """HTML paragraph add form, JSON renderer"""
-
-
@pagelet_config(name='properties.html', context=IIllustrationParagraph, layer=IPyAMSLayer,
permission=MANAGE_CONTENT_PERMISSION)
+@ajax_config(name='properties.json', context=IIllustrationParagraph, layer=IPyAMSLayer,
+ base=BaseParagraphAJAXEditForm)
class IllustrationPropertiesEditForm(BaseParagraphPropertiesEditForm):
"""Illustration properties edit form"""
@@ -107,7 +105,6 @@
'author', 'renderer')
fields['renderer'].widgetFactory = RendererFieldWidget
- ajax_handler = 'properties.json'
edit_permission = MANAGE_CONTENT_PERMISSION
def updateWidgets(self, prefix=None):
@@ -115,26 +112,21 @@
if 'description' in self.widgets:
self.widgets['description'].widget_css_class = 'textarea'
-
-@view_config(name='properties.json', context=IIllustrationParagraph, request_type=IPyAMSLayer,
- permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-class IllustrationPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, IllustrationPropertiesEditForm):
- """Illustration properties edit form, JSON renderer"""
-
def get_ajax_output(self, changes):
- output = super(IllustrationPropertiesAJAXEditForm, self).get_ajax_output(changes)
+ output = super(self.__class__, self).get_ajax_output(changes)
if 'title' in changes.get(IIllustration, ()):
output.setdefault('events', []).append(get_json_paragraph_refresh_event(self.context, self.request))
return output
@adapter_config(context=(IIllustrationParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
+@ajax_config(name='inner-properties.json', context=IIllustrationParagraph, layer=IPyAMSLayer,
+ base=BaseParagraphAJAXEditForm)
@implementer(IInnerForm)
class IllustrationInnerEditForm(IllustrationPropertiesEditForm):
"""Illustration inner edit form"""
legend = None
- ajax_handler = 'inner-properties.json'
@property
def buttons(self):
@@ -143,14 +135,8 @@
else:
return button.Buttons()
-
-@view_config(name='inner-properties.json', context=IIllustrationParagraph, request_type=IPyAMSLayer,
- permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
-class IllustrationInnerAJAXEditForm(BaseParagraphAJAXEditForm, IllustrationInnerEditForm):
- """Illustration paragraph inner edit form, JSON renderer"""
-
def get_ajax_output(self, changes):
- output = super(IllustrationInnerAJAXEditForm, self).get_ajax_output(changes)
+ output = super(self.__class__, self).get_ajax_output(changes)
updated = changes.get(IIllustration, ())
if 'title' in updated:
output.setdefault('events', []).append(get_json_paragraph_refresh_event(self.context, self.request))