Added imagemap preview in paragraph
authorThierry Florac <thierry.florac@onf.fr>
Fri, 13 Oct 2017 08:44:18 +0200
changeset 231 fbca11f0c1f4
parent 230 dabf155776a9
child 232 f08f65ad0818
Added imagemap preview in paragraph
src/pyams_content/shared/imagemap/zmi/paragraph.py
src/pyams_content/shared/imagemap/zmi/templates/imagemap-preview.pt
--- a/src/pyams_content/shared/imagemap/zmi/paragraph.py	Fri Oct 13 08:41:15 2017 +0200
+++ b/src/pyams_content/shared/imagemap/zmi/paragraph.py	Fri Oct 13 08:44:18 2017 +0200
@@ -23,7 +23,7 @@
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_content.shared.common.interfaces import IWfSharedContent
 from pyams_content.shared.imagemap.interfaces import IImageMapParagraph
-from pyams_form.interfaces.form import IInnerForm, IEditFormButtons
+from pyams_form.interfaces.form import IInnerForm, IEditFormButtons, IWidgetsSuffixViewletsManager
 from pyams_i18n.interfaces import II18n
 from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
 from pyams_skin.layer import IPyAMSLayer
@@ -38,7 +38,7 @@
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.traversing import get_parent
-from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider
+from pyams_viewlet.viewlet import viewlet_config, BaseContentProvider, Viewlet
 from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm
 from pyramid.view import view_config
 from z3c.form import field, button
@@ -128,6 +128,30 @@
 class ImagemapParagraphInnerAJAXEditForm(BaseParagraphAJAXEditForm, ImagemapParagraphInnerEditForm):
     """Image map paragraph properties inner edit form, JSON rendener"""
 
+    def get_ajax_output(self, changes):
+        output = super(ImagemapParagraphInnerAJAXEditForm, self).get_ajax_output(changes)
+        if 'reference' in changes.get(IImageMapParagraph, ()):
+            form = ImagemapParagraphInnerEditForm(self.context, self.request)
+            form.update()
+            content = form.getContent()
+            output.setdefault('events', []).append({
+                'event': 'PyAMS_content.changed_item',
+                'options': {'handler': 'PyAMS_content.refreshForm',
+                            'object_name': '{0}_{1}_{2}'.format(
+                                content.__class__.__name__,
+                                getattr(content, '__name__', 'noname').replace('++', ''),
+                                form.id),
+                            'form': form.render()}
+            })
+        return output
+
+
+@viewlet_config(name='imagemap-preview', context=IImageMapParagraph, request=IPyAMSLayer,
+                view=ImagemapParagraphInnerEditForm, manager=IWidgetsSuffixViewletsManager, weight=1)
+@template_config(template='templates/imagemap-preview.pt', layer=IPyAMSLayer)
+class ImagemapParagraphPreviewWidgetsSuffix(Viewlet):
+    """Image map paragraph preview widgets suffix"""
+
 
 #
 # Image map paragraph summary
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/shared/imagemap/zmi/templates/imagemap-preview.pt	Fri Oct 13 08:44:18 2017 +0200
@@ -0,0 +1,8 @@
+<div class="form-group" i18n:domain="pyams_content">
+	<div class="col-md-3"><!-- empty marker --></div>
+	<div class="col-md-9">
+		<img tal:define="map context.get_target();
+						 image i18n:map.image;"
+			 tal:attributes="src extension:absolute_url(image, '++thumb++600x480')" />
+	</div>
+</div>