Added 'simple' paragraphs table without extended 'name' column
authorThierry Florac <thierry.florac@onf.fr>
Fri, 10 Nov 2017 11:49:47 +0100
changeset 243 73b31fa70b8b
parent 242 2bbead234b84
child 244 175c2a77104d
Added 'simple' paragraphs table without extended 'name' column
src/pyams_content/component/paragraph/zmi/container.py
--- a/src/pyams_content/component/paragraph/zmi/container.py	Fri Nov 10 11:49:07 2017 +0100
+++ b/src/pyams_content/component/paragraph/zmi/container.py	Fri Nov 10 11:49:47 2017 +0100
@@ -21,8 +21,8 @@
 from pyams_content.component.association.interfaces import IAssociationContainer
 from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, IBaseParagraph
 from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphTitleToolbar, \
-    IParagraphContainerTable
-from pyams_form.interfaces.form import IFormSecurityContext
+    IParagraphContainerTable, IParagraphsParentForm, IParagraphContainerView
+from pyams_form.interfaces.form import IFormSecurityContext, IInnerSubForm
 from pyams_i18n.interfaces import II18n
 from pyams_skin.interfaces import IInnerPage, IPageHeader
 from pyams_skin.interfaces.container import ITableElementEditor
@@ -37,21 +37,23 @@
 from pyams_content.component.association.zmi import AssociationsContainerView
 from pyams_content.shared.common.zmi import WfModifiedContentColumnMixin
 from pyams_form.security import ProtectedFormObjectMixin
-from pyams_pagelet.pagelet import pagelet_config
+from pyams_pagelet.pagelet import pagelet_config, Pagelet
 from pyams_skin.page import DefaultPageHeaderAdapter
 from pyams_skin.table import BaseTable, I18nColumn, TrashColumn, JsActionColumn, SorterColumn, ImageColumn
 from pyams_skin.viewlet.menu import MenuItem
 from pyams_template.template import template_config
-from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
+from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter, NullAdapter
 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.view import AdminView, ContainerAdminView
 from pyramid.decorator import reify
+from z3c.form import field
 from z3c.table.column import GetAttrColumn
-from zope.interface import implementer
+from zope.interface import implementer, Interface
 
 from pyams_content import _
 
@@ -71,7 +73,7 @@
 #
 
 @implementer(IParagraphContainerTable)
-class ParagraphContainerTable(ProtectedFormObjectMixin, BaseTable):
+class ParagraphContainerBaseTable(ProtectedFormObjectMixin, BaseTable):
     """Paragraphs container table"""
 
     id = 'paragraphs_list'
@@ -88,7 +90,7 @@
 
     @property
     def data_attributes(self):
-        attributes = super(ParagraphContainerTable, self).data_attributes
+        attributes = super(ParagraphContainerBaseTable, self).data_attributes
         attributes['table'] = {'id': self.id,
                                'data-ams-plugins': 'pyams_content',
                                'data-ams-plugin-pyams_content-src':
@@ -100,32 +102,42 @@
                                'data-ams-tablednd-drop-target': 'set-paragraphs-order.json'}
         return attributes
 
+
+class ParagraphContainerTable(ParagraphContainerBaseTable):
+    """Paragraph container base table"""
+
     @reify
     def values(self):
-        return list(super(ParagraphContainerTable, self).values)
+        return list(super(ParagraphContainerBaseTable, self).values)
 
     def render(self):
         if not self.values:
             translate = self.request.localizer.translate
             return translate(_("No currently defined paragraph."))
-        return super(ParagraphContainerTable, self).render()
+        return super(ParagraphContainerBaseTable, self).render()
+
+
+@adapter_config(context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerBaseTable), provides=IValues)
+class ParagraphContainerValues(ContextRequestViewAdapter):
+    """Paragraphs container values"""
+
+    @property
+    def values(self):
+        return IParagraphContainer(self.context).values()
 
 
 @adapter_config(context=(IBaseParagraph, IPyAMSLayer, ParagraphContainerTable), provides=ITableElementEditor)
-class BaseParagraphTableElementEditor(ContextRequestViewAdapter):
+class BaseParagraphTableElementEditor(NullAdapter):
     """Base paragraph table element editor"""
 
-    def __new__(cls, *args, **kwargs):
-        return None
 
-
-@adapter_config(name='sorter', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable),
+@adapter_config(name='sorter', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerBaseTable),
                 provides=IColumn)
 class ParagraphContainerSorterColumn(ProtectedFormObjectMixin, SorterColumn):
     """Paragraphs container sorter column"""
 
 
-@adapter_config(name='show-hide', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable),
+@adapter_config(name='show-hide', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerBaseTable),
                 provides=IColumn)
 class ParagraphContainerShowHideColumn(ProtectedFormObjectMixin, JsActionColumn):
     """Paragraphs container visibility switcher column"""
@@ -154,7 +166,13 @@
             return super(ParagraphContainerShowHideColumn, self).renderCell(item)
 
 
-@adapter_config(name='pictogram', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable),
+@adapter_config(context=ParagraphContainerShowHideColumn, provides=IFormSecurityContext)
+def ShowHideColumnSecurityContextFactory(column):
+    """Show/hide column security context factory"""
+    return column.table.context
+
+
+@adapter_config(name='pictogram', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerBaseTable),
                 provides=IColumn)
 class ParagraphContainerPictogramColumn(ImageColumn):
     """Paragraph container pictogram column"""
@@ -168,21 +186,6 @@
         return self.request.localizer.translate(item.icon_hint)
 
 
-@pagelet_config(name='paragraphs.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
-                permission=VIEW_SYSTEM_PERMISSION)
-class ParagraphContainerView(ContainerAdminView):
-    """Paragraphs container view"""
-
-    title = _("Paragraphs list")
-    table_class = ParagraphContainerTable
-
-
-@adapter_config(context=ParagraphContainerShowHideColumn, provides=IFormSecurityContext)
-def ShowHideColumnSecurityContextFactory(column):
-    """Show/hide column security context factory"""
-    return column.table.context
-
-
 @viewletmanager_config(name='pyams_paragraph.title_toolbar', context=IBaseParagraph, layer=IPyAMSLayer,
                        view=ParagraphContainerTable, provides=IParagraphTitleToolbar)
 @template_config(template='templates/paragraph-title-toolbar.pt', layer=IPyAMSLayer)
@@ -201,15 +204,29 @@
         return provider.render()
 
 
+@adapter_config(name='name', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerBaseTable),
+                provides=IColumn)
+class ParagraphContainerBaseTitleColumn(I18nColumn, WfModifiedContentColumnMixin, GetAttrColumn):
+    """Paragraph container base title column"""
+
+    _header = _("Title")
+
+    weight = 50
+
+    def renderCell(self, item):
+        return '<span class="title">{0}</span>'.format(super(ParagraphContainerBaseTitleColumn, self).renderCell(item))
+
+    def getValue(self, obj):
+        return II18n(obj).query_attribute('title', request=self.request) or ' - - - - - - - -'
+
+
 @adapter_config(name='name', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable),
                 provides=IColumn)
-class ParagraphContainerTitleColumn(I18nColumn, WfModifiedContentColumnMixin, GetAttrColumn):
+class ParagraphContainerTitleColumn(ParagraphContainerBaseTitleColumn):
     """Paragraph container title column"""
 
     _header = _("Show/hide all paragraphs")
 
-    weight = 50
-
     def renderHeadCell(self):
         return '<span data-ams-stop-propagation="true"' \
                '      data-ams-click-handler="PyAMS_content.paragraphs.switchAllEditors">' \
@@ -227,14 +244,11 @@
                '    <span class="small hint" title="{hint}" data-ams-hint-gravity="e">' \
                '        <i class="fa fa-plus-square-o switch"></i>' \
                '    </span>&nbsp;&nbsp;&nbsp;<span class="title">{title}</span>' \
-               '</div>'.format(
+               '</div>' \
+               '<div class="inner-table-form editor margin-x-10 margin-bottom-0"></div>'.format(
                     provider=provider,
                     hint=self.request.localizer.translate(_("Click to open/close paragraph editor")),
-                    title=super(ParagraphContainerTitleColumn, self).renderCell(item)) + \
-               '<div class="inner-table-form editor margin-x-10 margin-bottom-0"></div>'
-
-    def getValue(self, obj):
-        return II18n(obj).query_attribute('title', request=self.request) or ' - - - - - - - -'
+                    title=super(ParagraphContainerTitleColumn, self).renderCell(item))
 
 
 @template_config(template='templates/paragraph-title-icon.pt', layer=IPyAMSLayer)
@@ -245,19 +259,51 @@
     count = None
 
 
-@adapter_config(name='trash', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable),
+@adapter_config(name='trash', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerBaseTable),
                 provides=IColumn)
 class ParagraphContainerTrashColumn(ProtectedFormObjectMixin, TrashColumn):
     """Paragraphs container trash column"""
 
 
-@adapter_config(context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable), provides=IValues)
-class ParagraphContainerValues(ContextRequestViewAdapter):
-    """Paragraphs container values"""
+@pagelet_config(name='paragraphs.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+@implementer(IParagraphContainerView)
+class ParagraphContainerView(ContainerAdminView):
+    """Paragraphs container view"""
+
+    title = _("Paragraphs list")
+    table_class = ParagraphContainerTable
+
+
+@pagelet_config(name='paragraphs-dialog.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
+                permission=VIEW_SYSTEM_PERMISSION)
+class ParagraphContainerDialogView(AdminDialogDisplayForm):
+    """Paragraphs container dialog view"""
+
+    title = _("Paragraphs list")
+    dialog_class = 'modal-large no-widget-toolbar'
+    fieldset_class = 'height-300'
 
-    @property
-    def values(self):
-        return IParagraphContainer(self.context).values()
+    fields = field.Fields(Interface)
+
+
+@adapter_config(name='paragraphs', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerDialogView),
+                provides=IInnerSubForm)
+@template_config(template='templates/paragraphs.pt', layer=IPyAMSLayer)
+@implementer(IParagraphContainerView)
+class ParagraphsView(Pagelet):
+    """Paragraphs view"""
+
+    weight = 90
+
+    def __init__(self, context, request, view):
+        super(ParagraphsView, self).__init__(context, request)
+        self.table = ParagraphContainerBaseTable(context, request)
+        self.table.view = self
+
+    def update(self):
+        super(ParagraphsView, self).update()
+        self.table.update()
 
 
 @adapter_config(context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerView), provides=IPageHeader)