Refresh count markers on HTML update
authorThierry Florac <thierry.florac@onf.fr>
Fri, 13 Oct 2017 08:30:36 +0200
changeset 216 724672199ef3
parent 215 8108753b99ba
child 217 57b690463135
Refresh count markers on HTML update
src/pyams_content/component/paragraph/zmi/html.py
--- a/src/pyams_content/component/paragraph/zmi/html.py	Fri Oct 13 08:30:00 2017 +0200
+++ b/src/pyams_content/component/paragraph/zmi/html.py	Fri Oct 13 08:30:36 2017 +0200
@@ -16,6 +16,7 @@
 # import standard library
 
 # import interfaces
+from pyams_content.component.association.interfaces import IAssociationTarget
 from pyams_content.component.association.zmi.interfaces import IAssociationsParentForm
 from pyams_content.component.illustration.interfaces import IIllustration, IIllustrationRenderer
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, \
@@ -36,7 +37,8 @@
 from pyams_content.component.paragraph.html import HTMLParagraph
 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
     BaseParagraphAddMenu
-from pyams_content.component.paragraph.zmi.container import ParagraphContainerView
+from pyams_content.component.paragraph.zmi.container import ParagraphContainerView, ParagraphContainerTable, \
+    ParagraphTitleToolbarViewletManager
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_template.template import template_config
 
@@ -142,11 +144,22 @@
     def get_ajax_output(self, changes):
         output = super(HTMLParagraphPropertiesAJAXEditForm, self).get_ajax_output(changes)
         if 'body' in changes.get(IHTMLParagraph, ()):
+            # refresh associations count markers
+            parent = get_parent(self.context, IAssociationTarget)
+            table = ParagraphContainerTable(parent, self.request)
+            viewlet = ParagraphTitleToolbarViewletManager(parent, self.request, table)
+            viewlet.update()
+            output.setdefault('events', []).append({
+                'event': 'PyAMS_content.changed_item',
+                'options': {'handler': 'PyAMS_content.paragraphs.updateToolbar',
+                            'object_name': self.context.__name__,
+                            'toolbar_tag': viewlet.render()}})
+            # refresh associations table
             associations_table = AssociationsTable(self.context, self.request)
             associations_table.update()
             output.setdefault('events', []).append({
                 'event': 'PyAMS_content.changed_item',
-                'options': {'object_type': 'associations',
+                'options': {'handler': 'PyAMS_content.associations.refreshAssociations',
                             'object_name': associations_table.id,
                             'table': associations_table.render()}})
         return output
@@ -176,11 +189,22 @@
     def get_ajax_output(self, changes):
         output = super(HTMLParagraphInnerAJAXEditForm, self).get_ajax_output(changes)
         if 'body' in changes.get(IHTMLParagraph, ()):
+            # refresh associations count markers
+            parent = get_parent(self.context, IAssociationTarget)
+            table = ParagraphContainerTable(parent, self.request)
+            viewlet = ParagraphTitleToolbarViewletManager(parent, self.request, table)
+            viewlet.update()
+            output.setdefault('events', []).append({
+                'event': 'PyAMS_content.changed_item',
+                'options': {'handler': 'PyAMS_content.paragraphs.updateToolbar',
+                            'object_name': self.context.__name__,
+                            'toolbar_tag': viewlet.render()}})
+            # refresh associations table
             associations_table = AssociationsTable(self.context, self.request)
             associations_table.update()
             output.setdefault('events', []).append({
                 'event': 'PyAMS_content.changed_item',
-                'options': {'object_type': 'associations',
+                'options': {'handler': 'PyAMS_content.associations.refreshAssociations',
                             'object_name': associations_table.id,
                             'table': associations_table.render()}
             })