mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-12 15:33:23 -05:00
Code cleanup, fixed browse queries,
This commit is contained in:
parent
172802161f
commit
24667c8d01
@ -956,8 +956,8 @@ table.calendar td.todaynoevent {
|
|||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
border-left: 1px solid #8CACBB;
|
border-left: 1px solid #8CACBB;
|
||||||
border-bottom: 1px solid #8CACBB;
|
border-bottom: 1px solid #8CACBB;
|
||||||
font-size: 80%;
|
|
||||||
margin: 1em 0em 1em 0em;
|
margin: 1em 0em 1em 0em;
|
||||||
|
font: icon; !important;
|
||||||
clear: both;
|
clear: both;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,19 +14,19 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
Genre<br />
|
Genre<br />
|
||||||
<select id="genre" name="select" size="10">
|
<select id="genre" name="select" multiple="multiple" size="10">
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
Artist<br />
|
Artist<br />
|
||||||
<select id="artist" name="select" size="10">
|
<select id="artist" name="select" multiple="multiple" size="10">
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
Album<br />
|
Album<br />
|
||||||
<select id="album" name="select" size="10">
|
<select id="album" name="select" multiple="multiple" size="10">
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
/* Detta script finns att hämta på http://www.jojoxx.net och
|
/* 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. */
|
får användas fritt så länge som dessa rader står kvar. */
|
||||||
|
|
||||||
function DataDumper(obj,n,prefix){
|
function DataDumper(obj,n,prefix){
|
||||||
var str=""; prefix=(prefix)?prefix:""; n=(n)?n+1:1; var ind=""; for(var i=0;i<n;i++){ ind+=" "; }
|
var str=""; prefix=(prefix)?prefix:""; n=(n)?n+1:1; var ind=""; for(var i=0;i<n;i++){ ind+=" "; }
|
||||||
if(typeof(obj)=="string"){
|
if(typeof(obj)=="string"){
|
||||||
@ -29,6 +28,8 @@ function DataDumper(obj,n,prefix){
|
|||||||
str+=ind+prefix+"Number:"+obj+"\n";
|
str+=ind+prefix+"Number:"+obj+"\n";
|
||||||
} else if(typeof(obj)=="function"){
|
} else if(typeof(obj)=="function"){
|
||||||
str+=ind+prefix+"Function:"+obj+"\n";
|
str+=ind+prefix+"Function:"+obj+"\n";
|
||||||
|
} else if(typeof(obj) == 'boolean') {
|
||||||
|
str+=ind+prefix+"Boolean:" + obj + "\n";
|
||||||
} else {
|
} else {
|
||||||
var type="Array";
|
var type="Array";
|
||||||
for(var i in obj){ type=(type=="Array"&&i==parseInt(i))?"Array":"Object" }
|
for(var i in obj){ type=(type=="Array"&&i==parseInt(i))?"Array":"Object" }
|
||||||
@ -43,7 +44,7 @@ function DataDumper(obj,n,prefix){
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
var g_req;
|
//var g_req;
|
||||||
var g_requestor;
|
var g_requestor;
|
||||||
var g_selectedGenres = Array();
|
var g_selectedGenres = Array();
|
||||||
var g_selectedAlbums = Array();
|
var g_selectedAlbums = Array();
|
||||||
@ -58,19 +59,25 @@ String.prototype.myEncodeURI = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Requestor = function(baseUrl) {
|
Requestor = function(baseUrl) {
|
||||||
|
g_requestor = this;
|
||||||
|
this.req = ''; // holds the request
|
||||||
|
this.responseHandler;
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
this.que = Array();
|
this.que = Array();
|
||||||
|
|
||||||
// All browsers but IE
|
// All browsers but IE
|
||||||
g_req = false;
|
|
||||||
if (window.XMLHttpRequest) {
|
if (window.XMLHttpRequest) {
|
||||||
g_req = new XMLHttpRequest();
|
this.req = new XMLHttpRequest();
|
||||||
// MS IE
|
// MS IE
|
||||||
} else if (window.ActiveXObject) {
|
} else if (window.ActiveXObject) {
|
||||||
g_req = new ActiveXObject("Microsoft.XMLHTTP");
|
this.req = new ActiveXObject("Microsoft.XMLHTTP");
|
||||||
}
|
}
|
||||||
this.busy = false;
|
this.busy = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Requestor.prototype.setResponseHandler = function(resp) {
|
||||||
|
this.responseHandler = resp;
|
||||||
|
};
|
||||||
Requestor.prototype.addRequest = function(url) {
|
Requestor.prototype.addRequest = function(url) {
|
||||||
if (this.busy) {
|
if (this.busy) {
|
||||||
this.que.push(url);
|
this.que.push(url);
|
||||||
@ -86,17 +93,36 @@ Requestor.prototype._openRequest = function(url) {
|
|||||||
} else {
|
} else {
|
||||||
url += '?output=xml';
|
url += '?output=xml';
|
||||||
}
|
}
|
||||||
g_req.open('get',this.baseUrl+url,true);
|
this.req.open('get',this.baseUrl+url,true);
|
||||||
g_req.onreadystatechange = Requestor_handleRequest;
|
this.req.onreadystatechange = Requestor_handleRequest;
|
||||||
g_req.send(null);
|
this.req.send(null);
|
||||||
};
|
};
|
||||||
Requestor_handleRequest = function() {
|
Requestor_handleRequest = function() {
|
||||||
if (4 == g_req.readyState) {
|
// readystate 4 means the whole document is loaded
|
||||||
// readystate 4 means the whole document is loaded
|
if (4 == g_requestor.req.readyState) {
|
||||||
if (200 == g_req.status) {
|
|
||||||
// Only try to parse the response if we got
|
// Only try to parse the response if we got
|
||||||
// ok from the server
|
// ok from the server
|
||||||
xmldoc = g_req.responseXML;
|
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) {
|
if ('daap.databaseplaylists' == xmldoc.firstChild.nodeName) {
|
||||||
el = document.getElementById('source');
|
el = document.getElementById('source');
|
||||||
addPlaylists(el,xmldoc);
|
addPlaylists(el,xmldoc);
|
||||||
@ -115,6 +141,8 @@ Requestor_handleRequest = function() {
|
|||||||
case 'daap.browsealbumlisting':
|
case 'daap.browsealbumlisting':
|
||||||
el = document.getElementById('album');
|
el = document.getElementById('album');
|
||||||
addOptions(el,'album',xmldoc);
|
addOptions(el,'album',xmldoc);
|
||||||
|
// All other boxes are updated, now get the songs
|
||||||
|
getSongs();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// We got something else back...
|
// We got something else back...
|
||||||
@ -123,28 +151,14 @@ Requestor_handleRequest = function() {
|
|||||||
// Songlist
|
// Songlist
|
||||||
addSongs(xmldoc);
|
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() {
|
function init() {
|
||||||
g_requestor = new Requestor(baseUrl);
|
req = new Requestor(baseUrl);
|
||||||
g_requestor.addRequest('databases/1/containers');
|
req.setResponseHandler(response);
|
||||||
g_requestor.addRequest('databases/1/browse/genres');
|
req.addRequest('databases/1/containers');
|
||||||
g_requestor.addRequest('databases/1/browse/artists');
|
req.addRequest('databases/1/browse/genres');
|
||||||
g_requestor.addRequest('databases/1/browse/albums');
|
req.addRequest('databases/1/browse/artists');
|
||||||
|
req.addRequest('databases/1/browse/albums');
|
||||||
el = document.getElementById('source');
|
el = document.getElementById('source');
|
||||||
el.addEventListener('change',playlistSelect,true);
|
el.addEventListener('change',playlistSelect,true);
|
||||||
|
|
||||||
@ -154,26 +168,10 @@ function init() {
|
|||||||
el = document.getElementById('artist');
|
el = document.getElementById('artist');
|
||||||
el.addEventListener('change',artistSelect,true);
|
el.addEventListener('change',artistSelect,true);
|
||||||
|
|
||||||
//###FIXME album select
|
|
||||||
return;
|
|
||||||
// get playlists
|
|
||||||
|
|
||||||
g_req.open('get',baseUrl+'databases/1/containers?output=xml',false);
|
|
||||||
g_req.send(null);
|
|
||||||
|
|
||||||
|
|
||||||
g_req.open('get',baseUrl+'databases/1/browse/genres?output=xml',false);
|
|
||||||
g_req.send(null);
|
|
||||||
|
|
||||||
g_req.open('get',baseUrl+'databases/1/browse/artists?output=xml',false);
|
|
||||||
g_req.send(null);
|
|
||||||
|
|
||||||
g_req.open('get',baseUrl+'databases/1/browse/albums?output=xml',false);
|
|
||||||
g_req.send(null);
|
|
||||||
el = document.getElementById('album');
|
el = document.getElementById('album');
|
||||||
addOptions(el,'album',g_req.responseXML);
|
el.addEventListener('change',albumSelect,true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addOptions(el,label,xmldoc) {
|
function addOptions(el,label,xmldoc) {
|
||||||
while(el.hasChildNodes()) {
|
while(el.hasChildNodes()) {
|
||||||
el.removeChild(el.firstChild);
|
el.removeChild(el.firstChild);
|
||||||
@ -191,26 +189,27 @@ function addOptions(el,label,xmldoc) {
|
|||||||
el.appendChild(option);
|
el.appendChild(option);
|
||||||
|
|
||||||
items = xmldoc.getElementsByTagName('dmap.listingitem');
|
items = xmldoc.getElementsByTagName('dmap.listingitem');
|
||||||
|
selectAll = true;
|
||||||
for (i=0; i<items.length; i++) {
|
for (i=0; i<items.length; i++) {
|
||||||
option = document.createElement('option');
|
option = document.createElement('option');
|
||||||
itemName = items[i].textContent;
|
itemName = items[i].textContent;
|
||||||
option.value = itemName;
|
option.value = itemName;
|
||||||
selectAll = true;
|
|
||||||
switch (label) {
|
switch (label) {
|
||||||
case 'genre':
|
case 'genre':
|
||||||
if (g_selectedGenres[itemName]) {
|
if (g_selectedGenres[itemName]) {
|
||||||
//option.selected = true;
|
option.selected = true;
|
||||||
selectAll = false;
|
selectAll = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'artist':
|
case 'artist':
|
||||||
if (g_selectedArtists[itemName]) {
|
if (g_selectedArtists[itemName]) {
|
||||||
//option.selected = true;
|
option.selected = true;
|
||||||
selectAll = false;
|
selectAll = false;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case 'album':
|
case 'album':
|
||||||
if (g_selectedAlbums[itemName]) {
|
if (g_selectedAlbums[itemName]) {
|
||||||
//option.selected = true;
|
option.selected = true;
|
||||||
selectAll = false;
|
selectAll = false;
|
||||||
}
|
}
|
||||||
default: // if we get here something is wrong
|
default: // if we get here something is wrong
|
||||||
@ -221,15 +220,26 @@ function addOptions(el,label,xmldoc) {
|
|||||||
el.appendChild(option);
|
el.appendChild(option);
|
||||||
}
|
}
|
||||||
if (selectAll) {
|
if (selectAll) {
|
||||||
|
// clear the global selections arrays
|
||||||
el.options[0].selected = true;
|
el.options[0].selected = true;
|
||||||
|
switch (label) {
|
||||||
|
case 'genre':
|
||||||
|
g_selectedGenres = Array();
|
||||||
|
break;
|
||||||
|
case 'artist':
|
||||||
|
g_selectedArtists = Array();
|
||||||
|
break;
|
||||||
|
case 'album':
|
||||||
|
g_selectedAlbums = Array();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Can't get here
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
el.removeAttribute('selected');
|
el.options[0].selected = false;
|
||||||
}
|
|
||||||
if ('album' == label) {
|
|
||||||
//### All other boxes are updated, this is the last one, now get the songs
|
|
||||||
getSongs();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPlaylists(el,xmldoc) {
|
function addPlaylists(el,xmldoc) {
|
||||||
//items = xmldoc.getElementsByTagName('dmap.listingitem');
|
//items = xmldoc.getElementsByTagName('dmap.listingitem');
|
||||||
list = xmldoc.childNodes[0].childNodes[4];
|
list = xmldoc.childNodes[0].childNodes[4];
|
||||||
@ -243,6 +253,7 @@ function addPlaylists(el,xmldoc) {
|
|||||||
el.appendChild(option);
|
el.appendChild(option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function playlistSelect(event) {
|
function playlistSelect(event) {
|
||||||
table = document.getElementById('songs');
|
table = document.getElementById('songs');
|
||||||
tableBody = removeRows(table);
|
tableBody = removeRows(table);
|
||||||
@ -345,6 +356,7 @@ function genreSelect(event) {
|
|||||||
}
|
}
|
||||||
filter = '?filter=' + filter.join(',');
|
filter = '?filter=' + filter.join(',');
|
||||||
}
|
}
|
||||||
|
//dump(DataDumper(g_selectedGenres));
|
||||||
g_requestor.addRequest('databases/1/browse/artists' + filter);
|
g_requestor.addRequest('databases/1/browse/artists' + filter);
|
||||||
g_requestor.addRequest('databases/1/browse/albums' + filter);
|
g_requestor.addRequest('databases/1/browse/albums' + filter);
|
||||||
}
|
}
|
||||||
@ -408,7 +420,7 @@ function getSongs() {
|
|||||||
// so set filter to empty
|
// so set filter to empty
|
||||||
query = '';
|
query = '';
|
||||||
} else {
|
} else {
|
||||||
query = '&query=' + query.join(',');
|
query = '&query=' + query.join(' ');
|
||||||
}
|
}
|
||||||
//alert(query);
|
//alert(query);
|
||||||
g_requestor.addRequest('databases/1/items' +
|
g_requestor.addRequest('databases/1/items' +
|
||||||
|
Loading…
Reference in New Issue
Block a user