Updated fields
authorThierry Florac <thierry.florac@onf.fr>
Fri, 08 Jun 2018 17:50:09 +0200
changeset 598 f9cd7d17430e
parent 597 f4912f6e4cde
child 599 7f97d8cae72e
Updated fields
src/pyams_content/component/paragraph/interfaces/video.py
src/pyams_content/component/paragraph/video.py
src/pyams_content/component/paragraph/zmi/video.py
src/pyams_content/component/video/interfaces/__init__.py
src/pyams_content/component/video/paragraph.py
src/pyams_content/component/video/zmi/paragraph.py
--- a/src/pyams_content/component/paragraph/interfaces/video.py	Fri Jun 08 17:06:07 2018 +0200
+++ b/src/pyams_content/component/paragraph/interfaces/video.py	Fri Jun 08 17:50:09 2018 +0200
@@ -20,7 +20,7 @@
 
 # import packages
 from pyams_file.schema import VideoField
-from pyams_i18n.schema import I18nHTMLField, I18nTextField
+from pyams_i18n.schema import I18nTextField, I18nTextLineField
 from zope.schema import TextLine, Choice
 
 from pyams_content import _
@@ -38,8 +38,12 @@
 class IVideoParagraph(IBaseParagraph):
     """Video paragraph"""
 
-    body = I18nHTMLField(title=_("Body"),
-                         required=False)
+    data = VideoField(title=_("Video data"),
+                      description=_("Video file content"),
+                      required=True)
+
+    title = I18nTextLineField(title=_("Legend"),
+                              required=False)
 
     description = I18nTextField(title=_("Description"),
                                 description=_("File description displayed by front-office template"),
@@ -49,10 +53,6 @@
                       description=_("Name of document's author"),
                       required=False)
 
-    data = VideoField(title=_("Video data"),
-                      description=_("Video file content"),
-                      required=True)
-
     renderer = Choice(title=_("Video template"),
                       description=_("Presentation template used for this video"),
                       vocabulary=VIDEO_PARAGRAPH_RENDERERS,
--- a/src/pyams_content/component/paragraph/video.py	Fri Jun 08 17:06:07 2018 +0200
+++ b/src/pyams_content/component/paragraph/video.py	Fri Jun 08 17:50:09 2018 +0200
@@ -43,10 +43,9 @@
     icon_class = 'fa-film'
     icon_hint = VIDEO_PARAGRAPH_NAME
 
-    body = FieldProperty(IVideoParagraph['body'])
+    data = FileProperty(IVideoParagraph['data'])
     description = FieldProperty(IVideoParagraph['description'])
     author = FieldProperty(IVideoParagraph['author'])
-    data = FileProperty(IVideoParagraph['data'])
     renderer = FieldProperty(IVideoParagraph['renderer'])
 
 
--- a/src/pyams_content/component/paragraph/zmi/video.py	Fri Jun 08 17:06:07 2018 +0200
+++ b/src/pyams_content/component/paragraph/zmi/video.py	Fri Jun 08 17:50:09 2018 +0200
@@ -31,16 +31,14 @@
 # import packages
 from pyams_content.component.paragraph.video import VideoParagraph
 from pyams_content.component.paragraph.zmi import BaseParagraphAJAXAddForm, BaseParagraphAJAXEditForm, \
-    BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, IParagraphEditFormButtons
+    BaseParagraphAddMenu, BaseParagraphPropertiesEditForm, IParagraphEditFormButtons, get_json_paragraph_refresh_event
 from pyams_content.features.renderer.zmi.widget import RendererFieldWidget
 from pyams_form.form import ajax_config
-from pyams_form.group import NamedWidgetsGroup
 from pyams_pagelet.pagelet import pagelet_config
 from pyams_skin.event import get_json_form_refresh_event, get_json_widget_refresh_event
 from pyams_utils.adapter import adapter_config
 from pyams_viewlet.viewlet import viewlet_config
 from pyams_zmi.form import AdminDialogAddForm
-from pyramid.view import view_config
 from z3c.form import field, button
 from zope.interface import implementer
 
@@ -76,20 +74,6 @@
         super(VideoParagraphAddForm, self).updateWidgets(prefix)
         if 'description' in self.widgets:
             self.widgets['description'].widget_css_class = 'textarea'
-        if 'body' in self.widgets:
-            self.widgets['body'].label = ''
-            
-    def updateGroups(self):
-        self.add_group(NamedWidgetsGroup(self, 'body_group', self.widgets, ('body',),
-                                         bordered=False,
-                                         legend=_("HTML content"),
-                                         css_class='inner switcher padding-right-10 no-y-padding pull-left',
-                                         switch=True,
-                                         display_mode='auto'))
-        self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets,
-                                         ('description', 'author', 'data', 'renderer'),
-                                         bordered=False))
-        super(VideoParagraphAddForm, self).updateGroups()
 
     def create(self, data):
         return VideoParagraph()
@@ -120,21 +104,6 @@
         super(VideoParagraphPropertiesEditForm, self).updateWidgets(prefix)
         if 'description' in self.widgets:
             self.widgets['description'].widget_css_class = 'textarea'
-        if 'body' in self.widgets:
-            self.widgets['body'].label = ''
-            
-    def updateGroups(self):
-        self.add_group(NamedWidgetsGroup(self, 'body_group', self.widgets, ('body',),
-                                         bordered=False,
-                                         fieldset_class='margin-top-10 padding-y-5',
-                                         legend=_("HTML content"),
-                                         css_class='inner switcher padding-right-10 no-y-padding pull-left',
-                                         switch=True,
-                                         display_mode='auto'))
-        self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets,
-                                         ('description', 'author', 'data', 'renderer'),
-                                         bordered=False))
-        super(VideoParagraphPropertiesEditForm, self).updateGroups()
 
 
 @adapter_config(context=(IVideoParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
@@ -161,8 +130,12 @@
             ITransactionManager(self.context).get().commit()
             output.setdefault('events', []).append(
                 get_json_form_refresh_event(self.context, self.request, VideoParagraphPropertiesInnerEditForm))
-        elif 'renderer' in updated:
-            output.setdefault('events', []).append(
-                get_json_widget_refresh_event(self.context, self.request,
-                                              VideoParagraphPropertiesInnerEditForm, 'renderer'))
+        else:
+            if 'title' in updated:
+                output.setdefault('events', []).append(
+                    get_json_paragraph_refresh_event(self.context, self.request))
+            if 'renderer' in updated:
+                output.setdefault('events', []).append(
+                    get_json_widget_refresh_event(self.context, self.request,
+                                                  VideoParagraphPropertiesInnerEditForm, 'renderer'))
         return output
--- a/src/pyams_content/component/video/interfaces/__init__.py	Fri Jun 08 17:06:07 2018 +0200
+++ b/src/pyams_content/component/video/interfaces/__init__.py	Fri Jun 08 17:50:09 2018 +0200
@@ -21,7 +21,7 @@
 from zope.contentprovider.interfaces import IContentProvider
 
 # import packages
-from pyams_i18n.schema import I18nHTMLField, I18nTextField
+from pyams_i18n.schema import I18nTextField, I18nTextLineField
 from zope.interface import Interface, Attribute
 from zope.schema import Choice, TextLine
 
@@ -72,8 +72,8 @@
 class IExternalVideoParagraph(IExternalVideo, IBaseParagraph):
     """External video paragraph"""
 
-    body = I18nHTMLField(title=_("Body"),
-                         required=False)
+    title = I18nTextLineField(title=_("Legend"),
+                              required=False)
 
     renderer = Choice(title=_("Video template"),
                       description=_("Presentation template used for this video"),
--- a/src/pyams_content/component/video/paragraph.py	Fri Jun 08 17:06:07 2018 +0200
+++ b/src/pyams_content/component/video/paragraph.py	Fri Jun 08 17:50:09 2018 +0200
@@ -44,7 +44,6 @@
     icon_class = 'fa-youtube-play'
     icon_hint = EXTERNAL_VIDEO_PARAGRAPH_NAME
 
-    body = FieldProperty(IExternalVideoParagraph['body'])
     renderer = FieldProperty(IExternalVideoParagraph['renderer'])
 
 
--- a/src/pyams_content/component/video/zmi/paragraph.py	Fri Jun 08 17:06:07 2018 +0200
+++ b/src/pyams_content/component/video/zmi/paragraph.py	Fri Jun 08 17:50:09 2018 +0200
@@ -76,15 +76,13 @@
     dialog_class = 'modal-large'
     icon_css_class = 'fa fa-fw fa-youtube-play'
 
-    fields = field.Fields(IExternalVideoParagraph).omit('__parent__', '__name__', 'visible')
+    fields = field.Fields(IExternalVideoParagraph).select('title', 'description', 'author', 'renderer', 'provider_name')
     edit_permission = MANAGE_CONTENT_PERMISSION
 
     def updateWidgets(self, prefix=None):
         super(ExternalVideoParagraphAddForm, self).updateWidgets(prefix)
         if 'description' in self.widgets:
             self.widgets['description'].widget_css_class = 'textarea'
-        if 'body' in self.widgets:
-            self.widgets['body'].label = ''
         if 'provider_name' in self.widgets:
             widget = self.widgets['provider_name']
             widget.object_data = {
@@ -98,19 +96,6 @@
             }
             alsoProvides(widget, IObjectData)
 
-    def updateGroups(self):
-        if 'body' in self.widgets:
-            self.add_group(NamedWidgetsGroup(self, 'body_group', self.widgets, ('body',),
-                                             bordered=False,
-                                             legend=_("HTML content"),
-                                             css_class='inner switcher padding-right-10 no-y-padding pull-left',
-                                             switch=True,
-                                             display_mode='auto'))
-            self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets,
-                                             ('description', 'author', 'renderer', 'provider_name'),
-                                             bordered=False))
-        super(ExternalVideoParagraphAddForm, self).updateGroups()
-
     def create(self, data):
         return ExternalVideoParagraph()
 
@@ -211,7 +196,8 @@
 
     @property
     def fields(self):
-        fields = field.Fields(IExternalVideoParagraph).omit('__parent__', '__name__', 'visible')
+        fields = field.Fields(IExternalVideoParagraph).select('title', 'description', 'author', 'renderer',
+                                                              'provider_name')
         fields['renderer'].widgetFactory = RendererFieldWidget
         provider = self.context.get_provider()
         if provider is not None:
@@ -222,23 +208,10 @@
         super(ExternalVideoParagraphPropertiesEditForm, self).updateWidgets(prefix)
         if 'description' in self.widgets:
             self.widgets['description'].widget_css_class = 'textarea'
-        if 'body' in self.widgets:
-            self.widgets['body'].label = ''
         if 'provider_name' in self.widgets:
             self.widgets['provider_name'].mode = DISPLAY_MODE
 
     def updateGroups(self):
-        if 'body' in self.widgets:
-            self.add_group(NamedWidgetsGroup(self, 'body_group', self.widgets, ('body',),
-                                             bordered=False,
-                                             fieldset_class='margin-top-10 padding-y-5',
-                                             legend=_("HTML content"),
-                                             css_class='inner switcher padding-right-10 no-y-padding pull-left',
-                                             switch=True,
-                                             display_mode='auto'))
-            self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets,
-                                             ('description', 'author', 'renderer', 'provider_name'),
-                                             bordered=False))
         if 'provider_name' in self.widgets:
             provider = self.context.get_provider()
             if provider is not None:
@@ -261,7 +234,7 @@
 
     def get_ajax_output(self, changes):
         output = super(self.__class__, self).get_ajax_output(changes)
-        if 'title' in changes.get(IBaseParagraph, ()):
+        if 'title' in changes.get(IExternalVideoParagraph, ()):
             output.setdefault('events', []).append(
                 get_json_paragraph_refresh_event(self.context, self.request))
         return output