src/pyams_content/component/extfile/zmi/__init__.py
changeset 527 5dd1aa8bedd9
parent 314 18da24db44b6
child 571 b2e79295caec
equal deleted inserted replaced
526:b15153f45957 527:5dd1aa8bedd9
    27 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
    27 from pyams_utils.interfaces import VIEW_SYSTEM_PERMISSION
    28 
    28 
    29 # import packages
    29 # import packages
    30 from pyams_content.component.association.zmi import AssociationItemAJAXAddForm, AssociationItemAJAXEditForm
    30 from pyams_content.component.association.zmi import AssociationItemAJAXAddForm, AssociationItemAJAXEditForm
    31 from pyams_content.component.extfile import EXTERNAL_FILES_FACTORIES
    31 from pyams_content.component.extfile import EXTERNAL_FILES_FACTORIES
       
    32 from pyams_content.component.paragraph.zmi import get_json_paragraph_markers_refresh_event
    32 from pyams_content.component.paragraph.zmi.container import ParagraphContainerCounterBase
    33 from pyams_content.component.paragraph.zmi.container import ParagraphContainerCounterBase
    33 from pyams_form.security import ProtectedFormObjectMixin
    34 from pyams_form.security import ProtectedFormObjectMixin
    34 from pyams_pagelet.pagelet import pagelet_config
    35 from pyams_pagelet.pagelet import pagelet_config
    35 from pyams_skin.viewlet.toolbar import ToolbarMenuItem, ToolbarMenuDivider
    36 from pyams_skin.viewlet.toolbar import ToolbarMenuItem, ToolbarMenuDivider
    36 from pyams_viewlet.viewlet import viewlet_config
    37 from pyams_viewlet.viewlet import viewlet_config
    70     weight = 20
    71     weight = 20
    71     action_class = 'action extfiles nowrap width-40'
    72     action_class = 'action extfiles nowrap width-40'
    72     icon_class = 'fa fa-fw fa-file-text-o'
    73     icon_class = 'fa fa-fw fa-file-text-o'
    73     icon_hint = _("External files")
    74     icon_hint = _("External files")
    74 
    75 
       
    76     marker_type = 'extfiles'
       
    77 
    75     @property
    78     @property
    76     def count(self):
    79     def count(self):
    77         return len([file for file in IAssociationContainer(self.context).values()
    80         return len([file for file in IAssociationContainer(self.context).values()
    78                     if IExtFile.providedBy(file) and not IExtMedia.providedBy(file)])
    81                     if IExtFile.providedBy(file) and not IExtMedia.providedBy(file)])
    79 
    82 
   122     """External file add form, JSON renderer"""
   125     """External file add form, JSON renderer"""
   123 
   126 
   124     def get_ajax_output(self, changes):
   127     def get_ajax_output(self, changes):
   125         output = super(ExtFileAJAXAddForm, self).get_ajax_output(changes)
   128         output = super(ExtFileAJAXAddForm, self).get_ajax_output(changes)
   126         if output:
   129         if output:
   127             counter = ExtFilesCounter(self.context, self.request, self, None)
   130             output.setdefault('events', []).append(get_json_paragraph_markers_refresh_event(self.context, self.request,
   128             counter.update()
   131                                                                                             self, ExtFilesCounter))
   129             output.setdefault('events', []).append({
       
   130                 'event': 'myams.refresh',
       
   131                 'options': {
       
   132                     'handler': 'PyAMS_content.paragraphs.updateMarkers',
       
   133                     'object_name': self.context.__name__,
       
   134                     'marker_type': 'extfiles',
       
   135                     'marker_tag': counter.render()
       
   136                 }
       
   137             })
       
   138         return output
   132         return output
   139 
   133 
   140 
   134 
   141 @pagelet_config(name='properties.html', context=IExtFile, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   135 @pagelet_config(name='properties.html', context=IExtFile, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   142 class ExtFilePropertiesEditForm(AdminDialogEditForm):
   136 class ExtFilePropertiesEditForm(AdminDialogEditForm):
   143     """External file properties edit form"""
   137     """External file properties edit form"""
       
   138 
       
   139     prefix = 'extfile_properties.'
   144 
   140 
   145     legend = _("Update file properties")
   141     legend = _("Update file properties")
   146     icon_css_class = 'fa fa-fw fa-file-text-o'
   142     icon_css_class = 'fa fa-fw fa-file-text-o'
   147     dialog_class = 'modal-large'
   143     dialog_class = 'modal-large'
   148 
   144 
   182     weight = 21
   178     weight = 21
   183     action_class = 'action extimages nowrap width-40'
   179     action_class = 'action extimages nowrap width-40'
   184     icon_class = 'fa fa-fw fa-file-image-o'
   180     icon_class = 'fa fa-fw fa-file-image-o'
   185     icon_hint = _("Images")
   181     icon_hint = _("Images")
   186 
   182 
       
   183     marker_type = 'extimages'
       
   184 
   187     @property
   185     @property
   188     def count(self):
   186     def count(self):
   189         return len([file for file in IAssociationContainer(self.context).values()
   187         return len([file for file in IAssociationContainer(self.context).values()
   190                     if IExtImage.providedBy(file)])
   188                     if IExtImage.providedBy(file)])
   191 
   189 
   233     """External image add form, JSON renderer"""
   231     """External image add form, JSON renderer"""
   234 
   232 
   235     def get_ajax_output(self, changes):
   233     def get_ajax_output(self, changes):
   236         output = super(ExtImageAJAXAddForm, self).get_ajax_output(changes)
   234         output = super(ExtImageAJAXAddForm, self).get_ajax_output(changes)
   237         if output:
   235         if output:
   238             counter = ExtImagesCounter(self.context, self.request, self, None)
   236             output.setdefault('events', []).append(get_json_paragraph_markers_refresh_event(self.context, self.request,
   239             counter.update()
   237                                                                                             self, ExtImagesCounter))
   240             output.setdefault('events', []).append({
       
   241                 'event': 'myams.refresh',
       
   242                 'options': {
       
   243                     'handler': 'PyAMS_content.paragraphs.updateMarkers',
       
   244                     'object_name': self.context.__name__,
       
   245                     'marker_type': 'extimages',
       
   246                     'marker_tag': counter.render()
       
   247                 }
       
   248             })
       
   249         return output
   238         return output
   250 
   239 
   251 
   240 
   252 @pagelet_config(name='properties.html', context=IExtImage, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   241 @pagelet_config(name='properties.html', context=IExtImage, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   253 class ExtImagePropertiesEditForm(ExtFilePropertiesEditForm):
   242 class ExtImagePropertiesEditForm(ExtFilePropertiesEditForm):
   293     weight = 22
   282     weight = 22
   294     action_class = 'action extvideos nowrap width-40'
   283     action_class = 'action extvideos nowrap width-40'
   295     icon_class = 'fa fa-fw fa-file-video-o'
   284     icon_class = 'fa fa-fw fa-file-video-o'
   296     icon_hint = _("Videos")
   285     icon_hint = _("Videos")
   297 
   286 
       
   287     marker_type = 'extvideos'
       
   288 
   298     @property
   289     @property
   299     def count(self):
   290     def count(self):
   300         return len([file for file in IAssociationContainer(self.context).values()
   291         return len([file for file in IAssociationContainer(self.context).values()
   301                     if IExtVideo.providedBy(file)])
   292                     if IExtVideo.providedBy(file)])
   302 
   293 
   336     """External video add form, JSON renderer"""
   327     """External video add form, JSON renderer"""
   337 
   328 
   338     def get_ajax_output(self, changes):
   329     def get_ajax_output(self, changes):
   339         output = super(ExtVideoAJAXAddForm, self).get_ajax_output(changes)
   330         output = super(ExtVideoAJAXAddForm, self).get_ajax_output(changes)
   340         if output:
   331         if output:
   341             counter = ExtVideosCounter(self.context, self.request, self, None)
   332             output.setdefault('events', []).append(get_json_paragraph_markers_refresh_event(self.context, self.request,
   342             counter.update()
   333                                                                                             self, ExtVideosCounter))
   343             output.setdefault('events', []).append({
       
   344                 'event': 'myams.refresh',
       
   345                 'options': {
       
   346                     'handler': 'PyAMS_content.paragraphs.updateMarkers',
       
   347                     'object_name': self.context.__name__,
       
   348                     'marker_type': 'extvideos',
       
   349                     'marker_tag': counter.render()
       
   350                 }
       
   351             })
       
   352         return output
   334         return output
   353 
   335 
   354 
   336 
   355 @pagelet_config(name='properties.html', context=IExtVideo, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   337 @pagelet_config(name='properties.html', context=IExtVideo, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   356 class ExtVideoPropertiesEditForm(ExtFilePropertiesEditForm):
   338 class ExtVideoPropertiesEditForm(ExtFilePropertiesEditForm):
   388     weight = 23
   370     weight = 23
   389     action_class = 'action extaudios nowrap width-40'
   371     action_class = 'action extaudios nowrap width-40'
   390     icon_class = 'fa fa-fw fa-file-audio-o'
   372     icon_class = 'fa fa-fw fa-file-audio-o'
   391     icon_hint = _("Audios files")
   373     icon_hint = _("Audios files")
   392 
   374 
       
   375     marker_type = 'extaudios'
       
   376 
   393     @property
   377     @property
   394     def count(self):
   378     def count(self):
   395         return len([file for file in IAssociationContainer(self.context).values()
   379         return len([file for file in IAssociationContainer(self.context).values()
   396                     if IExtAudio.providedBy(file)])
   380                     if IExtAudio.providedBy(file)])
   397 
   381 
   431     """External audio file add form, JSON renderer"""
   415     """External audio file add form, JSON renderer"""
   432 
   416 
   433     def get_ajax_output(self, changes):
   417     def get_ajax_output(self, changes):
   434         output = super(ExtAudioAJAXAddForm, self).get_ajax_output(changes)
   418         output = super(ExtAudioAJAXAddForm, self).get_ajax_output(changes)
   435         if output:
   419         if output:
   436             counter = ExtAudiosCounter(self.context, self.request, self, None)
   420             output.setdefault('events', []).append(get_json_paragraph_markers_refresh_event(self.context, self.request,
   437             counter.update()
   421                                                                                             self, ExtAudiosCounter))
   438             output.setdefault('events', []).append({
       
   439                 'event': 'myams.refresh',
       
   440                 'options': {
       
   441                     'handler': 'PyAMS_content.paragraphs.updateMarkers',
       
   442                     'object_name': self.context.__name__,
       
   443                     'marker_type': 'extaudios',
       
   444                     'marker_tag': counter.render()
       
   445                 }
       
   446             })
       
   447         return output
   422         return output
   448 
   423 
   449 
   424 
   450 @pagelet_config(name='properties.html', context=IExtAudio, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   425 @pagelet_config(name='properties.html', context=IExtAudio, layer=IPyAMSLayer, permission=VIEW_SYSTEM_PERMISSION)
   451 class ExtAudioPropertiesEditForm(ExtFilePropertiesEditForm):
   426 class ExtAudioPropertiesEditForm(ExtFilePropertiesEditForm):