/* * $Id$ * Javascript for playlist.html * * Copyright (C) 2005 Anders Betnér (andbe611@users.sourceforge.net) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Detta script finns att hämta på http://www.jojoxx.net och får användas fritt så länge som dessa rader står kvar. */ function DataDumper(obj,n,prefix){ var str=""; prefix=(prefix)?prefix:""; n=(n)?n+1:1; var ind=""; for(var i=0;i"); } } else { for(var i in obj){ str+=DataDumper(obj[i],n,i+"=>"); } } str+=ind+"]\n"; } return str; } //var g_req; var g_requestor; var g_selectedGenres = Array(); var g_selectedAlbums = Array(); var g_selectedArtists = Array(); var baseUrl = window.location.toString(); baseUrl = baseUrl.substr(0,baseUrl.length-13); String.prototype.myEncodeURI = function () { s = encodeURI(this); s = s.replace(/\'/,'%27'); return s.replace(/&/,'%26'); }; Requestor = function(baseUrl) { g_requestor = this; this.req = ''; // holds the request this.responseHandler; this.baseUrl = baseUrl; this.que = Array(); // All browsers but IE if (window.XMLHttpRequest) { this.req = new XMLHttpRequest(); // MS IE } else if (window.ActiveXObject) { this.req = new ActiveXObject("Microsoft.XMLHTTP"); } this.busy = false; }; Requestor.prototype.setResponseHandler = function(resp) { this.responseHandler = resp; }; Requestor.prototype.addRequest = function(url) { if (this.busy) { this.que.push(url); } else { this._openRequest(url); } }; Requestor.prototype._openRequest = function(url) { this.busy = true; if (url.search(/\?/)> -1) { url += '&output=xml'; } else { url += '?output=xml'; } this.req.open('get',this.baseUrl+url,true); this.req.onreadystatechange = Requestor_handleRequest; this.req.send(null); }; Requestor_handleRequest = function() { // readystate 4 means the whole document is loaded if (4 == g_requestor.req.readyState) { // Only try to parse the response if we got // ok from the server if (200 == g_requestor.req.status) { // send the recieved document off to the handler g_requestor.responseHandler(g_requestor.req.responseXML); } // Check if there are requests qued up if (g_requestor.que.length > 0) { // Just to be able to pull ourseves up by our boot straps window.setTimeout(Requestor_queChecker,5); return; } else { g_requestor.busy = false; } } }; function Requestor_queChecker() { if (url = g_requestor.que.shift()) { g_requestor._openRequest(url); } } function response(xmldoc) { if ('daap.databaseplaylists' == xmldoc.firstChild.nodeName) { el = document.getElementById('source'); addPlaylists(el,xmldoc); } else if ('daap.databasebrowse' == xmldoc.firstChild.nodeName) { // Ok we have response from a browse query switch (xmldoc.firstChild.childNodes[3].nodeName) { case 'daap.browsegenrelisting': el = document.getElementById('genre'); addOptions(el,'genre',xmldoc); break; case 'daap.browseartistlisting': el = document.getElementById('artist'); addOptions(el,'artist',xmldoc); break; case 'daap.browsealbumlisting': el = document.getElementById('album'); addOptions(el,'album',xmldoc); // All other boxes are updated, now get the songs getSongs(); break; default: // We got something else back... } } else if ('daap.databasesongs' == xmldoc.firstChild.nodeName) { // Songlist addSongs(xmldoc); } } function init() { req = new Requestor(baseUrl); req.setResponseHandler(response); req.addRequest('databases/1/containers'); req.addRequest('databases/1/browse/genres'); req.addRequest('databases/1/browse/artists'); req.addRequest('databases/1/browse/albums'); el = document.getElementById('source'); el.addEventListener('change',playlistSelect,true); el = document.getElementById('genre'); el.addEventListener('change',genreSelect,true); el = document.getElementById('artist'); el.addEventListener('change',artistSelect,true); el = document.getElementById('album'); el.addEventListener('change',albumSelect,true); } function addOptions(el,label,xmldoc) { while(el.hasChildNodes()) { el.removeChild(el.firstChild); } itemCnt = xmldoc.getElementsByTagName('dmap.specifiedtotalcount').item(0).textContent; if (parseInt(itemCnt) > 1) { plural = 's'; } else { plural = ''; } option = document.createElement('option'); option.value = '1'; option.selected = false; option.appendChild(document.createTextNode('All ('+itemCnt+' '+label +plural+')')); el.appendChild(option); items = xmldoc.getElementsByTagName('dmap.listingitem'); selectAll = true; for (i=0; i