Updated form events to only refresh renderer input widget on update
authorThierry Florac <thierry.florac@onf.fr>
Tue, 20 Mar 2018 13:51:32 +0100
changeset 489 dcdb0ce828f8
parent 488 826448236ec9
child 490 30fcd0659601
Updated form events to only refresh renderer input widget on update
src/pyams_content/component/association/zmi/paragraph.py
src/pyams_content/component/illustration/zmi/__init__.py
src/pyams_content/component/paragraph/zmi/frame.py
src/pyams_content/component/paragraph/zmi/header.py
src/pyams_content/component/paragraph/zmi/keypoint.py
src/pyams_content/component/paragraph/zmi/milestone.py
src/pyams_content/component/paragraph/zmi/pictogram.py
src/pyams_content/component/paragraph/zmi/verbatim.py
src/pyams_content/component/paragraph/zmi/video.py
src/pyams_content/shared/logo/zmi/paragraph.py
--- a/src/pyams_content/component/association/zmi/paragraph.py	Tue Mar 20 13:50:46 2018 +0100
+++ b/src/pyams_content/component/association/zmi/paragraph.py	Tue Mar 20 13:51:32 2018 +0100
@@ -139,11 +139,13 @@
             output.setdefault('events', []).append({
                 'event': 'myams.refresh',
                 'options': {
-                    'object_id': '{0}_{1}_{2}'.format(
+                    'handler': 'MyAMS.skin.refreshWidget',
+                    'parent_id': '{0}_{1}_{2}'.format(
                         self.context.__class__.__name__,
                         getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
                         form.id),
-                    'content': form.render()
+                    'widget_name': form.widgets['renderer'].name,
+                    'content': form.widgets['renderer'].render()
                 }
             })
         return output
--- a/src/pyams_content/component/illustration/zmi/__init__.py	Tue Mar 20 13:50:46 2018 +0100
+++ b/src/pyams_content/component/illustration/zmi/__init__.py	Tue Mar 20 13:51:32 2018 +0100
@@ -100,10 +100,11 @@
 
     def get_ajax_output(self, changes):
         output = super(IllustrationPropertiesInnerEditForm, self).get_ajax_output(changes)
-        illustration_changes = changes.get(IIllustration, ())
-        if ('data' in illustration_changes) or ('renderer' in illustration_changes):
-            # we have to commit transaction to be able to handle blobs...
-            ITransactionManager(self.context).get().commit()
+        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()
--- a/src/pyams_content/component/paragraph/zmi/frame.py	Tue Mar 20 13:50:46 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/frame.py	Tue Mar 20 13:51:32 2018 +0100
@@ -207,17 +207,20 @@
 
     def get_ajax_output(self, changes):
         output = super(FrameParagraphInnerAJAXEditForm, self).get_ajax_output(changes)
-        if 'renderer' in changes.get(IFrameParagraph, ()):
+        updated = changes.get(IFrameParagraph, ())
+        if 'renderer' in updated:
             form = FrameParagraphInnerEditForm(self.context, self.request)
             form.update()
             output.setdefault('events', []).append({
                 'event': 'myams.refresh',
                 'options': {
-                    'object_id': '{0}_{1}_{2}'.format(
+                    'handler': 'MyAMS.skin.refreshWidget',
+                    'parent_id': '{0}_{1}_{2}'.format(
                         self.context.__class__.__name__,
                         getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
                         form.id),
-                    'content': form.render()
+                    'widget_name': form.widgets['renderer'].name,
+                    'content': form.widgets['renderer'].render()
                 }
             })
         return output
--- a/src/pyams_content/component/paragraph/zmi/header.py	Tue Mar 20 13:50:46 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/header.py	Tue Mar 20 13:51:32 2018 +0100
@@ -158,11 +158,13 @@
             output.setdefault('events', []).append({
                 'event': 'myams.refresh',
                 'options': {
-                    'object_id': '{0}_{1}_{2}'.format(
+                    'handler': 'MyAMS.skin.refreshWidget',
+                    'parent_id': '{0}_{1}_{2}'.format(
                         self.context.__class__.__name__,
                         getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
                         form.id),
-                    'content': form.render()
+                    'widget_name': form.widgets['renderer'].name,
+                    'content': form.widgets['renderer'].render()
                 }
             })
         return output
--- a/src/pyams_content/component/paragraph/zmi/keypoint.py	Tue Mar 20 13:50:46 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/keypoint.py	Tue Mar 20 13:51:32 2018 +0100
@@ -158,11 +158,13 @@
             output.setdefault('events', []).append({
                 'event': 'myams.refresh',
                 'options': {
-                    'object_id': '{0}_{1}_{2}'.format(
+                    'handler': 'MyAMS;skin.refreshWidget',
+                    'parent_id': '{0}_{1}_{2}'.format(
                         self.context.__class__.__name__,
                         getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
                         form.id),
-                    'content': form.render()
+                    'widget_name': form.widgets['renderer'].name,
+                    'content': form.widgets['renderer'].render()
                 }
             })
         return output
--- a/src/pyams_content/component/paragraph/zmi/milestone.py	Tue Mar 20 13:50:46 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/milestone.py	Tue Mar 20 13:51:32 2018 +0100
@@ -163,11 +163,13 @@
             output.setdefault('events', []).append({
                 'event': 'myams.refresh',
                 'options': {
-                    'object_id': '{0}_{1}_{2}'.format(
+                    'handler': 'MyAMS.skin.refreshWidget',
+                    'parent_id': '{0}_{1}_{2}'.format(
                         self.context.__class__.__name__,
                         getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
                         form.id),
-                    'content': form.render()
+                    'widget_name': form.widgets['renderer'].name,
+                    'content': form.widgets['renderer'].render()
                 }
             })
         return output
--- a/src/pyams_content/component/paragraph/zmi/pictogram.py	Tue Mar 20 13:50:46 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/pictogram.py	Tue Mar 20 13:51:32 2018 +0100
@@ -165,11 +165,13 @@
             output.setdefault('events', []).append({
                 'event': 'myams.refresh',
                 'options': {
-                    'object_id': '{0}_{1}_{2}'.format(
+                    'handler': 'MyAMS.skin.refreshWidget',
+                    'parent_id': '{0}_{1}_{2}'.format(
                         self.context.__class__.__name__,
                         getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
                         form.id),
-                    'content': form.render()
+                    'widget_name': form.widgets['renderer'].name,
+                    'content': form.widgets['renderer'].render()
                 }
             })
         return output
--- a/src/pyams_content/component/paragraph/zmi/verbatim.py	Tue Mar 20 13:50:46 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/verbatim.py	Tue Mar 20 13:51:32 2018 +0100
@@ -139,17 +139,20 @@
 
     def get_ajax_output(self, changes):
         output = super(VerbatimParagraphInnerAJAXEditForm, self).get_ajax_output(changes)
-        if 'renderer' in changes.get(IVerbatimParagraph, ()):
+        updated = changes.get(IVerbatimParagraph, ())
+        if 'renderer' in updated:
             form = VerbatimParagraphInnerEditForm(self.context, self.request)
             form.update()
             output.setdefault('events', []).append({
                 'event': 'myams.refresh',
                 'options': {
-                    'object_id': '{0}_{1}_{2}'.format(
+                    'handler': 'MyAMS.skin.refreshWidget',
+                    'parent_id': '{0}_{1}_{2}'.format(
                         self.context.__class__.__name__,
                         getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
                         form.id),
-                    'content': form.render()
+                    'widget_name': form.widgets['renderer'].name,
+                    'content': form.widgets['renderer'].render()
                 }
             })
         return output
--- a/src/pyams_content/component/paragraph/zmi/video.py	Tue Mar 20 13:50:46 2018 +0100
+++ b/src/pyams_content/component/paragraph/zmi/video.py	Tue Mar 20 13:51:32 2018 +0100
@@ -185,10 +185,9 @@
                             'object_name': associations_table.id,
                             'table': associations_table.render()}
             })
-        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()
+        if 'data' in updated:
+            # we have to commit transaction to be able to handle blobs...
+            ITransactionManager(self.context).get().commit()
             form = VideoParagraphPropertiesInnerEditForm(self.context, self.request)
             form.update()
             output.setdefault('events', []).append({
@@ -201,6 +200,21 @@
                     'content': form.render()
                 }
             })
+        elif 'renderer' in updated:
+            form = VideoParagraphPropertiesInnerEditForm(self.context, self.request)
+            form.update()
+            output.setdefault('events', []).append({
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'MyAMS.skin.refreshWidget',
+                    'parent_id': '{0}_{1}_{2}'.format(
+                        self.context.__class__.__name__,
+                        getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
+                        form.id),
+                    'widget_name': form.widgets['renderer'].name,
+                    'content': form.widgets['renderer'].render()
+                }
+            })
         return output
 
 
--- a/src/pyams_content/shared/logo/zmi/paragraph.py	Tue Mar 20 13:50:46 2018 +0100
+++ b/src/pyams_content/shared/logo/zmi/paragraph.py	Tue Mar 20 13:51:32 2018 +0100
@@ -132,18 +132,20 @@
     def get_ajax_output(self, changes):
         output = super(LogosParagraphInnerAJAXEditForm, self).get_ajax_output(changes)
         updated = changes.get(ILogosParagraph, ())
-        if ('references' in updated) or ('renderer' in updated):
+        if 'renderer' in updated:
             form = LogosParagraphInnerEditForm(self.context, self.request)
             form.update()
             content = form.getContent()
             output.setdefault('events', []).append({
                 'evennt': 'myams.refresh',
                 'options': {
-                    'object_id': '{0}_{1}_{2}'.format(
+                    'handler': 'MyAMS.skin.refreshWidget',
+                    'parent_id': '{0}_{1}_{2}'.format(
                         content.__class__.__name__,
                         getattr(content, '__name__', 'noname').replace('++', ''),
                         form.id),
-                    'content': form.render()
+                    'widget_name': form.widgets['renderer'].name,
+                    'content': form.widgets['renderer'].render()
                 }
             })
         return output