Added count marker base interface
authorThierry Florac <thierry.florac@onf.fr>
Fri, 13 Oct 2017 08:29:43 +0200
changeset 214 533d8603d145
parent 213 fd2f6aaa2478
child 215 8108753b99ba
Added count marker base interface
src/pyams_content/component/paragraph/zmi/container.py
--- a/src/pyams_content/component/paragraph/zmi/container.py	Fri Oct 13 08:29:05 2017 +0200
+++ b/src/pyams_content/component/paragraph/zmi/container.py	Fri Oct 13 08:29:43 2017 +0200
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_skin.interfaces.container import ITableElementEditor
 
 __docformat__ = 'restructuredtext'
 
@@ -20,13 +19,13 @@
 # import interfaces
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_content.component.association.interfaces import IAssociationContainer
-from pyams_content.component.extfile.interfaces import IExtFileContainerTarget, IExtFile
-from pyams_content.component.links.interfaces import ILinkContainerTarget, IBaseLink
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, IBaseParagraph
-from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphTitleToolbar
+from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphTitleToolbar, \
+    IParagraphContainerTable
 from pyams_form.interfaces.form import IFormSecurityContext
 from pyams_i18n.interfaces import II18n
 from pyams_skin.interfaces import IInnerPage, IPageHeader
+from pyams_skin.interfaces.container import ITableElementEditor
 from pyams_skin.layer import IPyAMSLayer
 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
 from pyams_zmi.interfaces.menu import IPropertiesMenu
@@ -71,6 +70,7 @@
 # Paragraphs container view
 #
 
+@implementer(IParagraphContainerTable)
 class ParagraphContainerTable(ProtectedFormObjectMixin, BaseTable):
     """Paragraphs container table"""
 
@@ -94,6 +94,8 @@
                                'data-ams-plugin-pyams_content-src':
                                    '/--static--/pyams_content/js/pyams_content{MyAMS.devext}.js',
                                'data-ams-location': absolute_url(IParagraphContainer(self.context), self.request),
+                               'data-ams-pre-reload': 'PyAMS_content.paragraphs.preReload',
+                               'data-ams-post-reload': 'PyAMS_content.paragraphs.postReload',
                                'data-ams-tablednd-drag-handle': 'td.sorter',
                                'data-ams-tablednd-drop-target': 'set-paragraphs-order.json'}
         return attributes
@@ -235,6 +237,14 @@
         return II18n(obj).query_attribute('title', request=self.request) or ' - - - - - - - -'
 
 
+@template_config(template='templates/paragraph-title-icon.pt', layer=IPyAMSLayer)
+class ParagraphContainerCounterBase(Viewlet):
+    """Paragraph container base counter viewlet"""
+
+    weight = 0
+    count = None
+
+
 @adapter_config(name='trash', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable),
                 provides=IColumn)
 class ParagraphContainerTrashColumn(ProtectedFormObjectMixin, TrashColumn):
@@ -258,38 +268,6 @@
     icon_class = 'fa fa-fw fa-paragraph'
 
 
-@viewlet_config(name='links', context=ILinkContainerTarget, layer=IPyAMSLayer, view=ParagraphContainerTable,
-                manager=IParagraphTitleToolbar, permission=VIEW_SYSTEM_PERMISSION, weight=10)
-@template_config(template='templates/paragraph-title-icon.pt', layer=IPyAMSLayer)
-class ParagraphContainerLinksCounter(Viewlet):
-    """Paragraph container external links count column"""
-
-    action_class = 'action links nowrap width-40'
-    icon_class = 'fa fa-fw fa-link'
-    icon_hint = _("Links")
-
-    @property
-    def count(self):
-        return len([file for file in IAssociationContainer(self.context).values()
-                    if IBaseLink.providedBy(file)])
-
-
-@viewlet_config(name='files', context=IExtFileContainerTarget, layer=IPyAMSLayer, view=ParagraphContainerTable,
-                manager=IParagraphTitleToolbar, permission=VIEW_SYSTEM_PERMISSION, weight=10)
-@template_config(template='templates/paragraph-title-icon.pt', layer=IPyAMSLayer)
-class ParagraphContainerExtFileCounter(Viewlet):
-    """Paragraph container external files count column"""
-
-    action_class = 'action extfiles nowrap width-40'
-    icon_class = 'fa fa-fw fa-file-text-o'
-    icon_hint = _("External files")
-
-    @property
-    def count(self):
-        return len([file for file in IAssociationContainer(self.context).values()
-                    if IExtFile.providedBy(file)])
-
-
 @view_config(name='set-paragraphs-order.json', context=IParagraphContainer, request_type=IPyAMSLayer,
              permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
 def set_paragraphs_order(request):