src/pyams_zmi/skin.py
changeset 49 0b1285117171
parent 44 139c875eabaf
equal deleted inserted replaced
48:4f9900ac02a1 49:0b1285117171
    14 
    14 
    15 
    15 
    16 # import standard library
    16 # import standard library
    17 
    17 
    18 # import interfaces
    18 # import interfaces
    19 from pyams_skin.interfaces import ISkin, IUserSkinnable
    19 from pyams_skin.interfaces import ISkin
    20 from pyams_skin.layer import IPyAMSLayer
       
    21 from pyams_utils.interfaces import MANAGE_SKIN_PERMISSION
       
    22 from pyams_zmi.interfaces.menu import IPropertiesMenu
       
    23 from pyams_zmi.layer import IAdminLayer
    20 from pyams_zmi.layer import IAdminLayer
    24 
    21 
    25 # import packages
    22 # import packages
    26 from pyams_form.form import AJAXEditForm
       
    27 from pyams_pagelet.pagelet import pagelet_config
       
    28 from pyams_skin.viewlet.menu import MenuItem, MenuDivider
       
    29 from pyams_utils.registry import utility_config
    23 from pyams_utils.registry import utility_config
    30 from pyams_viewlet.viewlet import viewlet_config
       
    31 from pyams_zmi.form import AdminDialogEditForm
       
    32 from pyramid.view import view_config
       
    33 from z3c.form import field
       
    34 
    24 
    35 from pyams_zmi import _
    25 from pyams_zmi import _
    36 
    26 
    37 
    27 
    38 @utility_config(name='PyAMS admin skin', provides=ISkin)
    28 @utility_config(name='PyAMS admin skin', provides=ISkin)
    39 class AdminSkin(object):
    29 class AdminSkin(object):
    40     """PyAMS administration skin"""
    30     """PyAMS administration skin"""
    41 
    31 
    42     label = _("PyAMS management skin")
    32     label = _("PyAMS management skin")
    43     layer = IAdminLayer
    33     layer = IAdminLayer
    44 
       
    45 
       
    46 #
       
    47 # User skinnable properties configuration
       
    48 #
       
    49 
       
    50 @viewlet_config(name='user-skin-properties.divider', context=IUserSkinnable, layer=IAdminLayer, manager=IPropertiesMenu,
       
    51                 permission=MANAGE_SKIN_PERMISSION, weight=199)
       
    52 class UserSkinnablePropertiesMenuDivider(MenuDivider):
       
    53     """User skin properties menu divider"""
       
    54 
       
    55 
       
    56 @viewlet_config(name='user-skin-properties.menu', context=IUserSkinnable, layer=IAdminLayer, manager=IPropertiesMenu,
       
    57                 permission=MANAGE_SKIN_PERMISSION, weight=200)
       
    58 class UserSkinnablePropertiesMenuItem(MenuItem):
       
    59     """User skin properties menu"""
       
    60 
       
    61     label = _("Graphic theme...")
       
    62     icon_class = 'fa-paint-brush'
       
    63     url = 'user-skin-properties.html'
       
    64     modal_target = True
       
    65 
       
    66 
       
    67 @pagelet_config(name='user-skin-properties.html', context=IUserSkinnable, layer=IPyAMSLayer,
       
    68                 permission=MANAGE_SKIN_PERMISSION)
       
    69 class UserSkinnablePropertiesEditForm(AdminDialogEditForm):
       
    70     """User skin properties edit form"""
       
    71 
       
    72     legend = _("Graphic theme elements")
       
    73     label_css_class = 'control-label col-md-4'
       
    74     input_css_class = 'col-md-8'
       
    75 
       
    76     @property
       
    77     def fields(self):
       
    78         fields = field.Fields(IUserSkinnable)
       
    79         if not self.context.can_inherit_skin:
       
    80             fields = fields.omit('inherit_skin')
       
    81         return fields
       
    82 
       
    83     ajax_handler = 'user-skin-properties.json'
       
    84     edit_permission = MANAGE_SKIN_PERMISSION
       
    85 
       
    86 
       
    87 @view_config(name='user-skin-properties.json', context=IUserSkinnable, request_type=IPyAMSLayer,
       
    88              permission=MANAGE_SKIN_PERMISSION, renderer='json', xhr=True)
       
    89 class UserSkinnablePropertiesAJAXEditForm(AJAXEditForm, UserSkinnablePropertiesEditForm):
       
    90     """User skin properties edit form, JSON renderer"""