1 /*****************************************************************************
2 * vlm.js: VLC media player web interface
3 *****************************************************************************
4 * Copyright (C) 2005-2006 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /* replace quotes and spaces by underscores */
25 function addunderscores( str ){ return str.replace(/\'|\"| /g, '_'); }
27 /**********************************************************************
28 * Input dialog functions
29 *********************************************************************/
31 function vlm_input_edit( dest )
33 document.getElementById( 'input_dest' ).value = dest;
37 function vlm_input_change()
40 document.getElementById( value( 'input_dest' ) ).value = value( 'input_mrl' );
43 function vlm_output_edit( dest )
45 document.getElementById( 'sout_dest' ).value = dest;
49 function vlm_output_change()
52 document.getElementById( value( 'sout_dest' ) ).value = value( 'sout_mrl' ).substr(6); /* substr <-> remove :sout= */
55 function hide_vlm_add()
57 document.getElementById( 'vlm_add_broadcast' ).style.display = 'none';
58 document.getElementById( 'vlm_add_vod' ).style.display = 'none';
59 document.getElementById( 'vlm_add_schedule' ).style.display = 'none';
62 function update_vlm_add_broadcast()
64 cmd = document.getElementById( 'vlm_command' );
66 if( value( 'vlm_broadcast_name' ) )
68 cmd.value = "new " + addunderscores( value( 'vlm_broadcast_name' ) )
71 if( checked( 'vlm_broadcast_enabled' ) )
73 cmd.value += " enabled";
76 if( checked( 'vlm_broadcast_loop' ) )
81 if( value( 'vlm_broadcast_input' ) )
83 cmd.value += " input " + value( 'vlm_broadcast_input' );
86 if( value( 'vlm_broadcast_output' ) )
88 cmd.value += " output " + value( 'vlm_broadcast_output' );
97 function update_vlm_add_vod()
99 cmd = document.getElementById( 'vlm_command' );
101 if( value( 'vlm_vod_name' ) )
103 cmd.value = "new " + addunderscores( value( 'vlm_vod_name' ) )
106 if( checked( 'vlm_vod_enabled' ) )
108 cmd.value += " enabled";
111 if( value( 'vlm_vod_input' ) )
113 cmd.value += " input " + value( 'vlm_vod_input' );
116 if( value( 'vlm_vod_output' ) )
118 cmd.value += " output " + value( 'vlm_vod_output' );
127 function update_vlm_add_schedule()
131 function clear_vlm_add()
133 document.getElementById( 'vlm_command' ).value = "";
134 document.getElementById( 'vlm_broadcast_name' ).value = "";
135 document.getElementById( 'vlm_vod_name' ).value = "";
138 function clear_children( elt )
141 while( elt.hasChildNodes() )
142 elt.removeChild( elt.firstChild );
145 function parse_vlm_cmd()
147 if( req.readyState == 4 )
149 if( req.status == 200 )
151 vlm_answer = req.responseXML.documentElement;
152 error_tag = vlm_answer.getElementsByTagName( 'error' )[0];
153 vlme = document.getElementById( 'vlm_error' );
154 clear_children( vlme );
155 if( error_tag.hasChildNodes() )
157 vlme.appendChild( document.createTextNode( 'Error: ' + error_tag.firstChild.data ) );
158 vlme.style.color = "#f00";
162 vlme.appendChild( document.createTextNode( 'Command succesful (' + value( 'vlm_command' ) + ') ' ) );
163 vlme.style.color = "#0f0";
166 link = document.createElement( "input" );
167 link.setAttribute( 'type', 'button' );
168 link.setAttribute( 'onclick', 'clear_children( document.getElementById( "vlm_error" ) );' );
169 link.setAttribute( 'value', 'clear' );
170 vlme.appendChild( link );
177 function parse_vlm_elements()
179 if( req.readyState == 4 )
181 if( req.status == 200 )
183 vlmb = document.getElementById( 'vlm_broadcast_list' );
184 vlmv = document.getElementById( 'vlm_vod_list' );
185 vlms = document.getElementById( 'vlm_schedule_list' );
187 clear_children( vlmb );
188 clear_children( vlmv );
189 clear_children( vlms );
191 answer = req.responseXML.documentElement;
193 elt = answer.firstChild;
197 if( elt.nodeName == "broadcast" || elt.nodeName == "vod" )
199 nb = document.createElement( 'div' );
200 nb.setAttribute( 'class', 'list_element' );
201 if( elt.nodeName == "broadcast" )
203 vlmb.appendChild( nb );
207 vlmv.appendChild( nb );
209 nbname = document.createElement( 'b' );
210 nbname.appendChild( document.createTextNode( elt.getAttribute( 'name' ) ) );
211 nb.appendChild( nbname );
213 link = document.createElement( 'input' );
214 link.setAttribute( 'type', 'button' );
215 if( elt.getAttribute( 'enabled' ) == 'yes' )
217 nb.appendChild( document.createTextNode( " enabled " ) );
218 link.setAttribute( 'onclick', 'vlm_disable("'+elt.getAttribute( 'name' ) + '");' );
219 link.setAttribute( 'value', "Disable" );
223 nb.appendChild( document.createTextNode( " disabled " ) );
224 link.setAttribute( 'onclick', 'vlm_enable("'+elt.getAttribute( 'name' ) + '");' );
225 link.setAttribute( 'value', "Enable" );
227 nb.appendChild( link );
229 if( elt.nodeName == "broadcast" )
231 link = document.createElement( 'input' );
232 link.setAttribute( 'type', 'button' );
233 if( elt.getAttribute( 'loop' ) == 'yes' )
235 nb.appendChild( document.createTextNode( " loop " ) );
237 link.setAttribute( 'onclick', 'vlm_unloop("'+elt.getAttribute( 'name' ) + '");' );
238 link.setAttribute( 'value', "Un-loop" );
242 nb.appendChild( document.createTextNode( " play once " ) );
244 link.setAttribute( 'onclick', 'vlm_loop("'+elt.getAttribute( 'name' ) + '");' );
245 link.setAttribute( 'value', "Loop" );
247 nb.appendChild( link );
249 if( elt.getAttribute( 'enabled' ) == 'yes' )
251 nb.appendChild( document.createTextNode( " " ) );
252 link = document.createElement( 'input' );
253 link.setAttribute( 'type', 'button' );
254 link.setAttribute( 'onclick', 'vlm_play("'+elt.getAttribute('name')+'");' );
255 link.setAttribute( 'value', 'Play' );
256 nb.appendChild( link );
259 nb.appendChild( document.createTextNode( " " ) );
260 link = document.createElement( 'input' );
261 link.setAttribute( 'type', 'button' );
262 link.setAttribute( 'onclick', 'vlm_pause("'+elt.getAttribute('name')+'");' );
263 link.setAttribute( 'value', 'Pause' );
264 nb.appendChild( link );
266 nb.appendChild( document.createTextNode( " " ) );
267 link = document.createElement( 'input' );
268 link.setAttribute( 'type', 'button' );
269 link.setAttribute( 'onclick', 'vlm_stop("'+elt.getAttribute('name')+'");' );
270 link.setAttribute( 'value', 'Stop' );
271 nb.appendChild( link );
274 nb.appendChild( document.createTextNode( " " ) );
275 link = document.createElement( 'input' );
276 link.setAttribute( 'type', 'button' );
277 link.setAttribute( 'onclick', 'vlm_delete("'+elt.getAttribute( 'name' ) + '");' );
278 link.setAttribute( 'value', "Delete" );
279 nb.appendChild( link );
281 list = document.createElement( "ul" );
282 /* begin input list */
283 inputs = elt.getElementsByTagName( 'input' );
284 for( i = 0; i < inputs.length; i++ )
286 item = document.createElement( "li" );
287 item.appendChild( document.createTextNode( "Input: " + inputs[i].firstChild.data + " " ) );
288 link = document.createElement( "input" );
289 link.setAttribute( 'type', 'button' );
290 link.setAttribute( 'onclick', 'vlm_delete_input("' + elt.getAttribute( 'name' ) + '", '+(i+1)+' );' );
291 link.setAttribute( 'value', "Delete" );
292 item.appendChild( link );
293 list.appendChild( item );
297 item = document.createElement( "li" );
298 text = document.createElement( "input" );
299 text.setAttribute( 'type', 'text' );
300 text.setAttribute( 'size', '40' );
301 text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_input' );
302 item.appendChild( text );
303 item.appendChild( document.createTextNode( ' ' ) );
304 edit = document.createElement( "input" );
305 edit.setAttribute( 'type', 'button' );
306 edit.setAttribute( 'value', 'Edit' );
307 edit.setAttribute( 'onclick', 'vlm_input_edit("vlm_elt_'+elt.getAttribute('name')+'_input");');
308 item.appendChild( edit );
309 item.appendChild( document.createTextNode( ' ' ) );
310 link = document.createElement( "input" );
311 link.setAttribute( 'type', 'button' );
312 link.setAttribute( 'onclick', 'vlm_add_input("'+elt.getAttribute('name')+'",document.getElementById("vlm_elt_'+elt.getAttribute('name')+'_input").value );' );
313 link.setAttribute( 'value', 'Add input' );
314 item.appendChild( link );
316 list.appendChild( item );
317 /* end of input list */
320 item = document.createElement( "li" );
321 outputelt = elt.getElementsByTagName( 'output' )[0];
322 if( outputelt.hasChildNodes() )
324 output = outputelt.firstChild.data;
330 item.appendChild( document.createTextNode( 'Output: ' ) );
331 text = document.createElement( "input" );
332 text.setAttribute( 'type', 'text' );
333 text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_output' );
334 text.setAttribute( 'value', output );
335 item.appendChild( text );
337 item.appendChild( document.createTextNode( ' ' ) );
339 edit = document.createElement( "input" );
340 edit.setAttribute( 'type', 'button' );
341 edit.setAttribute( 'value', 'Edit' );
342 edit.setAttribute( 'onclick', 'vlm_output_edit("vlm_elt_'+elt.getAttribute('name')+'_output");');
343 item.appendChild( edit );
344 list.appendChild( item );
345 item.appendChild( document.createTextNode( ' ' ) );
346 link = document.createElement( "input" );
347 link.setAttribute( 'type', 'button' );
348 link.setAttribute( 'onclick', 'vlm_output("'+elt.getAttribute( 'name' )+ '",document.getElementById("vlm_elt_'+elt.getAttribute( 'name' )+'_output").value);' );
349 link.setAttribute( 'value', 'Change output' );
350 item.appendChild( link );
353 /* begin options list */
354 options = elt.getElementsByTagName( 'option' );
355 for( i = 0; i < options.length; i++ )
357 item = document.createElement( "li" );
358 item.appendChild( document.createTextNode( "Option: " + options[i].firstChild.data ) );
359 list.appendChild( item );
363 item = document.createElement( "li" );
364 item.appendChild( document.createTextNode( ' ' ) );
365 text = document.createElement( "input" );
366 text.setAttribute( 'type', 'text' );
367 text.setAttribute( 'size', '40' );
368 text.setAttribute( 'id', 'vlm_elt_'+elt.getAttribute('name')+'_option' );
369 item.appendChild( text );
370 item.appendChild( document.createTextNode( ' ' ) );
371 link = document.createElement( "input" );
372 link.setAttribute( 'type', 'button' );
373 link.setAttribute( 'onclick', 'vlm_option("'+elt.getAttribute('name')+'",document.getElementById("vlm_elt_'+elt.getAttribute('name')+'_option").value );' );
374 link.setAttribute( 'value', 'Add option' );
375 item.appendChild( link );
377 list.appendChild( item );
380 nb.appendChild( list );
383 else if( elt.nodeName == "schedule" )
386 elt = elt.nextSibling;
392 function vlm_cmd( cmd )
394 loadXMLDoc( 'requests/vlm_cmd.xml?command='+cmd.replace(/\#/g, '%23'), parse_vlm_cmd );
397 function vlm_get_elements( )
399 loadXMLDoc( 'requests/vlm.xml', parse_vlm_elements );
402 /* helper functions */
404 function vlm_disable( name )
406 document.getElementById( 'vlm_command' ).value = "setup "+name+" disabled";
407 vlm_cmd( value( 'vlm_command' ) );
410 function vlm_enable( name )
412 document.getElementById( 'vlm_command' ).value = "setup "+name+" enabled";
413 vlm_cmd( value( 'vlm_command' ) );
416 function vlm_loop( name )
418 document.getElementById( 'vlm_command' ).value = "setup "+name+" loop";
419 vlm_cmd( value( 'vlm_command' ) );
422 function vlm_unloop( name )
424 document.getElementById( 'vlm_command' ).value = "setup "+name+" unloop";
425 vlm_cmd( value( 'vlm_command' ) );
428 function vlm_play( name )
430 document.getElementById( 'vlm_command' ).value = "control "+name+" play";
431 vlm_cmd( value( 'vlm_command' ) );
434 function vlm_pause( name )
436 document.getElementById( 'vlm_command' ).value = "control "+name+" pause";
437 vlm_cmd( value( 'vlm_command' ) );
440 function vlm_stop( name )
442 document.getElementById( 'vlm_command' ).value = "control "+name+" stop";
443 vlm_cmd( value( 'vlm_command' ) );
446 function vlm_delete( name )
448 document.getElementById( 'vlm_command' ).value = "del "+name;
449 vlm_cmd( value( 'vlm_command' ) );
452 function vlm_delete_input( name, num )
454 document.getElementById( 'vlm_command' ).value = "setup "+name+" inputdeln "+num;
455 vlm_cmd( value( 'vlm_command' ) );
458 function vlm_add_input( name, input )
460 document.getElementById( 'vlm_command' ).value = "setup "+name+" input "+input;
461 vlm_cmd( value( 'vlm_command' ) );
464 function vlm_output( name, output )
466 document.getElementById( 'vlm_command' ).value = "setup "+name+" output "+output;
467 vlm_cmd( value( 'vlm_command' ) );
470 function vlm_option( name, option )
472 document.getElementById( 'vlm_command' ).value = "setup "+name+" option "+option;
473 vlm_cmd( value( 'vlm_command' ) );
478 vlm_cmd( value( 'vlm_command' ) );