src/pyams_content/component/gallery/zmi/__init__.py
changeset 591 b694d5667d17
parent 552 63d41f025390
child 842 7f0d72e427b1
equal deleted inserted replaced
590:4fafaf94701d 591:b694d5667d17
    31 from pyramid.interfaces import IView
    31 from pyramid.interfaces import IView
    32 
    32 
    33 # import packages
    33 # import packages
    34 from pyams_content.shared.common.zmi import WfSharedContentPermissionMixin
    34 from pyams_content.shared.common.zmi import WfSharedContentPermissionMixin
    35 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
    35 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
    36 from pyams_form.form import AJAXEditForm
    36 from pyams_form.form import ajax_config
    37 from pyams_pagelet.pagelet import pagelet_config
    37 from pyams_pagelet.pagelet import pagelet_config
    38 from pyams_template.template import template_config
    38 from pyams_template.template import template_config
    39 from pyams_utils.url import absolute_url
    39 from pyams_utils.url import absolute_url
    40 from pyams_viewlet.viewlet import viewlet_config, Viewlet
    40 from pyams_viewlet.viewlet import viewlet_config, Viewlet
    41 from pyams_zmi.form import AdminDialogEditForm, AdminDialogDisplayForm
    41 from pyams_zmi.form import AdminDialogEditForm, AdminDialogDisplayForm
    52 #
    52 #
    53 # Gallery properties
    53 # Gallery properties
    54 #
    54 #
    55 
    55 
    56 @pagelet_config(name='properties.html', context=IGallery, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
    56 @pagelet_config(name='properties.html', context=IGallery, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
       
    57 @ajax_config(name='properties.json', context=IGallery, layer=IPyAMSLayer)
    57 class GalleryPropertiesEditForm(AdminDialogEditForm):
    58 class GalleryPropertiesEditForm(AdminDialogEditForm):
    58     """Gallery properties edit form"""
    59     """Gallery properties edit form"""
    59 
    60 
    60     prefix = 'gallery_properties.'
    61     prefix = 'gallery_properties.'
    61 
    62 
    63     icon_css_class = 'fa fa-fw fa-picture-o'
    64     icon_css_class = 'fa fa-fw fa-picture-o'
    64 
    65 
    65     fields = field.Fields(IGallery).omit('__parent__', '__file__')
    66     fields = field.Fields(IGallery).omit('__parent__', '__file__')
    66     fields['renderer'].widgetFactory = RendererFieldWidget
    67     fields['renderer'].widgetFactory = RendererFieldWidget
    67 
    68 
    68     ajax_handler = 'properties.json'
       
    69     edit_permission = MANAGE_CONTENT_PERMISSION
    69     edit_permission = MANAGE_CONTENT_PERMISSION
    70 
    70 
    71     def updateWidgets(self, prefix=None):
    71     def updateWidgets(self, prefix=None):
    72         super(GalleryPropertiesEditForm, self).updateWidgets(prefix)
    72         super(GalleryPropertiesEditForm, self).updateWidgets(prefix)
    73         if 'description' in self.widgets:
    73         if 'description' in self.widgets:
    74             self.widgets['description'].widget_css_class = 'textarea'
    74             self.widgets['description'].widget_css_class = 'textarea'
    75 
       
    76 
       
    77 @view_config(name='properties.json', context=IGallery, request_type=IPyAMSLayer,
       
    78              permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
       
    79 class GalleryPropertiesAJAXEditForm(AJAXEditForm, GalleryPropertiesEditForm):
       
    80     """Gallery properties edit form, JSON renderer"""
       
    81 
    75 
    82     def get_ajax_output(self, changes):
    76     def get_ajax_output(self, changes):
    83         if 'title' in changes.get(IGallery, ()):
    77         if 'title' in changes.get(IGallery, ()):
    84             return {
    78             return {
    85                 'status': 'reload',
    79                 'status': 'reload',
    86                 'location': '#external-files.html'
    80                 'location': '#external-files.html'
    87             }
    81             }
    88         else:
    82         else:
    89             return super(GalleryPropertiesAJAXEditForm, self).get_ajax_output(changes)
    83             return super(self.__class__, self).get_ajax_output(changes)
    90 
    84 
    91 
    85 
    92 #
    86 #
    93 # Gallery contents
    87 # Gallery contents
    94 #
    88 #