Fixed playlist.js browse and search

Added index=0-50 to query. (Song lists with more than 51 hits will
be truncated to 51 hits.) This is temporary until the rico live
grid works.
This commit is contained in:
Anders Betnér 2006-03-25 12:48:51 +00:00
parent 51a3a6279c
commit 2dcb98d6e3

View File

@ -1,6 +1,7 @@
Event.observe(window,'load',initPlaylist); Event.observe(window,'load',initPlaylist);
var MAX_SONGS= 400;
var SEARCH_DELAY = 500; // # ms without typing before the search box searches var SEARCH_DELAY = 500; // # ms without typing before the search box searches
var BROWSE_TEXT_LEN = 30; // Length to truncate genre/artist/album select boxes
Ajax.Responders.register({ onCreate: function () {$('busymsg').style.visibility='visible';}, Ajax.Responders.register({ onCreate: function () {$('busymsg').style.visibility='visible';},
onComplete: function () {if (!Query.busy) {$('busymsg').style.visibility='hidden';}}}); onComplete: function () {if (!Query.busy) {$('busymsg').style.visibility='hidden';}}});
function initPlaylist() { function initPlaylist() {
@ -22,12 +23,12 @@ function initPlaylist() {
var Search = { var Search = {
timeOut: '', timeOut: '',
keyPress: function (e) { keyPress: function (e) {
if (this.timeOut) {
window.clearTimeout(this.timeOut);
}
if (e.keyCode == Event.KEY_RETURN) { if (e.keyCode == Event.KEY_RETURN) {
EventHandler.search(); EventHandler.search();
} else { } else {
if (this.timeOut) {
window.clearTimeout(this.timeOut);
}
this.timeOut = window.setTimeout(EventHandler.search,SEARCH_DELAY); this.timeOut = window.setTimeout(EventHandler.search,SEARCH_DELAY);
} }
} }
@ -128,6 +129,7 @@ var Query = {
var url; var url;
var handler; var handler;
var meta = ''; var meta = '';
var index = '';
switch (type) { switch (type) {
case 'genres': case 'genres':
url = '/databases/1/browse/genres'; url = '/databases/1/browse/genres';
@ -144,10 +146,11 @@ var Query = {
case 'songs': case 'songs':
url = '/databases/1/items'; url = '/databases/1/items';
meta = '&meta=daap.songalbum,daap.songartist,daap.songgenre,dmap.itemid,daap.songtime,dmap.itemname'; meta = '&meta=daap.songalbum,daap.songartist,daap.songgenre,dmap.itemid,daap.songtime,dmap.itemname';
index = '&index=0-50';
handler = rsSongs; handler = rsSongs;
break; break;
} }
url = url + '?output=xml' + meta + this.getUrl(type); url = url + '?output=xml' + index + meta + this.getUrl(type);
new Ajax.Request(url ,{method: 'get',onComplete:handler}); new Ajax.Request(url ,{method: 'get',onComplete:handler});
} }
}; };
@ -175,6 +178,7 @@ var ResponseHandler = {
o.value = 'all'; o.value = 'all';
o.appendChild(document.createTextNode('All (' + items.length + ' ' + type + ')')); o.appendChild(document.createTextNode('All (' + items.length + ' ' + type + ')'));
select.appendChild(o); select.appendChild(o);
Query.clearSelection(type);
addOptions(select,items); addOptions(select,items);
select.value='all'; select.value='all';
switch (type) { switch (type) {
@ -237,13 +241,6 @@ function rsSongs(request) {
var items = $A(request.responseXML.getElementsByTagName('dmap.listingitem')); var items = $A(request.responseXML.getElementsByTagName('dmap.listingitem'));
var songsTable = $('songs_data'); var songsTable = $('songs_data');
Element.removeChildren(songsTable); Element.removeChildren(songsTable);
if (items.length > MAX_SONGS) {
var tr = document.createElement('tr');
tr.appendChild(Builder.node('td',{colspan: '5'},'Search returned > '+MAX_SONGS+' results'));
songsTable.appendChild(tr);
Query.busy = false;
return;
}
items.each(function (item) { items.each(function (item) {
var tr = document.createElement('tr'); var tr = document.createElement('tr');
var time = parseInt(Element.textContent(item.getElementsByTagName('daap.songtime')[0])); var time = parseInt(Element.textContent(item.getElementsByTagName('daap.songtime')[0]));
@ -266,11 +263,11 @@ function rsSongs(request) {
function addOptions(element,options) { function addOptions(element,options) {
options.each(function (option) { options.each(function (option) {
var node; var node;
var text = option.truncate(25); var text = option.truncate(BROWSE_TEXT_LEN);
if (option.length != text.length) { if (option.length != text.length) {
node = Builder.node('option',{value: option, title: option},option.truncate(25)); node = Builder.node('option',{value: option, title: option},text);
} else { } else {
node = Builder.node('option',{value: option},option.truncate(25)); node = Builder.node('option',{value: option},text);
} }
node.selected = false; node.selected = false;
element.appendChild(node); element.appendChild(node);