Updated refresh events
authorThierry Florac <tflorac@ulthar.net>
Sun, 26 Nov 2017 09:51:48 +0100
changeset 283 9139536eab90
parent 282 2990223a5b7f
child 284 796b6f241aff
Updated refresh events
src/pyams_content/component/association/zmi/__init__.py
src/pyams_content/component/extfile/zmi/__init__.py
src/pyams_content/component/gallery/zmi/file.py
src/pyams_content/component/gallery/zmi/paragraph.py
src/pyams_content/component/illustration/zmi/__init__.py
src/pyams_content/component/illustration/zmi/paragraph.py
src/pyams_content/component/links/zmi/__init__.py
src/pyams_content/component/paragraph/zmi/__init__.py
src/pyams_content/component/paragraph/zmi/container.py
src/pyams_content/component/paragraph/zmi/header.py
src/pyams_content/component/paragraph/zmi/html.py
src/pyams_content/component/paragraph/zmi/video.py
src/pyams_content/features/review/zmi/__init__.py
--- a/src/pyams_content/component/association/zmi/__init__.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/association/zmi/__init__.py	Sun Nov 26 09:51:48 2017 +0100
@@ -62,10 +62,10 @@
         return {'status': 'success',
                 'message': self.request.localizer.translate(_("Association was correctly added.")),
                 'events': [{
-                    'event': 'PyAMS_content.changed_item',
+                    'event': 'myams.refresh',
                     'options': {
                         'handler': 'PyAMS_content.associations.refreshAssociations',
-                        'object_name': associations_table.id,
+                        'object_id': associations_table.id,
                         'table': associations_table.render()
                     }
                 }]}
@@ -81,10 +81,10 @@
         return {'status': 'success',
                 'message': self.request.localizer.translate(self.successMessage),
                 'events': [{
-                    'event': 'PyAMS_content.changed_item',
+                    'event': 'myams.refresh',
                     'options': {
                         'handler': 'PyAMS_content.associations.refreshAssociations',
-                        'object_name': associations_table.id,
+                        'object_id': associations_table.id,
                         'table': associations_table.render()
                     }
                 }]}
@@ -294,7 +294,7 @@
     return {'status': 'success',
             'handle_json': True,
             'events': [{
-                'event': 'PyAMS_content.changed_item',
+                'event': 'myams.refresh',
                 'options': {'handler': 'PyAMS_content.paragraphs.updateToolbar',
                             'object_name': parent.__name__,
                             'toolbar_tag': viewlet.render()}
--- a/src/pyams_content/component/extfile/zmi/__init__.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/extfile/zmi/__init__.py	Sun Nov 26 09:51:48 2017 +0100
@@ -127,11 +127,13 @@
             counter = ExtFilesCounter(self.context, self.request, self, None)
             counter.update()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                            'object_name': self.context.__name__,
-                            'marker_type': 'extfiles',
-                            'marker_tag': counter.render()}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
+                    'object_name': self.context.__name__,
+                    'marker_type': 'extfiles',
+                    'marker_tag': counter.render()
+                }
             })
         return output
 
@@ -229,11 +231,13 @@
             counter = ExtImagesCounter(self.context, self.request, self, None)
             counter.update()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                            'object_name': self.context.__name__,
-                            'marker_type': 'extimages',
-                            'marker_tag': counter.render()}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
+                    'object_name': self.context.__name__,
+                    'marker_type': 'extimages',
+                    'marker_tag': counter.render()
+                }
             })
         return output
 
@@ -323,11 +327,13 @@
             counter = ExtVideosCounter(self.context, self.request, self, None)
             counter.update()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                            'object_name': self.context.__name__,
-                            'marker_type': 'extvideos',
-                            'marker_tag': counter.render()}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
+                    'object_name': self.context.__name__,
+                    'marker_type': 'extvideos',
+                    'marker_tag': counter.render()
+                }
             })
         return output
 
@@ -416,11 +422,13 @@
             counter = ExtAudiosCounter(self.context, self.request, self, None)
             counter.update()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                            'object_name': self.context.__name__,
-                            'marker_type': 'extaudios',
-                            'marker_tag': counter.render()}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
+                    'object_name': self.context.__name__,
+                    'marker_type': 'extaudios',
+                    'marker_tag': counter.render()
+                }
             })
         return output
 
--- a/src/pyams_content/component/gallery/zmi/file.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/gallery/zmi/file.py	Sun Nov 26 09:51:48 2017 +0100
@@ -202,7 +202,7 @@
             gallery = get_parent(self.context, IGallery)
             if gallery is not None:
                 output.setdefault('events', []).append({
-                    'event': 'PyAMS_content.changed_item',
+                    'event': 'myams.refresh',
                     'options': {
                         'handler': 'PyAMS_content.galleries.updateImageTitle',
                         'image_id': 'image_{0}_{1}'.format(gallery.__name__, self.context.__name__),
--- a/src/pyams_content/component/gallery/zmi/paragraph.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/gallery/zmi/paragraph.py	Sun Nov 26 09:51:48 2017 +0100
@@ -115,11 +115,13 @@
         if 'title' in updated:
             return {'status': 'success',
                     'events': [{
-                        'event': 'PyAMS_content.changed_item',
-                        'options': {'handler': 'PyAMS_content.paragraphs.refreshParagraph',
-                                    'object_name': self.context.__name__,
-                                    'title': II18n(self.context).query_attribute('title', request=self.request),
-                                    'visible': self.context.visible}
+                        'event': 'myams.refresh',
+                        'options': {
+                            'handler': 'PyAMS_content.paragraphs.refreshParagraph',
+                            'object_name': self.context.__name__,
+                            'title': II18n(self.context).query_attribute('title', request=self.request),
+                            'visible': self.context.visible
+                        }
                     }]}
         else:
             return super(GalleryPropertiesAJAXEditForm, self).get_ajax_output(changes)
--- a/src/pyams_content/component/illustration/zmi/__init__.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/illustration/zmi/__init__.py	Sun Nov 26 09:51:48 2017 +0100
@@ -147,23 +147,26 @@
             form.update()
             illustration = form.getContent()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.refreshForm',
-                            'object_name': '{0}_{1}_{2}'.format(
-                                self.context.__class__.__name__,
-                                getattr(illustration, '__name__', 'noname').replace('++', ''),
-                                form.id),
-                            'form': form.render()}
+                'event': 'myams.refresh',
+                'options': {
+                    'object_id': '{0}_{1}_{2}'.format(
+                        self.context.__class__.__name__,
+                        getattr(illustration, '__name__', 'noname').replace('++', ''),
+                        form.id),
+                    'content': form.render()
+                }
             })
             viewlet = ParagraphContainerIllustrationMarker(self.context, self.request, self, None)
             if viewlet is not None:
                 viewlet.update()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                            'object_name': self.context.__name__,
-                            'marker_type': 'illustration',
-                            'marker_tag': viewlet.render() if viewlet is not None else ''}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
+                    'object_name': self.context.__name__,
+                    'marker_type': 'illustration',
+                    'marker_tag': viewlet.render() if viewlet is not None else ''
+                }
             })
         return output
 
--- a/src/pyams_content/component/illustration/zmi/paragraph.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/illustration/zmi/paragraph.py	Sun Nov 26 09:51:48 2017 +0100
@@ -117,11 +117,13 @@
         output = super(IllustrationPropertiesAJAXEditForm, self).get_ajax_output(changes)
         if 'title' in changes.get(IIllustration, ()):
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.refreshParagraph',
-                            'object_name': self.context.__name__,
-                            'title': II18n(self.context).query_attribute('title', request=self.request),
-                            'visible': self.context.visible}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.refreshParagraph',
+                    'object_name': self.context.__name__,
+                    'title': II18n(self.context).query_attribute('title', request=self.request),
+                    'visible': self.context.visible
+                }
             })
         return output
 
@@ -152,11 +154,13 @@
         updated = changes.get(IIllustration, ())
         if 'title' in updated:
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.refreshParagraph',
-                            'object_name': self.context.__name__,
-                            'title': II18n(self.context).query_attribute('title', request=self.request),
-                            'visible': self.context.visible}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.refreshParagraph',
+                    'object_name': self.context.__name__,
+                    'title': II18n(self.context).query_attribute('title', request=self.request),
+                    'visible': self.context.visible
+                }
             })
         if 'data' in updated:
             # we have to commit transaction to be able to handle blobs...
@@ -164,13 +168,14 @@
             form = IllustrationInnerEditForm(self.context, self.request)
             form.update()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.refreshForm',
-                            'object_name': '{0}_{1}_{2}'.format(
-                                self.context.__class__.__name__,
-                                getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
-                                form.id),
-                            'form': form.render()}
+                'event': 'myams.refresh',
+                'options': {
+                    'object_id': '{0}_{1}_{2}'.format(
+                        self.context.__class__.__name__,
+                        getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
+                        form.id),
+                    'content': form.render()
+                }
             })
         return output
 
--- a/src/pyams_content/component/links/zmi/__init__.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/links/zmi/__init__.py	Sun Nov 26 09:51:48 2017 +0100
@@ -108,11 +108,13 @@
             counter = InternalLinksCounter(self.context, self.request, self, None)
             counter.update()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                            'object_name': self.context.__name__,
-                            'marker_type': 'internal-links',
-                            'marker_tag': counter.render()}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
+                    'object_name': self.context.__name__,
+                    'marker_type': 'internal-links',
+                    'marker_tag': counter.render()
+                }
             })
         return output
 
@@ -214,11 +216,13 @@
             counter = ExternalLinksCounter(self.context, self.request, self, None)
             counter.update()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                            'object_name': self.context.__name__,
-                            'marker_type': 'external-links',
-                            'marker_tag': counter.render()}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
+                    'object_name': self.context.__name__,
+                    'marker_type': 'external-links',
+                    'marker_tag': counter.render()
+                }
             })
         return output
 
@@ -320,11 +324,13 @@
             counter = MailtoLinksCounter(self.context, self.request, self, None)
             counter.update()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                            'object_name': self.context.__name__,
-                            'marker_type': 'mailto-links',
-                            'marker_tag': counter.render()}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
+                    'object_name': self.context.__name__,
+                    'marker_type': 'mailto-links',
+                    'marker_tag': counter.render()
+                }
             })
         return output
 
--- a/src/pyams_content/component/paragraph/zmi/__init__.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/paragraph/zmi/__init__.py	Sun Nov 26 09:51:48 2017 +0100
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyramid.location import lineage
 
 __docformat__ = 'restructuredtext'
 
@@ -39,6 +38,7 @@
 from pyams_utils.traversing import get_parent
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogEditForm
+from pyramid.location import lineage
 from pyramid.view import view_config
 from z3c.form import field
 
@@ -118,10 +118,10 @@
         return {'status': 'success',
                 'message': self.request.localizer.translate(_("Paragraph was correctly added.")),
                 'events': [{
-                    'event': 'PyAMS_content.changed_item',
+                    'event': 'myams.refresh',
                     'options': {
                         'handler': 'PyAMS_content.paragraphs.refreshParagraphs',
-                        'object_name': paragraphs_table.id,
+                        'object_id': paragraphs_table.id,
                         'table': paragraphs_table.render()
                     }
                 }]}
@@ -150,10 +150,12 @@
         output = super(BaseParagraphAJAXEditForm, self).get_ajax_output(changes)
         if 'title' in changes.get(IBaseParagraph, ()):
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.refreshParagraph',
-                            'object_name': self.context.__name__,
-                            'title': II18n(self.context).query_attribute('title', request=self.request),
-                            'visible': self.context.visible}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.refreshParagraph',
+                    'object_name': self.context.__name__,
+                    'title': II18n(self.context).query_attribute('title', request=self.request),
+                    'visible': self.context.visible
+                }
             })
         return output
--- a/src/pyams_content/component/paragraph/zmi/container.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/paragraph/zmi/container.py	Sun Nov 26 09:51:48 2017 +0100
@@ -19,9 +19,10 @@
 # import interfaces
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_content.component.association.interfaces import IAssociationContainer
-from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, IBaseParagraph
+from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, IBaseParagraph, \
+    IParagraphFactorySettings
 from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphTitleToolbar, \
-    IParagraphContainerTable, IParagraphsParentForm, IParagraphContainerView
+    IParagraphContainerTable, IParagraphContainerView
 from pyams_form.interfaces.form import IFormSecurityContext, IInnerSubForm
 from pyams_i18n.interfaces import II18n
 from pyams_skin.interfaces import IInnerPage, IPageHeader
@@ -43,12 +44,13 @@
 from pyams_skin.viewlet.menu import MenuItem
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter, NullAdapter
+from pyams_utils.traversing import get_parent
 from pyams_utils.url import absolute_url
 from pyams_viewlet.manager import viewletmanager_config, WeightOrderedViewletManager, TemplateBasedViewletManager
 from pyramid.exceptions import NotFound
 from pyramid.view import view_config
 from pyams_viewlet.viewlet import viewlet_config, Viewlet
-from pyams_zmi.form import AdminDialogDisplayForm, InnerAdminDisplayForm
+from pyams_zmi.form import AdminDialogDisplayForm
 from pyams_zmi.view import AdminView, ContainerAdminView
 from pyramid.decorator import reify
 from z3c.form import field
@@ -113,7 +115,13 @@
     def render(self):
         if not self.values:
             translate = self.request.localizer.translate
-            return translate(_("No currently defined paragraph."))
+            message = translate(_("No currently defined paragraph."))
+            manager = get_parent(self.context, IParagraphFactorySettings)
+            if (manager is not None) and not manager.allowed_paragraphs:
+                message = '{0}<br />{1}'.format(message,
+                                                translate(_("Check allowed paragraph types to be able to create new "
+                                                            "paragraphs.")))
+            return message
         return super(ParagraphContainerBaseTable, self).render()
 
 
--- a/src/pyams_content/component/paragraph/zmi/header.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/paragraph/zmi/header.py	Sun Nov 26 09:51:48 2017 +0100
@@ -111,11 +111,13 @@
         output = super(HeaderParagraphPropertiesAJAXEditForm, self).get_ajax_output(changes)
         if 'header' in changes.get(IHeaderParagraph, ()):
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.paragraphs.refreshParagraph',
-                            'object_name': self.context.__name__,
-                            'title': II18n(self.context).query_attribute('title', request=self.request),
-                            'visible': self.context.visible}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.paragraphs.refreshParagraph',
+                    'object_name': self.context.__name__,
+                    'title': II18n(self.context).query_attribute('title', request=self.request),
+                    'visible': self.context.visible
+                }
             })
         return output
 
--- a/src/pyams_content/component/paragraph/zmi/html.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/paragraph/zmi/html.py	Sun Nov 26 09:51:48 2017 +0100
@@ -145,18 +145,24 @@
             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()}})
+                'event': 'myams.refresh',
+                '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': {'handler': 'PyAMS_content.associations.refreshAssociations',
-                            'object_name': associations_table.id,
-                            'table': associations_table.render()}})
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.associations.refreshAssociations',
+                    'object_id': associations_table.id,
+                    'table': associations_table.render()
+                }
+            })
         return output
 
 
@@ -190,18 +196,23 @@
             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()}})
+                'event': 'myams.refresh',
+                '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': {'handler': 'PyAMS_content.associations.refreshAssociations',
-                            'object_name': associations_table.id,
-                            'table': associations_table.render()}
+                'event': 'myams.refresh',
+                'options': {
+                    'handler': 'PyAMS_content.associations.refreshAssociations',
+                    'object_id': associations_table.id,
+                    'table': associations_table.render()
+                }
             })
         return output
 
--- a/src/pyams_content/component/paragraph/zmi/video.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/component/paragraph/zmi/video.py	Sun Nov 26 09:51:48 2017 +0100
@@ -189,13 +189,12 @@
             form = VideoParagraphPropertiesInnerEditForm(self.context, self.request)
             form.update()
             output.setdefault('events', []).append({
-                'event': 'PyAMS_content.changed_item',
-                'options': {'handler': 'PyAMS_content.refreshForm',
-                            'object_name': '{0}_{1}_{2}'.format(
+                'event': 'myams.refresh',
+                'options': {'object_id': '{0}_{1}_{2}'.format(
                                 self.context.__class__.__name__,
                                 getattr(form.getContent(), '__name__', 'noname').replace('++', ''),
                                 form.id),
-                            'form': form.render()}
+                            'content': form.render()}
             })
         return output
 
--- a/src/pyams_content/features/review/zmi/__init__.py	Sun Nov 26 09:50:28 2017 +0100
+++ b/src/pyams_content/features/review/zmi/__init__.py	Sun Nov 26 09:51:48 2017 +0100
@@ -138,15 +138,19 @@
                     'message': translate(_("Request successful. "
                                            "{count} new notification(s) have been sent")).format(count=changes),
                     'events': [{
-                        'event': 'PyAMS_content.changed_item',
-                        'options': {'handler': 'PyAMS_content.review.updateComments'}
+                        'event': 'myams.refresh',
+                        'options': {
+                            'handler': 'PyAMS_content.review.updateComments'
+                        }
                     }]}
         else:
             return {'status': 'info',
                     'message': translate(_("Request successful. No new notification have been sent")),
                     'events': [{
-                        'event': 'PyAMS_content.changed_item',
-                        'options': {'handler': 'PyAMS_content.review.updateComments'}
+                        'event': 'myams.refresh',
+                        'options': {
+                            'handler': 'PyAMS_content.review.updateComments'
+                        }
                     }]}