From 797cf2f2d0ec18893dad5c6deac1b25be9a61af0 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Tue, 15 Feb 2011 11:11:14 +0000
Subject: [PATCH] make autoplay, controls, loop and preload boolean so that we
 can enable/disable appropriately.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43345 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/AudioField.py | 32 +++++++++++++++++++-------------
 product/ERP5Form/VideoField.py | 32 +++++++++++++++++++-------------
 2 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/product/ERP5Form/AudioField.py b/product/ERP5Form/AudioField.py
index 1336b14684..99a30de84c 100644
--- a/product/ERP5Form/AudioField.py
+++ b/product/ERP5Form/AudioField.py
@@ -13,10 +13,10 @@ class AudioWidget(Widget.TextWidget):
           ['audio_controls', 'audio_error_message', 'audio_loop', \
               'audio_preload', 'audio_autoplay', 'js_enabled', 'audio_player']
 
-  audio_controls = fields.StringField('audio_controls',
+  audio_controls = fields.CheckBoxField('audio_controls',
                          title='Audio Controls',
                          description=("Controls to be used in Audio Player."),
-                         default='controls',
+                         default=1,
                          required=0)
 
   audio_error_message = fields.StringField('audio_error_message',
@@ -26,25 +26,25 @@ class AudioWidget(Widget.TextWidget):
                          default='Your browser does not support audio tag.',
                          required=0)
 
-  audio_loop = fields.StringField('audio_loop',
+  audio_loop = fields.CheckBoxField('audio_loop',
                          title='Audio Loop',
                          description=("Specifies that the audio file \
           will start over again, every time it is finished."),
-                         default='none',
+                         default=0,
                          required=0)
 
-  audio_preload = fields.StringField('audio_preload',
+  audio_preload = fields.CheckBoxField('audio_preload',
                          title='Audio Preload',
                          description=("Configure that you would like to \
       start downloading the audio file as soon as possible."),
-                         default='preload',
+                         default=1,
                          required=0)
 
-  audio_autoplay = fields.StringField('audio_autoplay',
+  audio_autoplay = fields.CheckBoxField('audio_autoplay',
                          title='Audio Autoplay',
                          description=("Configure that you would like to \
       start downloading and playing the audio file as soon as possible."),
-                         default='',
+                         default=0,
                          required=0)
 
   js_enabled = fields.CheckBoxField('js_enabled',
@@ -71,14 +71,20 @@ class AudioWidget(Widget.TextWidget):
       return ''
     audio_player = field.get_value('audio_player')
     if audio_player == 'html5_audio':
+      extra_kw = {}
+      if field.get_value('audio_autoplay'):
+        extra_kw['autoplay']='autoplay'
+      if field.get_value('audio_controls'):
+        extra_kw['controls']='controls'
+      if field.get_value('audio_loop'):
+        extra_kw['loop']='loop'
+      if field.get_value('audio_preload'):
+        extra_kw['preload']='preload'
       return Widget.render_element("audio",
                               src=value,
                               extra=field.get_value('extra'),
-                              controls=field.get_value('audio_controls'),
-                              loop=field.get_value('audio_loop'),
-                              preload=field.get_value('audio_preload'),
-                              autoplay=field.get_value('audio_autoplay'),
-                              contents=field.get_value('audio_error_message'))
+                              contents=field.get_value('audio_error_message'),
+                              **extra_kw)
     elif audio_player == 'flowplayer':
       a_element = Widget.render_element("a",
                         href="%s" % value,
diff --git a/product/ERP5Form/VideoField.py b/product/ERP5Form/VideoField.py
index 6054c418b9..f80e43e37e 100644
--- a/product/ERP5Form/VideoField.py
+++ b/product/ERP5Form/VideoField.py
@@ -14,10 +14,10 @@ class VideoWidget(Widget.TextWidget):
               'video_width', 'video_height', 'video_preload', \
               'video_autoplay', 'js_enabled', 'video_player']
 
-  video_controls = fields.StringField('video_controls',
+  video_controls = fields.CheckBoxField('video_controls',
                          title='Video Controls',
                          description=("Controls to be used in Video Player."),
-                         default='controls',
+                         default=1,
                          required=0)
 
   video_error_message = fields.StringField('video_error_message',
@@ -27,11 +27,11 @@ class VideoWidget(Widget.TextWidget):
                          default='Your browser does not support video tag.',
                          required=0)
 
-  video_loop = fields.StringField('video_loop',
+  video_loop = fields.CheckBoxField('video_loop',
                          title='Video Loop',
                          description=("Specifies that the video file \
           will start over again, every time it is finished."),
-                         default='none',
+                         default=0,
                          required=0)
 
   video_width = fields.IntegerField('video_width',
@@ -48,18 +48,18 @@ class VideoWidget(Widget.TextWidget):
                              default=85,
                              required=0)
 
-  video_preload = fields.StringField('video_preload',
+  video_preload = fields.CheckBoxField('video_preload',
                          title='Video Preload',
                          description=("Configure that you would like to \
       start downloading the video file as soon as possible."),
-                         default='preload',
+                         default=1,
                          required=0)
 
-  video_autoplay = fields.StringField('video_autoplay',
+  video_autoplay = fields.CheckBoxField('video_autoplay',
                          title='Video Autoplay',
                          description=("Configure that you would like to \
       start downloading and playing the video file as soon as possible."),
-                         default='',
+                         default=0,
                          required=0)
 
   js_enabled = fields.CheckBoxField('js_enabled',
@@ -86,16 +86,22 @@ class VideoWidget(Widget.TextWidget):
       return ''
     video_player = field.get_value('video_player')
     if video_player == 'html5_video':
+      extra_kw = {}
+      if field.get_value('video_autoplay'):
+        extra_kw['autoplay']='autoplay'
+      if field.get_value('video_controls'):
+        extra_kw['controls']='controls'
+      if field.get_value('video_loop'):
+        extra_kw['loop']='loop'
+      if field.get_value('video_preload'):
+        extra_kw['preload']='preload'
       return Widget.render_element("video",
                         src=value,
                         extra=field.get_value('extra'),
-                        controls=field.get_value('video_controls'),
-                        loop=field.get_value('video_loop'),
                         width=field.get_value('video_width'),
                         height=field.get_value('video_height'),
-                        preload=field.get_value('video_preload'),
-                        autoplay=field.get_value('video_autoplay'),
-                        contents=field.get_value('video_error_message'))
+                        contents=field.get_value('video_error_message'),
+                        **extra_kw)
     elif video_player == 'flowplayer':
       a_element = Widget.render_element("a",
                         href="%s" % value,
-- 
2.30.9