src/pyams_content/shared/imagemap/zmi/__init__.py
changeset 69 8c5bbc396670
parent 16 8c652535a9a2
equal deleted inserted replaced
68:cf21b8cd6e74 69:8c5bbc396670
       
     1 #
       
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from pyams_content.interfaces import CREATE_CONTENT_PERMISSION
       
    20 from pyams_content.shared.imagemap.interfaces import IImageMapManager, IWfImageMap
       
    21 from pyams_i18n.interfaces import II18n
       
    22 from pyams_skin.interfaces.viewlet import IWidgetTitleViewletManager, IMenuHeader
       
    23 from pyams_skin.layer import IPyAMSLayer
       
    24 from pyams_zmi.interfaces.menu import IContentManagementMenu
       
    25 from pyams_zmi.layer import IAdminLayer
       
    26 
       
    27 # import packages
       
    28 from pyams_content.shared.common.zmi import SharedContentAddForm, SharedContentAJAXAddForm
       
    29 from pyams_pagelet.pagelet import pagelet_config
       
    30 from pyams_skin.interfaces import IContentTitle
       
    31 from pyams_skin.viewlet.toolbar import ToolbarAction
       
    32 from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter, ContextRequestAdapter
       
    33 from pyams_viewlet.viewlet import viewlet_config
       
    34 from pyramid.view import view_config
       
    35 from zope.interface import Interface
       
    36 
       
    37 from pyams_content import _
       
    38 
       
    39 
       
    40 @adapter_config(context=(IWfImageMap, IContentManagementMenu), provides=IMenuHeader)
       
    41 class ImageMapContentMenuHeader(ContextRequestAdapter):
       
    42     """Image map content menu header adapter"""
       
    43 
       
    44     header = _("This image map")
       
    45 
       
    46 
       
    47 @adapter_config(context=(IWfImageMap, IPyAMSLayer, Interface), provides=IContentTitle)
       
    48 class ImageMapTitleAdapter(ContextRequestViewAdapter):
       
    49     """Image map title adapter"""
       
    50 
       
    51     @property
       
    52     def title(self):
       
    53         translate = self.request.localizer.translate
       
    54         return translate(_("Image map « {title} »")).format(
       
    55             title=II18n(self.context).query_attribute('title', request=self.request))
       
    56 
       
    57 
       
    58 @viewlet_config(name='add-shared-content.action', context=IImageMapManager, layer=IAdminLayer, view=Interface,
       
    59                 manager=IWidgetTitleViewletManager, permission=CREATE_CONTENT_PERMISSION, weight=1)
       
    60 class ImageMapAddAction(ToolbarAction):
       
    61     """Image map adding action"""
       
    62 
       
    63     label = _("Add image map")
       
    64     url = 'add-shared-content.html'
       
    65     modal_target = True
       
    66 
       
    67 
       
    68 @pagelet_config(name='add-shared-content.html', context=IImageMapManager, layer=IPyAMSLayer,
       
    69                 permission=CREATE_CONTENT_PERMISSION)
       
    70 class ImageMapAddForm(SharedContentAddForm):
       
    71     """Image map add form"""
       
    72 
       
    73     legend = _("Adding image map")
       
    74 
       
    75 
       
    76 @view_config(name='add-shared-content.json', context=IImageMapManager, request_type=IPyAMSLayer,
       
    77              permission=CREATE_CONTENT_PERMISSION, renderer='json', xhr=True)
       
    78 class ImageMapAJAXAddForm(SharedContentAJAXAddForm, ImageMapAddForm):
       
    79     """Image map add form, JSON renderer"""