src/pyams_content/component/paragraph/zmi/video.py
changeset 591 b694d5667d17
parent 585 9fa8e9776bda
child 598 f9cd7d17430e
equal deleted inserted replaced
590:4fafaf94701d 591:b694d5667d17
    31 # import packages
    31 # import packages
    32 from pyams_content.component.paragraph.video import VideoParagraph
    32 from pyams_content.component.paragraph.video import VideoParagraph
    33 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
    33 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
    34     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, IParagraphEditFormButtons
    34     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, IParagraphEditFormButtons
    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 ajax_config
    36 from pyams_form.group import NamedWidgetsGroup
    37 from pyams_form.group import NamedWidgetsGroup
    37 from pyams_pagelet.pagelet import pagelet_config
    38 from pyams_pagelet.pagelet import pagelet_config
    38 from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event
    39 from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event
    39 from pyams_utils.adapter import adapter_config
    40 from pyams_utils.adapter import adapter_config
    40 from pyams_viewlet.viewlet import viewlet_config
    41 from pyams_viewlet.viewlet import viewlet_config
    57     paragraph_type = VIDEO_PARAGRAPH_TYPE
    58     paragraph_type = VIDEO_PARAGRAPH_TYPE
    58 
    59 
    59 
    60 
    60 @pagelet_config(name='add-video-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
    61 @pagelet_config(name='add-video-paragraph.html', context=IParagraphContainerTarget, layer=IPyAMSLayer,
    61                 permission=MANAGE_CONTENT_PERMISSION)
    62                 permission=MANAGE_CONTENT_PERMISSION)
       
    63 @ajax_config(name='add-video-paragraph.json', context=IParagraphContainerTarget, layer=IPyAMSLayer,
       
    64              base=BaseParagraphAJAXAddForm)
    62 class VideoParagraphAddForm(AdminDialogAddForm):
    65 class VideoParagraphAddForm(AdminDialogAddForm):
    63     """Video paragraph add form"""
    66     """Video paragraph add form"""
    64 
    67 
    65     legend = _("Add new video paragraph")
    68     legend = _("Add new video paragraph")
    66     dialog_class = 'modal-large'
    69     dialog_class = 'modal-large'
    67     icon_css_class = 'fa fa-fw fa-film'
    70     icon_css_class = 'fa fa-fw fa-film'
    68 
    71 
    69     fields = field.Fields(IVideoParagraph).omit('__parent__', '__name__', 'visible')
    72     fields = field.Fields(IVideoParagraph).omit('__parent__', '__name__', 'visible')
    70     ajax_handler = 'add-video-paragraph.json'
       
    71     edit_permission = MANAGE_CONTENT_PERMISSION
    73     edit_permission = MANAGE_CONTENT_PERMISSION
    72 
    74 
    73     def updateWidgets(self, prefix=None):
    75     def updateWidgets(self, prefix=None):
    74         super(VideoParagraphAddForm, self).updateWidgets(prefix)
    76         super(VideoParagraphAddForm, self).updateWidgets(prefix)
    75         if 'description' in self.widgets:
    77         if 'description' in self.widgets:
    94 
    96 
    95     def add(self, object):
    97     def add(self, object):
    96         IParagraphContainer(self.context).append(object)
    98         IParagraphContainer(self.context).append(object)
    97 
    99 
    98 
   100 
    99 @view_config(name='add-video-paragraph.json', context=IParagraphContainerTarget, request_type=IPyAMSLayer,
       
   100              permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
       
   101 class VideoParagraphAJAXAddForm(BaseParagraphAJAXAddForm, VideoParagraphAddForm):
       
   102     """Video paragraph add form, JSON renderer"""
       
   103 
       
   104 
       
   105 @pagelet_config(name='properties.html', context=IVideoParagraph, layer=IPyAMSLayer,
   101 @pagelet_config(name='properties.html', context=IVideoParagraph, layer=IPyAMSLayer,
   106                 permission=MANAGE_CONTENT_PERMISSION)
   102                 permission=MANAGE_CONTENT_PERMISSION)
       
   103 @ajax_config(name='properties.json', context=IVideoParagraph, layer=IPyAMSLayer,
       
   104              base=BaseParagraphAJAXEditForm)
   107 class VideoParagraphPropertiesEditForm(BaseParagraphPropertiesEditForm):
   105 class VideoParagraphPropertiesEditForm(BaseParagraphPropertiesEditForm):
   108     """Video paragraph properties edit form"""
   106     """Video paragraph properties edit form"""
   109 
   107 
   110     prefix = 'video_properties.'
   108     prefix = 'video_properties.'
   111 
   109 
   114     icon_css_class = 'fa fa-fw fa-film'
   112     icon_css_class = 'fa fa-fw fa-film'
   115 
   113 
   116     fields = field.Fields(IVideoParagraph).omit('__parent__', '__name__', 'visible')
   114     fields = field.Fields(IVideoParagraph).omit('__parent__', '__name__', 'visible')
   117     fields['renderer'].widgetFactory = RendererFieldWidget
   115     fields['renderer'].widgetFactory = RendererFieldWidget
   118 
   116 
   119     ajax_handler = 'properties.json'
       
   120     edit_permission = MANAGE_CONTENT_PERMISSION
   117     edit_permission = MANAGE_CONTENT_PERMISSION
   121 
   118 
   122     def updateWidgets(self, prefix=None):
   119     def updateWidgets(self, prefix=None):
   123         super(VideoParagraphPropertiesEditForm, self).updateWidgets(prefix)
   120         super(VideoParagraphPropertiesEditForm, self).updateWidgets(prefix)
   124         if 'description' in self.widgets:
   121         if 'description' in self.widgets:
   138                                          ('description', 'author', 'data', 'renderer'),
   135                                          ('description', 'author', 'data', 'renderer'),
   139                                          bordered=False))
   136                                          bordered=False))
   140         super(VideoParagraphPropertiesEditForm, self).updateGroups()
   137         super(VideoParagraphPropertiesEditForm, self).updateGroups()
   141 
   138 
   142 
   139 
   143 @view_config(name='properties.json', context=IVideoParagraph, request_type=IPyAMSLayer,
       
   144              permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
       
   145 class VideoParagraphPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, VideoParagraphPropertiesEditForm):
       
   146     """Video paragraph properties edit form, JSON renderer"""
       
   147 
       
   148 
       
   149 @adapter_config(context=(IVideoParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
   140 @adapter_config(context=(IVideoParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
       
   141 @ajax_config(name='inner-properties.json', context=IVideoParagraph, layer=IPyAMSLayer,
       
   142              base=BaseParagraphAJAXEditForm)
   150 @implementer(IInnerForm, IPropertiesEditForm, IAssociationsParentForm)
   143 @implementer(IInnerForm, IPropertiesEditForm, IAssociationsParentForm)
   151 class VideoParagraphPropertiesInnerEditForm(VideoParagraphPropertiesEditForm):
   144 class VideoParagraphPropertiesInnerEditForm(VideoParagraphPropertiesEditForm):
   152     """Video paragraph properties inner edit form"""
   145     """Video paragraph properties inner edit form"""
   153 
   146 
   154     legend = None
   147     legend = None
   155     ajax_handler = 'inner-properties.json'
       
   156 
   148 
   157     @property
   149     @property
   158     def buttons(self):
   150     def buttons(self):
   159         if self.mode == INPUT_MODE:
   151         if self.mode == INPUT_MODE:
   160             return button.Buttons(IParagraphEditFormButtons)
   152             return button.Buttons(IParagraphEditFormButtons)
   161         else:
   153         else:
   162             return button.Buttons()
   154             return button.Buttons()
   163 
   155 
   164 
       
   165 @view_config(name='inner-properties.json', context=IVideoParagraph, request_type=IPyAMSLayer,
       
   166              permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
       
   167 class VideoParagraphPropertiesInnerAJAXEditForm(BaseParagraphAJAXEditForm, VideoParagraphPropertiesInnerEditForm):
       
   168     """Video paragraph properties inner deit form, JSON renderer"""
       
   169 
       
   170     def get_ajax_output(self, changes):
   156     def get_ajax_output(self, changes):
   171         output = super(VideoParagraphPropertiesInnerAJAXEditForm, self).get_ajax_output(changes)
   157         output = super(self.__class__, self).get_ajax_output(changes)
   172         updated = changes.get(IVideoParagraph, ())
   158         updated = changes.get(IVideoParagraph, ())
   173         if 'data' in updated:
   159         if 'data' in updated:
   174             # we have to commit transaction to be able to handle blobs...
   160             # we have to commit transaction to be able to handle blobs...
   175             ITransactionManager(self.context).get().commit()
   161             ITransactionManager(self.context).get().commit()
   176             output.setdefault('events', []).append(
   162             output.setdefault('events', []).append(