Switch from callbacks to events in several forms output
authorThierry Florac <thierry.florac@onf.fr>
Wed, 20 Sep 2017 12:11:23 +0200
changeset 175 fb51fb6d6129
parent 174 3e6b4514cacb
child 176 64e00f5537fe
Switch from callbacks to events in several forms output
src/pyams_content/component/association/zmi/__init__.py
src/pyams_content/component/illustration/zmi/__init__.py
src/pyams_content/component/illustration/zmi/paragraph.py
src/pyams_content/component/paragraph/zmi/html.py
--- a/src/pyams_content/component/association/zmi/__init__.py	Tue Sep 19 13:43:54 2017 +0200
+++ b/src/pyams_content/component/association/zmi/__init__.py	Wed Sep 20 12:11:23 2017 +0200
@@ -61,9 +61,12 @@
         associations_table.update()
         return {'status': 'success',
                 'message': self.request.localizer.translate(_("Association was correctly added.")),
-                'callback': 'PyAMS_content.associations.afterUpdateCallback',
-                'options': {'parent': associations_table.id,
-                            'table': associations_table.render()}}
+                'events': [{
+                    'event': 'PyAMS_content.changed_item',
+                    'options': {'object_type': 'associations',
+                                'object_name': associations_table.id,
+                                'table': associations_table.render()}
+                }]}
 
 
 class AssociationItemAJAXEditForm(AJAXEditForm):
@@ -75,9 +78,12 @@
         associations_table.update()
         return {'status': 'success',
                 'message': self.request.localizer.translate(self.successMessage),
-                'callback': 'PyAMS_content.associations.afterUpdateCallback',
-                'options': {'parent': associations_table.id,
-                            'table': associations_table.render()}}
+                'events': [{
+                    'event': 'PyAMS_content.changed_item',
+                    'options': {'object_type': 'associations',
+                                'object_name': associations_table.id,
+                                'table': associations_table.render()}
+                }]}
 
 
 #
--- a/src/pyams_content/component/illustration/zmi/__init__.py	Tue Sep 19 13:43:54 2017 +0200
+++ b/src/pyams_content/component/illustration/zmi/__init__.py	Wed Sep 20 12:11:23 2017 +0200
@@ -122,14 +122,15 @@
         if 'data' in changes.get(IIllustration, ()):
             # we have to commit transaction to be able to handle blobs...
             ITransactionManager(self.context).get().commit()
-            context = IIllustration(self.context)
-            form = IllustrationPropertiesInnerEditForm(context, self.request)
+            form = IllustrationPropertiesInnerEditForm(self.context, self.request)
             form.update()
-            output.setdefault('callbacks', []).append({
-                'callback': 'PyAMS_content.illustration.afterUpdateCallback',
-                'options': {'parent': '{0}_{1}_{2}'.format(self.context.__class__.__name__,
-                                                           getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
-                                                           form.id),
+            output.setdefault('events', []).append({
+                'event': 'PyAMS_content.changed_item',
+                'options': {'object_type': 'illustration',
+                            'object_name': '{0}_{1}_{2}'.format(
+                                self.context.__class__.__name__,
+                                getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
+                                form.id),
                             'form': form.render()}
             })
         return output
--- a/src/pyams_content/component/illustration/zmi/paragraph.py	Tue Sep 19 13:43:54 2017 +0200
+++ b/src/pyams_content/component/illustration/zmi/paragraph.py	Wed Sep 20 12:11:23 2017 +0200
@@ -170,14 +170,15 @@
         if 'data' in updated:
             # we have to commit transaction to be able to handle blobs...
             ITransactionManager(self.context).get().commit()
-            context = IIllustrationParagraph(self.context)
-            form = IllustrationInnerEditForm(context, self.request)
+            form = IllustrationInnerEditForm(self.context, self.request)
             form.update()
-            output.setdefault('callbacks', []).append({
-                'callback': 'PyAMS_content.illustration.afterUpdateCallback',
-                'options': {'parent': '{0}_{1}_{2}'.format(self.context.__class__.__name__,
-                                                           getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
-                                                           form.id),
+            output.setdefault('events', []).append({
+                'event': 'PyAMS_content.changed_item',
+                'options': {'object_type': 'illustration',
+                            'object_name': '{0}_{1}_{2}'.format(
+                                self.context.__class__.__name__,
+                                getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
+                                form.id),
                             'form': form.render()}
             })
         return output
--- a/src/pyams_content/component/paragraph/zmi/html.py	Tue Sep 19 13:43:54 2017 +0200
+++ b/src/pyams_content/component/paragraph/zmi/html.py	Wed Sep 20 12:11:23 2017 +0200
@@ -145,9 +145,10 @@
         if 'body' in changes.get(IHTMLParagraph, ()):
             associations_table = AssociationsTable(self.context, self.request, None)
             associations_table.update()
-            output.setdefault('callbacks', []).append({
-                'callback': 'PyAMS_content.associations.afterUpdateCallback',
-                'options': {'parent': associations_table.id,
+            output.setdefault('events', []).append({
+                'event': 'PyAMS_content.changed_item',
+                'options': {'object_type': 'associations',
+                            'object_name': associations_table.id,
                             'table': associations_table.render()}})
         return output
 
@@ -178,9 +179,10 @@
         if 'body' in changes.get(IHTMLParagraph, ()):
             associations_table = AssociationsTable(self.context, self.request, None)
             associations_table.update()
-            output.setdefault('callbacks', []).append({
-                'callback': 'PyAMS_content.associations.afterUpdateCallback',
-                'options': {'parent': associations_table.id,
+            output.setdefault('events', []).append({
+                'event': 'PyAMS_content.changed_item',
+                'options': {'object_type': 'associations',
+                            'object_name': associations_table.id,
                             'table': associations_table.render()}
             })
         return output