--- a/src/pyams_content/component/links/zmi/__init__.py Fri Oct 13 08:27:20 2017 +0200
+++ b/src/pyams_content/component/links/zmi/__init__.py Fri Oct 13 08:27:52 2017 +0200
@@ -20,21 +20,27 @@
from pyams_content.component.association.zmi.interfaces import IAssociationsView
from pyams_content.component.links.interfaces import ILinkContainerTarget, IInternalLink, IBaseLink, \
IExternalLink, IMailtoLink
+from pyams_content.component.paragraph.zmi.interfaces import IParagraphContainerTable, IParagraphTitleToolbar
from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
from pyams_skin.interfaces.viewlet import IToolbarAddingMenu
from pyams_skin.layer import IPyAMSLayer
from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+from z3c.form.interfaces import IDataExtractedEvent
+from zope.schema.interfaces import InvalidURI
# import packages
from pyams_content.component.association.zmi import AssociationItemAJAXAddForm, AssociationItemAJAXEditForm
from pyams_content.component.links import InternalLink, ExternalLink, MailtoLink
+from pyams_content.component.paragraph.zmi.container import ParagraphContainerCounterBase
from pyams_form.security import ProtectedFormObjectMixin
from pyams_pagelet.pagelet import pagelet_config
from pyams_skin.viewlet.toolbar import ToolbarMenuItem
from pyams_viewlet.viewlet import viewlet_config
from pyams_zmi.form import AdminDialogAddForm, AdminDialogEditForm
+from pyramid.events import subscriber
from pyramid.view import view_config
from z3c.form import field
+from zope.interface import implementer, Interface
from pyams_content import _
@@ -43,6 +49,22 @@
# Internal links views
#
+@viewlet_config(name='internal-links', context=ILinkContainerTarget, layer=IPyAMSLayer, view=IParagraphContainerTable,
+ manager=IParagraphTitleToolbar, permission=VIEW_SYSTEM_PERMISSION, weight=10)
+class InternalLinksCounter(ParagraphContainerCounterBase):
+ """Internal links count column"""
+
+ weight = 10
+ action_class = 'action internal-links nowrap width-40'
+ icon_class = 'fa fa-fw fa-external-link-square fa-rotate-90'
+ icon_hint = _("Internal links")
+
+ @property
+ def count(self):
+ return len([file for file in IAssociationContainer(self.context).values()
+ if IInternalLink.providedBy(file)])
+
+
@viewlet_config(name='add-internal-link.menu', context=ILinkContainerTarget, view=IAssociationsView,
layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=50)
class InternalLinkAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
@@ -84,6 +106,20 @@
class InternalLinkAJAXAddForm(AssociationItemAJAXAddForm, InternalLinkAddForm):
"""Internal link add form, JSON renderer"""
+ 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': 'PyAMS_content.changed_item',
+ 'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
+ 'object_name': self.context.__name__,
+ 'marker_type': 'internal-links',
+ 'marker_tag': counter.render()}
+ })
+ return output
+
@pagelet_config(name='properties.html', context=IInternalLink, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
class InternalLinkPropertiesEditForm(AdminDialogEditForm):
@@ -119,6 +155,22 @@
# External links views
#
+@viewlet_config(name='external-links', context=ILinkContainerTarget, layer=IPyAMSLayer, view=IParagraphContainerTable,
+ manager=IParagraphTitleToolbar, permission=VIEW_SYSTEM_PERMISSION, weight=11)
+class ExternalLinksCounter(ParagraphContainerCounterBase):
+ """External links count column"""
+
+ weight = 11
+ action_class = 'action external-links nowrap width-40'
+ icon_class = 'fa fa-fw fa-external-link'
+ icon_hint = _("External links")
+
+ @property
+ def count(self):
+ return len([file for file in IAssociationContainer(self.context).values()
+ if IExternalLink.providedBy(file)])
+
+
@viewlet_config(name='add-external-link.menu', context=ILinkContainerTarget, view=IAssociationsView,
layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=51)
class ExternalLinkAddMenu(ProtectedFormObjectMixin, ToolbarMenuItem):
@@ -160,6 +212,20 @@
class ExternalLinkAJAXAddForm(AssociationItemAJAXAddForm, ExternalLinkAddForm):
"""External link add form, JSON renderer"""
+ 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': 'PyAMS_content.changed_item',
+ 'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
+ 'object_name': self.context.__name__,
+ 'marker_type': 'external-links',
+ 'marker_tag': counter.render()}
+ })
+ return output
+
@pagelet_config(name='properties.html', context=IExternalLink, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
class ExternalLinkPropertiesEditForm(AdminDialogEditForm):
@@ -195,6 +261,21 @@
# Mailto links views
#
+@viewlet_config(name='mailto-links', context=ILinkContainerTarget, layer=IPyAMSLayer, view=IParagraphContainerTable,
+ manager=IParagraphTitleToolbar, permission=VIEW_SYSTEM_PERMISSION, weight=12)
+class MailtoLinksCounter(ParagraphContainerCounterBase):
+ """Mailto links count column"""
+
+ weight = 12
+ action_class = 'action mailto-links nowrap width-40'
+ icon_class = 'fa fa-fw fa-envelope-o'
+ icon_hint = _("Mailto links")
+
+ @property
+ def count(self):
+ return len([file for file in IAssociationContainer(self.context).values()
+ if IMailtoLink.providedBy(file)])
+
@viewlet_config(name='add-mailto-link.menu', context=ILinkContainerTarget, view=IAssociationsView,
layer=IPyAMSLayer, manager=IToolbarAddingMenu, weight=52)
@@ -237,6 +318,20 @@
class MailtoLinkAJAXAddForm(AssociationItemAJAXAddForm, MailtoLinkAddForm):
"""Mailto link add form, JSON renderer"""
+ 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': 'PyAMS_content.changed_item',
+ 'options': {'handler': 'PyAMS_content.paragraphs.updateMarkers',
+ 'object_name': self.context.__name__,
+ 'marker_type': 'mailto-links',
+ 'marker_tag': counter.render()}
+ })
+ return output
+
@pagelet_config(name='properties.html', context=IMailtoLink, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
class MailtoLinkPropertiesEditForm(AdminDialogEditForm):