Updated image properties edit form AJAX output
authortflorac@xsup98-004.onf.fr
Thu, 12 Oct 2017 22:30:38 +0200
changeset 203 6120de3dd9ec
parent 202 7d7947f69fce
child 204 eb6b575b4bf6
Updated image properties edit form AJAX output
src/pyams_content/component/gallery/zmi/file.py
--- a/src/pyams_content/component/gallery/zmi/file.py	Thu Oct 12 22:28:32 2017 +0200
+++ b/src/pyams_content/component/gallery/zmi/file.py	Thu Oct 12 22:30:38 2017 +0200
@@ -9,7 +9,6 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_utils.traversing import get_parent
 
 __docformat__ = 'restructuredtext'
 
@@ -17,7 +16,7 @@
 # import standard library
 
 # import interfaces
-from pyams_content.component.gallery.interfaces import IGallery, IGalleryFile
+from pyams_content.component.gallery.interfaces import IGallery, IGalleryFile, IGalleryTarget
 from pyams_content.component.gallery.zmi.interfaces import IGalleryImageAddFields, IGalleryImagesView
 from pyams_content.interfaces import MANAGE_CONTENT_PERMISSION
 from pyams_file.interfaces.archive import IArchiveExtractor
@@ -34,9 +33,11 @@
 from pyams_file.file import get_magic_content_type
 from pyams_file.zmi.file import FilePropertiesAction
 from pyams_form.form import AJAXAddForm, AJAXEditForm
+from pyams_form.group import NamedWidgetsGroup
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.viewlet.toolbar import ToolbarAction, JsToolbarActionItem
 from pyams_utils.registry import query_utility
+from pyams_utils.traversing import get_parent
 from pyams_utils.url import absolute_url
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogEditForm, AdminDialogAddForm
@@ -177,8 +178,17 @@
             self.widgets['description'].widget_css_class = 'textarea'
         if 'author_comments' in self.widgets:
             self.widgets['author_comments'].widget_css_class = 'textarea'
+        if 'pif_number' in self.widgets:
+            self.widgets['pif_number'].input_css_class = 'col-md-3'
         if 'sound_description' in self.widgets:
             self.widgets['sound_description'].widget_css_class = 'textarea'
+        self.add_group(NamedWidgetsGroup(self, 'audio_file', self.widgets,
+                                         ('sound', 'sound_title', 'sound_description'),
+                                         bordered=False,
+                                         legend=_("Audio content"),
+                                         css_class='inner',
+                                         switch=True,
+                                         hide_if_empty=True))
 
 
 @view_config(name='gallery-file-properties.json', context=IGalleryFile, request_type=IPyAMSLayer,
@@ -186,6 +196,21 @@
 class GalleryFileInfoPropertiesAJAXEditForm(AJAXEditForm, GalleryFilePropertiesEditForm):
     """Gallery file properties edit form, JSON renderer"""
 
+    def get_ajax_output(self, changes):
+        output = super(GalleryFileInfoPropertiesAJAXEditForm, self).get_ajax_output(changes)
+        if 'title' in changes.get(IGalleryFile, ()):
+            gallery = get_parent(self.context, IGallery)
+            if gallery is not None:
+                output.setdefault('events', []).append({
+                    'event': 'PyAMS_content.changed_item',
+                    'options': {
+                        'handler': 'PyAMS_content.galleries.updateImageTitle',
+                        'image_id': 'image_{0}_{1}'.format(gallery.__name__, self.context.__name__),
+                        'title': II18n(self.context).query_attribute('title', request=self.request)
+                    }
+                })
+        return output
+
 
 @viewlet_config(name='gallery-file-download.action', context=IGalleryFile, layer=IPyAMSLayer, view=IGalleryImagesView,
                 manager=IContextActions, permission=VIEW_PERMISSION, weight=89)