--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_content/component/gallery/zmi/container.py Thu Oct 08 13:37:29 2015 +0200
@@ -0,0 +1,198 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from pyams_content.component.gallery.interfaces import IGalleryContainerTarget, IGalleryContainer, \
+ IGalleryLinksContainerTarget, IGalleryLinksContainer
+from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
+from pyams_i18n.interfaces import II18n
+from pyams_skin.interfaces import IInnerPage, IPageHeader
+from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
+from pyams_utils.interfaces.data import IObjectData
+from pyams_zmi.interfaces.menu import IPropertiesMenu
+from pyams_zmi.layer import IAdminLayer
+from z3c.table.interfaces import IColumn, IValues
+
+# import packages
+from pyams_content.component.gallery.zmi.widget import GalleryLinkSelectFieldWidget
+from pyams_content.shared.common.zmi import WfModifiedContentColumnMixin
+from pyams_form.form import AJAXEditForm
+from pyams_form.security import ProtectedFormObjectMixin
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.layer import IPyAMSLayer
+from pyams_skin.page import DefaultPageHeaderAdapter
+from pyams_skin.table import BaseTable, I18nColumn, TrashColumn, ActionColumn
+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.url import absolute_url
+from pyams_viewlet.viewlet import viewlet_config
+from pyams_zmi.form import AdminDialogEditForm
+from pyams_zmi.view import AdminView
+from pyramid.decorator import reify
+from pyramid.view import view_config
+from z3c.table.column import GetAttrColumn
+from z3c.form import field
+from zope.interface import implementer, alsoProvides
+
+from pyams_content import _
+
+
+@viewlet_config(name='galleries.menu', context=IGalleryContainerTarget, layer=IAdminLayer,
+ manager=IPropertiesMenu, permission=VIEW_SYSTEM_PERMISSION, weight=220)
+class GalleryContainerMenu(MenuItem):
+ """Galleries container menu"""
+
+ label = _("Images galleries...")
+ icon_class = 'fa-picture-o'
+ url = '#galleries.html'
+
+
+#
+# Galleries container views
+#
+
+@pagelet_config(name='galleries.html', context=IGalleryContainerTarget, layer=IPyAMSLayer,
+ permission=VIEW_SYSTEM_PERMISSION)
+@template_config(template='templates/container.pt', layer=IPyAMSLayer)
+@implementer(IInnerPage)
+class GalleryContainerView(AdminView):
+ """Galleries container view"""
+
+ title = _("Galleries list")
+
+ def __init__(self, context, request):
+ super(GalleryContainerView, self).__init__(context, request)
+ self.galleries_table = GalleryContainerTable(context, request)
+
+ def update(self):
+ super(GalleryContainerView, self).update()
+ self.galleries_table.update()
+
+
+class GalleryContainerTable(BaseTable):
+ """Galleries container table"""
+
+ hide_header = True
+ cssClasses = {'table': 'table table-bordered table-striped table-hover table-tight'}
+
+ def __init__(self, context, request):
+ super(GalleryContainerTable, self).__init__(context, request)
+ self.object_data = {'ams-widget-toggle-button': 'false'}
+ alsoProvides(self, IObjectData)
+
+ @property
+ def data_attributes(self):
+ attributes = super(GalleryContainerTable, self).data_attributes
+ attributes['table'] = {'data-ams-location': absolute_url(IGalleryContainer(self.context), self.request),
+ 'data-ams-datatable-sort': 'false',
+ 'data-ams-datatable-pagination': 'false'}
+ return attributes
+
+ @reify
+ def values(self):
+ return list(super(GalleryContainerTable, self).values)
+
+ def render(self):
+ if not self.values:
+ translate = self.request.localizer.translate
+ return translate(_("No currently defined gallery."))
+ return super(GalleryContainerTable, self).render()
+
+
+@adapter_config(name='name', context=(IGalleryContainerTarget, IPyAMSLayer, GalleryContainerTable), provides=IColumn)
+class GalleryContainerNameColumn(I18nColumn, WfModifiedContentColumnMixin, GetAttrColumn):
+ """Galleries container name column"""
+
+ _header = _("Title")
+
+ weight = 10
+
+ def getValue(self, obj):
+ return II18n(obj).query_attribute('title', request=self.request)
+
+
+@adapter_config(name='count', context=(IGalleryContainerTarget, IPyAMSLayer, GalleryContainerTable), provides=IColumn)
+class GalleryContainerCountColumn(I18nColumn, GetAttrColumn):
+ """Gallery container images counter column"""
+
+ _header = _("Images")
+
+ weight = 20
+
+ def getValue(self, obj):
+ return len(obj)
+
+
+@adapter_config(name='manage', context=(IGalleryContainerTarget, IPyAMSLayer, GalleryContainerTable), provides=IColumn)
+class GalleryContainerManageColumn(ActionColumn):
+ """Gallery container manage column"""
+
+ icon_class = 'fa fa-fw fa-camera'
+ icon_hint = _("Display gallery contents")
+
+ url = 'contents.html'
+ target = None
+ modal_target = True
+
+ weight = 30
+
+
+@adapter_config(name='trash', context=(IGalleryContainerTarget, IPyAMSLayer, GalleryContainerTable), provides=IColumn)
+class GalleryContainerTrashColumn(ProtectedFormObjectMixin, TrashColumn):
+ """Galleries container trash column"""
+
+
+@adapter_config(context=(IGalleryContainerTarget, IPyAMSLayer, GalleryContainerTable), provides=IValues)
+class GalleryContainerValues(ContextRequestViewAdapter):
+ """Galleries container values"""
+
+ @property
+ def values(self):
+ return IGalleryContainer(self.context).values()
+
+
+@adapter_config(context=(IGalleryContainerTarget, IPyAMSLayer, GalleryContainerView), provides=IPageHeader)
+class GalleryHeaderAdapter(DefaultPageHeaderAdapter):
+ """Galleries container header adapter"""
+
+ back_url = '#properties.html'
+ icon_class = 'fa fa-fw fa-picture-o'
+
+
+#
+# Galleries links edit form
+#
+
+@pagelet_config(name='gallery-links.html', context=IGalleryLinksContainerTarget, layer=IPyAMSLayer,
+ permission=VIEW_SYSTEM_PERMISSION)
+class GalleryLinksContainerLinksEditForm(AdminDialogEditForm):
+ """Galleries links container edit form"""
+
+ legend = _("Edit galleries links")
+
+ fields = field.Fields(IGalleryLinksContainer)
+ fields['galleries'].widgetFactory = GalleryLinkSelectFieldWidget
+
+ ajax_handler = 'gallery-links.json'
+ edit_permission = MANAGE_CONTENT_PERMISSION
+
+
+@view_config(name='gallery-links.json', context=IGalleryLinksContainerTarget, request_type=IPyAMSLayer,
+ permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
+class GalleryLinksContainerAJAXEditForm(AJAXEditForm, GalleryLinksContainerLinksEditForm):
+ """Galleries links container edit form, JSON renderer"""