Switched playlist.html from DAAP XML requests to RSP.

This is quite a bit of a fast hack, just to se if it works.
This commit is contained in:
Anders Betnér 2006-05-03 19:03:33 +00:00
parent 4fd83e45a9
commit db6e5dc480
2 changed files with 39 additions and 45 deletions

View File

@ -1974,12 +1974,12 @@ Rico.LiveGridBuffer.prototype = {
loadRows: function(ajaxResponse) { loadRows: function(ajaxResponse) {
var newRows = []; var newRows = [];
$A(ajaxResponse.responseXML.getElementsByTagName('dmap.listingitem')).each(function (el) { $A(ajaxResponse.responseXML.getElementsByTagName('item')).each(function (el) {
var row = []; var row = [];
row.push({id:Element.textContent(el.getElementsByTagName('dmap.itemid')[0]), row.push({id:Element.textContent(el.getElementsByTagName('id')[0]),
name: Element.textContent(el.getElementsByTagName('dmap.itemname')[0])}); name: Element.textContent(el.getElementsByTagName('title')[0])});
['daap.songtime','daap.songartist','daap.songalbum'].each(function (name) { ['disc','artist','album'].each(function (name) {
if ('daap.songtime' == name) { if ('disc' == name) {
var time = parseInt(Element.textContent(el.getElementsByTagName(name)[0])); var time = parseInt(Element.textContent(el.getElementsByTagName(name)[0]));
time = Math.round(time / 1000); time = Math.round(time / 1000);
var seconds = time % 60; var seconds = time % 60;
@ -2406,7 +2406,7 @@ Rico.LiveGrid.prototype = {
this.ajaxOptions.parameters = queryString; this.ajaxOptions.parameters = queryString;
var end = bufferStartPos+fetchSize; var end = bufferStartPos+fetchSize;
new Ajax.Request(Query.getFullUrl('songs')+'&index='+bufferStartPos+'-'+end,{method: 'get',onComplete: this.ajaxUpdate.bind(this)}); new Ajax.Request(Query.getFullUrl('songs')+'&offset='+bufferStartPos+'&limit='+fetchSize,{method: 'get',onComplete: this.ajaxUpdate.bind(this)});
// ajaxEngine.sendRequest( this.tableId + '_request', this.ajaxOptions ); // ajaxEngine.sendRequest( this.tableId + '_request', this.ajaxOptions );
this.timeoutHandler = setTimeout( this.handleTimedOut.bind(this), this.options.bufferTimeout); this.timeoutHandler = setTimeout( this.handleTimedOut.bind(this), this.options.bufferTimeout);
@ -2426,7 +2426,7 @@ Rico.LiveGrid.prototype = {
ajaxUpdate: function(ajaxResponse) { ajaxUpdate: function(ajaxResponse) {
try { try {
clearTimeout( this.timeoutHandler ); clearTimeout( this.timeoutHandler );
var totalRows = ajaxResponse.responseXML.getElementsByTagName('dmap.specifiedtotalcount')[0].firstChild.nodeValue; var totalRows = ajaxResponse.responseXML.getElementsByTagName('totalrecords')[0].firstChild.nodeValue;
if (this.metaData.getTotalRows() != totalRows) { if (this.metaData.getTotalRows() != totalRows) {
this.setTotalRows(totalRows); this.setTotalRows(totalRows);
} }

View File

@ -256,8 +256,8 @@ var EventHandler = {
}; };
var Query = { var Query = {
baseUrl: '/databases/1/', baseUrl: '/rsp/db/',
playlistUrl: '', playlistId: '1',
genres: [], genres: [],
artists:[], artists:[],
albums: [], albums: [],
@ -277,34 +277,30 @@ var Query = {
Query.clearSelection('artists'); Query.clearSelection('artists');
Query.clearSelection('albums'); Query.clearSelection('albums');
Query.setSearchString(''); Query.setSearchString('');
if (1 == playlistId) { Query.playlistId = playlistId;
Query.playlistUrl = '';
} else {
Query.playlistUrl = 'containers/' + playlistId + '/';
}
}, },
getUrl: function (type) { getUrl: function (type) {
var query=[]; var query=[];
switch (type) { switch (type) {
case 'artists': case 'artists':
if (this.genres.length > 0) { if (this.genres.length > 0) {
query = this.genres.collect(function(value){return "'daap.songgenre:"+value.encode()+"'";}); query = this.genres.collect(function(value){return 'genre%3D"'+value.encode()+'"';});
} }
break; break;
case 'albums': case 'albums':
if (this.artists.length > 0) { if (this.artists.length > 0) {
query = this.artists.collect(function(value){return "'daap.songartist:"+value.encode()+"'";}); query = this.artists.collect(function(value){return 'artist%3D"'+value.encode()+'"';});
} else if (this.genres.length > 0) { } else if (this.genres.length > 0) {
query = this.genres.collect(function(value){return "'daap.songgenre:"+value.encode()+"'";}); query = this.genres.collect(function(value){return 'genre%3D"'+value.encode()+'"';});
} }
break; break;
case 'songs': case 'songs':
if (this.albums.length > 0) { if (this.albums.length > 0) {
query = this.albums.collect(function(value){return "'daap.songalbum:"+value.encode()+"'";}); query = this.albums.collect(function(value){return 'album%3D"'+value.encode()+'"';});
} else if (this.artists.length > 0) { } else if (this.artists.length > 0) {
query = this.artists.collect(function(value){return "'daap.songartist:"+value.encode()+"'";}); query = this.artists.collect(function(value){return 'artist%3D"'+value.encode()+'"';});
} else if (this.genres.length > 0) { } else if (this.genres.length > 0) {
query = this.genres.collect(function(value){return "'daap.songgenre:"+value.encode()+"'";}); query = this.genres.collect(function(value){return 'genre%3D"'+value.encode()+'"';});
} }
break; break;
default: default:
@ -314,17 +310,17 @@ var Query = {
if (this.searchString) { if (this.searchString) {
var search = []; var search = [];
var string = this.searchString.encode(); var string = this.searchString.encode();
['daap.songgenre','daap.songartist','daap.songalbum','dmap.itemname'].each(function (item) { ['genre','artist','album','title'].each(function (item) {
search.push("'" + item +':*' + string + "*'"); search.push(item +' includes "' + string + '"');
}); });
if (query.length > 0) { if (query.length > 0) {
return '&query=(' +search.join(',') + ')+('.encode() + query.join(',')+ ')'; return '&query=(' + search.join(' or ') + ') and ('.encode() + query.join(' or ')+ ')';
} else { } else {
return '&query=' + search.join(','); return '&query=' + search.join(' or ');
} }
} else { } else {
if (query.length > 0) { if (query.length > 0) {
return '&query=' + query.join(','); return '&query=' + query.join(' or ');
} else { } else {
return ''; return '';
} }
@ -337,27 +333,27 @@ var Query = {
var meta = ''; var meta = '';
switch (type) { switch (type) {
case 'genres': case 'genres':
url = 'browse/genres'; url = '/genre';
break; break;
case 'artists': case 'artists':
url = 'browse/artists'; url = '/artist';
break; break;
case 'albums': case 'albums':
url = 'browse/albums'; url = '/album';
break; break;
case 'songs': case 'songs':
url = 'items'; url = '';
meta = '&meta=daap.songalbum,daap.songartist,daap.songgenre,dmap.itemid,daap.songtime,dmap.itemname'; meta = '&type=browse';
break; break;
default: default:
alert("Shouldn't happen 2"); alert("Shouldn't happen 2");
break; break;
} }
return this.baseUrl + this.playlistUrl + url + '?output=xml' + meta + this.getUrl(type); return this.baseUrl + this.playlistId + url + '?dummy=' + meta + this.getUrl(type);
}, },
send: function(type) { send: function(type) {
if (('genres' == type) || ('artists' == type) || ('albums' == type)) { if (('genres' == type) || ('artists' == type) || ('albums' == type)) {
handler = ResponseHandler.genreAlbumArtist; handler = ResponseHandler[type];
} else { } else {
return; return;
// handler = rsSongs; // handler = rsSongs;
@ -366,19 +362,17 @@ var Query = {
} }
}; };
var ResponseHandler = { var ResponseHandler = {
genreAlbumArtist: function (request) { genres: function (request) {
var type; ResponseHandler._genreAlbumArtist(request,'genres');
if (request.responseXML.getElementsByTagName('daap.browsegenrelisting').length > 0) { },
type = 'genres'; artists: function (request) {
} ResponseHandler._genreAlbumArtist(request,'artists');
if (request.responseXML.getElementsByTagName('daap.browseartistlisting').length > 0) { },
type = 'artists'; albums: function (request) {
} ResponseHandler._genreAlbumArtist(request,'albums');
if (request.responseXML.getElementsByTagName('daap.browsealbumlisting').length > 0) { },
type = 'albums'; _genreAlbumArtist: function (request,type) {
} var items = $A(request.responseXML.getElementsByTagName('item'));
var items = $A(request.responseXML.getElementsByTagName('dmap.listingitem'));
items = items.collect(function (el) { items = items.collect(function (el) {
return Element.textContent(el); return Element.textContent(el);
}).sort(); }).sort();