Updated portlet properties AJAX response
authorThierry Florac <thierry.florac@onf.fr>
Mon, 18 Jun 2018 17:11:37 +0200
changeset 118 15e0ccc31b91
parent 117 4d5187421912
child 119 d2d0c38fa8f8
Updated portlet properties AJAX response
src/pyams_portal/zmi/portlet.py
--- a/src/pyams_portal/zmi/portlet.py	Fri Jun 15 15:40:26 2018 +0200
+++ b/src/pyams_portal/zmi/portlet.py	Mon Jun 18 17:11:37 2018 +0200
@@ -26,6 +26,7 @@
 from pyams_form.form import ajax_config
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_portal.zmi.widget import PortletRendererFieldWidget
+from pyams_skin.event import get_json_widget_refresh_event
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.url import absolute_url
@@ -108,6 +109,24 @@
 
     weight = 10
 
+    def get_ajax_output(self, changes):
+
+        def get_form_factory(context, request):
+            return PortletSettingsPropertiesEditor(context, request, self.parent_form)
+
+        output = super(PortletSettingsPropertiesEditor, self).get_ajax_output(changes)
+        if 'renderer' in changes.get(IPortletSettings, ()):
+            renderer = self.context.get_renderer()
+            if (renderer is not None) and \
+               (renderer.target_interface is None) and \
+               (renderer.settings_interface is not None):
+                output.update({
+                    'close_form': False
+                })
+                output.setdefault('events', []).append(
+                    get_json_widget_refresh_event(self.context, self.request, get_form_factory, 'renderer'))
+        return output
+
 
 #
 # Portlet renderer settings edit form