Added control panel "Thesaurus" entry
authorThierry Florac <thierry.florac@onf.fr>
Tue, 30 Jun 2015 14:20:38 +0200
changeset 8 2064d2a24a70
parent 7 6a22cec2899b
child 9 cef1c49d26b0
Added control panel "Thesaurus" entry
src/pyams_thesaurus/zmi/manager.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_thesaurus/zmi/manager.py	Tue Jun 30 14:20:38 2015 +0200
@@ -0,0 +1,116 @@
+#
+# 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.
+#
+from z3c.table.interfaces import IColumn, IValues
+from zope.component.interfaces import ISite
+from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.container import ContainerView
+from pyams_skin.interfaces import IInnerPage, IPageHeader
+from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager
+from pyams_skin.layer import IPyAMSLayer
+from pyams_skin.page import DefaultPageHeaderAdapter
+from pyams_skin.table import BaseTable, TrashColumn
+from pyams_skin.viewlet.menu import MenuItem
+from pyams_skin.viewlet.toolbar import ToolbarAction
+from pyams_thesaurus.interfaces.thesaurus import IThesaurus
+from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
+from pyams_utils.registry import get_utilities_for
+from pyams_utils.url import absolute_url
+from pyams_viewlet.manager import viewletmanager_config
+from pyams_viewlet.viewlet import viewlet_config
+from pyams_zmi.interfaces.menu import IControlPanelMenu
+from pyams_zmi.layer import IAdminLayer
+from pyams_zmi.view import AdminView
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+
+# import packages
+from zope.interface import implementer, Interface
+
+from pyams_thesaurus import _
+
+
+@viewlet_config(name='thesaurus.menu', context=ISite, layer=IAdminLayer, manager=IControlPanelMenu,
+                permission='system.view', weight=15)
+@viewletmanager_config(name='thesaurus.menu', context=ISite, layer=IAdminLayer)
+class ThesaurusMenuItem(MenuItem):
+    """Thesaurus menu item"""
+
+    label = _("Thesaurus")
+    icon_class = 'fa-language'
+    url = '#thesaurus.html'
+
+
+class ControlPanelThesaurusTable(BaseTable):
+    """Control panel thesaurus table"""
+
+    title = _("Registered thesaurus")
+
+    @property
+    def data_attributes(self):
+        manager = self.context.getSiteManager()
+        attributes = super(ControlPanelThesaurusTable, self).data_attributes
+        table_attrs = {'data-ams-location': absolute_url(manager, self.request)}
+        if 'table' in attributes:
+            attributes['table'].update(table_attrs)
+        else:
+            attributes['table'] = table_attrs
+        return attributes
+
+
+@adapter_config(name='trash', context=(Interface, IAdminLayer, ControlPanelThesaurusTable), provides=IColumn)
+class ControlPanelThesaurusTrashColumn(TrashColumn):
+    """Thesaurus trash column"""
+
+    icon_hint = _("Delete thesaurus")
+    permission = 'system.manage'
+
+
+@adapter_config(context=(ISite, IAdminLayer, ControlPanelThesaurusTable), provides=IValues)
+class ControlPanelThesaurusValuesAdapter(ContextRequestViewAdapter):
+    """Thesaurus table values adapter"""
+
+    @property
+    def values(self):
+        for name, thesaurus in get_utilities_for(IThesaurus):
+            yield thesaurus
+
+
+@pagelet_config(name='thesaurus.html', context=ISite, layer=IPyAMSLayer, permission='system.view')
+@implementer(IInnerPage)
+class ControlPanelThesaurusView(AdminView, ContainerView):
+    """Control panel thesaurus view"""
+
+    table_class = ControlPanelThesaurusTable
+
+
+@adapter_config(context=(ISite, IAdminLayer, ControlPanelThesaurusView), provides=IPageHeader)
+class ControlPanelThesaurusHeaderAdapter(DefaultPageHeaderAdapter):
+    """Thesaurus view header adapter"""
+
+    icon_class = 'fa fa-fw fa-language'
+    title = _("Control panel")
+    subtitle = _("Thesaurus")
+
+
+@viewlet_config(name='add-thesaurus.action', context=ISite, view=ControlPanelThesaurusTable, layer=IAdminLayer,
+                manager=IWidgetTitleViewletManager, permission='system.manage')
+class ThesaurusAddAction(ToolbarAction):
+    """Thesaurus add action"""
+
+    label = _("Add thesaurus")
+    url = 'add-thesaurus.html'
+    modal_target = True