--- a/src/pyams_content/component/illustration/zmi/__init__.py Wed Apr 11 16:44:46 2018 +0200
+++ b/src/pyams_content/component/illustration/zmi/__init__.py Wed Apr 11 16:46:31 2018 +0200
@@ -17,6 +17,7 @@
# import interfaces
from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationTarget
+from pyams_content.component.paragraph import IBaseParagraph
from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar
from pyams_form.interfaces.form import IInnerSubForm, IWidgetsPrefixViewletsManager
from pyams_skin.layer import IPyAMSLayer
@@ -26,14 +27,16 @@
from transaction.interfaces import ITransactionManager
# import packages
+from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event
from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
from pyams_content.skin import pyams_content
from pyams_form.security import ProtectedFormObjectMixin
+from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event
from pyams_skin.viewlet.toolbar import JsToolbarAction
from pyams_template.template import template_config
from pyams_utils.adapter import adapter_config
from pyams_utils.fanstatic import get_resource_path
-from pyams_viewlet.viewlet import viewlet_config, Viewlet
+from pyams_viewlet.viewlet import viewlet_config, Viewlet, EmptyViewlet
from pyams_zmi.form import InnerAdminEditForm
from z3c.form import field
from zope.interface import implementer
@@ -56,14 +59,15 @@
icon_class = 'fa fa-fw fa-file-image-o'
icon_hint = _("Illustration")
- def __new__(cls, context, request, view, manager):
- illustration = IIllustration(context, None)
- if (not illustration) or not illustration.data:
- return None
- for value in illustration.data.values():
- if value:
- return Viewlet.__new__(cls)
- return None
+ marker_type = 'illustration'
+
+ def render(self):
+ illustration = IIllustration(self.context, None)
+ if illustration and illustration.data:
+ for value in illustration.data.values():
+ if value:
+ return super(ParagraphContainerIllustrationMarker, self).render()
+ return ''
@adapter_config(name='illustration', context=(IIllustrationTarget, IPyAMSLayer, IPropertiesEditForm),
@@ -101,35 +105,23 @@
def get_ajax_output(self, changes):
output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
updated = changes.get(IIllustration, ())
- if ('data' in updated) or ('renderer' in updated):
- if 'data' in updated:
- # we have to commit transaction to be able to handle blobs...
- ITransactionManager(self.context).get().commit()
- form = IllustrationPropertiesInnerEditForm(self.context, self.request)
- form.update()
- illustration = form.getContent()
- output.setdefault('events', []).append({
- 'event': 'myams.refresh',
- 'options': {
- 'object_id': '{0}_{1}_{2}'.format(
- self.context.__class__.__name__,
- getattr(illustration, '__name__', 'noname').replace('++', ''),
- form.id),
- 'content': form.render()
- }
- })
- viewlet = ParagraphContainerIllustrationMarker(self.context, self.request, self, None)
- if viewlet is not None:
- viewlet.update()
- output.setdefault('events', []).append({
- 'event': 'myams.refresh',
- 'options': {
- 'handler': 'PyAMS_content.paragraphs.updateMarkers',
- 'object_name': self.context.__name__,
- 'marker_type': 'illustration',
- 'marker_tag': viewlet.render() if viewlet is not None else ''
- }
- })
+ events = output.setdefault('events', [])
+ if 'data' in updated:
+ # we have to commit transaction to be able to handle blobs...
+ ITransactionManager(self.context).get().commit()
+ events.append(get_json_form_refresh_event(self.context, self.request,
+ IllustrationPropertiesInnerEditForm))
+ if IBaseParagraph.providedBy(self.context):
+ if self.getContent().data:
+ events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self,
+ ParagraphContainerIllustrationMarker))
+ else:
+ events.append(get_json_paragraph_markers_refresh_event(self.context, self.request, self,
+ EmptyViewlet,
+ ParagraphContainerIllustrationMarker.marker_type))
+ elif 'renderer' in updated:
+ events.append(get_json_widget_refresh_event(self.context, self.request,
+ IllustrationPropertiesInnerEditForm, 'renderer'))
return output