src/pyams_content/component/links/zmi/__init__.py
changeset 527 5dd1aa8bedd9
parent 283 9139536eab90
child 550 9658debb49a3
--- a/src/pyams_content/component/links/zmi/__init__.py	Wed Apr 11 16:44:46 2018 +0200
+++ b/src/pyams_content/component/links/zmi/__init__.py	Wed Apr 11 16:46:31 2018 +0200
@@ -9,6 +9,7 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
+from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event
 
 __docformat__ = 'restructuredtext'
 
@@ -55,6 +56,8 @@
     icon_class = 'fa fa-fw fa-external-link-square fa-rotate-90'
     icon_hint = _("Internal links")
 
+    marker_type = 'internal-links'
+
     @property
     def count(self):
         return len([file for file in IAssociationContainer(self.context).values()
@@ -105,17 +108,8 @@
     def get_ajax_output(self, changes):
         output = super(InternalLinkAJAXAddForm, self).get_ajax_output(changes)
         if output:
-            counter = InternalLinksCounter(self.context, self.request, self, None)
-            counter.update()
-            output.setdefault('events', []).append({
-                'event': 'myams.refresh',
-                'options': {
-                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                    'object_name': self.context.__name__,
-                    'marker_type': 'internal-links',
-                    'marker_tag': counter.render()
-                }
-            })
+            output.setdefault('events', []).append(get_json_paragraph_markers_refresh_event(self.context, self.request,
+                                                                                            self, InternalLinksCounter))
         return output
 
 
@@ -123,6 +117,8 @@
 class InternalLinkPropertiesEditForm(AdminDialogEditForm):
     """Internal link properties edit form"""
 
+    prefix = 'internallink_properties.'
+
     legend = _("Edit internal link properties")
     icon_css_class = 'fa fa-fw fa-external-link-square fa-rotate-90'
 
@@ -163,6 +159,8 @@
     icon_class = 'fa fa-fw fa-external-link'
     icon_hint = _("External links")
 
+    marker_type = 'external-links'
+
     @property
     def count(self):
         return len([file for file in IAssociationContainer(self.context).values()
@@ -213,17 +211,8 @@
     def get_ajax_output(self, changes):
         output = super(ExternalLinkAJAXAddForm, self).get_ajax_output(changes)
         if output:
-            counter = ExternalLinksCounter(self.context, self.request, self, None)
-            counter.update()
-            output.setdefault('events', []).append({
-                'event': 'myams.refresh',
-                'options': {
-                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                    'object_name': self.context.__name__,
-                    'marker_type': 'external-links',
-                    'marker_tag': counter.render()
-                }
-            })
+            output.setdefault('events', []).append(get_json_paragraph_markers_refresh_event(self.context, self.request,
+                                                                                            self, ExternalLinksCounter))
         return output
 
 
@@ -231,6 +220,8 @@
 class ExternalLinkPropertiesEditForm(AdminDialogEditForm):
     """External link properties edit form"""
 
+    prefix = 'externallink_properties.'
+
     legend = _("Edit external link properties")
     icon_css_class = 'fa fa-fw fa-external-link'
 
@@ -271,6 +262,8 @@
     icon_class = 'fa fa-fw fa-envelope-o'
     icon_hint = _("Mailto links")
 
+    marker_type = 'mailto-links'
+
     @property
     def count(self):
         return len([file for file in IAssociationContainer(self.context).values()
@@ -321,17 +314,8 @@
     def get_ajax_output(self, changes):
         output = super(MailtoLinkAJAXAddForm, self).get_ajax_output(changes)
         if output:
-            counter = MailtoLinksCounter(self.context, self.request, self, None)
-            counter.update()
-            output.setdefault('events', []).append({
-                'event': 'myams.refresh',
-                'options': {
-                    'handler': 'PyAMS_content.paragraphs.updateMarkers',
-                    'object_name': self.context.__name__,
-                    'marker_type': 'mailto-links',
-                    'marker_tag': counter.render()
-                }
-            })
+            output.setdefault('events', []).append(get_json_paragraph_markers_refresh_event(self.context, self.request,
+                                                                                            self, MailtoLinksCounter))
         return output
 
 
@@ -339,6 +323,8 @@
 class MailtoLinkPropertiesEditForm(AdminDialogEditForm):
     """Mailto link properties edit form"""
 
+    prefix = 'mailtolink_properties.'
+
     legend = _("Edit mailto link properties")
     icon_css_class = 'fa fa-fw fa-envelope-o'
 
@@ -358,8 +344,7 @@
     """Mailto link properties edit form, JSON renderer"""
 
     def get_ajax_output(self, changes):
-        if ('title' in changes.get(IBaseLink, ())) or \
-           ('reference' in changes.get(IMailtoLink, ())):
+        if ('title' in changes.get(IBaseLink, ())) or changes.get(IMailtoLink, ()):
             return self.get_associations_table()
         else:
             return super(MailtoLinkPropertiesAJAXEditForm, self).get_ajax_output(changes)