@@ -10,31 +9,32 @@
|
+
Genre
|
Artist
|
Album
|
-
-
+
+
Song |
@@ -44,7 +44,8 @@ Album
Genre |
-
+
+ | | | | |
diff --git a/admin-root/playlist.js b/admin-root/playlist.js
index 8b8250b7..683b22c7 100644
--- a/admin-root/playlist.js
+++ b/admin-root/playlist.js
@@ -18,56 +18,213 @@
* 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');
+};
-function createRequest() {
+Requestor = function(baseUrl) {
+ this.baseUrl = baseUrl;
+ this.que = Array();
// All browsers but IE
- g_req = false;
- if (window.XMLHttpRequest) {
- g_req = new XMLHttpRequest();
+ g_req = false;
+ if (window.XMLHttpRequest) {
+ g_req = new XMLHttpRequest();
// MS IE
- } else if (window.ActiveXObject) {
- g_req = new ActiveXObject("Microsoft.XMLHTTP");
+ } else if (window.ActiveXObject) {
+ g_req = new ActiveXObject("Microsoft.XMLHTTP");
+ }
+ this.busy = false;
+
+};
+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';
}
+ g_req.open('get',this.baseUrl+url,true);
+ g_req.onreadystatechange = Requestor_handleRequest;
+ g_req.send(null);
+};
+Requestor_handleRequest = function() {
+ if (4 == g_req.readyState) {
+ // readystate 4 means the whole document is loaded
+ if (200 == g_req.status) {
+ // Only try to parse the response if we got
+ // ok from the server
+ xmldoc = g_req.responseXML;
+ 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);
+ break;
+ default:
+ // We got something else back...
+ }
+ } else if ('daap.databasesongs' == xmldoc.firstChild.nodeName) {
+ // Songlist
+ addSongs(xmldoc);
+ }
+ }
+ 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 init() {
+ g_requestor = new Requestor(baseUrl);
+ g_requestor.addRequest('databases/1/containers');
+ g_requestor.addRequest('databases/1/browse/genres');
+ g_requestor.addRequest('databases/1/browse/artists');
+ g_requestor.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);
+
+//###FIXME album select
+return;
// get playlists
- createRequest();
- //alert(baseUrl+'databases/1/browse/genres?output=xml');
+
g_req.open('get',baseUrl+'databases/1/containers?output=xml',false);
g_req.send(null);
- el = document.getElementById('source');
- addPlaylists(el,g_req.responseXML);
- el.addEventListener('change',playlistSelect,true);
+
g_req.open('get',baseUrl+'databases/1/browse/genres?output=xml',false);
g_req.send(null);
- el = document.getElementById('genre');
- addOptions(el,g_req.responseXML);
-
+
g_req.open('get',baseUrl+'databases/1/browse/artists?output=xml',false);
g_req.send(null);
- el = document.getElementById('artist');
- addOptions(el,g_req.responseXML);
-
+
g_req.open('get',baseUrl+'databases/1/browse/albums?output=xml',false);
g_req.send(null);
el = document.getElementById('album');
- addOptions(el,g_req.responseXML);
+ addOptions(el,'album',g_req.responseXML);
}
-function addOptions(el,xmldoc) {
+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');
for (i=0; i |