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 import Widget, Validator
from Products.Formulator import Widget
from Products.Formulator.DummyField import fields
from Products.Formulator import Validator
from Products.ERP5Form.ListBox import lazyMethod
class AudioWidget(Widget.TextWidget):
"""
......@@ -69,6 +70,8 @@ class AudioWidget(Widget.TextWidget):
def render_view(self, field, value, REQUEST=None, render_prefix=None):
if value is None:
return ''
audio_player = field.get_value('audio_player')
if audio_player == 'html5_audio':
return Widget.render_element("audio",
src=value,
extra=field.get_value('extra'),
......@@ -77,6 +80,19 @@ class AudioWidget(Widget.TextWidget):
preload=field.get_value('audio_preload'),
autoplay=field.get_value('audio_autoplay'),
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):
"""
......@@ -84,7 +100,7 @@ class AudioWidget(Widget.TextWidget):
"""
if field.get_value('js_enabled'):
audio_player = field.get_value('audio_player')
context = getContext(field, REQUEST)
context = self.getContext(field, REQUEST)
if audio_player == 'html5_audio':
# XXX Instead of harcoding library name
# it should be better to call a python script, as
......@@ -95,14 +111,23 @@ class AudioWidget(Widget.TextWidget):
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:
value = getForm(field).aq_parent
value = self.getForm().aq_parent
return value
getContext = lazyMethod(getContext)
def getForm(self):
"""Return the form which contains the Field.
"""
return self.field.aq_parent
getForm = lazyMethod(getForm)
AudioWidgetInstance = AudioWidget()
class AudioField(ZMIField):
......@@ -112,4 +137,3 @@ class AudioField(ZMIField):
widget = AudioWidgetInstance
validator = Validator.SuppressValidatorInstance
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 import Validator
from Products.ERP5Form.ListBox import lazyMethod
class VideoWidget(Widget.TextWidget):
"""
......@@ -84,6 +85,8 @@ class VideoWidget(Widget.TextWidget):
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'),
......@@ -94,6 +97,18 @@ class VideoWidget(Widget.TextWidget):
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):
"""
......@@ -101,26 +116,34 @@ class VideoWidget(Widget.TextWidget):
"""
if field.get_value('js_enabled'):
video_player = field.get_value('video_player')
context = getContext(field, REQUEST)
context = self.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()]
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.
def getContext(self):
"""Return the context of rendering this Field..
"""
value = REQUEST.get('here')
value = self.request.get('here')
if value is None:
value = getForm(field).aq_parent
value = self.getForm().aq_parent
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()
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