Commit c9c78dbe authored by Rafael Monnerat's avatar Rafael Monnerat

Small improvements, still experimental and requires erp5_dms_media for now.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43330 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7ba08b4b
from Products.Formulator.Field import ZMIField from Products.Formulator.Field import ZMIField
from Products.Formulator import Widget, Validator from Products.Formulator import Widget
from Products.Formulator.DummyField import fields from Products.Formulator.DummyField import fields
from Products.Formulator import Validator from Products.Formulator import Validator
from Products.ERP5Form.ListBox import lazyMethod
class AudioWidget(Widget.TextWidget): class AudioWidget(Widget.TextWidget):
""" """
A widget that displays a Audio HTML element. A widget that displays a Audio HTML element.
This widget is intended to be used in This widget is intended to be used in
conjunction with WebSite. conjunction with WebSite.
""" """
property_names = Widget.TextWidget.property_names + \ property_names = Widget.TextWidget.property_names + \
['audio_controls', 'audio_error_message', 'audio_loop', \ ['audio_controls', 'audio_error_message', 'audio_loop', \
'audio_preload', 'audio_autoplay', 'js_enabled', 'audio_player'] 'audio_preload', 'audio_autoplay', 'js_enabled', 'audio_player']
audio_controls = fields.StringField('audio_controls', audio_controls = fields.StringField('audio_controls',
title='Audio Controls', title='Audio Controls',
description=("Controls to be used in Audio Player."), description=("Controls to be used in Audio Player."),
default='controls', default='controls',
required=0) required=0)
audio_error_message = fields.StringField('audio_error_message', audio_error_message = fields.StringField('audio_error_message',
title='Audio Error Message', title='Audio Error Message',
description=("Error message to be showed when \ description=("Error message to be showed when \
user's browser does not support the audio tag."), user's browser does not support the audio tag."),
default='Your browser does not support audio tag.', default='Your browser does not support audio tag.',
required=0) required=0)
audio_loop = fields.StringField('audio_loop', audio_loop = fields.StringField('audio_loop',
title='Audio Loop', title='Audio Loop',
description=("Specifies that the audio file \ description=("Specifies that the audio file \
will start over again, every time it is finished."), will start over again, every time it is finished."),
default='none', default='none',
required=0) required=0)
audio_preload = fields.StringField('audio_preload', audio_preload = fields.StringField('audio_preload',
title='Audio Preload', title='Audio Preload',
description=("Configure that you would like to \ description=("Configure that you would like to \
start downloading the audio file as soon as possible."), start downloading the audio file as soon as possible."),
default='preload', default='preload',
required=0) required=0)
audio_autoplay = fields.StringField('audio_autoplay', audio_autoplay = fields.StringField('audio_autoplay',
title='Audio Autoplay', title='Audio Autoplay',
description=("Configure that you would like to \ description=("Configure that you would like to \
start downloading and playing the audio file as soon as possible."), start downloading and playing the audio file as soon as possible."),
default='', default='',
required=0) required=0)
js_enabled = fields.CheckBoxField('js_enabled', js_enabled = fields.CheckBoxField('js_enabled',
title='Enable on the fly video player change (based on java script)', title='Enable on the fly video player change (based on java script)',
description='Define if javascript is enabled or not on the current Video', description='Define if javascript is enabled or not on the current Video',
default=1, default=1,
required=1) required=1)
audio_player = fields.ListField('audio_player', audio_player = fields.ListField('audio_player',
title='Audio Player', title='Audio Player',
description=( description=(
"The video player to be used to show video."), "The video player to be used to show video."),
default="html5_audio", default="html5_audio",
required=1, required=1,
size=1, size=1,
items=[('HTML5 Audio', 'html5_audio'), items=[('HTML5 Audio', 'html5_audio'),
('Flowplayer', 'flowplayer'),]) ('Flowplayer', 'flowplayer'),])
def render(self, field, key, value, REQUEST, render_prefix=None): def render(self, field, key, value, REQUEST, render_prefix=None):
return self.render_view(field, value, REQUEST, render_prefix) return self.render_view(field, value, REQUEST, render_prefix)
def render_view(self, field, value, REQUEST=None, render_prefix=None): def render_view(self, field, value, REQUEST=None, render_prefix=None):
if value is None: if value is None:
return '' return ''
return Widget.render_element("audio", audio_player = field.get_value('audio_player')
if audio_player == 'html5_audio':
return Widget.render_element("audio",
src=value, src=value,
extra=field.get_value('extra'), extra=field.get_value('extra'),
controls=field.get_value('audio_controls'), controls=field.get_value('audio_controls'),
...@@ -77,39 +80,60 @@ class AudioWidget(Widget.TextWidget): ...@@ -77,39 +80,60 @@ class AudioWidget(Widget.TextWidget):
preload=field.get_value('audio_preload'), preload=field.get_value('audio_preload'),
autoplay=field.get_value('audio_autoplay'), autoplay=field.get_value('audio_autoplay'),
contents=field.get_value('audio_error_message')) contents=field.get_value('audio_error_message'))
elif audio_player == 'flowplayer':
a_element = Widget.render_element("a",
href="%s" % value,
style="display:block;width:%spx;height:%spx;" % \
(field.get_value('video_width'),
field.get_value('video_height'),),
id="player")
script_element = """<script language="JavaScript">
flowplayer("player", "%s/flowplayer.swf");
</script>""" % self.getContext(field, REQUEST).getPortalObject().portal_url()
return ' '.join(a_element,script_element)
def get_javascript_list(self, field, REQUEST=None):
""" def get_javascript_list(self, field, REQUEST=None):
Returns list of javascript needed by the widget """
""" Returns list of javascript needed by the widget
if field.get_value('js_enabled'): """
audio_player = field.get_value('audio_player') if field.get_value('js_enabled'):
context = getContext(field, REQUEST) audio_player = field.get_value('audio_player')
if audio_player == 'html5_audio': context = self.getContext(field, REQUEST)
# XXX Instead of harcoding library name if audio_player == 'html5_audio':
# it should be better to call a python script, as # XXX Instead of harcoding library name
# it is done on type base method. # it should be better to call a python script, as
return ['%s/html5media.min.js' % context.portal_url()] # it is done on type base method.
elif audio_player == 'flowplayer': return ['%s/html5media.min.js' % context.portal_url()]
return ['%s/flowplayer.min.js' % context.portal_url()] elif audio_player == 'flowplayer':
else: return ['%s/flowplayer.min.js' % context.portal_url()]
return [] else:
return []
def getContext(field, REQUEST):
"""Return the context of rendering this VideoField. def getContext(self):
"""Return the context of rendering this Field..
""" """
value = REQUEST.get('here') value = self.request.get('here')
if value is None: if value is None:
value = getForm(field).aq_parent value = self.getForm().aq_parent
return value return value
AudioWidgetInstance = AudioWidget() getContext = lazyMethod(getContext)
class AudioField(ZMIField): def getForm(self):
""" Audio field """Return the form which contains the Field.
""" """
meta_type = "AudioField" return self.field.aq_parent
getForm = lazyMethod(getForm)
widget = AudioWidgetInstance AudioWidgetInstance = AudioWidget()
validator = Validator.SuppressValidatorInstance
class AudioField(ZMIField):
""" Audio field
"""
meta_type = "AudioField"
widget = AudioWidgetInstance
validator = Validator.SuppressValidatorInstance
from Products.Formulator.Field import ZMIField from Products.Formulator.Field import ZMIField
from Products.Formulator import Widget, Validator from Products.Formulator import Widget
from Products.Formulator.DummyField import fields from Products.Formulator.DummyField import fields
from Products.Formulator import Validator from Products.Formulator import Validator
from Products.ERP5Form.ListBox import lazyMethod
class VideoWidget(Widget.TextWidget): class VideoWidget(Widget.TextWidget):
"""
A widget that displays a Video HTML element.
This widget is intended to be used in
conjunction with WebSite.
"""
property_names = Widget.TextWidget.property_names + \
['video_controls', 'video_error_message', 'video_loop', \
'video_width', 'video_height', 'video_preload', \
'video_autoplay', 'js_enabled', 'video_player']
video_controls = fields.StringField('video_controls',
title='Video Controls',
description=("Controls to be used in Video Player."),
default='controls',
required=0)
video_error_message = fields.StringField('video_error_message',
title='Video Error Message',
description=("Error message to be showed when \
user's browser does not support the video tag."),
default='Your browser does not support video tag.',
required=0)
video_loop = fields.StringField('video_loop',
title='Video Loop',
description=("Specifies that the video file \
will start over again, every time it is finished."),
default='none',
required=0)
video_width = fields.IntegerField('video_width',
title='Video Width',
description=(
"The width to be used when playing the video."),
default=160,
required=0)
video_height = fields.IntegerField('video_height',
title='Video Height',
description=(
"The height to be used when playing the video."),
default=85,
required=0)
video_preload = fields.StringField('video_preload',
title='Video Preload',
description=("Configure that you would like to \
start downloading the video file as soon as possible."),
default='preload',
required=0)
video_autoplay = fields.StringField('video_autoplay',
title='Video Autoplay',
description=("Configure that you would like to \
start downloading and playing the video file as soon as possible."),
default='',
required=0)
js_enabled = fields.CheckBoxField('js_enabled',
title='Enable on the fly video player change (based on java script)',
description='Define if javascript is enabled or not on the current Video',
default=1,
required=1)
video_player = fields.ListField('video_player',
title='Video Player',
description=(
"The video player to be used to show video."),
default="html5_video",
required=1,
size=1,
items=[('HTML5 Video', 'html5_video'),
('Flowplayer', 'flowplayer'),])
def render(self, field, key, value, REQUEST, render_prefix=None):
return self.render_view(field, value, REQUEST, render_prefix)
def render_view(self, field, value, REQUEST=None, render_prefix=None):
if value is None:
return ''
video_player = field.get_value('video_player')
if video_player == 'html5_video':
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'))
elif video_player == 'flowplayer':
a_element = Widget.render_element("a",
href="%s" % value,
style="display:block;width:%spx;height:%spx;" % \
(field.get_value('video_width'),
field.get_value('video_height'),),
id="player")
script_element = """<script language="JavaScript">
flowplayer("player", "%s/flowplayer.swf");
</script>""" % self.getContext(field, REQUEST).getPortalObject().portal_url()
return ' '.join(a_element,script_element)
def get_javascript_list(self, field, REQUEST=None):
""" """
A widget that displays a Video HTML element. Returns list of javascript needed by the widget
This widget is intended to be used in
conjunction with WebSite.
""" """
property_names = Widget.TextWidget.property_names + \ if field.get_value('js_enabled'):
['video_controls', 'video_error_message', 'video_loop', \ video_player = field.get_value('video_player')
'video_width', 'video_height', 'video_preload', \ context = self.getContext(field, REQUEST)
'video_autoplay', 'js_enabled', 'video_player'] if video_player == 'html5_video':
# XXX Instead of harcoding library name
video_controls = fields.StringField('video_controls', # it should be better to call a python script, as
title='Video Controls', # it is done on type base method.
description=("Controls to be used in Video Player."), return ['%s/html5media.min.js' % context.portal_url()]
default='controls', elif video_player == 'flowplayer':
required=0) return ['%s/flowplayer.min.js' % context.portal_url()]
else:
video_error_message = fields.StringField('video_error_message', return []
title='Video Error Message',
description=("Error message to be showed when \ def getContext(self):
user's browser does not support the video tag."), """Return the context of rendering this Field..
default='Your browser does not support video tag.',
required=0)
video_loop = fields.StringField('video_loop',
title='Video Loop',
description=("Specifies that the video file \
will start over again, every time it is finished."),
default='none',
required=0)
video_width = fields.IntegerField('video_width',
title='Video Width',
description=(
"The width to be used when playing the video."),
default=160,
required=0)
video_height = fields.IntegerField('video_height',
title='Video Height',
description=(
"The height to be used when playing the video."),
default=85,
required=0)
video_preload = fields.StringField('video_preload',
title='Video Preload',
description=("Configure that you would like to \
start downloading the video file as soon as possible."),
default='preload',
required=0)
video_autoplay = fields.StringField('video_autoplay',
title='Video Autoplay',
description=("Configure that you would like to \
start downloading and playing the video file as soon as possible."),
default='',
required=0)
js_enabled = fields.CheckBoxField('js_enabled',
title='Enable on the fly video player change (based on java script)',
description='Define if javascript is enabled or not on the current Video',
default=1,
required=1)
video_player = fields.ListField('video_player',
title='Video Player',
description=(
"The video player to be used to show video."),
default="html5_video",
required=1,
size=1,
items=[('HTML5 Video', 'html5_video'),
('Flowplayer', 'flowplayer'),])
def render(self, field, key, value, REQUEST, render_prefix=None):
return self.render_view(field, value, REQUEST, render_prefix)
def render_view(self, field, value, REQUEST=None, render_prefix=None):
if value is None:
return ''
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'))
def get_javascript_list(self, field, REQUEST=None):
"""
Returns list of javascript needed by the widget
"""
if field.get_value('js_enabled'):
video_player = field.get_value('video_player')
context = getContext(field, REQUEST)
if video_player == 'html5_video':
# XXX Instead of harcoding library name
# it should be better to call a python script, as
# it is done on type base method.
return []
# return ['%s/html5media.min.js' % context.portal_url()]
elif video_player == 'flowplayer':
return ['%s/flowplayer.min.js' % context.portal_url()]
else:
return []
def getContext(field, REQUEST):
"""Return the context of rendering this VideoField.
""" """
value = REQUEST.get('here') value = self.request.get('here')
if value is None: if value is None:
value = getForm(field).aq_parent value = self.getForm().aq_parent
return value return value
getContext = lazyMethod(getContext)
def getForm(self):
"""Return the form which contains the Field.
"""
return self.field.aq_parent
getForm = lazyMethod(getForm)
VideoWidgetInstance = VideoWidget() VideoWidgetInstance = VideoWidget()
class VideoField(ZMIField): class VideoField(ZMIField):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment