]> git.sesse.net Git - vlc/blobdiff - share/http/js/vlm.js
Fix error in javascript "playlist xml" -> html routine which messed up display of...
[vlc] / share / http / js / vlm.js
index f5ffb520d986568bd1d32f47cae804876d4ba417..daa3f2a5a4c4b4fcfa7d80035c42a8e7623f289a 100644 (file)
@@ -28,6 +28,27 @@ function addunderscores( str ){ return str.replace(/\'|\"| /g, '_'); }
  * Input dialog functions
  *********************************************************************/
 
+function toggle_show_vlm_helper()
+{
+    var vlmh = document.getElementById( "vlm_helper" );
+    var vlmhctrl = document.getElementById( "vlm_helper_controls" );
+    var btn = document.getElementById( "btn_vlm_helper_toggle" );
+    if( vlmh.style.display == 'block' || vlmh.style.display == '')
+    {
+        vlmh.style.display = 'none';
+        vlmhctrl.style.display = 'none';
+        btn.removeChild( btn.firstChild );
+        btn.appendChild( document.createTextNode( 'Show VLM helper' ) );
+    }
+    else
+    {
+        vlmh.style.display = 'block';
+        vlmhctrl.style.display = 'inline';
+        btn.removeChild( btn.firstChild );
+        btn.appendChild( document.createTextNode( 'Hide VLM helper' ) );
+    }
+}
+
 function vlm_input_edit( dest )
 {
     document.getElementById( 'input_dest' ).value = dest;
@@ -36,7 +57,7 @@ function vlm_input_edit( dest )
 
 function vlm_input_change()
 {
-    document.getElementById( value( 'input_dest' ) ).value = value( 'input_mrl' );
+    document.getElementById( value( 'input_dest' ) ).value = value( 'input_mrl' ).replace( /\ :/g, " option " );
     hide( 'input' );
     document.getElementById( value( 'input_dest' ) ).focus();
 }
@@ -49,7 +70,7 @@ function vlm_output_edit( dest )
 
 function vlm_output_change()
 {
-    document.getElementById( value( 'sout_dest' ) ).value = value( 'sout_mrl' ).substr(6); /* substr <-> remove :sout= */
+    document.getElementById( value( 'sout_dest' ) ).value = value( 'sout_mrl' ).substr(6).replace( /\ :/g, " option " ); /* substr <-> remove :sout= */
     hide( 'sout' );
     document.getElementById( value( 'sout_dest' ) ).focus();
 }
@@ -130,6 +151,11 @@ function vlm_schedule_type_change( name )
     }
 }
 
+function sanitize_input( str )
+{
+    return str.replace( /\"/g, '\\\"' ).replace( /^/, '"' ).replace( /$/, '"' ).replace( /\ option\ /g, '" option "' );
+}
+
 function update_vlm_add_broadcast()
 {
     var cmd = document.getElementById( 'vlm_command' );
@@ -151,7 +177,7 @@ function update_vlm_add_broadcast()
 
         if( value( 'vlm_broadcast_input' ) )
         {
-            cmd.value += " input " + value( 'vlm_broadcast_input' );
+            cmd.value += " input " + sanitize_input( value( 'vlm_broadcast_input' ) );
         }
 
         if( value( 'vlm_broadcast_output' ) )
@@ -181,7 +207,7 @@ function update_vlm_add_vod()
         
         if( value( 'vlm_vod_input' ) )
         {
-            cmd.value += " input " + value( 'vlm_vod_input' );
+            cmd.value += " input " + sanitize_input( value( 'vlm_vod_input' ) );
         }
 
         if( value( 'vlm_vod_output' ) )
@@ -260,19 +286,19 @@ function clear_vlm_add()
     document.getElementById( 'vlm_vod_name' ).value = "";
 }
 
-function clear_children( elt )
-{
-    if( elt )
-        while( elt.hasChildNodes() )
-            elt.removeChild( elt.firstChild );
-}
-
 function create_button( caption, action )
 {
-    var link = document.createElement( "input" );
-    link.setAttribute( 'type', 'button' );
-    link.setAttribute( 'onclick', action );
-    link.setAttribute( 'value', caption );
+/*    var link = document.createElement( "input" );
+    link.setAttribute( 'type', 'button' );*/
+    /* link.setAttribute( 'onclick', action ); */
+    /* Above doesn't work on ie. You need to use something like
+     * link.onclick = function() { alert( 'pouet' ); };
+     * instead ... conclusion: IE is crap */
+   /* link.setAttribute( 'value', caption );*/
+
+    var d = document.createElement( 'div' );
+    d.innerHTML = "<input type='button' onclick='"+action+"' value='"+caption+"' />"; /* other IE work around  ... still crap. Use double quotes only in action */
+    var link = d.firstChild;
     return link;
 }
 function create_option( caption, value )
@@ -334,7 +360,7 @@ function parse_vlm_elements()
                 if( elt.nodeName == "broadcast" || elt.nodeName == "vod" )
                 {
                     var nb = document.createElement( 'div' );
-                    nb.setAttribute( 'class', 'list_element' );
+                    setclass( nb, 'list_element' );
                     if( elt.nodeName == "broadcast" )
                     {
                         vlmb.appendChild( nb );
@@ -347,41 +373,31 @@ function parse_vlm_elements()
                     nbname.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
                     nb.appendChild( nbname );
                     
-                    var link = document.createElement( 'input' );
-                    link.setAttribute( 'type', 'button' );
                     if( elt.getAttribute( 'enabled' ) == 'yes' )
                     {
                         nb.appendChild( document.createTextNode( " enabled " ) );
-                        link.setAttribute( 'onclick', 'vlm_disable("'+elt.getAttribute( 'name' ) + '");' );
-                        link.setAttribute( 'value', "Disable" );
+                        nb.appendChild( create_button( "Disable", 'vlm_disable("'+elt.getAttribute( 'name' ) + '");' ) );
                     }
                     else
                     {
                         nb.appendChild( document.createTextNode( " disabled " ) );
-                        link.setAttribute( 'onclick', 'vlm_enable("'+elt.getAttribute( 'name' ) + '");' );
-                        link.setAttribute( 'value', "Enable" );
+                        nb.appendChild( create_button( "Enable", 'vlm_enable("'+elt.getAttribute( 'name' ) + '");' ) );
                     }
-                    nb.appendChild( link );
                     
                     if( elt.nodeName == "broadcast" )
                     {
-                        link = document.createElement( 'input' );
-                        link.setAttribute( 'type', 'button' );
                         if( elt.getAttribute( 'loop' ) == 'yes' )
                         {
                             nb.appendChild( document.createTextNode( " loop " ) );
 
-                            link.setAttribute( 'onclick', 'vlm_unloop("'+elt.getAttribute( 'name' ) + '");' );
-                            link.setAttribute( 'value', "Un-loop" );
+                            nb.appendChild( create_button( 'Un-loop', 'vlm_unloop("'+elt.getAttribute( 'name' ) + '");' ) );
                         }
                         else
                         {
                             nb.appendChild( document.createTextNode( " play once " ) );
+                            nb.appendChild( create_button( 'Loop', 'vlm_loop("'+elt.getAttribute( 'name' ) + '");' ) );
                             
-                            link.setAttribute( 'onclick', 'vlm_loop("'+elt.getAttribute( 'name' ) + '");' );
-                            link.setAttribute( 'value', "Loop" );
                         }
-                        nb.appendChild( link );
 
                         if( elt.getAttribute( 'enabled' ) == 'yes' )
                         {
@@ -409,6 +425,7 @@ function parse_vlm_elements()
                     text.setAttribute( 'type', 'text' );
                     text.setAttribute( 'size', '40' );
                     text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_input' );
+                    text.setAttribute( 'onkeypress', 'if( event.keyCode == 13 ) vlm_add_input("'+elt.getAttribute('name')+'",document.getElementById("vlm_elt_'+elt.getAttribute('name')+'_input").value );' );
                     item.appendChild( text );
                     item.appendChild( document.createTextNode( ' ' ) );
                     item.appendChild( create_button( 'Edit', 'vlm_input_edit("vlm_elt_'+elt.getAttribute('name')+'_input");') );
@@ -419,7 +436,7 @@ function parse_vlm_elements()
                     if( inputs.length > 0 )
                     {
                         var ilist = document.createElement( "ol" );
-                        ilist.setAttribute( 'start', '0' );
+                        ilist.setAttribute( 'start', '1' );
                         item.appendChild( ilist );
                         for( i = 0; i < inputs.length; i++ )
                         {
@@ -447,6 +464,7 @@ function parse_vlm_elements()
                     text.setAttribute( 'type', 'text' );
                     text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_output' );
                     text.setAttribute( 'value', output );
+                    text.setAttribute( 'onkeypress', 'if( event.keyCode == 13 )  vlm_output("'+elt.getAttribute( 'name' )+ '",document.getElementById("vlm_elt_'+elt.getAttribute( 'name' )+'_output").value);' );
                     item.appendChild( text );
 
                     item.appendChild( document.createTextNode( ' ' ) );
@@ -466,6 +484,7 @@ function parse_vlm_elements()
                     text.setAttribute( 'type', 'text' );
                     text.setAttribute( 'size', '40' );
                     text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_option' );
+                    text.setAttribute( 'onkeypress', 'if( event.keyCode == 13 ) vlm_option("'+elt.getAttribute('name')+'",document.getElementById("vlm_elt_'+elt.getAttribute('name')+'_option").value );' );
                     item.appendChild( text );
                     item.appendChild( document.createTextNode( ' ' ) );
                     item.appendChild( create_button( 'Add option', 'vlm_option("'+elt.getAttribute('name')+'",document.getElementById("vlm_elt_'+elt.getAttribute('name')+'_option").value );' ) );
@@ -504,9 +523,10 @@ function parse_vlm_elements()
                             var ititle = instances[i].getAttribute( 'title' );
                             var ichapter = instances[i].getAttribute( 'chapter' );
                             var iseekable = instances[i].getAttribute( 'seekable' );
+                            var iplaylistindex = instances[i].getAttribute( 'playlistindex' );
                             
                             var item = document.createElement( "li" );
-                            item.appendChild( document.createTextNode( iname + ": " + istate + " " + (iposition.toFixed(2)) + "%" + " " + format_time( itime ) + "/" + format_time( ilength ) ) );
+                            item.appendChild( document.createTextNode( iname + ": " + istate + " (" + iplaylistindex + ") " + (iposition.toFixed(2)) + "%" + " " + format_time( itime ) + "/" + format_time( ilength ) ) );
                             ilist.appendChild( item );
                         }
                     }
@@ -518,28 +538,23 @@ function parse_vlm_elements()
                 else if( elt.nodeName == "schedule" )
                 {
                     var nb = document.createElement( 'div' );
-                    nb.setAttribute( 'class', 'list_element' );
+                    setclass( nb, 'list_element' );
                     vlms.appendChild( nb );
 
                     var nbname = document.createElement( 'b' );
                     nbname.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
                     nb.appendChild( nbname );
                     
-                    var link = document.createElement( 'input' );
-                    link.setAttribute( 'type', 'button' );
                     if( elt.getAttribute( 'enabled' ) == 'yes' )
                     {
                         nb.appendChild( document.createTextNode( " enabled " ) );
-                        link.setAttribute( 'onclick', 'vlm_disable("'+elt.getAttribute( 'name' ) + '");' );
-                        link.setAttribute( 'value', "Disable" );
+                        nb.appendChild( create_button( "Disable", 'vlm_disable("'+elt.getAttribute( 'name' ) + '");' ) );
                     }
                     else
                     {
                         nb.appendChild( document.createTextNode( " disabled " ) );
-                        link.setAttribute( 'onclick', 'vlm_enable("'+elt.getAttribute( 'name' ) + '");' );
-                        link.setAttribute( 'value', "Enable" );
+                        nb.appendChild( create_button( "Enable", 'vlm_enable("'+elt.getAttribute( 'name' ) + '");' ) );
                     }
-                    nb.appendChild( link );
 
                     nb.appendChild( document.createTextNode( " " ) );
                     nb.appendChild( create_button( "Delete", 'vlm_delete("'+elt.getAttribute( 'name' ) + '");' ) );
@@ -620,7 +635,7 @@ function parse_vlm_elements()
 
 function vlm_cmd( cmd )
 {
-    loadXMLDoc( 'requests/vlm_cmd.xml?command='+cmd.replace(/\#/g, '%23'), parse_vlm_cmd );
+    loadXMLDoc( 'requests/vlm_cmd.xml?command='+encodeURIComponent(cmd), parse_vlm_cmd );
 }
 
 function vlm_get_elements( )
@@ -686,7 +701,7 @@ function vlm_delete_input( name, num )
 
 function vlm_add_input( name, input )
 {
-    document.getElementById( 'vlm_command' ).value = "setup "+name+" input "+input;
+    document.getElementById( 'vlm_command' ).value = "setup "+name+" input "+sanitize_input( input );
     vlm_cmd( value( 'vlm_command' ) );
 }