src/pyams_content/component/paragraph/zmi/video.py
changeset 585 9fa8e9776bda
parent 570 196121e4a6f4
child 591 b694d5667d17
equal deleted inserted replaced
584:bfc376efd87c 585:9fa8e9776bda
    27 from pyams_zmi.interfaces import IPropertiesEditForm
    27 from pyams_zmi.interfaces import IPropertiesEditForm
    28 from transaction.interfaces import ITransactionManager
    28 from transaction.interfaces import ITransactionManager
    29 from z3c.form.interfaces import INPUT_MODE
    29 from z3c.form.interfaces import INPUT_MODE
    30 
    30 
    31 # import packages
    31 # import packages
    32 from pyams_content.component.association.zmi import AssociationsTable
       
    33 from pyams_content.component.paragraph.video import VideoParagraph
    32 from pyams_content.component.paragraph.video import VideoParagraph
    34 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
    33 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
    35     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, IParagraphEditFormButtons
    34     BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, IParagraphEditFormButtons
    36 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
    35 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
    37 from pyams_form.group import NamedWidgetsGroup
    36 from pyams_form.group import NamedWidgetsGroup
   144 @view_config(name='properties.json', context=IVideoParagraph, request_type=IPyAMSLayer,
   143 @view_config(name='properties.json', context=IVideoParagraph, request_type=IPyAMSLayer,
   145              permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
   144              permission=MANAGE_CONTENT_PERMISSION, renderer='json', xhr=True)
   146 class VideoParagraphPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, VideoParagraphPropertiesEditForm):
   145 class VideoParagraphPropertiesAJAXEditForm(BaseParagraphAJAXEditForm, VideoParagraphPropertiesEditForm):
   147     """Video paragraph properties edit form, JSON renderer"""
   146     """Video paragraph properties edit form, JSON renderer"""
   148 
   147 
   149     def get_ajax_output(self, changes):
       
   150         output = super(VideoParagraphPropertiesAJAXEditForm, self).get_ajax_output(changes)
       
   151         if 'body' in changes.get(IVideoParagraph, ()):
       
   152             associations_table = AssociationsTable(self.context, self.request)
       
   153             associations_table.update()
       
   154             output.setdefault('events', []).append({
       
   155                 'event': 'PyAMS_content.changed_item',
       
   156                 'options': {'handler': 'PyAMS_content.associations.refreshAssociations',
       
   157                             'object_name': associations_table.id,
       
   158                             'table': associations_table.render()}})
       
   159         return output
       
   160 
       
   161 
   148 
   162 @adapter_config(context=(IVideoParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
   149 @adapter_config(context=(IVideoParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
   163 @implementer(IInnerForm, IPropertiesEditForm, IAssociationsParentForm)
   150 @implementer(IInnerForm, IPropertiesEditForm, IAssociationsParentForm)
   164 class VideoParagraphPropertiesInnerEditForm(VideoParagraphPropertiesEditForm):
   151 class VideoParagraphPropertiesInnerEditForm(VideoParagraphPropertiesEditForm):
   165     """Video paragraph properties inner edit form"""
   152     """Video paragraph properties inner edit form"""
   181     """Video paragraph properties inner deit form, JSON renderer"""
   168     """Video paragraph properties inner deit form, JSON renderer"""
   182 
   169 
   183     def get_ajax_output(self, changes):
   170     def get_ajax_output(self, changes):
   184         output = super(VideoParagraphPropertiesInnerAJAXEditForm, self).get_ajax_output(changes)
   171         output = super(VideoParagraphPropertiesInnerAJAXEditForm, self).get_ajax_output(changes)
   185         updated = changes.get(IVideoParagraph, ())
   172         updated = changes.get(IVideoParagraph, ())
   186         if 'body' in updated:
       
   187             associations_table = AssociationsTable(self.context, self.request)
       
   188             associations_table.update()
       
   189             output.setdefault('events', []).append({
       
   190                 'event': 'PyAMS_content.changed_item',
       
   191                 'options': {'handler': 'PyAMS_content.associations.refreshAssociations',
       
   192                             'object_name': associations_table.id,
       
   193                             'table': associations_table.render()}
       
   194             })
       
   195         if 'data' in updated:
   173         if 'data' in updated:
   196             # we have to commit transaction to be able to handle blobs...
   174             # we have to commit transaction to be able to handle blobs...
   197             ITransactionManager(self.context).get().commit()
   175             ITransactionManager(self.context).get().commit()
   198             output.setdefault('events', []).append(
   176             output.setdefault('events', []).append(
   199                 get_json_form_refresh_event(self.context, self.request, VideoParagraphPropertiesInnerEditForm))
   177                 get_json_form_refresh_event(self.context, self.request, VideoParagraphPropertiesInnerEditForm))