2010-12-22 05:33:58 +01:00
//--------------------------------------------------------------------------------------------------------------------------------
2012-02-04 19:27:26 +01:00
// Playlist Functions
2010-12-22 05:33:58 +01:00
//--------------------------------------------------------------------------------------------------------------------------------
2012-02-04 15:52:31 +01:00
var AIRTIME = ( function ( AIRTIME ) {
2012-02-04 19:27:26 +01:00
2012-03-30 16:04:00 +02:00
if ( AIRTIME . playlist === undefined ) {
AIRTIME . playlist = { } ;
}
2012-03-14 17:50:48 +01:00
2012-03-30 16:04:00 +02:00
var mod = AIRTIME . playlist ,
viewport ,
$lib ,
$pl ,
widgetHeight ,
2012-05-04 18:13:01 +02:00
resizeTimeout ,
2012-03-30 16:04:00 +02:00
width ;
2012-02-04 15:52:31 +01:00
2012-02-06 11:07:10 +01:00
function isTimeValid ( time ) {
var regExpr = new RegExp ( "^\\d{2}[:]\\d{2}[:]\\d{2}([.]\\d{1,6})?$" ) ;
return regExpr . test ( time ) ;
}
function isFadeValid ( fade ) {
2012-02-06 18:46:53 +01:00
var regExpr = new RegExp ( "^\\d{1}(\\d{1})?([.]\\d{1,6})?$" ) ;
2012-02-02 21:59:35 +01:00
return regExpr . test ( fade ) ;
2011-01-17 19:55:43 +01:00
}
2012-02-06 11:07:10 +01:00
2012-02-20 18:24:04 +01:00
function playlistError ( json ) {
alert ( json . error ) ;
openPlaylist ( json ) ;
}
2012-02-06 11:07:10 +01:00
2012-02-04 15:52:31 +01:00
function stopAudioPreview ( ) {
// stop any preview playing
$ ( '#jquery_jplayer_1' ) . jPlayer ( 'stop' ) ;
2011-01-17 19:55:43 +01:00
}
2012-02-04 15:52:31 +01:00
function highlightActive ( el ) {
2011-01-17 19:55:43 +01:00
2012-02-04 15:52:31 +01:00
$ ( el ) . addClass ( "ui-state-active" ) ;
2011-01-17 19:55:43 +01:00
}
2012-02-04 15:52:31 +01:00
function unHighlightActive ( el ) {
2011-01-17 19:55:43 +01:00
2012-02-04 15:52:31 +01:00
$ ( el ) . removeClass ( "ui-state-active" ) ;
2011-01-17 19:55:43 +01:00
}
2012-02-04 19:27:26 +01:00
function showError ( el , error ) {
$ ( el ) . parent ( ) . next ( )
. empty ( )
. append ( error )
. show ( ) ;
}
2011-05-17 23:30:17 +02:00
2012-02-04 19:27:26 +01:00
function hideError ( el ) {
$ ( el ) . parent ( ) . next ( )
. empty ( )
. hide ( ) ;
2011-01-18 20:57:54 +01:00
}
2012-02-04 19:27:26 +01:00
function changeCueIn ( event ) {
event . stopPropagation ( ) ;
2011-02-08 00:44:42 +01:00
2012-02-20 18:24:04 +01:00
var span = $ ( this ) ,
id = span . parent ( ) . attr ( "id" ) . split ( "_" ) . pop ( ) ,
url = "/Playlist/set-cue" ,
cueIn = $ . trim ( span . text ( ) ) ,
li = span . parents ( "li" ) ,
unqid = li . attr ( "unqid" ) ,
2012-07-25 17:00:46 +02:00
lastMod = getModified ( ) ,
type = $ ( '#obj_type' ) . val ( ) ;
2011-01-17 00:37:02 +01:00
2012-02-20 18:24:04 +01:00
if ( ! isTimeValid ( cueIn ) ) {
2012-02-04 19:27:26 +01:00
showError ( span , "please put in a time '00:00:00 (.000000)'" ) ;
return ;
}
2011-01-17 00:37:02 +01:00
2012-02-20 18:24:04 +01:00
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , cueIn : cueIn , id : id , modified : lastMod , type : type } ,
2012-02-20 18:24:04 +01:00
function ( json ) {
2012-02-04 19:27:26 +01:00
2012-02-20 18:24:04 +01:00
if ( json . error !== undefined ) {
playlistError ( json ) ;
return ;
}
if ( json . cue _error !== undefined ) {
showError ( span , json . cue _error ) ;
return ;
}
setPlaylistContent ( json ) ;
li = $ ( '#side_playlist li[unqid=' + unqid + ']' ) ;
li . find ( ".cue-edit" ) . toggle ( ) ;
highlightActive ( li ) ;
highlightActive ( li . find ( '.spl_cue' ) ) ;
} ) ;
2012-02-04 19:27:26 +01:00
}
2011-05-17 23:30:17 +02:00
2012-02-04 19:27:26 +01:00
function changeCueOut ( event ) {
event . stopPropagation ( ) ;
2011-01-27 00:31:59 +01:00
2012-02-20 18:24:04 +01:00
var span = $ ( this ) ,
id = span . parent ( ) . attr ( "id" ) . split ( "_" ) . pop ( ) ,
url = "/Playlist/set-cue" ,
cueOut = $ . trim ( span . text ( ) ) ,
li = span . parents ( "li" ) ,
unqid = li . attr ( "unqid" ) ,
2012-07-25 17:00:46 +02:00
lastMod = getModified ( ) ,
type = $ ( '#obj_type' ) . val ( ) ;
2011-01-17 00:37:02 +01:00
2012-02-20 18:24:04 +01:00
if ( ! isTimeValid ( cueOut ) ) {
2012-02-04 19:27:26 +01:00
showError ( span , "please put in a time '00:00:00 (.000000)'" ) ;
return ;
}
2011-02-08 00:44:42 +01:00
2012-02-20 18:24:04 +01:00
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , cueOut : cueOut , id : id , modified : lastMod , type : type } ,
2012-02-20 18:24:04 +01:00
function ( json ) {
2012-02-04 19:27:26 +01:00
2012-02-20 18:24:04 +01:00
if ( json . error !== undefined ) {
playlistError ( json ) ;
return ;
}
if ( json . cue _error !== undefined ) {
showError ( span , json . cue _error ) ;
return ;
}
setPlaylistContent ( json ) ;
li = $ ( '#side_playlist li[unqid=' + unqid + ']' ) ;
li . find ( ".cue-edit" ) . toggle ( ) ;
highlightActive ( li ) ;
highlightActive ( li . find ( '.spl_cue' ) ) ;
} ) ;
2010-12-22 05:33:58 +01:00
}
2012-02-04 19:27:26 +01:00
function changeFadeIn ( event ) {
event . stopPropagation ( ) ;
2011-05-17 23:30:17 +02:00
2012-02-20 18:24:04 +01:00
var span = $ ( this ) ,
id = span . parent ( ) . attr ( "id" ) . split ( "_" ) . pop ( ) ,
url = "/Playlist/set-fade" ,
fadeIn = $ . trim ( span . text ( ) ) ,
li = span . parents ( "li" ) ,
unqid = li . attr ( "unqid" ) ,
2012-07-25 17:00:46 +02:00
lastMod = getModified ( ) ,
type = $ ( '#obj_type' ) . val ( ) ;
2010-12-22 05:33:58 +01:00
2012-02-20 18:24:04 +01:00
if ( ! isFadeValid ( fadeIn ) ) {
2012-02-06 11:07:10 +01:00
showError ( span , "please put in a time in seconds '00 (.000000)'" ) ;
2012-02-04 19:27:26 +01:00
return ;
}
2011-05-17 23:30:17 +02:00
2012-02-20 18:24:04 +01:00
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , fadeIn : fadeIn , id : id , modified : lastMod , type : type } ,
2012-02-20 18:24:04 +01:00
function ( json ) {
2012-02-04 19:27:26 +01:00
2012-02-20 18:24:04 +01:00
if ( json . error !== undefined ) {
playlistError ( json ) ;
return ;
}
if ( json . fade _error !== undefined ) {
showError ( span , json . fade _error ) ;
return ;
}
setPlaylistContent ( json ) ;
li = $ ( '#side_playlist li[unqid=' + unqid + ']' ) ;
li . find ( '.crossfade' ) . toggle ( ) ;
highlightActive ( li . find ( '.spl_fade_control' ) ) ;
} ) ;
2012-02-04 19:27:26 +01:00
}
2011-01-27 21:11:19 +01:00
2012-02-04 19:27:26 +01:00
function changeFadeOut ( event ) {
event . stopPropagation ( ) ;
2011-01-27 21:11:19 +01:00
2012-02-20 18:24:04 +01:00
var span = $ ( this ) ,
id = span . parent ( ) . attr ( "id" ) . split ( "_" ) . pop ( ) ,
url = "/Playlist/set-fade" ,
fadeOut = $ . trim ( span . text ( ) ) ,
li = span . parents ( "li" ) ,
unqid = li . attr ( "unqid" ) ,
2012-07-25 17:00:46 +02:00
lastMod = getModified ( ) ,
type = $ ( '#obj_type' ) . val ( ) ;
2011-01-27 21:11:19 +01:00
2012-02-20 18:24:04 +01:00
if ( ! isFadeValid ( fadeOut ) ) {
2012-02-06 11:07:10 +01:00
showError ( span , "please put in a time in seconds '00 (.000000)'" ) ;
2012-02-04 19:27:26 +01:00
return ;
2011-01-27 21:11:19 +01:00
}
2011-05-17 23:30:17 +02:00
2012-02-20 18:24:04 +01:00
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , fadeOut : fadeOut , id : id , modified : lastMod , type : type } ,
2012-02-20 18:24:04 +01:00
function ( json ) {
if ( json . error !== undefined ) {
playlistError ( json ) ;
return ;
}
if ( json . fade _error !== undefined ) {
showError ( span , json . fade _error ) ;
return ;
}
setPlaylistContent ( json ) ;
li = $ ( '#side_playlist li[unqid=' + unqid + ']' ) ;
li . find ( '.crossfade' ) . toggle ( ) ;
highlightActive ( li . find ( '.spl_fade_control' ) ) ;
} ) ;
2012-02-04 19:27:26 +01:00
}
2010-12-22 05:33:58 +01:00
2012-02-04 19:27:26 +01:00
function submitOnEnter ( event ) {
//enter was pressed
if ( event . keyCode === 13 ) {
event . preventDefault ( ) ;
$ ( this ) . blur ( ) ;
}
}
2010-12-22 05:33:58 +01:00
2012-02-04 19:27:26 +01:00
function openFadeEditor ( event ) {
2012-03-19 14:09:05 +01:00
var li ;
2012-02-04 19:27:26 +01:00
event . stopPropagation ( ) ;
2010-12-22 05:33:58 +01:00
2012-03-19 14:09:05 +01:00
li = $ ( this ) . parents ( "li" ) ;
2012-02-04 19:27:26 +01:00
li . find ( ".crossfade" ) . toggle ( ) ;
2011-01-17 00:37:02 +01:00
2012-03-19 14:09:05 +01:00
if ( $ ( this ) . hasClass ( "ui-state-active" ) ) {
2012-02-04 19:27:26 +01:00
unHighlightActive ( this ) ;
}
else {
highlightActive ( this ) ;
}
}
2010-12-22 05:33:58 +01:00
2012-02-04 19:27:26 +01:00
function openCueEditor ( event ) {
2012-03-19 14:09:05 +01:00
var li , icon ;
2012-02-04 19:27:26 +01:00
event . stopPropagation ( ) ;
2010-12-22 05:33:58 +01:00
2012-02-04 19:27:26 +01:00
icon = $ ( this ) ;
2012-03-19 14:09:05 +01:00
li = $ ( this ) . parents ( "li" ) ;
2012-02-04 19:27:26 +01:00
li . find ( ".cue-edit" ) . toggle ( ) ;
2010-12-22 05:33:58 +01:00
2012-02-04 19:27:26 +01:00
if ( li . hasClass ( "ui-state-active" ) ) {
unHighlightActive ( li ) ;
unHighlightActive ( icon ) ;
}
else {
highlightActive ( li ) ;
highlightActive ( icon ) ;
}
}
2012-03-06 00:59:31 +01:00
2012-02-04 19:27:26 +01:00
function editName ( ) {
2012-02-20 18:24:04 +01:00
var nameElement = $ ( this ) ,
2012-07-25 17:00:46 +02:00
lastMod = getModified ( ) ,
type = $ ( '#obj_type' ) . val ( ) ;
2012-08-08 02:48:58 +02:00
//remove any newlines if user somehow snuck them in (easy to do if dragging/dropping text)
nameElement . text ( nameElement . text ( ) . replace ( "\n" , "" ) ) ;
/ * - - u n t i l w e d e c i d e w h e t h e r P l a y l i s t n a m e s h o u l d a u t o s a v e o r n o t
2012-03-19 14:09:05 +01:00
url = '/Playlist/set-playlist-name' ;
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , name : nameElement . text ( ) , modified : lastMod , type : type } ,
2012-03-19 14:09:05 +01:00
function ( json ) {
if ( json . error !== undefined ) {
playlistError ( json ) ;
}
else {
setModified ( json . modified ) ;
nameElement . text ( json . playlistName ) ;
redrawLib ( ) ;
}
} ) ;
2012-08-08 02:48:58 +02:00
* /
2012-02-04 19:27:26 +01:00
}
2012-02-04 15:52:31 +01:00
function redrawLib ( ) {
2012-04-27 11:22:44 +02:00
var dt = $lib . find ( "#library_display" ) . dataTable ( ) ;
2012-02-07 14:58:16 +01:00
2012-05-10 14:19:36 +02:00
dt . fnStandingRedraw ( ) ;
AIRTIME . library . redrawChosen ( ) ;
2012-02-04 15:52:31 +01:00
}
function setPlaylistContent ( json ) {
2012-03-14 17:50:48 +01:00
2012-02-04 15:52:31 +01:00
$ ( '#spl_name > a' )
. empty ( )
. append ( json . name ) ;
$ ( '#spl_length' )
. empty ( )
. append ( json . length ) ;
$ ( '#fieldset-metadate_change textarea' )
. empty ( )
. val ( json . description ) ;
$ ( '#spl_sortable' )
. empty ( )
. append ( json . html ) ;
2012-02-20 18:24:04 +01:00
setModified ( json . modified ) ;
2012-02-04 15:52:31 +01:00
redrawLib ( ) ;
}
function getId ( ) {
2012-07-25 18:44:37 +02:00
return parseInt ( $ ( "#obj_id" ) . val ( ) , 10 ) ;
2012-02-04 15:52:31 +01:00
}
function getModified ( ) {
2012-07-25 18:44:37 +02:00
return parseInt ( $ ( "#obj_lastMod" ) . val ( ) , 10 ) ;
2012-02-04 15:52:31 +01:00
}
2012-02-20 18:24:04 +01:00
function setModified ( modified ) {
2012-07-25 18:44:37 +02:00
$ ( "#obj_lastMod" ) . val ( modified ) ;
2012-02-20 18:24:04 +01:00
}
2012-02-04 15:52:31 +01:00
function openPlaylist ( json ) {
$ ( "#side_playlist" )
. empty ( )
. append ( json . html ) ;
2012-07-16 17:01:34 +02:00
2012-02-04 21:26:21 +01:00
setUpPlaylist ( ) ;
2012-07-17 20:40:52 +02:00
// functions in smart_playlistbuilder.js
setupUI ( ) ;
appendAddButton ( ) ;
2012-08-08 19:16:02 +02:00
appendModAddButton ( ) ;
2012-07-17 20:40:52 +02:00
removeButtonCheck ( ) ;
2012-02-04 19:27:26 +01:00
}
2012-02-04 15:52:31 +01:00
2012-02-04 19:27:26 +01:00
//sets events dynamically for playlist entries (each row in the playlist)
2012-03-30 16:04:00 +02:00
function setPlaylistEntryEvents ( ) {
2012-02-04 15:52:31 +01:00
2012-03-30 16:04:00 +02:00
$pl . delegate ( "#spl_sortable .ui-icon-closethick" ,
2012-02-04 19:27:26 +01:00
{ "click" : function ( ev ) {
var id ;
id = parseInt ( $ ( this ) . attr ( "id" ) . split ( "_" ) . pop ( ) , 10 ) ;
AIRTIME . playlist . fnDeleteItems ( [ id ] ) ;
} } ) ;
2011-01-17 19:55:43 +01:00
2012-03-30 16:04:00 +02:00
$pl . delegate ( ".spl_fade_control" ,
2012-02-04 19:27:26 +01:00
{ "click" : openFadeEditor } ) ;
2011-11-29 15:30:05 +01:00
2012-03-30 16:04:00 +02:00
$pl . delegate ( ".spl_cue" ,
2012-02-04 19:27:26 +01:00
{ "click" : openCueEditor } ) ;
2011-05-17 23:30:17 +02:00
2012-03-06 00:59:31 +01:00
//add the play function to the play icon
2012-03-30 16:04:00 +02:00
$pl . delegate ( ".big_play" ,
2012-03-06 00:59:31 +01:00
{ "click" : openAudioPreview } ) ;
2012-07-30 23:18:33 +02:00
$pl . delegate ( ".spl_block_expand" ,
{ "click" : function ( ev ) {
var id = parseInt ( $ ( this ) . attr ( "id" ) . split ( "_" ) . pop ( ) , 10 ) ;
2012-08-02 22:36:12 +02:00
var blockId = parseInt ( $ ( this ) . attr ( "blockId" ) , 10 ) ;
2012-07-30 23:18:33 +02:00
if ( $ ( this ) . hasClass ( 'close' ) ) {
var sUrl = "/playlist/get-block-info" ;
mod . disableUI ( ) ;
2012-08-02 22:36:12 +02:00
$ . post ( sUrl , { format : "json" , id : blockId } , function ( json ) {
2012-07-30 23:18:33 +02:00
$html = "" ;
var data = $ . parseJSON ( json ) ;
var isStatic = data . isStatic ;
delete data . type ;
if ( isStatic ) {
2012-08-02 23:02:24 +02:00
console . log ( data ) ;
2012-07-30 23:18:33 +02:00
$ . each ( data , function ( index , ele ) {
2012-08-02 23:02:24 +02:00
if ( ele . track _title !== undefined ) {
$html += "<div>" + ele . track _title + " " + ele . creator + " " + ele . length + "</div>" ;
}
2012-07-30 23:18:33 +02:00
} )
} else {
for ( var key in data . crit ) {
$ . each ( data . crit [ key ] , function ( index , ele ) {
var extra = ( ele [ 'extra' ] == null ) ? "" : ele [ 'extra' ] ;
$html += "<div>" + ele [ 'display_name' ] + " " + ele [ 'modifier' ] + " " + ele [ 'value' ] + " " + extra + "</div>" ;
} ) ;
}
$html += "<div>" + data . limit . value + " " + data . limit . modifier ;
}
$pl . find ( "#block_" + id + "_info" ) . html ( $html ) ;
mod . enableUI ( ) ;
} ) ;
$ ( this ) . removeClass ( 'close' ) ;
} else {
$pl . find ( "#block_" + id + "_info" ) . html ( "" ) ;
$ ( this ) . addClass ( 'close' ) ;
}
} } ) ;
2011-01-18 20:57:54 +01:00
}
2011-11-29 15:30:05 +01:00
2012-02-04 19:27:26 +01:00
//sets events dynamically for the cue editor.
2012-03-30 16:04:00 +02:00
function setCueEvents ( ) {
2011-11-29 15:30:05 +01:00
2012-03-30 16:04:00 +02:00
$pl . delegate ( ".spl_cue_in span" ,
2012-02-04 19:27:26 +01:00
{ "focusout" : changeCueIn ,
"keydown" : submitOnEnter } ) ;
2012-03-30 16:04:00 +02:00
$pl . delegate ( ".spl_cue_out span" ,
2012-02-04 19:27:26 +01:00
{ "focusout" : changeCueOut ,
"keydown" : submitOnEnter } ) ;
2011-11-29 15:30:05 +01:00
}
2012-02-04 19:27:26 +01:00
//sets events dynamically for the fade editor.
2012-03-30 16:04:00 +02:00
function setFadeEvents ( ) {
2012-02-04 19:27:26 +01:00
2012-03-30 16:04:00 +02:00
$pl . delegate ( ".spl_fade_in span" ,
2012-02-04 19:27:26 +01:00
{ "focusout" : changeFadeIn ,
"keydown" : submitOnEnter } ) ;
2012-03-30 16:04:00 +02:00
$pl . delegate ( ".spl_fade_out span" ,
2012-02-04 19:27:26 +01:00
{ "focusout" : changeFadeOut ,
"keydown" : submitOnEnter } ) ;
2011-01-27 00:31:59 +01:00
}
2012-02-04 15:52:31 +01:00
2012-03-19 14:09:05 +01:00
function initialEvents ( ) {
2012-03-30 16:04:00 +02:00
var cachedDescription ;
2012-03-19 14:09:05 +01:00
//main playlist fades events
2012-03-30 16:04:00 +02:00
$pl . on ( "click" , "#spl_crossfade" , function ( ) {
2012-07-25 17:00:46 +02:00
var lastMod = getModified ( ) ,
2012-07-30 23:18:33 +02:00
type = $ ( '#obj_type' ) . val ( ) ;
2012-02-04 15:52:31 +01:00
if ( $ ( this ) . hasClass ( "ui-state-active" ) ) {
$ ( this ) . removeClass ( "ui-state-active" ) ;
2012-03-30 16:04:00 +02:00
$pl . find ( "#crossfade_main" ) . hide ( ) ;
2012-02-04 15:52:31 +01:00
}
else {
$ ( this ) . addClass ( "ui-state-active" ) ;
2012-02-05 23:38:12 +01:00
var url = '/Playlist/get-playlist-fades' ;
2012-07-30 23:18:33 +02:00
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , modified : lastMod , type : type } ,
2012-02-20 18:24:04 +01:00
function ( json ) {
if ( json . error !== undefined ) {
playlistError ( json ) ;
}
else {
2012-03-30 16:04:00 +02:00
$pl . find ( "span.spl_main_fade_in" )
2012-02-20 18:24:04 +01:00
. empty ( )
. append ( json . fadeIn ) ;
2012-03-19 14:09:05 +01:00
2012-03-30 16:04:00 +02:00
$pl . find ( "span.spl_main_fade_out" )
2012-02-20 18:24:04 +01:00
. empty ( )
. append ( json . fadeOut ) ;
2012-03-30 16:04:00 +02:00
$pl . find ( "#crossfade_main" ) . show ( ) ;
2012-02-20 18:24:04 +01:00
}
} ) ;
2012-02-04 15:52:31 +01:00
}
} ) ;
2012-03-19 14:09:05 +01:00
2012-03-30 16:04:00 +02:00
$pl . on ( "blur" , "span.spl_main_fade_in" , function ( event ) {
2012-02-04 15:52:31 +01:00
event . stopPropagation ( ) ;
2011-02-09 22:53:11 +01:00
2012-02-20 18:24:04 +01:00
var url = "/Playlist/set-playlist-fades" ,
span = $ ( this ) ,
fadeIn = $ . trim ( span . text ( ) ) ,
2012-07-25 17:00:46 +02:00
lastMod = getModified ( ) ,
type = $ ( '#obj_type' ) . val ( ) ;
2012-02-20 18:24:04 +01:00
if ( ! isFadeValid ( fadeIn ) ) {
2012-02-06 11:07:10 +01:00
showError ( span , "please put in a time in seconds '00 (.000000)'" ) ;
2011-02-08 22:10:48 +01:00
return ;
}
2012-02-20 18:24:04 +01:00
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , fadeIn : fadeIn , modified : lastMod , type : type } ,
2012-02-20 18:24:04 +01:00
function ( json ) {
hideError ( span ) ;
2012-03-19 14:09:05 +01:00
if ( json . modified !== undefined ) {
setModified ( json . modified ) ;
}
2012-02-20 18:24:04 +01:00
} ) ;
2011-02-08 22:10:48 +01:00
} ) ;
2012-03-30 16:04:00 +02:00
$pl . on ( "blur" , "span.spl_main_fade_out" , function ( event ) {
2012-02-04 15:52:31 +01:00
event . stopPropagation ( ) ;
2011-02-08 22:10:48 +01:00
2012-02-20 18:24:04 +01:00
var url = "/Playlist/set-playlist-fades" ,
span = $ ( this ) ,
fadeOut = $ . trim ( span . text ( ) ) ,
2012-07-25 17:00:46 +02:00
lastMod = getModified ( ) ,
type = $ ( '#obj_type' ) . val ( ) ;
2011-02-08 22:10:48 +01:00
2012-03-19 14:09:05 +01:00
if ( ! isFadeValid ( fadeOut ) ) {
2012-02-06 11:07:10 +01:00
showError ( span , "please put in a time in seconds '00 (.000000)'" ) ;
2011-02-08 22:10:48 +01:00
return ;
}
2012-02-20 18:24:04 +01:00
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , fadeOut : fadeOut , modified : lastMod , type : type } ,
2012-02-20 18:24:04 +01:00
function ( json ) {
hideError ( span ) ;
2012-03-19 14:09:05 +01:00
if ( json . modified !== undefined ) {
setModified ( json . modified ) ;
}
2012-02-20 18:24:04 +01:00
} ) ;
2011-02-08 22:10:48 +01:00
} ) ;
2012-03-30 16:04:00 +02:00
$pl . on ( "keydown" , "span.spl_main_fade_in, span.spl_main_fade_out" , submitOnEnter ) ;
2011-02-08 00:44:42 +01:00
2012-03-30 16:04:00 +02:00
$pl . on ( "click" , "#crossfade_main > .ui-icon-closethick" , function ( ) {
$pl . find ( "#spl_crossfade" ) . removeClass ( "ui-state-active" ) ;
$pl . find ( "#crossfade_main" ) . hide ( ) ;
2012-02-04 15:52:31 +01:00
} ) ;
2012-03-19 14:09:05 +01:00
//end main playlist fades.
//edit playlist name event
2012-03-30 16:04:00 +02:00
$pl . on ( "keydown" , "#playlist_name_display" , submitOnEnter ) ;
$pl . on ( "blur" , "#playlist_name_display" , editName ) ;
2012-03-19 14:09:05 +01:00
//edit playlist description events
2012-03-30 16:04:00 +02:00
$pl . on ( "click" , "legend" , function ( ) {
2012-03-19 14:21:34 +01:00
var $fs = $ ( this ) . parents ( "fieldset" ) ;
2012-03-19 14:09:05 +01:00
if ( $fs . hasClass ( "closed" ) ) {
cachedDescription = $fs . find ( "textarea" ) . val ( ) ;
$fs . removeClass ( "closed" ) ;
}
else {
$fs . addClass ( "closed" ) ;
}
} ) ;
2012-08-01 21:37:50 +02:00
2012-07-19 00:27:39 +02:00
$pl . on ( "click" , "#webstream_save" , function ( ) {
//get all fields and POST to server
//description
//stream url
//default_length
//playlist name
2012-08-03 21:59:34 +02:00
var id = $pl . find ( "#ws_id" ) . attr ( "value" ) ;
2012-07-19 00:27:39 +02:00
var description = $pl . find ( "#description" ) . val ( ) ;
var streamurl = $pl . find ( "#streamurl-element input" ) . val ( ) ;
var length = $pl . find ( "#streamlength-element input" ) . val ( ) ;
var name = $pl . find ( "#playlist_name_display" ) . text ( ) ;
2012-08-02 21:45:15 +02:00
//hide any previous errors (if any)
$ ( "#side_playlist .errors" ) . empty ( ) . hide ( ) ;
2012-07-19 00:27:39 +02:00
var url = 'Webstream/save' ;
$ . post ( url ,
2012-08-03 21:59:34 +02:00
{ format : "json" , id : id , description : description , url : streamurl , length : length , name : name } ,
2012-08-01 21:37:50 +02:00
function ( json ) {
2012-08-02 21:45:15 +02:00
if ( json . analysis ) {
for ( var s in json . analysis ) {
var field = json . analysis [ s ] ;
if ( ! field [ 0 ] ) {
var elemId = "#" + s + "-error" ;
var $div = $ ( "#side_playlist " + elemId ) . text ( field [ 1 ] ) . show ( ) ;
}
}
} else {
var $status = $ ( "#side_playlist .status" ) ;
$status . html ( json . statusMessage ) ;
$status . show ( ) ;
setTimeout ( function ( ) { $status . fadeOut ( "slow" , function ( ) { $status . empty ( ) } ) } , 5000 ) ;
2012-08-08 01:49:26 +02:00
//redraw the library to show the new webstream
redrawLib ( ) ;
2012-08-02 21:45:15 +02:00
}
2012-08-01 21:37:50 +02:00
} ) ;
2012-07-19 00:27:39 +02:00
}
)
2012-03-30 16:04:00 +02:00
$pl . on ( "click" , "#description_save" , function ( ) {
var textarea = $pl . find ( "#fieldset-metadate_change textarea" ) ,
2012-03-19 14:09:05 +01:00
description = textarea . val ( ) ,
url ,
2012-07-25 17:00:46 +02:00
lastMod = getModified ( ) ,
type = $ ( '#obj_type' ) . val ( ) ;
2012-03-19 14:09:05 +01:00
url = '/Playlist/set-playlist-description' ;
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , description : description , modified : lastMod , type : type } ,
2012-03-19 14:09:05 +01:00
function ( json ) {
if ( json . error !== undefined ) {
playlistError ( json ) ;
}
else {
setModified ( json . modified ) ;
textarea . val ( json . description ) ;
2012-03-30 16:04:00 +02:00
$pl . find ( "#fieldset-metadate_change" ) . addClass ( "closed" ) ;
2012-03-19 14:09:05 +01:00
redrawLib ( ) ;
}
} ) ;
} ) ;
2012-03-30 16:04:00 +02:00
$pl . on ( "click" , "#description_cancel" , function ( ) {
var textarea = $pl . find ( "#fieldset-metadate_change textarea" ) ;
2012-03-19 14:09:05 +01:00
textarea . val ( cachedDescription ) ;
2012-03-30 16:04:00 +02:00
$pl . find ( "#fieldset-metadate_change" ) . addClass ( "closed" ) ;
2012-03-19 14:09:05 +01:00
} ) ;
2012-03-30 16:04:00 +02:00
//end edit playlist description events.
2012-03-19 14:09:05 +01:00
}
2012-03-30 16:04:00 +02:00
function setUpPlaylist ( ) {
var sortableConf ;
2011-11-29 15:30:05 +01:00
2012-02-04 19:27:26 +01:00
sortableConf = ( function ( ) {
2012-02-28 13:13:40 +01:00
var aReceiveItems ,
2012-02-20 20:44:35 +01:00
html ,
2012-02-04 19:27:26 +01:00
fnReceive ,
fnUpdate ;
fnReceive = function ( event , ui ) {
2012-02-28 23:52:20 +01:00
var aItems = [ ] ,
aSelected ,
i ,
length ;
2012-05-11 11:04:16 +02:00
AIRTIME . library . addToChosen ( ui . item ) ;
2012-02-28 23:52:20 +01:00
//filter out anything that isn't an audiofile.
2012-04-02 19:03:11 +02:00
aSelected = AIRTIME . library . getSelectedData ( ) ;
2012-02-28 13:13:40 +01:00
2012-02-28 23:52:20 +01:00
for ( i = 0 , length = aSelected . length ; i < length ; i ++ ) {
2012-07-26 22:16:07 +02:00
aItems . push ( new Array ( aSelected [ i ] . id , aSelected [ i ] . ftype ) ) ;
2012-02-28 23:52:20 +01:00
}
2012-02-28 13:13:40 +01:00
aReceiveItems = aItems ;
2012-02-20 20:44:35 +01:00
html = ui . helper . html ( ) ;
2012-05-10 14:19:36 +02:00
AIRTIME . library . removeFromChosen ( ui . item ) ;
2012-02-04 19:27:26 +01:00
} ;
fnUpdate = function ( event , ui ) {
var prev ,
2012-02-20 20:44:35 +01:00
aItems = [ ] ,
2012-02-04 19:27:26 +01:00
iAfter ,
sAddType ;
prev = ui . item . prev ( ) ;
if ( prev . hasClass ( "spl_empty" ) || prev . length === 0 ) {
iAfter = undefined ;
sAddType = 'before' ;
}
else {
iAfter = parseInt ( prev . attr ( "id" ) . split ( "_" ) . pop ( ) , 10 ) ;
sAddType = 'after' ;
}
//item was dragged in from library datatable
2012-02-28 13:13:40 +01:00
if ( aReceiveItems !== undefined ) {
2012-02-20 20:44:35 +01:00
2012-03-30 16:04:00 +02:00
$pl . find ( "tr.ui-draggable" )
2012-02-20 20:44:35 +01:00
. after ( html )
. empty ( ) ;
2012-02-28 13:13:40 +01:00
aItems = aReceiveItems ;
aReceiveItems = undefined ;
2012-02-20 20:44:35 +01:00
AIRTIME . playlist . fnAddItems ( aItems , iAfter , sAddType ) ;
2012-02-04 19:27:26 +01:00
}
//item was reordered.
else {
2012-02-20 20:44:35 +01:00
aItems . push ( parseInt ( ui . item . attr ( "id" ) . split ( "_" ) . pop ( ) , 10 ) ) ;
AIRTIME . playlist . fnMoveItems ( aItems , iAfter ) ;
2012-02-04 19:27:26 +01:00
}
} ;
return {
items : 'li' ,
2012-02-27 23:58:08 +01:00
//hack taken from
//http://stackoverflow.com/questions/2150002/jquery-ui-sortable-how-can-i-change-the-appearance-of-the-placeholder-object
placeholder : {
element : function ( currentItem ) {
2012-02-28 13:13:40 +01:00
2012-02-27 23:58:08 +01:00
return $ ( '<li class="placeholder ui-state-highlight"></li>' ) [ 0 ] ;
} ,
update : function ( container , p ) {
return ;
}
} ,
2012-02-04 19:27:26 +01:00
forcePlaceholderSize : true ,
handle : 'div.list-item-container' ,
start : function ( event , ui ) {
2012-02-27 23:58:08 +01:00
ui . placeholder . height ( 56 ) ;
2012-02-04 19:27:26 +01:00
} ,
receive : fnReceive ,
update : fnUpdate
} ;
} ( ) ) ;
2012-03-30 16:04:00 +02:00
$pl . find ( "#spl_sortable" ) . sortable ( sortableConf ) ;
2012-02-04 19:27:26 +01:00
}
2011-09-08 21:09:12 +02:00
2012-02-04 19:27:26 +01:00
mod . fnNew = function ( ) {
2012-07-20 23:38:11 +02:00
var url = '/Playlist/new' ;
2010-12-22 05:33:58 +01:00
2012-02-04 19:27:26 +01:00
stopAudioPreview ( ) ;
2012-02-20 18:24:04 +01:00
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , type : 'playlist' } ,
2012-02-20 18:24:04 +01:00
function ( json ) {
openPlaylist ( json ) ;
redrawLib ( ) ;
} ) ;
2012-02-07 14:58:16 +01:00
} ;
2012-07-25 04:24:08 +02:00
mod . fnWsNew = function ( ) {
var url = '/Webstream/new' ;
stopAudioPreview ( ) ;
$ . post ( url ,
{ format : "json" } ,
function ( json ) {
openPlaylist ( json ) ;
redrawLib ( ) ;
} ) ;
} ;
2011-11-29 15:30:05 +01:00
2012-07-25 17:00:46 +02:00
mod . fnNewBlock = function ( ) {
var url = '/Playlist/new' ;
stopAudioPreview ( ) ;
$ . post ( url ,
{ format : "json" , type : 'block' } ,
function ( json ) {
openPlaylist ( json ) ;
redrawLib ( ) ;
} ) ;
} ;
2012-08-03 21:59:34 +02:00
mod . fnEdit = function ( id , type , url ) {
2012-02-05 18:19:22 +01:00
stopAudioPreview ( ) ;
2012-02-04 15:52:31 +01:00
2012-02-05 18:19:22 +01:00
$ . post ( url ,
2012-07-25 23:08:22 +02:00
{ format : "json" , id : id , type : type } ,
2012-02-05 18:19:22 +01:00
function ( json ) {
openPlaylist ( json ) ;
2012-02-20 18:24:04 +01:00
} ) ;
2012-02-07 14:58:16 +01:00
} ;
2012-08-03 21:59:34 +02:00
2011-11-29 15:30:05 +01:00
2012-02-05 18:19:22 +01:00
mod . fnDelete = function ( plid ) {
2012-02-04 19:27:26 +01:00
var url , id , lastMod ;
2012-02-04 15:52:31 +01:00
2012-02-04 19:27:26 +01:00
stopAudioPreview ( ) ;
2012-02-05 18:19:22 +01:00
id = ( plid === undefined ) ? getId ( ) : plid ;
2012-07-25 17:00:46 +02:00
lastMod = getModified ( ) ;
type = $ ( '#obj_type' ) . val ( ) ;
2012-02-04 19:27:26 +01:00
url = '/Playlist/delete' ;
$ . post ( url ,
2012-07-25 17:00:46 +02:00
{ format : "json" , ids : id , modified : lastMod , type : type } ,
2012-02-04 19:27:26 +01:00
function ( json ) {
openPlaylist ( json ) ;
redrawLib ( ) ;
2012-02-20 18:24:04 +01:00
} ) ;
2012-02-07 14:58:16 +01:00
} ;
2011-11-29 15:30:05 +01:00
2012-05-04 15:00:18 +02:00
mod . disableUI = function ( ) {
$lib . block ( {
message : "" ,
theme : true ,
applyPlatformOpacityRules : false
} ) ;
$pl . block ( {
message : "" ,
theme : true ,
applyPlatformOpacityRules : false
} ) ;
} ;
2012-07-16 23:18:37 +02:00
mod . fnOpenPlaylist = function ( json ) {
openPlaylist ( json ) ;
} ;
2012-05-04 15:00:18 +02:00
mod . enableUI = function ( ) {
$lib . unblock ( ) ;
$pl . unblock ( ) ;
//Block UI changes the postion to relative to display the messages.
$lib . css ( "position" , "static" ) ;
$pl . css ( "position" , "static" ) ;
2012-07-18 17:52:09 +02:00
setupUI ( ) ;
2012-05-04 15:00:18 +02:00
} ;
function playlistResponse ( json ) {
if ( json . error !== undefined ) {
playlistError ( json ) ;
}
else {
setPlaylistContent ( json ) ;
}
mod . enableUI ( ) ;
}
2012-03-14 17:50:48 +01:00
function playlistRequest ( sUrl , oData ) {
2012-07-25 17:00:46 +02:00
var lastMod ,
obj _type = $ ( '#obj_type' ) . val ( ) ;
2012-02-04 19:27:26 +01:00
2012-05-04 15:00:18 +02:00
mod . disableUI ( ) ;
2012-03-14 17:50:48 +01:00
2012-05-04 15:00:18 +02:00
lastMod = getModified ( ) ;
2012-03-14 17:50:48 +01:00
2012-05-04 15:00:18 +02:00
oData [ "modified" ] = lastMod ;
2012-07-25 17:00:46 +02:00
oData [ "obj_type" ] = obj _type ;
2012-05-04 15:00:18 +02:00
oData [ "format" ] = "json" ;
2012-03-14 17:50:48 +01:00
$ . post (
sUrl ,
oData ,
2012-05-04 15:00:18 +02:00
playlistResponse
2012-03-14 17:50:48 +01:00
) ;
}
mod . fnAddItems = function ( aItems , iAfter , sAddType ) {
var sUrl = "/playlist/add-items" ;
2012-07-20 23:38:11 +02:00
oData = { "aItems" : aItems , "afterItem" : iAfter , "type" : sAddType } ;
2012-03-14 17:50:48 +01:00
playlistRequest ( sUrl , oData ) ;
2012-02-04 19:27:26 +01:00
} ;
2011-11-29 16:24:41 +01:00
2012-02-04 19:27:26 +01:00
mod . fnMoveItems = function ( aIds , iAfter ) {
2012-03-14 17:50:48 +01:00
var sUrl = "/playlist/move-items" ,
oData = { "ids" : aIds , "afterItem" : iAfter } ;
2012-02-04 19:27:26 +01:00
2012-03-14 17:50:48 +01:00
playlistRequest ( sUrl , oData ) ;
2012-02-04 19:27:26 +01:00
} ;
2012-02-04 15:52:31 +01:00
2012-02-04 19:27:26 +01:00
mod . fnDeleteItems = function ( aItems ) {
2012-03-14 17:50:48 +01:00
var sUrl = "/playlist/delete-items" ,
oData = { "ids" : aItems } ;
2012-02-04 19:27:26 +01:00
2012-03-14 17:50:48 +01:00
playlistRequest ( sUrl , oData ) ;
2012-02-04 19:27:26 +01:00
} ;
2012-02-04 15:52:31 +01:00
2012-02-04 21:26:21 +01:00
mod . init = function ( ) {
2012-07-25 17:00:46 +02:00
$ . contextMenu ( {
2012-07-26 23:51:47 +02:00
selector : '#spl_new, #ws_new' ,
2012-07-25 17:00:46 +02:00
trigger : "left" ,
ignoreRightClick : true ,
items : {
"sp" : { name : "New Playlist" , callback : AIRTIME . playlist . fnNew } ,
2012-07-26 23:51:47 +02:00
"sb" : { name : "New Smart Playlist" , callback : AIRTIME . playlist . fnNewBlock } ,
"ws" : { name : "New Webstream" , callback : AIRTIME . playlist . fnWsNew }
2012-07-25 17:00:46 +02:00
}
} ) ;
/ *
2012-03-30 16:04:00 +02:00
$pl . delegate ( "#spl_new" ,
2012-07-25 17:00:46 +02:00
{ "click" : AIRTIME . playlist . fnNew } ) ; * /
2011-11-10 21:35:27 +01:00
2012-03-30 16:04:00 +02:00
$pl . delegate ( "#spl_delete" , { "click" : function ( ev ) {
2012-02-07 18:42:34 +01:00
AIRTIME . playlist . fnDelete ( ) ;
} } ) ;
2012-02-04 21:26:21 +01:00
2012-03-30 16:04:00 +02:00
setPlaylistEntryEvents ( ) ;
setCueEvents ( ) ;
setFadeEvents ( ) ;
2012-02-04 21:26:21 +01:00
2012-03-19 14:09:05 +01:00
initialEvents ( ) ;
2012-03-30 16:04:00 +02:00
setUpPlaylist ( ) ;
} ;
function setWidgetSize ( ) {
viewport = AIRTIME . utilities . findViewportDimensions ( ) ;
widgetHeight = viewport . height - 185 ;
2012-04-03 14:58:10 +02:00
width = Math . floor ( viewport . width - 80 ) ;
2012-03-30 16:33:43 +02:00
var libTableHeight = widgetHeight - 130 ;
2012-03-30 16:04:00 +02:00
$lib . height ( widgetHeight )
2012-03-30 16:33:43 +02:00
. find ( ".dataTables_scrolling" )
. css ( "max-height" , libTableHeight )
. end ( )
2012-03-30 16:04:00 +02:00
. width ( Math . floor ( width * 0.55 ) ) ;
$pl . height ( widgetHeight )
. width ( Math . floor ( width * 0.45 ) ) ;
}
mod . onReady = function ( ) {
$lib = $ ( "#library_content" ) ;
$pl = $ ( "#side_playlist" ) ;
setWidgetSize ( ) ;
AIRTIME . library . libraryInit ( ) ;
AIRTIME . playlist . init ( ) ;
$pl . find ( ".ui-icon-alert" ) . qtip ( {
content : {
2012-04-11 23:24:26 +02:00
text : "Airtime is unsure about the status of this file. This can happen when the file is on a remote drive that is unaccessible or the file is in a directory that isn't \"watched\" anymore."
2012-03-30 16:04:00 +02:00
} ,
position : {
adjust : {
resize : true ,
method : "flip flip"
} ,
at : "right center" ,
my : "left top" ,
viewport : $ ( window )
} ,
style : {
classes : "ui-tooltip-dark"
} ,
show : 'mouseover' ,
hide : 'mouseout'
} ) ;
} ;
mod . onResize = function ( ) {
2012-05-04 18:13:01 +02:00
clearTimeout ( resizeTimeout ) ;
resizeTimeout = setTimeout ( setWidgetSize , 100 ) ;
2012-02-07 14:58:16 +01:00
} ;
2011-11-29 15:30:05 +01:00
2012-02-04 19:27:26 +01:00
return AIRTIME ;
2011-11-29 15:30:05 +01:00
2012-02-04 19:27:26 +01:00
} ( AIRTIME || { } ) ) ;
2011-12-02 17:49:48 +01:00
2011-05-17 23:30:17 +02:00
2012-03-30 16:04:00 +02:00
$ ( document ) . ready ( AIRTIME . playlist . onReady ) ;
$ ( window ) . resize ( AIRTIME . playlist . onResize ) ;