Updated groups management
authorThierry Florac <thierry.florac@onf.fr>
Thu, 03 May 2018 11:05:45 +0200
changeset 543 2125a235d3a0
parent 542 782b0d0dcba0
child 544 6928ddfc1c0f
Updated groups management
src/pyams_content/component/video/zmi/paragraph.py
--- a/src/pyams_content/component/video/zmi/paragraph.py	Thu May 03 10:49:44 2018 +0200
+++ b/src/pyams_content/component/video/zmi/paragraph.py	Thu May 03 11:05:45 2018 +0200
@@ -82,15 +82,6 @@
             self.widgets['description'].widget_css_class = 'textarea'
         if 'body' in self.widgets:
             self.widgets['body'].label = ''
-            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,
-                                             hide_if_empty=True))
-            self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets,
-                                             ('description', 'author', 'provider_name'),
-                                             bordered=False))
         if 'provider_name' in self.widgets:
             widget = self.widgets['provider_name']
             widget.object_data = {
@@ -104,6 +95,19 @@
             }
             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,
+                                             hide_if_empty=True))
+            self.add_group(NamedWidgetsGroup(self, 'data_group', self.widgets,
+                                             ('description', 'author', 'provider_name'),
+                                             bordered=False))
+        super(ExternalVideoParagraphAddForm, self).updateGroups()
+
     def create(self, data):
         return ExternalVideoParagraph()
 
@@ -147,6 +151,32 @@
     """External video settings edit form widgets suffix"""
 
 
+class ExternalVideoProviderSettingsAddForm(InnerAdminAddForm):
+    """External video provider settings add form"""
+
+    def __init__(self, context, request, provider):
+        super(ExternalVideoProviderSettingsAddForm, self).__init__(context, request)
+        self.provider = provider
+
+    def updateGroups(self):
+        if 'integration_code' in self.widgets:  # custom video provider
+            self.widgets['integration_code'].widget_css_class = 'textarea'
+            self.add_group(NamedWidgetsGroup(self, 'integration_code', self.widgets, ('integration_code', ),
+                                             bordered=False))
+        elif 'video_id' in self.widgets:
+            self.add_group(NamedWidgetsGroup(self, 'video_id', self.widgets, ('video_id', ), bordered=False))
+        field_names = getFieldNamesInOrder(self.provider.settings_interface)
+        if len(field_names) > 1:
+            self.add_group(NamedWidgetsGroup(self, 'provider_group', self.widgets,
+                                             field_names[1:],
+                                             bordered=False,
+                                             legend=_("Other settings"),
+                                             css_class="inner switcher padding-right-10 no-y-padding",
+                                             switch=True,
+                                             hide_if_empty=True))
+        super(ExternalVideoProviderSettingsAddForm, self).updateGroups()
+
+
 @view_config(name='get-video-provider-settings-add-form.html', context=IParagraphContainerTarget,
              request_type=IPyAMSLayer, permission=MANAGE_CONTENT_PERMISSION, xhr=True)
 def external_video_provider_settings_add_form(request):
@@ -158,28 +188,13 @@
         return Response('')
     else:
         provider = get_utility(IExternalVideoProvider, name=provider_name)
-        form = InnerAdminAddForm(request.context, request)
+        form = ExternalVideoProviderSettingsAddForm(request.context, request, provider)
         form.prefix = ExternalVideoParagraphAddForm.prefix
         form.legend = request.localizer.translate(_("Video provider settings"))
         form.label_css_class = 'control-label col-md-4'
         form.input_css_class = 'col-md-8'
         form.fields = field.Fields(provider.settings_interface)
         form.update()
-        if 'integration_code' in form.widgets:  # custom video provider
-            form.widgets['integration_code'].widget_css_class = 'textarea'
-            form.add_group(NamedWidgetsGroup(form, 'integration_code', form.widgets, ('integration_code', ),
-                                             bordered=False))
-        elif 'video_id' in form.widgets:
-            form.add_group(NamedWidgetsGroup(form, 'video_id', form.widgets, ('video_id', ), bordered=False))
-        field_names = getFieldNamesInOrder(provider.settings_interface)
-        if len(field_names) > 1:
-            form.add_group(NamedWidgetsGroup(form, 'provider_group', form.widgets,
-                                             field_names[1:],
-                                             bordered=False,
-                                             legend=_("Other settings"),
-                                             css_class="inner switcher padding-right-10 no-y-padding",
-                                             switch=True,
-                                             hide_if_empty=True))
         return Response(form.render())
 
 
@@ -210,6 +225,11 @@
             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',
@@ -221,7 +241,6 @@
                                              ('description', 'author', 'provider_name'),
                                              bordered=False))
         if 'provider_name' in self.widgets:
-            self.widgets['provider_name'].mode = DISPLAY_MODE
             provider = self.context.get_provider()
             if provider is not None:
                 if 'integration_code' in self.widgets:  # custom video provider