--- a/src/pyams_media/skin/resources/js/pyams_media.js Thu Sep 20 13:42:05 2018 +0200
+++ b/src/pyams_media/skin/resources/js/pyams_media.js Thu Sep 20 13:47:23 2018 +0200
@@ -6,20 +6,26 @@
var PyAMS_media = {
- initPlayer: function() {
- var player = $(this);
- MyAMS.dialog.registerShownCallback(PyAMS_media.initPlayerDialog, player);
- var flowplayer = player.flowplayer();
- var events = player.data('ams-flowplayer-events');
- if (events) {
- for (var event in events) {
- if (!events.hasOwnProperty(event)) {
- continue;
- }
- flowplayer.on(event, MyAMS.getFunctionByName(events[event]));
- }
- }
- MyAMS.dialog.registerHideCallback(PyAMS_media.shutdownPlayerDialog, player);
+ initPlayer: function(element) {
+ MyAMS.ajax.check($.fn.flowplayer,
+ '/--static--/pyams_media/flowplayer/flowplayer' + MyAMS.devext + '.js',
+ function(first_load) {
+ if (first_load) {
+ MyAMS.dialog.registerShownCallback(PyAMS_media.initPlayerDialog, player);
+ MyAMS.dialog.registerHideCallback(PyAMS_media.shutdownPlayerDialog, player);
+ }
+ var player = $(element);
+ var flowplayer = player.flowplayer();
+ var events = player.data('ams-flowplayer-events');
+ if (events) {
+ for (var event in events) {
+ if (!events.hasOwnProperty(event)) {
+ continue;
+ }
+ flowplayer.on(event, MyAMS.getFunctionByName(events[event]));
+ }
+ }
+ });
},
initPlayerDialog: function() {
@@ -28,12 +34,18 @@
.removeClass('modal-viewport');
},
- getPlayerTime: function(e, api) {
+ shutdownPlayerDialog: function() {
+ var dialog = $(this);
+ var player = $('.flowplayer', dialog).data('flowplayer');
+ player.shutdown();
+ },
+
+ getPlayerTime: function(/* e, api */) {
var parent = $(this);
+ if (!parent.hasClass('flowplayer')) {
+ parent = $('.flowplayer', parent);
+ }
var player = parent.data('flowplayer');
- if (player.playing) {
- return;
- }
var video = player.video;
if (!video.time && player.conf.flowplayer) {
video = player.conf.flowplayer.video;
@@ -45,10 +57,14 @@
}
},
- shutdownPlayerDialog: function() {
- var dialog = $(this);
- var player = $('.flowplayer', dialog).data('flowplayer');
- player.shutdown();
+ pausePlayer: function() {
+ var form = $(this);
+ var player = $('.flowplayer', form).data('flowplayer');
+ if (player.playing) {
+ player.pause();
+ }
+ PyAMS_media.getPlayerTime.call(form);
+ return {};
}
};
globals.PyAMS_media = PyAMS_media;
--- a/src/pyams_media/skin/resources/js/pyams_media.min.js Thu Sep 20 13:42:05 2018 +0200
+++ b/src/pyams_media/skin/resources/js/pyams_media.min.js Thu Sep 20 13:47:23 2018 +0200
@@ -1,1 +1,1 @@
-!function(a,e){"use strict";var i=e.MyAMS,t={initPlayer:function(){var e=a(this);i.dialog.registerShownCallback(t.initPlayerDialog,e);var r=e.flowplayer(),o=e.data("ams-flowplayer-events");if(o)for(var l in o)o.hasOwnProperty(l)&&r.on(l,i.getFunctionByName(o[l]));i.dialog.registerHideCallback(t.shutdownPlayerDialog,e)},initPlayerDialog:function(){var e=a(this);a(".modal-viewport",e).removeAttr("style").removeClass("modal-viewport")},getPlayerTime:function(e,i){var t=a(this),r=t.data("flowplayer");if(!r.playing){var o=r.video;if(!o.time&&r.conf.flowplayer&&(o=r.conf.flowplayer.video),o&&o.time){var l=o.time,n=t.parents("form");a('INPUT[name="thumbnail_form.widgets.time"]',n).val(l)}}},shutdownPlayerDialog:function(){var e=a(this);a(".flowplayer",e).data("flowplayer").shutdown()}};e.PyAMS_media=t}(jQuery,this);
+!function(a,e){"use strict";var l=e.MyAMS,r={initPlayer:function(e){l.ajax.check(a.fn.flowplayer,"/--static--/pyams_media/flowplayer/flowplayer"+l.devext+".js",function(i){i&&(l.dialog.registerShownCallback(r.initPlayerDialog,t),l.dialog.registerHideCallback(r.shutdownPlayerDialog,t));var t=a(e),o=t.flowplayer(),n=t.data("ams-flowplayer-events");if(n)for(var y in n)n.hasOwnProperty(y)&&o.on(y,l.getFunctionByName(n[y]))})},initPlayerDialog:function(){var e=a(this);a(".modal-viewport",e).removeAttr("style").removeClass("modal-viewport")},shutdownPlayerDialog:function(){var e=a(this);a(".flowplayer",e).data("flowplayer").shutdown()},getPlayerTime:function(){var e=a(this);e.hasClass("flowplayer")||(e=a(".flowplayer",e));var l=e.data("flowplayer"),r=l.video;if(!r.time&&l.conf.flowplayer&&(r=l.conf.flowplayer.video),r&&r.time){var i=r.time,t=e.parents("form");a('INPUT[name="thumbnail_form.widgets.time"]',t).val(i)}},pausePlayer:function(){var e=a(this),l=a(".flowplayer",e).data("flowplayer");return l.playing&&l.pause(),r.getPlayerTime.call(e),{}}};e.PyAMS_media=r}(jQuery,this);
--- a/src/pyams_media/zmi/templates/video-preview.pt Thu Sep 20 13:42:05 2018 +0200
+++ b/src/pyams_media/zmi/templates/video-preview.pt Thu Sep 20 13:47:23 2018 +0200
@@ -1,10 +1,8 @@
<div class="flowplayer"
- data-ams-plugins="flowplayer"
- data-ams-plugin-flowplayer-async="false"
- data-ams-callback="PyAMS_media.initPlayer"
- tal:attributes="data-ams-plugin-flowplayer-src tales:resource_path('pyams_media.skin:flowplayer');
- data-ams-plugin-flowplayer-css tales:resource_path('pyams_media.skin:functional_css');
- data-ams-callback-source tales:resource_path('pyams_media.skin:pyams_media');">
+ data-ams-plugins="pyams_media"
+ data-ams-plugin-pyams_media-callback="PyAMS_media.initPlayer"
+ tal:attributes="data-ams-plugin-pyams_media-src tales:resource_path('pyams_media.skin:pyams_media');
+ data-ams-plugin-pyams_media-css tales:resource_path('pyams_media.skin:functional_css');">
<video
tal:define="href tales:absolute_url(context);
conversions tales:conversions(context);
--- a/src/pyams_media/zmi/templates/video-thumbnail.pt Thu Sep 20 13:42:05 2018 +0200
+++ b/src/pyams_media/zmi/templates/video-thumbnail.pt Thu Sep 20 13:47:23 2018 +0200
@@ -1,10 +1,8 @@
<div class="flowplayer"
- data-ams-plugins="flowplayer"
- data-ams-plugin-flowplayer-async="false"
- data-ams-callback="PyAMS_media.initPlayer"
- tal:attributes="data-ams-plugin-flowplayer-src tales:resource_path('pyams_media.skin:flowplayer');
- data-ams-plugin-flowplayer-css tales:resource_path('pyams_media.skin:functional_css');
- data-ams-callback-source tales:resource_path('pyams_media.skin:pyams_media');"
+ data-ams-plugins="pyams_media"
+ data-ams-plugin-pyams_media-callback="PyAMS_media.initPlayer"
+ tal:attributes="data-ams-plugin-pyams_media-src tales:resource_path('pyams_media.skin:pyams_media');
+ data-ams-plugin-pyams_media-css tales:resource_path('pyams_media.skin:functional_css');"
data-ams-flowplayer-events='{"pause": "PyAMS_media.getPlayerTime", "seek": "PyAMS_media.getPlayerTime"}'>
<video
tal:define="href tales:absolute_url(context);
--- a/src/pyams_media/zmi/video.py Thu Sep 20 13:42:05 2018 +0200
+++ b/src/pyams_media/zmi/video.py Thu Sep 20 13:47:23 2018 +0200
@@ -12,36 +12,31 @@
__docformat__ = 'restructuredtext'
-
-# import standard library
from datetime import datetime
from decimal import Decimal
-# import interfaces
-from pyams_file.interfaces import IVideo, IThumbnails, IMediaWidget
-from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager, IFormHelp
-from pyams_skin.interfaces.viewlet import IContextActions
-from pyams_utils.interfaces import MANAGE_PERMISSION, VIEW_PERMISSION
-from pyams_zmi.layer import IAdminLayer
+from z3c.form import field, button
from z3c.form.interfaces import HIDDEN_MODE
+from zope.interface import Interface, alsoProvides
-# import packages
-from pyams_form.form import AJAXAddForm
+from pyams_file.interfaces import IVideo, IThumbnails, IMediaWidget
+from pyams_form.form import AJAXAddForm, ajax_config
from pyams_form.help import FormHelp
+from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager, IFormHelp
from pyams_form.schema import CloseButton
+from pyams_media import _
from pyams_pagelet.pagelet import pagelet_config
+from pyams_skin.interfaces.viewlet import IContextActions
from pyams_skin.layer import IPyAMSLayer
from pyams_skin.viewlet.toolbar import ToolbarActionItem
from pyams_template.template import template_config
from pyams_utils.adapter import adapter_config
+from pyams_utils.interfaces import MANAGE_PERMISSION, VIEW_PERMISSION
+from pyams_utils.interfaces.data import IObjectData
from pyams_utils.schema import DottedDecimalField
from pyams_viewlet.viewlet import viewlet_config, Viewlet
from pyams_zmi.form import AdminDialogAddForm, AdminDialogDisplayForm
-from pyramid.view import view_config
-from z3c.form import field, button
-from zope.interface import Interface
-
-from pyams_media import _
+from pyams_zmi.layer import IAdminLayer
#
@@ -101,6 +96,8 @@
@pagelet_config(name='video-thumbnail.html', context=IVideo, layer=IPyAMSLayer, permission=MANAGE_PERMISSION)
+@ajax_config(name='video-thumbnail.json', context=IVideo, layer=IPyAMSLayer, permission=MANAGE_PERMISSION,
+ base=AJAXAddForm)
class VideoThumbnailEditForm(AdminDialogAddForm):
"""Video thumbnail selection form"""
@@ -125,6 +122,10 @@
super(VideoThumbnailEditForm, self).updateActions()
if 'select' in self.actions:
self.actions['select'].addClass('btn-primary')
+ self.object_data = {
+ 'ams-form-data-init-callback': 'PyAMS_media.pausePlayer'
+ }
+ alsoProvides(self, IObjectData)
def createAndAdd(self, data):
data = data.get(self, data)
@@ -137,12 +138,6 @@
thumbnailer.clear_thumbnails()
return thumbnailer.get_thumbnail('{0[0]}x{0[1]}'.format(size), 'png', time)
-
-@view_config(name='video-thumbnail.json', context=IVideo, request_type=IPyAMSLayer,
- permission=MANAGE_PERMISSION, renderer='json', xhr=True)
-class VideoThumbnailAJAXEditForm(AJAXAddForm, VideoThumbnailEditForm):
- """Video thumbnail selection form, JSON renderer"""
-
def get_ajax_output(self, changes):
translate = self.request.localizer.translate
if changes: