--- a/src/pyams_content/component/paragraph/zmi/container.py Thu Apr 21 18:10:03 2016 +0200
+++ b/src/pyams_content/component/paragraph/zmi/container.py Thu Apr 21 18:11:18 2016 +0200
@@ -9,7 +9,11 @@
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
+from zope.contentprovider.interfaces import IContentProvider
+
from pyams_form.interfaces.form import IFormSecurityContext
+from pyams_viewlet.interfaces import IViewletManager
+from pyams_viewlet.manager import viewletmanager_config, WeightOrderedViewletManager, TemplateBasedViewletManager
__docformat__ = 'restructuredtext'
@@ -23,7 +27,7 @@
from pyams_content.component.gallery.interfaces import IGalleryLinksContainerTarget, IGalleryLinksContainer
from pyams_content.component.links.interfaces import ILinkLinksContainerTarget, ILinkLinksContainer
from pyams_content.component.paragraph.interfaces import IParagraphContainerTarget, IParagraphContainer, IBaseParagraph
-from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor
+from pyams_content.component.paragraph.zmi.interfaces import IParagraphInnerEditor, IParagraphTitleToolbar
from pyams_i18n.interfaces import II18n
from pyams_skin.interfaces import IInnerPage, IPageHeader
from pyams_skin.layer import IPyAMSLayer
@@ -44,7 +48,7 @@
from pyams_utils.url import absolute_url
from pyramid.exceptions import NotFound
from pyramid.view import view_config
-from pyams_viewlet.viewlet import viewlet_config
+from pyams_viewlet.viewlet import viewlet_config, Viewlet
from pyams_zmi.view import AdminView
from pyramid.decorator import reify
from z3c.table.column import GetAttrColumn
@@ -180,88 +184,66 @@
return column.table.context
-@adapter_config(name='files', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable),
- provides=IColumn)
-class ParagraphContainerExtFileLinksColumn(ActionColumn):
- """Paragraphs container external files links column"""
+@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)
+@implementer(IParagraphTitleToolbar)
+class ParagraphTitleToolbarViewletManager(TemplateBasedViewletManager, WeightOrderedViewletManager):
+ """Paragraph title toolbar viewlet manager"""
+
+@viewlet_config(name='files', context=IExtFileLinksContainerTarget, layer=IPyAMSLayer, view=ParagraphContainerTable,
+ manager=IParagraphTitleToolbar, permission=VIEW_SYSTEM_PERMISSION, weight=10)
+@template_config(template='templates/paragraph-title-icon.pt', layer=IPyAMSLayer)
+class ParagraphContainerExtFileLinksAction(Viewlet):
+ """Paragraph container external files links column"""
+
+ action_class = 'action extfiles nowrap width-40'
icon_class = 'fa fa-fw fa-file-text-o'
icon_hint = _("External files")
- cssClasses = {'td': 'action extfiles nowrap'}
-
url = 'extfile-links.html'
modal_target = True
- weight = 10
-
- def renderCell(self, item):
- if not IExtFileLinksContainerTarget.providedBy(item):
- return ''
- action = '{action} <span class="count">{{count}}</span>'.format(
- action=super(ParagraphContainerExtFileLinksColumn, self).renderCell(item))
- length = len(IExtFileLinksContainer(item).files or ())
- if length:
- action = action.format(count='({0})'.format(length))
- else:
- action = action.format(count='')
- return action
+ @property
+ def count(self):
+ return len(IExtFileLinksContainer(self.context).files or ())
-@adapter_config(name='links', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable),
- provides=IColumn)
-class ParagraphContainerLinkLinksColumn(ActionColumn):
- """Paragraphs container links links column"""
+@viewlet_config(name='links', context=ILinkLinksContainerTarget, layer=IPyAMSLayer, view=ParagraphContainerTable,
+ manager=IParagraphTitleToolbar, permission=VIEW_SYSTEM_PERMISSION, weight=20)
+@template_config(template='templates/paragraph-title-icon.pt', layer=IPyAMSLayer)
+class ParagraphContainerLinkLinksAction(Viewlet):
+ """Paragraph container links links column"""
+ action_class = 'action links nowrap width-40'
icon_class = 'fa fa-fw fa-link'
icon_hint = _("Useful links")
- cssClasses = {'td': 'action links nowrap'}
-
url = 'link-links.html'
modal_target = True
- weight = 15
-
- def renderCell(self, item):
- if not ILinkLinksContainerTarget.providedBy(item):
- return ''
- action = '{action} <span class="count">{{count}}</span>'.format(
- action=super(ParagraphContainerLinkLinksColumn, self).renderCell(item))
- length = len(ILinkLinksContainer(item).links or ())
- if length:
- action = action.format(count='({0})'.format(length))
- else:
- action = action.format(count='')
- return action
+ @property
+ def count(self):
+ return len(ILinkLinksContainer(self.context).links or ())
-@adapter_config(name='gallery', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable),
- provides=IColumn)
-class ParagraphContainerGalleryLinksColumn(ActionColumn):
- """Paragraphs container gallery links column"""
+@viewlet_config(name='gallery', context=IGalleryLinksContainerTarget, layer=IPyAMSLayer, view=ParagraphContainerTable,
+ manager=IParagraphTitleToolbar, permission=VIEW_SYSTEM_PERMISSION, weight=30)
+@template_config(template='templates/paragraph-title-icon.pt', layer=IPyAMSLayer)
+class ParagraphContainerGalleryLinksAction(Viewlet):
+ """Paragraph container gallery links column"""
+ action_class = 'action galleries nowrap width-40'
icon_class = 'fa fa-fw fa-picture-o'
icon_hint = _("Images galleries")
- cssClasses = {'td': 'action galleries nowrap'}
-
url = 'gallery-links.html'
modal_target = True
- weight = 20
-
- def renderCell(self, item):
- if not IGalleryLinksContainerTarget.providedBy(item):
- return ''
- action = '{action} <span class="count">{{count}}</span>'.format(
- action=super(ParagraphContainerGalleryLinksColumn, self).renderCell(item))
- length = len(IGalleryLinksContainer(item).galleries or ())
- if length:
- action = action.format(count='({0})'.format(length))
- else:
- action = action.format(count='')
- return action
+ @property
+ def count(self):
+ return len(IGalleryLinksContainer(self.context).galleries or ())
@adapter_config(name='name', context=(IParagraphContainerTarget, IPyAMSLayer, ParagraphContainerTable),
@@ -283,12 +265,20 @@
super(ParagraphContainerTitleColumn, self).renderHeadCell()
def renderCell(self, item):
- return '<div><span class="small hint" title="{title}" data-ams-hint-gravity="e"' \
+ registry = self.request.registry
+ provider = registry.queryMultiAdapter((item, self.request, self.table), IContentProvider,
+ name='pyams_paragraph.title_toolbar')
+ if provider is not None:
+ provider.update()
+ provider = provider.render()
+ else:
+ provider = ''
+ return '<div>{provider}<span class="small hint" title="{title}" data-ams-hint-gravity="e"' \
' data-ams-stop-propagation="true" ' \
' data-ams-click-handler="PyAMS_content.paragraphs.switchEditor">' \
' <i class="fa fa-plus-square-o"></i>' \
- '</span> '.format(
- title=self.request.localizer.translate(_("Click to open/close paragraph editor"))) + \
+ '</span> '.format(provider=provider,
+ title=self.request.localizer.translate(_("Click to open/close paragraph editor"))) + \
'<span class="title">{0}</span>'.format(super(ParagraphContainerTitleColumn, self).renderCell(item)) + \
'</div><div class="inner-table-form editor margin-x-10 margin-bottom-0"></div>'