src/pyams_content/component/gallery/zmi/paragraph.py
changeset 591 b694d5667d17
parent 555 8e8a14452567
child 842 7f0d72e427b1
equal deleted inserted replaced
590:4fafaf94701d 591:b694d5667d17
    32 from pyams_content.component.gallery.paragraph import Gallery
    32 from pyams_content.component.gallery.paragraph import Gallery
    33 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
    33 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
    34     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, get_json_paragraph_refresh_event, IParagraphEditFormButtons
    34     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, get_json_paragraph_refresh_event, IParagraphEditFormButtons
    35 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
    35 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
    36 from pyams_content.shared.common.zmi import WfSharedContentPermissionMixin
    36 from pyams_content.shared.common.zmi import WfSharedContentPermissionMixin
       
    37 from pyams_form.form import ajax_config
    37 from pyams_pagelet.pagelet import pagelet_config
    38 from pyams_pagelet.pagelet import pagelet_config
    38 from pyams_skin.viewlet.toolbar import ToolbarAction
    39 from pyams_skin.viewlet.toolbar import ToolbarAction
    39 from pyams_template.template import template_config
    40 from pyams_template.template import template_config
    40 from pyams_utils.adapter import adapter_config
    41 from pyams_utils.adapter import adapter_config
    41 from pyams_utils.url import absolute_url
    42 from pyams_utils.url import absolute_url
    42 from pyams_viewlet.viewlet import viewlet_config
    43 from pyams_viewlet.viewlet import viewlet_config
    43 from pyams_zmi.form import AdminDialogAddForm, InnerAdminDisplayForm
    44 from pyams_zmi.form import AdminDialogAddForm, InnerAdminDisplayForm
    44 from pyramid.view import view_config
       
    45 from z3c.form import field, button
    45 from z3c.form import field, button
    46 from zope.interface import implementer, Interface
    46 from zope.interface import implementer, Interface
    47 
    47 
    48 from pyams_content import _
    48 from pyams_content import _
    49 
    49 
    59     paragraph_type = GALLERY_PARAGRAPH_TYPE
    59     paragraph_type = GALLERY_PARAGRAPH_TYPE
    60 
    60 
    61 
    61 
    62 @pagelet_config(name='add-gallery.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
    62 @pagelet_config(name='add-gallery.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
    63                 permission=MANAGE_CONTENT_PERMISSION)
    63                 permission=MANAGE_CONTENT_PERMISSION)
       
    64 @ajax_config(name='add-gallery.json', context=IParagraphContainerTarget, layer=IPyAMSLayer,
       
    65              base=BaseParagraphAJAXAddForm)
    64 class GalleryAddForm(AdminDialogAddForm):
    66 class GalleryAddForm(AdminDialogAddForm):
    65     """Gallery add form"""
    67     """Gallery add form"""
    66 
    68 
    67     legend = _("Add new gallery")
    69     legend = _("Add new gallery")
    68     icon_css_class = 'fa fa-fw fa-picture-o'
    70     icon_css_class = 'fa fa-fw fa-picture-o'
    69 
    71 
    70     fields = field.Fields(IGalleryParagraph).omit('__parent__', '__name__', 'visible')
    72     fields = field.Fields(IGalleryParagraph).omit('__parent__', '__name__', 'visible')
    71     ajax_handler = 'add-gallery.json'
       
    72     edit_permission = MANAGE_CONTENT_PERMISSION
    73     edit_permission = MANAGE_CONTENT_PERMISSION
    73 
    74 
    74     def updateWidgets(self, prefix=None):
    75     def updateWidgets(self, prefix=None):
    75         super(GalleryAddForm, self).updateWidgets(prefix)
    76         super(GalleryAddForm, self).updateWidgets(prefix)
    76         if 'description' in self.widgets:
    77         if 'description' in self.widgets:
    81 
    82 
    82     def add(self, object):
    83     def add(self, object):
    83         IParagraphContainer(self.context).append(object)
    84         IParagraphContainer(self.context).append(object)
    84 
    85 
    85 
    86 
    86 @view_config(name='add-gallery.json', context=IParagraphContainerTarget, request_type=IPyAMSLayer,
       
    87              permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
       
    88 class GalleryAJAXAddForm(BaseParagraphAJAXAddForm, GalleryAddForm):
       
    89     """Gallery paragraph add form, JSON renderer"""
       
    90 
       
    91 
       
    92 @pagelet_config(name='properties.html', context=IGalleryParagraph, layer=IPyAMSLayer,
    87 @pagelet_config(name='properties.html', context=IGalleryParagraph, layer=IPyAMSLayer,
    93                 permission=MANAGE_CONTENT_PERMISSION)
    88                 permission=MANAGE_CONTENT_PERMISSION)
       
    89 @ajax_config(name='properties.json', context=IGalleryParagraph, layer=IPyAMSLayer,
       
    90              base=BaseParagraphAJAXEditForm)
    94 class GalleryPropertiesEditForm(BaseParagraphPropertiesEditForm):
    91 class GalleryPropertiesEditForm(BaseParagraphPropertiesEditForm):
    95     """Gallery properties edit form"""
    92     """Gallery properties edit form"""
    96 
    93 
    97     prefix = 'gallery_properties.'
    94     prefix = 'gallery_properties.'
    98 
    95 
   100     icon_css_class = 'fa fa-fw fa-picture-o'
    97     icon_css_class = 'fa fa-fw fa-picture-o'
   101 
    98 
   102     fields = field.Fields(IGalleryParagraph).omit('__parent__', '__name__', 'visible')
    99     fields = field.Fields(IGalleryParagraph).omit('__parent__', '__name__', 'visible')
   103     fields['renderer'].widgetFactory = RendererFieldWidget
   100     fields['renderer'].widgetFactory = RendererFieldWidget
   104 
   101 
   105     ajax_handler = 'properties.json'
       
   106     edit_permission = MANAGE_CONTENT_PERMISSION
   102     edit_permission = MANAGE_CONTENT_PERMISSION
   107 
   103 
   108     def updateWidgets(self, prefix=None):
   104     def updateWidgets(self, prefix=None):
   109         super(GalleryPropertiesEditForm, self).updateWidgets(prefix)
   105         super(GalleryPropertiesEditForm, self).updateWidgets(prefix)
   110         if 'description' in self.widgets:
   106         if 'description' in self.widgets:
   111             self.widgets['description'].widget_css_class = 'textarea'
   107             self.widgets['description'].widget_css_class = 'textarea'
   112 
       
   113 
       
   114 @view_config(name='properties.json', context=IGalleryParagraph, request_type=IPyAMSLayer,
       
   115              permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
       
   116 class GalleryPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, GalleryPropertiesEditForm):
       
   117     """Gallery paragraph properties edit form, JSON renderer"""
       
   118 
   108 
   119     def get_ajax_output(self, changes):
   109     def get_ajax_output(self, changes):
   120         updated = changes.get(IBaseGallery, ())
   110         updated = changes.get(IBaseGallery, ())
   121         if 'title' in updated:
   111         if 'title' in updated:
   122             return {
   112             return {
   123                 'status': 'success',
   113                 'status': 'success',
   124                 'events': [get_json_paragraph_refresh_event(self.context, self.request), ]
   114                 'events': [get_json_paragraph_refresh_event(self.context, self.request), ]
   125             }
   115             }
   126         else:
   116         else:
   127             return super(GalleryPropertiesAJAXEditForm, self).get_ajax_output(changes)
   117             return super(self.__class__, self).get_ajax_output(changes)
   128 
   118 
   129 
   119 
   130 @adapter_config(context=(IGalleryParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
   120 @adapter_config(context=(IGalleryParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
   131 @implementer(IInnerForm)
   121 @implementer(IInnerForm)
   132 class GalleryInnerEditForm(GalleryPropertiesEditForm):
   122 class GalleryInnerEditForm(GalleryPropertiesEditForm):