2011-08-18 19:53:12 +02:00
function showErrorSections ( ) {
2011-08-15 22:10:46 +02:00
2011-08-18 19:53:12 +02:00
$ ( ".errors" ) . each ( function ( i ) {
if ( $ ( this ) . length > 0 ) {
2011-11-16 22:31:27 +01:00
var div = $ ( this ) . closest ( "div" )
if ( div . attr ( 'class' ) == "stream-setting-content" ) {
$ ( this ) . closest ( "div" ) . show ( ) ;
$ ( this ) . closest ( "fieldset" ) . removeClass ( 'closed' ) ;
$ ( window ) . scrollTop ( $ ( this ) . closest ( "div" ) . position ( ) . top ) ;
}
2011-08-18 19:53:12 +02:00
}
2011-08-15 22:10:46 +02:00
} ) ;
2011-08-18 19:53:12 +02:00
}
2011-08-19 22:35:23 +02:00
function rebuildStreamURL ( ele ) {
2011-09-06 17:44:21 +02:00
var div = ele . closest ( "div" )
2011-08-19 22:35:23 +02:00
host = div . find ( "input:[id$=-host]" ) . val ( )
port = div . find ( "input:[id$=-port]" ) . val ( )
mount = div . find ( "input:[id$=-mount]" ) . val ( )
streamurl = ""
if ( div . find ( "select:[id$=-output]" ) . val ( ) == "icecast" ) {
streamurl = "http://" + host
if ( $ . trim ( port ) != "" ) {
streamurl += ":" + port
2011-08-18 19:53:12 +02:00
}
2011-08-19 22:35:23 +02:00
if ( $ . trim ( mount ) != "" ) {
streamurl += "/" + mount
}
} else {
streamurl = "http://" + host + ":" + port + "/"
}
2013-01-29 21:17:29 +01:00
div . find ( "#stream_url" ) . text ( streamurl )
2011-08-18 19:53:12 +02:00
}
2011-09-06 17:44:21 +02:00
function restrictOggBitrate ( ele , on ) {
var div = ele . closest ( "div" )
if ( on ) {
2011-11-13 21:34:26 +01:00
if ( parseInt ( div . find ( "select[id$=data-bitrate]" ) . val ( ) , 10 ) < 48 ) {
div . find ( "select[id$=data-bitrate]" ) . find ( "option[value='48']" ) . attr ( "selected" , "selected" ) ;
}
2011-09-06 17:44:21 +02:00
div . find ( "select[id$=data-bitrate]" ) . find ( "option[value='24']" ) . attr ( "disabled" , "disabled" ) ;
div . find ( "select[id$=data-bitrate]" ) . find ( "option[value='32']" ) . attr ( "disabled" , "disabled" ) ;
} else {
2012-12-08 01:25:19 +01:00
div . find ( "select[id$=data-bitrate]" ) . find ( "option[value='24']" ) . removeAttr ( "disabled" ) ;
div . find ( "select[id$=data-bitrate]" ) . find ( "option[value='32']" ) . removeAttr ( "disabled" ) ;
2011-09-06 17:44:21 +02:00
}
}
2011-08-24 23:13:56 +02:00
function hideForShoutcast ( ele ) {
2011-09-06 17:44:21 +02:00
var div = ele . closest ( "div" )
div . find ( "#outputMountpoint-label" ) . hide ( )
div . find ( "#outputMountpoint-element" ) . hide ( )
div . find ( "#outputUser-label" ) . hide ( )
div . find ( "#outputUser-element" ) . hide ( )
div . find ( "select[id$=data-type]" ) . find ( "option[value='mp3']" ) . attr ( 'selected' , 'selected' ) ;
div . find ( "select[id$=data-type]" ) . find ( "option[value='ogg']" ) . attr ( "disabled" , "disabled" ) ;
restrictOggBitrate ( ele , false )
2011-08-24 23:13:56 +02:00
}
2011-09-13 21:21:23 +02:00
function validate ( ele , evt ) {
var theEvent = evt || window . event ;
var key = theEvent . keyCode || theEvent . which ;
if ( ( ele . val ( ) . length >= 5 || ( key < 48 || key > 57 ) ) && ! ( key == 8 || key == 9 || key == 13 || key == 37 || key == 39 || key == 46 ) ) {
theEvent . returnValue = false ;
if ( theEvent . preventDefault ) theEvent . preventDefault ( ) ;
}
}
2011-08-24 23:13:56 +02:00
function showForIcecast ( ele ) {
2011-09-06 17:44:21 +02:00
var div = ele . closest ( "div" )
div . find ( "#outputMountpoint-label" ) . show ( )
div . find ( "#outputMountpoint-element" ) . show ( )
div . find ( "#outputUser-label" ) . show ( )
div . find ( "#outputUser-element" ) . show ( )
div . find ( "select[id$=data-type]" ) . find ( "option[value='ogg']" ) . attr ( "disabled" , "" ) ;
2011-08-24 23:13:56 +02:00
}
2011-10-13 20:20:08 +02:00
function checkLiquidsoapStatus ( ) {
2013-01-14 22:00:38 +01:00
var url = baseUrl + 'Preference/get-liquidsoap-status/format/json' ;
2011-10-13 20:20:08 +02:00
var id = $ ( this ) . attr ( "id" ) ;
2013-02-07 21:41:47 +01:00
$ . post ( url , function ( json _obj ) {
2011-10-13 20:20:08 +02:00
for ( var i = 0 ; i < json _obj . length ; i ++ ) {
var obj = json _obj [ i ] ;
2011-12-05 18:34:11 +01:00
var id ;
var status ;
2011-10-13 20:20:08 +02:00
for ( var key in obj ) {
if ( key == "id" ) {
id = obj [ key ] ;
}
if ( key == "status" ) {
status = obj [ key ] ;
}
}
2011-12-05 18:34:11 +01:00
var html ;
2011-11-10 22:32:56 +01:00
if ( status == "OK" ) {
2012-11-20 17:16:10 +01:00
html = '<div class="stream-status status-good"><h3>' + $ . i18n . _ ( "Connected to the streaming server" ) + '</h3></div>' ;
2011-11-10 22:32:56 +01:00
} else if ( status == "N/A" ) {
2012-11-20 17:16:10 +01:00
html = '<div class="stream-status status-disabled"><h3>' + $ . i18n . _ ( "The stream is disabled" ) + '</h3></div>' ;
2011-11-30 02:15:38 +01:00
} else if ( status == "waiting" ) {
2012-11-20 17:16:10 +01:00
html = '<div class="stream-status status-info"><h3>' + $ . i18n . _ ( "Getting information from the server..." ) + '</h3></div>' ;
2011-11-10 22:32:56 +01:00
} else {
2012-11-20 17:16:10 +01:00
html = '<div class="stream-status status-error"><h3>' + $ . i18n . _ ( "Can not connect to the streaming server" ) + '</h3><p>' + status + '</p></div>' ;
2011-11-10 22:32:56 +01:00
}
$ ( "#s" + id + "Liquidsoap-error-msg-element" ) . html ( html ) ;
2011-10-13 20:20:08 +02:00
}
} ) ;
}
2012-03-10 00:48:23 +01:00
function setLiveSourceConnectionOverrideListener ( ) {
2012-03-19 21:08:23 +01:00
$ ( "[id=connection_url_override]" ) . click ( function ( event ) {
2012-06-06 19:10:57 +02:00
var url _input = $ ( this ) . parent ( ) . find ( "#stream_url" ) . children ( )
url _input . removeAttr ( "readonly" )
$ ( this ) . parent ( ) . find ( "div[id$='_dj_connection_url_actions']" ) . show ( )
2012-03-19 21:08:23 +01:00
event . preventDefault ( )
2012-03-10 00:48:23 +01:00
} )
// set action for "OK" and "X"
2012-06-06 19:10:57 +02:00
var live _dj _actions = $ ( "#live_dj_connection_url_actions" )
var live _dj _input = live _dj _actions . parent ( ) . find ( "#stream_url" ) . children ( )
var master _dj _actions = $ ( "#master_dj_connection_url_actions" )
var master _dj _input = master _dj _actions . parent ( ) . find ( "#stream_url" ) . children ( )
2012-03-10 00:48:23 +01:00
2012-06-06 19:10:57 +02:00
live _dj _actions . find ( "#ok" ) . click ( function ( event ) {
2012-03-19 21:08:23 +01:00
event . preventDefault ( )
2012-06-06 19:10:57 +02:00
var url = live _dj _input . val ( )
live _dj _input . val ( url )
live _dj _input . attr ( "readonly" , "readonly" )
live _dj _actions . hide ( )
2013-01-14 22:00:38 +01:00
$ . get ( baseUrl + "Preference/set-source-connection-url/" , { format : "json" , type : "livedj" , url : encodeURIComponent ( url ) , override : 1 } ) ;
2012-03-19 21:08:23 +01:00
event . preventDefault ( )
2012-03-10 00:48:23 +01:00
} )
2012-06-06 19:10:57 +02:00
live _dj _actions . find ( "#reset" ) . click ( function ( event ) {
2012-03-19 21:08:23 +01:00
event . preventDefault ( )
2012-03-10 00:48:23 +01:00
var port = $ ( "#dj_harbor_input_port" ) . val ( )
var mount = $ ( "#dj_harbor_input_mount_point" ) . val ( )
var url = "http://" + location . hostname + ":" + port + "/" + mount
2012-06-12 00:08:36 +02:00
if ( port == '' || mount == '' ) {
url = 'N/A'
}
2012-06-06 19:10:57 +02:00
live _dj _input . val ( url )
live _dj _input . attr ( "readonly" , "readonly" )
live _dj _actions . hide ( )
2013-01-14 22:00:38 +01:00
$ . get ( baseUrl + "Preference/set-source-connection-url" , { format : "json" , type : "livedj" , url : encodeURIComponent ( url ) , override : 0 } ) ;
2012-03-19 21:08:23 +01:00
event . preventDefault ( )
2012-03-10 00:48:23 +01:00
} )
2012-06-06 19:10:57 +02:00
master _dj _actions . find ( "#ok" ) . click ( function ( event ) {
var url = master _dj _input . val ( )
master _dj _input . val ( url )
master _dj _input . attr ( "readonly" , "readonly" )
master _dj _actions . hide ( )
2013-01-14 22:00:38 +01:00
$ . get ( baseUrl + "Preference/set-source-connection-url" , { format : "json" , type : "masterdj" , url : encodeURIComponent ( url ) , override : 1 } )
2012-03-19 21:08:23 +01:00
event . preventDefault ( )
2012-03-10 00:48:23 +01:00
} )
2012-06-06 19:10:57 +02:00
master _dj _actions . find ( "#reset" ) . click ( function ( event ) {
2012-03-10 00:48:23 +01:00
var port = $ ( "#master_harbor_input_port" ) . val ( )
var mount = $ ( "#master_harbor_input_mount_point" ) . val ( )
var url = "http://" + location . hostname + ":" + port + "/" + mount
2012-06-12 00:08:36 +02:00
if ( port == '' || mount == '' ) {
url = 'N/A'
}
2012-06-06 19:10:57 +02:00
master _dj _input . val ( url )
master _dj _input . attr ( "readonly" , "readonly" )
master _dj _actions . hide ( )
2013-01-14 22:00:38 +01:00
$ . get ( baseUrl + "Preference/set-source-connection-url" , { format : "json" , type : "masterdj" , url : encodeURIComponent ( url ) , override : 0 } )
2012-03-19 21:08:23 +01:00
event . preventDefault ( )
2012-03-10 00:48:23 +01:00
} )
}
2011-10-13 20:20:08 +02:00
2012-11-12 18:06:22 +01:00
function setupEventListeners ( ) {
2011-08-19 22:35:23 +02:00
// initial stream url
$ ( "dd[id=outputStreamURL-element]" ) . each ( function ( ) {
rebuildStreamURL ( $ ( this ) )
} )
$ ( "input:[id$=-host], input:[id$=-port], input:[id$=-mount]" ) . keyup ( function ( ) {
rebuildStreamURL ( $ ( this ) )
} )
2011-09-13 21:21:23 +02:00
$ ( "input:[id$=-port]" ) . keypress ( function ( e ) {
validate ( $ ( this ) , e )
} )
2011-08-19 22:35:23 +02:00
$ ( "select:[id$=-output]" ) . change ( function ( ) {
rebuildStreamURL ( $ ( this ) )
} )
2011-08-18 19:53:12 +02:00
2012-01-13 22:56:02 +01:00
if ( ! $ ( "#output_sound_device" ) . is ( ':checked' ) ) {
$ ( "select[id=output_sound_device_type]" ) . attr ( 'disabled' , 'disabled' )
} else {
$ ( "select[id=output_sound_device_type]" ) . removeAttr ( 'disabled' )
}
2011-12-01 01:01:40 +01:00
$ ( "#output_sound_device" ) . change ( function ( ) {
if ( $ ( this ) . is ( ':checked' ) ) {
$ ( "select[id=output_sound_device_type]" ) . removeAttr ( 'disabled' )
} else {
$ ( "select[id=output_sound_device_type]" ) . attr ( 'disabled' , 'disabled' )
}
} )
2011-09-06 17:44:21 +02:00
$ ( "select[id$=data-type]" ) . change ( function ( ) {
if ( $ ( this ) . val ( ) == 'ogg' ) {
restrictOggBitrate ( $ ( this ) , true )
} else {
restrictOggBitrate ( $ ( this ) , false )
}
} )
$ ( "select[id$=data-type]" ) . each ( function ( ) {
if ( $ ( this ) . val ( ) == 'ogg' ) {
restrictOggBitrate ( $ ( this ) , true )
}
} )
$ ( "select[id$=data-output]" ) . change ( function ( ) {
2011-08-19 22:35:23 +02:00
if ( $ ( this ) . val ( ) == 'shoutcast' ) {
2011-08-24 23:13:56 +02:00
hideForShoutcast ( $ ( this ) )
2011-08-19 22:35:23 +02:00
} else {
2011-08-24 23:13:56 +02:00
showForIcecast ( $ ( this ) )
}
} )
2011-09-06 17:44:21 +02:00
$ ( "select[id$=data-output]" ) . each ( function ( ) {
2011-08-24 23:13:56 +02:00
if ( $ ( this ) . val ( ) == 'shoutcast' ) {
hideForShoutcast ( $ ( this ) )
2011-08-19 22:35:23 +02:00
}
} )
2013-01-03 20:54:07 +01:00
$ ( '.toggle legend' ) . click ( function ( ) {
2011-09-19 17:31:10 +02:00
$ ( this ) . parent ( ) . toggleClass ( 'closed' ) ;
2011-09-07 15:48:02 +02:00
return false ;
} ) ;
2011-10-03 23:00:39 +02:00
$ ( '.collapsible-header' ) . click ( function ( ) {
$ ( this ) . next ( ) . toggle ( 'fast' ) ;
2012-09-14 23:35:14 +02:00
$ ( this ) . toggleClass ( "closed" ) ;
2011-10-03 23:00:39 +02:00
return false ;
} )
2012-03-10 00:48:23 +01:00
setLiveSourceConnectionOverrideListener ( )
2011-08-18 19:53:12 +02:00
showErrorSections ( )
2011-11-30 02:15:38 +01:00
setInterval ( 'checkLiquidsoapStatus()' , 1000 )
2012-04-24 17:26:22 +02:00
// qtip for help text
$ ( ".override_help_icon" ) . qtip ( {
content : {
2012-11-20 17:16:10 +01:00
text : $ . i18n . _ ( "If Airtime is behind a router or firewall, you may need to configure port forwarding and this field information will be incorrect. In this case you will need to manually update this field so it shows the correct host/port/mount that your DJ's need to connect to. The allowed range is between 1024 and 49151." ) + " " +
2012-11-20 23:42:26 +01:00
sprintf ( $ . i18n . _ (
"For more details, please read the %sAirtime Manual%s" ) , "<a target='_blank' href='http://www.sourcefabric.org/en/airtime/manuals/'>" , "</a>" )
2012-04-24 17:26:22 +02:00
} ,
hide : {
delay : 500 ,
fixed : true
} ,
style : {
border : {
width : 0 ,
radius : 4
} ,
classes : "ui-tooltip-dark ui-tooltip-rounded"
} ,
position : {
my : "left bottom" ,
at : "right center"
} ,
} )
2012-06-04 17:22:23 +02:00
$ ( ".icecast_metadata_help_icon" ) . qtip ( {
content : {
2012-11-20 17:16:10 +01:00
text : $ . i18n . _ ( "Check this option to enable metadata for OGG streams (stream metadata is the track title, artist, and show name that is displayed in an audio player). VLC and mplayer have a serious bug when playing an OGG/VORBIS stream that has metadata information enabled: they will disconnect from the stream after every song. If you are using an OGG stream and your listeners do not require support for these audio players, then feel free to enable this option." )
2012-06-05 22:41:41 +02:00
} ,
hide : {
delay : 500 ,
fixed : true
} ,
style : {
border : {
width : 0 ,
radius : 4
} ,
classes : "ui-tooltip-dark ui-tooltip-rounded"
} ,
position : {
my : "left bottom" ,
at : "right center"
} ,
} )
$ ( "#auto_transition_help" ) . qtip ( {
content : {
2012-11-20 17:16:10 +01:00
text : $ . i18n . _ ( "Check this box to automatically switch off Master/Show source upon source disconnection." )
2012-06-12 21:38:03 +02:00
} ,
hide : {
delay : 500 ,
fixed : true
} ,
style : {
border : {
width : 0 ,
radius : 4
} ,
classes : "ui-tooltip-dark ui-tooltip-rounded"
} ,
position : {
my : "left bottom" ,
at : "right center"
} ,
} )
$ ( "#auto_switch_help" ) . qtip ( {
content : {
2012-11-20 17:16:10 +01:00
text : $ . i18n . _ ( "Check this box to automatically switch on Master/Show source upon source connection." )
2012-06-04 17:22:23 +02:00
} ,
hide : {
delay : 500 ,
fixed : true
} ,
style : {
border : {
width : 0 ,
radius : 4
} ,
classes : "ui-tooltip-dark ui-tooltip-rounded"
} ,
position : {
my : "left bottom" ,
at : "right center"
} ,
} )
2012-06-11 20:55:26 +02:00
$ ( ".stream_username_help_icon" ) . qtip ( {
2012-10-22 22:37:06 +02:00
content : {
2012-11-20 17:16:10 +01:00
text : $ . i18n . _ ( "If your Icecast server expects a username of 'source', this field can be left blank." )
2012-10-22 22:37:06 +02:00
} ,
hide : {
delay : 500 ,
fixed : true
} ,
style : {
border : {
width : 0 ,
radius : 4
} ,
classes : "ui-tooltip-dark ui-tooltip-rounded"
} ,
position : {
my : "left bottom" ,
at : "right center"
} ,
} )
2013-01-03 23:58:50 +01:00
$ ( ".admin_username_help_icon" ) . qtip ( {
content : {
2013-01-08 22:47:00 +01:00
text : $ . i18n . _ ( "This is the admin username and password for Icecast/SHOUTcast to get listener statistics." )
2013-01-03 23:58:50 +01:00
} ,
hide : {
delay : 500 ,
fixed : true
} ,
style : {
border : {
width : 0 ,
radius : 4
} ,
classes : "ui-tooltip-dark ui-tooltip-rounded"
} ,
position : {
my : "left bottom" ,
at : "right center"
} ,
} )
2012-10-22 22:37:06 +02:00
$ ( ".master_username_help_icon" ) . qtip ( {
2012-06-11 20:55:26 +02:00
content : {
2012-11-20 17:16:10 +01:00
text : $ . i18n . _ ( "If your live streaming client does not ask for a username, this field should be 'source'." )
2012-06-11 20:55:26 +02:00
} ,
hide : {
delay : 500 ,
fixed : true
} ,
style : {
border : {
width : 0 ,
radius : 4
} ,
classes : "ui-tooltip-dark ui-tooltip-rounded"
} ,
position : {
my : "left bottom" ,
at : "right center"
} ,
} )
2012-11-12 18:06:22 +01:00
}
2012-12-28 04:58:41 +01:00
function setSliderForReplayGain ( ) {
$ ( "#slider-range-max" ) . slider ( {
range : "max" ,
min : - 10 ,
max : 10 ,
value : $ ( "#rg_modifier_value" ) . html ( ) ,
slide : function ( event , ui ) {
$ ( "#replayGainModifier" ) . val ( ui . value ) ;
$ ( "#rg_modifier_value" ) . html ( ui . value ) ;
}
} ) ;
$ ( "#replayGainModifier" ) . val ( $ ( "#slider-range-max" ) . slider ( "value" ) ) ;
}
2013-01-16 20:36:56 +01:00
function setPseudoAdminPassword ( s1 , s2 , s3 ) {
if ( s1 ) {
$ ( '#s1_data-admin_pass' ) . val ( 'xxxxxx' ) ;
}
if ( s2 ) {
$ ( '#s2_data-admin_pass' ) . val ( 'xxxxxx' ) ;
}
if ( s3 ) {
$ ( '#s3_data-admin_pass' ) . val ( 'xxxxxx' ) ;
}
}
function getAdminPasswordStatus ( ) {
$ . ajax ( { url : baseUrl + 'Preference/get-admin-password-status/format/json' , dataType : "json" , success : function ( data ) {
setPseudoAdminPassword ( data . s1 , data . s2 , data . s3 ) ;
} } ) ;
}
2012-11-12 18:06:22 +01:00
$ ( document ) . ready ( function ( ) {
setupEventListeners ( ) ;
2012-12-28 04:58:41 +01:00
setSliderForReplayGain ( ) ;
2013-01-16 20:36:56 +01:00
getAdminPasswordStatus ( ) ;
2013-01-03 20:54:07 +01:00
$ ( '#stream_save' ) . live ( 'click' , function ( ) {
var confirm _pypo _restart _text = $ . i18n . _ ( "If you change the username or password values for an enabled stream the playout engine will be rebooted and your listeners will hear silence for 5-10 seconds. Changing the following fields will NOT cause a reboot: Stream Label (Global Settings), and Switch Transition Fade(s), Master Username, and Master Password (Input Stream Settings). If Airtime is recording, and if the change causes a playout engine restart, the recording will be interrupted." ) ;
if ( confirm ( confirm _pypo _restart _text ) ) {
var data = $ ( '#stream_form' ) . serialize ( ) ;
2013-01-14 22:00:38 +01:00
var url = baseUrl + 'Preference/stream-setting' ;
2013-01-03 20:54:07 +01:00
2013-02-07 21:41:47 +01:00
$ . post ( url , { format : "json" , data : data } , function ( json ) {
2013-01-03 20:54:07 +01:00
$ ( '#content' ) . empty ( ) . append ( json . html ) ;
setupEventListeners ( ) ;
setSliderForReplayGain ( ) ;
2013-01-16 20:36:56 +01:00
setPseudoAdminPassword ( json . s1 _set _admin _pass , json . s2 _set _admin _pass , json . s3 _set _admin _pass ) ;
2013-01-03 20:54:07 +01:00
} ) ;
}
} ) ;
2011-12-05 18:34:11 +01:00
} ) ;
2012-11-12 18:06:22 +01:00