2018-04-29 18:54:05 +02:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
global functions
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
// modal function:
// display an overlay window for warings, clip previews, etc.
2019-03-08 10:48:04 +01:00
function modal ( btOK , btCan , video , title , content , x , y , callback ) {
2018-04-29 18:54:05 +02:00
if ( video ) {
text = '<video id="preview_player" class="video-js" controls preload="auto" autoplay="true" data-setup={}> <source src="' + content + '" type="video/mp4" /> </video>' ;
} else {
text = content ;
}
var modalStr = '<p>' + text + '</p>' ;
$ ( '#dialog-confirm' ) . html ( modalStr ) ;
$ ( "#dialog-confirm" ) . dialog ( {
title : title ,
resizable : false ,
height : y ,
width : x ,
modal : true ,
buttons : [ {
id : "button-ok" ,
text : "Ok" ,
click : function ( ) {
$ ( '#preview_player' ) . remove ( )
$ ( this ) . dialog ( "close" ) ;
2019-03-08 10:48:04 +01:00
callback ( true ) ;
2018-04-29 18:54:05 +02:00
}
} ,
{
id : "button-cancel" ,
text : "Cancel" ,
click : function ( ) {
$ ( this ) . dialog ( "close" ) ;
2019-03-08 10:48:04 +01:00
callback ( false ) ;
2018-04-29 18:54:05 +02:00
}
}
]
} ) ;
if ( ! btOK ) {
$ ( "#button-ok" ) . remove ( ) ;
}
if ( ! btCan ) {
$ ( "#button-cancel" ) . remove ( ) ;
}
}
//get date
2019-08-15 13:51:27 +02:00
function get _date ( t , seek _day ) {
var datetime = moment ( ) ;
var l _time = t . split ( ":" ) ;
l _stamp = parseInt ( l _time [ 0 ] ) * 3600 + parseInt ( l _time [ 1 ] ) * 60 + parseInt ( l _time [ 2 ] ) ;
t _stamp = moment . duration ( datetime . format ( "H:M:S" ) ) . asSeconds ( ) ;
if ( l _stamp > 0 && l _stamp > t _stamp && seek _day ) {
return datetime . add ( - 1 , 'days' ) ;
2018-04-29 18:54:05 +02:00
} else {
2019-08-15 13:51:27 +02:00
return datetime ;
2018-04-29 18:54:05 +02:00
}
}
// calendar settings
$ ( '.calender' ) . pignoseCalendar ( {
lang : 'de' ,
theme : 'dark' ,
date : moment ( ) ,
format : 'YYYY-MM-DD' ,
week : 0 ,
init : function ( ) {
$ ( this ) . find ( '.pignose-calendar-unit-active' ) . children ( ) . addClass ( 'calender-bold' ) ;
} ,
select : function ( date ) {
$ . get ( "resources/list_op.php?list_start=get" , function ( result ) {
var list _date = get _date ( result , true ) ;
if ( date [ 0 ] . format ( 'YYYY-MM-DD' ) === list _date . format ( 'YYYY-MM-DD' ) ) {
$ ( '#playlistBody' ) . attr ( 'listday' , list _date . format ( 'YYYY-MM-DD' ) ) ;
2019-03-08 10:48:04 +01:00
get _json ( list _date . format ( 'YYYY-MM-DD' ) , true ) ;
2018-04-29 18:54:05 +02:00
} else {
$ ( '#playlistBody' ) . attr ( 'listday' , date [ 0 ] . format ( 'YYYY-MM-DD' ) ) ;
2019-03-08 10:48:04 +01:00
get _json ( date [ 0 ] . format ( 'YYYY-MM-DD' ) , true ) ;
2018-04-29 18:54:05 +02:00
}
} ) ;
}
} ) ;
// make directory listen resizeble
$ ( '#mainNav' ) . resizable ( {
handles : 'e, w'
} ) ;
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
directory listen functions
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
// initalize file browser click functions
// this is nessesary because the folder list gets generated from php
// and javascript don't know them before the init time
function init _browse _click ( ) {
// folder navigation
// all clickable links (folders and files) has the clearfix class
$ ( '.clearfix' ) . click ( function ( e ) {
var current _data = $ ( this ) . attr ( "href" ) ;
browse ( current _data ) ;
// level_up navigate to the parent directory
if ( $ ( this ) . find ( "i" ) . hasClass ( 'fa-level-up' ) ) {
var level _up = current _data . split ( "?" ) . pop ( ) ;
if ( ! level _up . match ( "http" ) ) {
browse ( '?' + level _up ) ;
}
}
e . preventDefault ( ) ;
} ) ;
// header navigation
$ ( '.breadcumb' ) . click ( function ( e ) {
var current _data = $ ( this ) . attr ( "href" ) ;
var change _level = current _data . split ( "?" ) . pop ( ) ;
browse ( '?' + change _level ) ;
e . preventDefault ( ) ;
} ) ;
// video preview
// when click on file link, open the modal windows and preview the clip
$ ( '.file-info-button' ) . click ( function ( e ) {
var current _element = $ ( this ) ;
var rawpath = current _element . closest ( 'li' ) . attr ( 'data-href' ) . replace ( /^\?dir=/g , current _element ) ;
2019-03-08 10:48:04 +01:00
modal ( true , null , true , decodeURIComponent ( rawpath . split ( "/" ) . pop ( ) ) , rawpath , 1039 , 716 , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
e . preventDefault ( ) ;
} ) ;
}
// call php script to navigatge to the selected folder on the server
2019-08-15 13:51:27 +02:00
function browse ( c _data ) {
$ . get ( "functions.php" + c _data + "&head=get" , function ( data ) {
2018-04-29 18:54:05 +02:00
$ ( '#browserHead' ) . html ( data ) ;
} ) ;
2019-08-15 13:51:27 +02:00
$ . get ( "functions.php" + c _data + "&ul=get" , function ( data ) {
2018-04-29 18:54:05 +02:00
$ ( '#rootDirectory' ) . html ( data ) ;
init _browse _click ( ) ;
} ) ;
}
// first page load will open the media directory
window . onload = function ( ) {
$ . get ( "resources/list_op.php?clips_root=get" , function ( result ) {
2019-08-15 13:51:27 +02:00
browse ( "?dir=" + result . replace ( /^\//g , '' ) ) ;
2018-04-29 18:54:05 +02:00
} ) ;
$ . get ( "resources/list_op.php?list_start=get" , function ( result ) {
2019-08-15 13:51:27 +02:00
var l _time = result . split ( ":" ) ;
var l _stamp = parseInt ( l _time [ 0 ] ) * 3600 + parseInt ( l _time [ 1 ] ) * 60 + parseInt ( l _time [ 2 ] ) ;
2018-04-29 18:54:05 +02:00
var list _date = get _date ( result , true ) ;
// write playlist date to list attribute, for later use
$ ( '#playlistBody' ) . attr ( 'listday' , list _date . format ( "YYYY-MM-DD" ) ) ;
2019-08-15 13:51:27 +02:00
$ ( '#playlistBody' ) . attr ( 'liststart' , l _stamp ) ;
2018-04-29 18:54:05 +02:00
// read playlist from current day
2019-03-08 10:48:04 +01:00
get _json ( list _date . format ( "YYYY-MM-DD" ) , true ) ;
2018-04-29 18:54:05 +02:00
} ) ;
}
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
playlist functions
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
// initalize buttons and input dialogs,
// after the playlist has loaded
function init _list _op ( ) {
// video preview
$ ( '.file-play' ) . click ( function ( e ) {
var file _path = $ ( this ) . attr ( 'data-href' ) ;
var play _URL = encodeURIComponent ( file _path ) ;
2019-03-08 10:48:04 +01:00
modal ( true , null , true , decodeURIComponent ( file _path . split ( "/" ) . pop ( ) ) , play _URL , 1039 , 716 , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
e . preventDefault ( ) ;
} ) ;
var enableButton = function ( ) {
$ ( '.row-del' ) . removeClass ( 'disabled' ) ;
}
// delete clip from playlist
$ ( '.row-del' ) . click ( function ( ) {
if ( ! $ ( this ) . hasClass ( 'disabled' ) ) {
$ ( this ) . parent ( ) . parent ( ) . remove ( ) ;
reorder _playlist ( ) ;
$ ( '.row-del' ) . addClass ( 'disabled' ) ;
// limit click rate
setTimeout ( enableButton , 1000 ) ;
return true ;
} else {
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Delete Item" , "Removing items is limited to every second." , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
}
} ) ;
// input field for seek in clip
$ ( '.input-in' ) . change ( function ( ) {
var in _seconds = moment . duration ( $ ( this ) . val ( ) ) . asSeconds ( ) ;
var in _duration = $ ( this ) . closest ( 'ul' ) . parent ( ) . attr ( 'dur' ) ;
if ( in _seconds > in _duration ) {
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Seek in Video" , "Seek Value is bigger then Duration!<br/>Please fix that..." , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
$ ( this ) . val ( "00:00:00" ) ;
} else {
$ ( this ) . closest ( 'ul' ) . parent ( ) . attr ( 'in' , in _seconds ) ;
reorder _playlist ( ) ;
}
} ) ;
// input field for cut out clip at specific time
$ ( '.input-out' ) . change ( function ( ) {
var cur _val = $ ( this ) . val ( ) ;
var out _seconds = moment . duration ( $ ( this ) . val ( ) ) . asSeconds ( ) ;
var out _dur = $ ( this ) . closest ( 'ul' ) . parent ( ) . attr ( 'dur' ) ;
if ( out _seconds > out _dur ) {
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Cut Video" , "Cut Value is bigger then Duration!<br/>Please fix that..." , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
$ ( this ) . val ( cur _val ) ;
} else {
$ ( this ) . closest ( 'ul' ) . parent ( ) . attr ( 'out' , out _seconds ) ;
reorder _playlist ( ) ;
}
} ) ;
// reset button
$ ( '#bt_reset' ) . click ( function ( ) {
// scroll to playlist top
2019-03-08 10:48:04 +01:00
get _json ( $ ( '#playlistBody' ) . attr ( 'listday' ) , false ) ;
2018-04-29 18:54:05 +02:00
} ) ;
}
// read formated playlist from php function
2019-03-08 10:48:04 +01:00
function get _json ( date , jump ) {
$ . get ( "resources/list_op.php?json_path=" + date , function ( result ) {
2018-04-29 18:54:05 +02:00
$ ( '#playlistBody' ) . html ( result ) ;
init _list _op ( ) ;
if ( jump ) {
jump _and _colorize _title ( true ) ;
} else {
jump _and _colorize _title ( false ) ;
}
} ) ;
}
// when new clips are dragged,
// or clips are moved, or deleted, calculate the starting time new
// it also take care of the in and out time
function reorder _playlist ( ) {
// get start time from: /etc/ffplayout/ffplayout.conf
$ . get ( "resources/list_op.php?list_start=get" , function ( result ) {
var reorder = document . getElementById ( "playlistBody" ) . getElementsByClassName ( "list-item" ) ;
2019-08-15 13:51:27 +02:00
var l _time = result . split ( ":" ) ;
var start _time = parseFloat ( l _time [ 0 ] ) * 3600 + parseFloat ( l _time [ 1 ] ) * 60 + parseFloat ( l _time [ 2 ] ) ;
2018-04-29 18:54:05 +02:00
var time _format , cur _in , cur _out ;
for ( var i = 0 ; i < reorder . length ; i ++ ) {
time _format = moment . utc ( start _time * 1000 ) . format ( 'HH:mm:ss' ) ;
cur _in = parseFloat ( $ ( reorder [ i ] ) . attr ( 'in' ) ) ;
cur _out = parseFloat ( $ ( reorder [ i ] ) . attr ( 'out' ) ) ;
$ ( reorder [ i ] ) . attr ( 'begin' , start _time ) ;
$ ( reorder [ i ] ) . removeClass ( 'current_item next_item last_items' ) ;
$ ( reorder [ i ] ) . find ( '.row-start' ) . html ( time _format ) ;
start _time += cur _out - cur _in ;
}
init _list _op ( ) ;
jump _and _colorize _title ( false ) ;
} ) ;
}
// jump to right time in playlist
// and colorize the list
function jump _and _colorize _title ( jump ) {
var moment _time = moment ( ) . format ( 'HH:mm:ss' ) ;
var time _in _seconds = parseFloat ( moment . duration ( moment _time ) . asSeconds ( ) ) ;
var play _items = document . getElementById ( "playlistBody" ) . getElementsByClassName ( "list-item" ) ;
var play _begin , play _dur ;
$ . get ( "resources/list_op.php?list_start=get" , function ( result ) {
2019-08-15 13:51:27 +02:00
var list _date = get _date ( result , true ) ;
2018-04-29 18:54:05 +02:00
if ( list _date . format ( "H" ) < parseInt ( result ) ) {
time _in _seconds += 86400
}
2019-08-15 13:51:27 +02:00
if ( $ ( '#playlistBody' ) . attr ( 'listday' ) === list _date . format ( "YYYY-MM-DD" ) ) {
for ( var i = 0 ; i < play _items . length ; i ++ ) {
play _begin = parseFloat ( $ ( play _items [ i ] ) . attr ( 'begin' ) ) ;
play _dur = parseFloat ( $ ( play _items [ i ] ) . attr ( 'dur' ) ) ;
if ( play _begin + play _dur >= time _in _seconds ) {
// jump to position only after page load
if ( jump ) {
$ ( '#list-container' ) . animate ( {
scrollTop : $ ( '#playlistBody li:nth-child(' + ( i - 1 ) + ')' ) . position ( ) . top
} , 500 , "easeOutQuint" ) ;
2018-04-29 18:54:05 +02:00
}
2019-08-15 13:51:27 +02:00
// colorize items
$ ( play _items [ i ] ) . addClass ( 'current_item' ) ;
$ ( play _items [ i + 1 ] ) . addClass ( 'next_item' ) ;
$ ( '.list-item:gt(' + ( i + 1 ) + ')' ) . addClass ( 'last_items' ) ;
break ;
2018-04-29 18:54:05 +02:00
}
}
2019-08-15 13:51:27 +02:00
} else {
// scroll to playlist top
if ( jump ) {
$ ( '#list-container' ) . animate ( { scrollTop : 0 } , 500 , "easeOutQuint" ) ;
}
}
2018-04-29 18:54:05 +02:00
} ) ;
}
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
footer functions
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
function get _log ( logtype ) {
$ . get ( "resources/logging.php?log_from=" + logtype , function ( result ) {
$ ( '#output' ) . html ( result ) ;
scroll _div = $ ( '.log-content div' ) ;
scroll _div . animate ( {
scrollTop : scroll _div [ 0 ] . scrollHeight - scroll _div [ 0 ] . clientHeight
} , 500 , "easeOutQuint" ) ;
} ) ;
}
// logging tabs
$ ( '#bt_play' ) . click ( function ( ) {
$ ( this ) . addClass ( "active" ) ;
$ ( '#bt_sys' ) . removeClass ( "active" ) ;
2019-11-18 10:07:50 +01:00
$ ( '#bt_enc' ) . removeClass ( "active" ) ;
$ ( '#bt_dec' ) . removeClass ( "active" ) ;
2018-04-29 18:54:05 +02:00
get _log ( "playing" ) ;
} ) ;
2019-11-18 10:07:50 +01:00
$ ( '#bt_dec' ) . click ( function ( ) {
$ ( this ) . addClass ( "active" ) ;
$ ( '#bt_sys' ) . removeClass ( "active" ) ;
$ ( '#bt_enc' ) . removeClass ( "active" ) ;
$ ( '#bt_play' ) . removeClass ( "active" ) ;
get _log ( "decoder" ) ;
} ) ;
$ ( '#bt_enc' ) . click ( function ( ) {
$ ( this ) . addClass ( "active" ) ;
$ ( '#bt_sys' ) . removeClass ( "active" ) ;
$ ( '#bt_dec' ) . removeClass ( "active" ) ;
$ ( '#bt_play' ) . removeClass ( "active" ) ;
get _log ( "encoder" ) ;
} ) ;
2018-04-29 18:54:05 +02:00
$ ( '#bt_sys' ) . click ( function ( ) {
$ ( this ) . addClass ( "active" ) ;
$ ( '#bt_play' ) . removeClass ( "active" ) ;
2019-11-18 10:07:50 +01:00
$ ( '#bt_enc' ) . removeClass ( "active" ) ;
$ ( '#bt_dec' ) . removeClass ( "active" ) ;
2018-04-29 18:54:05 +02:00
get _log ( "system" ) ;
} ) ;
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
header functions
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
function get _track _list ( interval ) {
2019-08-15 13:51:27 +02:00
var begin , seek , out , time _left ;
2018-04-29 18:54:05 +02:00
$ . get ( "resources/player.php?track=get" , function ( result ) {
function get _track ( ) {
var moment _time = moment ( ) . format ( 'HH:mm:ss' ) ;
var time _in _seconds = parseFloat ( moment . duration ( moment _time ) . asSeconds ( ) ) ;
var json = $ . parseJSON ( result ) ;
2019-08-15 13:51:27 +02:00
var playlist _start = parseFloat ( $ ( '#playlistBody' ) . attr ( 'liststart' ) ) ;
2018-04-29 18:54:05 +02:00
2019-08-15 13:51:27 +02:00
if ( 0.0 <= time _in _seconds && time _in _seconds < playlist _start ) {
2018-04-29 18:54:05 +02:00
time _in _seconds += 86400.0 ;
}
2019-08-15 13:51:27 +02:00
begin = playlist _start ;
$ . each ( json , function ( _index , value ) {
seek = parseFloat ( value [ 'in' ] ) ;
out = parseFloat ( value [ 'out' ] ) ;
2018-04-29 18:54:05 +02:00
if ( time _in _seconds < begin + out - seek ) {
time _left = begin + out - seek - time _in _seconds ;
$ ( '#countdown' ) . html ( moment . utc ( time _left * 1000 ) . format ( 'HH:mm:ss' ) ) ;
$ ( '#title' ) . html ( ( value [ 'src' ] ) ) ;
return false ;
}
2019-08-15 13:51:27 +02:00
begin += out - seek ;
2018-04-29 18:54:05 +02:00
} ) ;
}
if ( interval ) {
refreshIntervalId = setInterval ( get _track , 1000 ) ;
} else {
clearInterval ( refreshIntervalId ) ;
}
} ) ;
}
function set _time ( ) {
$ ( '#clock' ) . html ( moment ( ) . format ( 'H:mm:ss' ) ) ;
}
// start stream
$ ( '#bt_start' ) . click ( function ( ) {
$ . ajax ( {
url : "resources/player.php" ,
type : "POST" ,
data : "playout=start" ,
beforeSend : function ( ) {
2019-03-08 10:48:04 +01:00
modal ( false , null , null , "Start Playout" , '<div style="text-align:center; min-width: 120px"><img src="resources/img/35.png" height="46" width="46"></div>' , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
} ,
success : function ( result ) {
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Start Playout" , '<div style="text-align:center;min-width: 120px">' + result + '</div>' , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
videojs ( 'myStream' ) . play ( ) ;
get _track _list ( true ) ;
get _log ( "playing" ) ;
} ,
} ) ;
} ) ;
// stop stream
$ ( '#bt_stop' ) . click ( function ( ) {
2019-03-08 10:48:04 +01:00
modal ( true , true , null , "Stop Playout" , '<div style="text-align:center;min-width: 120px">Are you really sure, you want to do this?</div>' , 'auto' , 'auto' , function ( result ) {
if ( result ) {
$ . ajax ( {
url : "resources/player.php" ,
type : "POST" ,
data : "playout=stop" ,
beforeSend : function ( ) {
modal ( false , null , null , "Stop Playout" , '<div style="text-align:center; min-width: 120px"><img src="resources/img/35.png" height="46" width="46"></div>' , 'auto' , 'auto' , function ( result ) { } ) ;
} ,
success : function ( result ) {
modal ( true , null , null , "Stop Playout" , '<div style="text-align:center;min-width: 120px">' + result + '</div>' , 'auto' , 'auto' , function ( result ) { } ) ;
videojs ( 'myStream' ) . pause ( ) ;
get _track _list ( false ) ;
} ,
} ) ;
}
2018-04-29 18:54:05 +02:00
} ) ;
} ) ;
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ready state
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
// when page is loaded, do something with the staff
$ ( document ) . ready ( function ( ) {
// init browser and playlist controlls
init _browse _click ( ) ;
init _list _op ( ) ;
get _log ( "playing" ) ;
// set player standards
videojs ( 'myStream' , { techOrder : [ 'flash' , 'html5' ] } ) ;
videojs ( 'myStream' ) . volume ( 0.2 ) ;
setInterval ( set _time , 1000 ) ;
get _track _list ( true ) ;
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sorting
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- * /
// sort: drag and drop function from directory listen to playlist
var el = document . getElementById ( 'rootDirectory' ) ;
Sortable . create ( el , {
animation : 200 ,
filter : ".folder" ,
group : {
name : "shared" ,
pull : "clone" ,
revertClone : true ,
} ,
sort : false ,
onStart : function ( evt ) {
$ ( evt . item ) . addClass ( 'list-item' ) . removeClass ( 'file' ) ;
} ,
onEnd : function ( evt ) {
var itemEl = evt . item ;
if ( $ ( itemEl ) . parent ( ) . attr ( 'class' ) === "list-group" ) {
var url = $ ( itemEl ) . find ( "a" ) . attr ( "href" ) ;
var lis = document . getElementById ( "playlistBody" ) . getElementsByClassName ( "list-item" ) ;
for ( li of lis ) {
if ( $ ( li ) . attr ( 'src' ) === "None" ) {
$ ( li ) . remove ( ) ;
}
}
$ . get ( "resources/list_op.php?li_path=" + "/" + url , function ( result ) {
$ ( itemEl ) . replaceWith ( result ) ;
reorder _playlist ( ) ;
init _list _op ( ) ;
} ) ;
} else {
$ ( evt . item ) . addClass ( 'file' ) . removeClass ( 'list-item' ) ;
}
} ,
} ) ;
// drag and drop within the playlist
Sortable . create ( playlistBody , {
group : "shared" ,
handle : ".handle" ,
ghostClass : 'ghost' ,
sort : true ,
onEnd : function ( evt ) {
reorder _playlist ( ) ;
}
} ) ;
// save button
$ ( '#bt_save' ) . click ( function ( ) {
var start _time = parseFloat ( $ ( '.list-item' ) . first ( ) . attr ( 'begin' ) ) ;
var last _start = parseFloat ( $ ( '.list-item' ) . last ( ) . attr ( 'begin' ) ) ;
var last _in = parseFloat ( $ ( '.list-item' ) . last ( ) . attr ( 'in' ) ) ;
var last _out = parseFloat ( $ ( '.list-item' ) . last ( ) . attr ( 'out' ) ) ;
var over _length = last _start - start _time + last _out - last _in - 86400 ;
2019-08-16 16:52:10 +02:00
/ * T O D O : n o l e n g t h c h e c k f o r n o w
2018-04-29 18:54:05 +02:00
if ( over _length > 0 ) {
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Save Playlist" , "Playtime from Playlist is to long!<br/><b>Difference:</b> " + over _length , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
} else if ( over _length < - 6 ) {
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Save Playlist" , "Playtime from Playlist is to short!<br/><b>Difference:</b> " + over _length , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
} else {
2019-08-16 16:52:10 +02:00
* /
2018-04-29 18:54:05 +02:00
var save _list = [ ] ;
$ ( '#playlistBody li.list-item' ) . each ( function ( ) {
save _list . push ( {
src : $ ( this ) . attr ( 'src' ) ,
dur : $ ( this ) . attr ( 'dur' ) ,
in : $ ( this ) . attr ( 'in' ) ,
out : $ ( this ) . attr ( 'out' )
} ) ;
} ) ;
var json = encodeURIComponent ( JSON . stringify ( save _list ) ) ;
var date = $ ( '#playlistBody' ) . attr ( 'listday' ) ;
$ . ajax ( {
type : "POST" ,
url : "resources/list_op.php" ,
data : "date=" + date + "&save=" + json ,
success : function ( result ) {
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Save Playlist" , result , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
}
} ) ;
2019-08-16 16:52:10 +02:00
//}
2018-04-29 18:54:05 +02:00
} ) ;
// fill end of playlist to get full 24 hours
$ ( '#bt_filler' ) . click ( function ( ) {
var start _time = parseFloat ( $ ( '.list-item' ) . first ( ) . attr ( 'begin' ) ) ;
var last _start = parseFloat ( $ ( '.list-item' ) . last ( ) . attr ( 'begin' ) ) ;
var last _in = parseFloat ( $ ( '.list-item' ) . last ( ) . attr ( 'in' ) ) ;
var last _out = parseFloat ( $ ( '.list-item' ) . last ( ) . attr ( 'out' ) ) ;
var missed _length = last _start - start _time + last _out - last _in - 86400 ;
if ( missed _length > 0 ) {
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Fill Playlist" , "Playtime from Playlist is to long!<br/><b>Difference:</b> " + missed _length , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
} else if ( missed _length > - 6 ) {
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Fill Playlist" , "Playtime from Playlist is in range!<br/><b>No change will made...</b>" , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
} else if ( missed _length < - 2700 ) {
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Fill Playlist" , "Missed length to fill is bigger then 45 minutes!<br/><b>Please add more clips...</b>" , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
} else {
date = $ ( '#playlistBody' ) . attr ( 'listday' ) ;
var save _list = [ ] ;
$ ( '#playlistBody li.list-item' ) . each ( function ( ) {
save _list . push ( {
src : $ ( this ) . attr ( 'src' ) ,
dur : $ ( this ) . attr ( 'dur' ) ,
in : $ ( this ) . attr ( 'in' ) ,
out : $ ( this ) . attr ( 'out' )
} ) ;
} ) ;
var json = encodeURIComponent ( JSON . stringify ( save _list ) ) ;
var date = $ ( '#playlistBody' ) . attr ( 'listday' ) ;
$ . ajax ( {
type : "POST" ,
url : "resources/list_op.php" ,
2019-03-08 10:48:04 +01:00
data : "fill_playlist=" + date + "&diff_len=" + Math . abs ( missed _length ) + "&start_time=" + ( last _start + last _out - last _in ) + "&old_list=" + json ,
2018-04-29 18:54:05 +02:00
beforeSend : function ( ) {
2019-03-08 10:48:04 +01:00
modal ( null , null , null , "Fill Playlist" , "Filling Playlist in progress..." , 'auto' , 'auto' , function ( result ) { } ) ;
2018-04-29 18:54:05 +02:00
} ,
success : function ( result ) {
$ ( '#dialog-confirm' ) . dialog ( "close" ) ;
2019-03-08 10:48:04 +01:00
modal ( true , null , null , "Fill Playlist" , result + "<br/><b>Filled Time:</b> " + moment . utc ( Math . abs ( missed _length ) * 1000 ) . format ( 'HH:mm:ss' ) , 'auto' , 'auto' , function ( result ) { } ) ;
get _json ( date , false ) ;
2018-04-29 18:54:05 +02:00
}
} ) ;
}
} ) ;
} ) ;