2006-03-29 04:02:39 -05:00
|
|
|
// TODO
|
|
|
|
// Find a decent spinner instad of the busy text
|
|
|
|
// Handle 'all' in select boxes
|
|
|
|
// move stuff to responsehandler
|
|
|
|
// handle source change events
|
|
|
|
// navigate source with arrow keys and then click selected should initiate edit
|
|
|
|
// new playlist twice gives server response 500
|
|
|
|
// After playlist name edit, it should be activated again.
|
|
|
|
// After playlist delete, select another one
|
|
|
|
|
2006-03-21 16:59:18 -05:00
|
|
|
Event.observe(window,'load',initPlaylist);
|
2006-03-25 07:48:51 -05:00
|
|
|
|
2006-03-24 06:44:50 -05:00
|
|
|
var SEARCH_DELAY = 500; // # ms without typing before the search box searches
|
2006-03-25 07:48:51 -05:00
|
|
|
var BROWSE_TEXT_LEN = 30; // Length to truncate genre/artist/album select boxes
|
2006-03-21 16:59:18 -05:00
|
|
|
Ajax.Responders.register({ onCreate: function () {$('busymsg').style.visibility='visible';},
|
2006-03-24 06:44:50 -05:00
|
|
|
onComplete: function () {if (!Query.busy) {$('busymsg').style.visibility='hidden';}}});
|
2006-03-21 16:59:18 -05:00
|
|
|
function initPlaylist() {
|
|
|
|
new Ajax.Request('/databases/1/containers?output=xml',{method: 'get',onComplete:rsSource});
|
|
|
|
Query.send('genres');
|
2006-03-23 17:00:38 -05:00
|
|
|
Event.observe('search','keypress',Search.keyPress);
|
|
|
|
Event.observe('source','change',EventHandler.sourceChange);
|
2006-03-27 15:26:12 -05:00
|
|
|
Event.observe('source','click',EventHandler.sourceClick);
|
2006-03-27 17:19:18 -05:00
|
|
|
Event.observe('source','keypress',EventHandler.sourceKeyPress);
|
2006-03-23 17:00:38 -05:00
|
|
|
Event.observe('genres','change',EventHandler.genresChange);
|
|
|
|
Event.observe('artists','change',EventHandler.artistsChange);
|
|
|
|
Event.observe('albums','change',EventHandler.albumsChange);
|
2006-03-27 15:26:12 -05:00
|
|
|
|
|
|
|
Event.observe(document,'click',GlobalEvents.click);
|
|
|
|
Event.observe('edit_playlist_name','keypress',EditPlaylistName.keyPress);
|
2006-03-24 02:47:43 -05:00
|
|
|
// Firefox remebers the search box value on page reload
|
2006-03-24 06:44:50 -05:00
|
|
|
Field.clear('search');
|
2006-03-23 17:00:38 -05:00
|
|
|
}
|
2006-03-27 15:26:12 -05:00
|
|
|
var GlobalEvents = {
|
2006-03-27 16:56:26 -05:00
|
|
|
_clickListeners: [],
|
2006-03-27 15:26:12 -05:00
|
|
|
click: function (e) {
|
2006-03-27 16:56:26 -05:00
|
|
|
GlobalEvents._clickListeners.each(function (name) {
|
2006-03-27 15:26:12 -05:00
|
|
|
name.click(e);
|
|
|
|
});
|
|
|
|
},
|
2006-03-27 16:56:26 -05:00
|
|
|
addClickListener: function (el) {
|
|
|
|
this._clickListeners.push(el);
|
2006-03-27 15:26:12 -05:00
|
|
|
},
|
2006-03-27 16:56:26 -05:00
|
|
|
removeClickListener: function (el) {
|
|
|
|
this._clickListeners = this._clickListeners.findAll(function (element) {
|
2006-03-27 15:26:12 -05:00
|
|
|
return (element != el);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2006-03-24 02:47:43 -05:00
|
|
|
|
2006-03-23 17:00:38 -05:00
|
|
|
var Search = {
|
2006-03-24 06:44:50 -05:00
|
|
|
timeOut: '',
|
2006-03-23 17:00:38 -05:00
|
|
|
keyPress: function (e) {
|
2006-03-25 07:48:51 -05:00
|
|
|
if (this.timeOut) {
|
|
|
|
window.clearTimeout(this.timeOut);
|
|
|
|
}
|
2006-03-23 17:00:38 -05:00
|
|
|
if (e.keyCode == Event.KEY_RETURN) {
|
|
|
|
EventHandler.search();
|
2006-03-24 06:44:50 -05:00
|
|
|
} else {
|
|
|
|
this.timeOut = window.setTimeout(EventHandler.search,SEARCH_DELAY);
|
2006-03-23 17:00:38 -05:00
|
|
|
}
|
|
|
|
}
|
2006-03-26 16:24:20 -05:00
|
|
|
};
|
2006-03-27 15:26:12 -05:00
|
|
|
var EditPlaylistName = {
|
|
|
|
playlistId: '',
|
|
|
|
playlistName: '',
|
2006-03-27 17:19:18 -05:00
|
|
|
_getOptionElement: function (id) {
|
2006-03-27 15:26:12 -05:00
|
|
|
return option = $A($('source').getElementsByTagName('option')).find(function (el) {
|
2006-03-27 17:19:18 -05:00
|
|
|
return (el.value == (id || EditPlaylistName.playlistId));
|
2006-03-27 15:26:12 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
keyPress: function (e) {
|
|
|
|
input = $('edit_playlist_name');
|
|
|
|
if (e.keyCode == Event.KEY_ESC) {
|
|
|
|
EditPlaylistName.hide();
|
|
|
|
}
|
|
|
|
if (e.keyCode == Event.KEY_RETURN) {
|
|
|
|
EditPlaylistName.save();
|
|
|
|
}
|
|
|
|
},
|
2006-03-27 16:56:26 -05:00
|
|
|
add: function () {
|
|
|
|
var url = '/databases/1/containers/add?output=xml';
|
2006-03-29 04:02:39 -05:00
|
|
|
url += '&org.mt-daapd.playlist-type=0&dmap.itemname=untitled%20playlist';
|
2006-03-27 16:56:26 -05:00
|
|
|
new Ajax.Request(url ,{method: 'get',onComplete:EditPlaylistName.responseAdd});
|
|
|
|
},
|
2006-03-27 17:19:18 -05:00
|
|
|
remove: function () {
|
|
|
|
if (window.confirm('Really delete playlist?')) {
|
|
|
|
var url = '/databases/1/containers/del?output=xml';
|
|
|
|
url += '&dmap.itemid=' + $('source').value;
|
|
|
|
new Ajax.Request(url ,{method: 'get',onComplete:EditPlaylistName.response});
|
|
|
|
var option = EditPlaylistName._getOptionElement($('source').value);
|
|
|
|
Element.remove(option);
|
|
|
|
}
|
|
|
|
},
|
2006-03-27 15:26:12 -05:00
|
|
|
save: function () {
|
|
|
|
input = $('edit_playlist_name');
|
|
|
|
var url = '/databases/1/containers/edit?output=xml';
|
|
|
|
url += '&dmap.itemid=' + EditPlaylistName.playlistId;
|
2006-03-29 06:24:46 -05:00
|
|
|
url += '&dmap.itemname=' + encodeURIComponent(input.value);
|
2006-03-27 15:26:12 -05:00
|
|
|
new Ajax.Request(url ,{method: 'get',onComplete:EditPlaylistName.response});
|
|
|
|
var option = EditPlaylistName._getOptionElement();
|
|
|
|
option.text = input.value;
|
|
|
|
EditPlaylistName.hide();
|
|
|
|
},
|
|
|
|
show: function () {
|
|
|
|
input = $('edit_playlist_name');
|
2006-03-27 16:56:26 -05:00
|
|
|
input.style.top = RicoUtil.toDocumentPosition(EditPlaylistName._getOptionElement()).y+ 'px';
|
2006-03-27 15:26:12 -05:00
|
|
|
input.value = this.playlistName;
|
|
|
|
input.style.display = 'block';
|
|
|
|
Field.activate(input);
|
2006-03-27 16:56:26 -05:00
|
|
|
GlobalEvents.addClickListener(this);
|
2006-03-27 15:26:12 -05:00
|
|
|
},
|
|
|
|
hide: function () {
|
|
|
|
$('edit_playlist_name').style.display = 'none';
|
|
|
|
EditPlaylistName.playlistId = '';
|
2006-03-27 16:56:26 -05:00
|
|
|
GlobalEvents.removeClickListener(this);
|
2006-03-27 15:26:12 -05:00
|
|
|
},
|
|
|
|
response: function (request) {
|
2006-03-27 16:12:28 -05:00
|
|
|
// Check that the save gave response 200 OK
|
2006-03-27 15:26:12 -05:00
|
|
|
},
|
2006-03-27 16:56:26 -05:00
|
|
|
responseAdd: function(request) {
|
|
|
|
var status = Element.textContent(request.responseXML.getElementsByTagName('dmap.status')[0]);
|
|
|
|
if ('200' != status) {
|
2006-03-29 04:02:39 -05:00
|
|
|
alert('There is a playlist with that name, write some code to handle this');
|
2006-03-27 16:56:26 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
EditPlaylistName.playlistId = Element.textContent(request.responseXML.getElementsByTagName('dmap.itemid')[0]);
|
2006-03-29 04:02:39 -05:00
|
|
|
EditPlaylistName.playlistName = 'untitled playlist';
|
2006-03-27 16:56:26 -05:00
|
|
|
var o = document.createElement('option');
|
|
|
|
o.value = EditPlaylistName.playlistId;
|
|
|
|
o.text = EditPlaylistName.playlistName;
|
|
|
|
$('static_playlists').appendChild(o);
|
|
|
|
$('source').value = EditPlaylistName.playlistId;
|
|
|
|
EditPlaylistName.show();
|
|
|
|
Query.setSource(EditPlaylistName.playlistId);
|
|
|
|
Query.send('genres');
|
|
|
|
},
|
2006-03-27 15:26:12 -05:00
|
|
|
click: function (e) {
|
2006-03-27 16:12:28 -05:00
|
|
|
var x = Event.pointerX(e);
|
|
|
|
var y = Event.pointerY(e);
|
|
|
|
var el = $('edit_playlist_name');
|
|
|
|
var pos = RicoUtil.toViewportPosition(el);
|
|
|
|
if ((x > pos.x) && (x < pos.x + el.offsetWidth) &&
|
|
|
|
(y > pos.y) && (y < pos.y + el.offsetHeight)) {
|
|
|
|
// Click was in input box
|
|
|
|
return;
|
|
|
|
}
|
2006-03-27 15:26:12 -05:00
|
|
|
if (EditPlaylistName.playlistId) {
|
2006-03-27 16:12:28 -05:00
|
|
|
EditPlaylistName.save();
|
2006-03-27 15:26:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-03-23 17:00:38 -05:00
|
|
|
var EventHandler = {
|
2006-03-27 15:26:12 -05:00
|
|
|
sourceClickCount: [],
|
|
|
|
sourceClick: function (e) {
|
|
|
|
var playlistId = Event.element(e).value;
|
|
|
|
if (1 == playlistId) {
|
|
|
|
// do nothing for Library
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (EventHandler.sourceClickCount[playlistId]) {
|
|
|
|
EventHandler.sourceClickCount[playlistId]++
|
|
|
|
} else {
|
|
|
|
EventHandler.sourceClickCount[playlistId] = 1;
|
|
|
|
}
|
|
|
|
if (EventHandler.sourceClickCount[playlistId] > 1) {
|
|
|
|
el = Event.element(e);
|
|
|
|
if (!el.text) {
|
|
|
|
// Firefox generates and event when clicking in and empty area
|
|
|
|
// of the select box
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EditPlaylistName.playlistId = el.value;
|
|
|
|
EditPlaylistName.playlistName = el.text;
|
|
|
|
EditPlaylistName.show();
|
|
|
|
}
|
|
|
|
},
|
2006-03-23 17:00:38 -05:00
|
|
|
sourceChange: function (e) {
|
2006-03-27 15:26:12 -05:00
|
|
|
EventHandler.sourceClickCount = [];
|
2006-03-27 04:34:12 -05:00
|
|
|
Field.clear('search');
|
|
|
|
var playlistId = $('source').value;
|
2006-03-27 16:56:26 -05:00
|
|
|
Query.setSource(playlistId);
|
2006-03-27 04:34:12 -05:00
|
|
|
Query.send('genres');
|
2006-03-23 17:00:38 -05:00
|
|
|
},
|
2006-03-27 17:19:18 -05:00
|
|
|
sourceKeyPress: function (e) {
|
|
|
|
if (e.keyCode == Event.KEY_DELETE) {
|
|
|
|
EditPlaylistName.remove();
|
|
|
|
}
|
2006-03-29 04:02:39 -05:00
|
|
|
if (113 == e.keyCode) {
|
|
|
|
// F2
|
|
|
|
//TODO edit playist, what is the key on a mac?
|
|
|
|
}
|
2006-03-27 17:19:18 -05:00
|
|
|
},
|
2006-03-23 17:00:38 -05:00
|
|
|
search: function () {
|
|
|
|
Query.setSearchString($('search').value);
|
|
|
|
Query.send('genres');
|
|
|
|
},
|
|
|
|
genresChange: function (e) {
|
|
|
|
EventHandler.setSelected('genres');
|
|
|
|
Query.send('artists');
|
|
|
|
},
|
|
|
|
artistsChange: function (e) {
|
|
|
|
EventHandler.setSelected('artists');
|
|
|
|
Query.send('albums');
|
|
|
|
},
|
|
|
|
albumsChange: function (e) {
|
|
|
|
EventHandler.setSelected('albums');
|
|
|
|
Query.send('songs');
|
|
|
|
},
|
|
|
|
setSelected: function (type) {
|
|
|
|
var options = $A($(type).options);
|
|
|
|
Query.clearSelection(type);
|
|
|
|
if ($(type).value != 'all') {
|
|
|
|
options.each(function (option) {
|
|
|
|
if (option.selected) {
|
|
|
|
Query.addSelection(type,option.value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2006-03-26 16:24:20 -05:00
|
|
|
};
|
2006-03-26 16:14:03 -05:00
|
|
|
|
2006-03-21 16:59:18 -05:00
|
|
|
var Query = {
|
2006-03-27 04:34:12 -05:00
|
|
|
baseUrl: '/databases/1/',
|
|
|
|
playlistUrl: '',
|
2006-03-23 17:00:38 -05:00
|
|
|
genres: [],
|
|
|
|
artists:[],
|
|
|
|
albums: [],
|
2006-03-24 06:44:50 -05:00
|
|
|
busy: '',
|
2006-03-24 02:09:31 -05:00
|
|
|
searchString: '',
|
2006-03-23 17:00:38 -05:00
|
|
|
clearSelection: function (type) {
|
|
|
|
this[type] = [];
|
2006-03-21 16:59:18 -05:00
|
|
|
},
|
|
|
|
addSelection: function (type,value){
|
|
|
|
this[type].push(value);
|
|
|
|
},
|
2006-03-23 17:00:38 -05:00
|
|
|
setSearchString: function (string) {
|
|
|
|
this.searchString = string;
|
|
|
|
},
|
2006-03-27 16:56:26 -05:00
|
|
|
setSource: function (playlistId) {
|
|
|
|
Query.clearSelection('genres');
|
|
|
|
Query.clearSelection('artists');
|
|
|
|
Query.clearSelection('albums');
|
|
|
|
Query.setSearchString('');
|
|
|
|
if (1 == playlistId) {
|
|
|
|
Query.playlistUrl = '';
|
|
|
|
} else {
|
|
|
|
Query.playlistUrl = 'containers/' + playlistId + '/';
|
|
|
|
}
|
|
|
|
},
|
2006-03-21 16:59:18 -05:00
|
|
|
getUrl: function (type) {
|
2006-03-23 17:00:38 -05:00
|
|
|
var query=[];
|
2006-03-21 16:59:18 -05:00
|
|
|
switch (type) {
|
|
|
|
case 'artists':
|
|
|
|
if (this.genres.length > 0) {
|
2006-03-26 16:14:03 -05:00
|
|
|
query = this.genres.collect(function(value){return "'daap.songgenre:"+value.encode()+"'";});
|
2006-03-21 16:59:18 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'albums':
|
|
|
|
if (this.artists.length > 0) {
|
|
|
|
query = this.artists.collect(function(value){return "'daap.songartist:"+value.encode()+"'";});
|
|
|
|
} else if (this.genres.length > 0) {
|
|
|
|
query = this.genres.collect(function(value){return "'daap.songgenre:"+value.encode()+"'";});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'songs':
|
|
|
|
if (this.albums.length > 0) {
|
|
|
|
query = this.albums.collect(function(value){return "'daap.songalbum:"+value.encode()+"'";});
|
|
|
|
} else if (this.artists.length > 0) {
|
|
|
|
query = this.artists.collect(function(value){return "'daap.songartist:"+value.encode()+"'";});
|
|
|
|
} else if (this.genres.length > 0) {
|
|
|
|
query = this.genres.collect(function(value){return "'daap.songgenre:"+value.encode()+"'";});
|
|
|
|
}
|
|
|
|
break;
|
2006-03-26 16:24:20 -05:00
|
|
|
default:
|
2006-03-26 16:34:57 -05:00
|
|
|
// Do nothing
|
2006-03-26 16:24:20 -05:00
|
|
|
break;
|
2006-03-21 16:59:18 -05:00
|
|
|
}
|
2006-03-23 17:00:38 -05:00
|
|
|
if (this.searchString) {
|
|
|
|
var search = [];
|
2006-03-24 02:47:43 -05:00
|
|
|
var string = this.searchString.encode();
|
2006-03-23 17:00:38 -05:00
|
|
|
['daap.songgenre','daap.songartist','daap.songalbum','dmap.itemname'].each(function (item) {
|
|
|
|
search.push("'" + item +':*' + string + "*'");
|
|
|
|
});
|
|
|
|
if (query.length > 0) {
|
2006-03-24 02:47:43 -05:00
|
|
|
return '&query=(' +search.join(',') + ')+('.encode() + query.join(',')+ ')';
|
2006-03-23 17:00:38 -05:00
|
|
|
} else {
|
|
|
|
return '&query=' + search.join(',');
|
|
|
|
}
|
2006-03-24 02:09:31 -05:00
|
|
|
} else {
|
|
|
|
if (query.length > 0) {
|
|
|
|
return '&query=' + query.join(',');
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
2006-03-21 16:59:18 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
send: function (type) {
|
2006-03-24 06:44:50 -05:00
|
|
|
this.busy = true;
|
2006-03-21 16:59:18 -05:00
|
|
|
var url;
|
|
|
|
var handler;
|
|
|
|
var meta = '';
|
2006-03-25 07:48:51 -05:00
|
|
|
var index = '';
|
2006-03-21 16:59:18 -05:00
|
|
|
switch (type) {
|
|
|
|
case 'genres':
|
2006-03-27 04:34:12 -05:00
|
|
|
url = 'browse/genres';
|
2006-03-23 17:00:38 -05:00
|
|
|
handler = ResponseHandler.genreAlbumArtist;
|
2006-03-21 16:59:18 -05:00
|
|
|
break;
|
|
|
|
case 'artists':
|
2006-03-27 04:34:12 -05:00
|
|
|
url = 'browse/artists';
|
2006-03-23 17:00:38 -05:00
|
|
|
handler = ResponseHandler.genreAlbumArtist;
|
2006-03-21 16:59:18 -05:00
|
|
|
break;
|
|
|
|
case 'albums':
|
2006-03-27 04:34:12 -05:00
|
|
|
url = 'browse/albums';
|
2006-03-23 17:00:38 -05:00
|
|
|
handler = ResponseHandler.genreAlbumArtist;
|
2006-03-21 16:59:18 -05:00
|
|
|
break;
|
|
|
|
case 'songs':
|
2006-03-27 04:34:12 -05:00
|
|
|
url = 'items';
|
2006-03-21 16:59:18 -05:00
|
|
|
meta = '&meta=daap.songalbum,daap.songartist,daap.songgenre,dmap.itemid,daap.songtime,dmap.itemname';
|
2006-03-25 07:48:51 -05:00
|
|
|
index = '&index=0-50';
|
2006-03-21 16:59:18 -05:00
|
|
|
handler = rsSongs;
|
|
|
|
break;
|
2006-03-26 16:24:20 -05:00
|
|
|
default:
|
|
|
|
alert("Shouldn't happen 2");
|
|
|
|
break;
|
2006-03-21 16:59:18 -05:00
|
|
|
}
|
2006-03-27 04:34:12 -05:00
|
|
|
url = this.baseUrl + this.playlistUrl + url + '?output=xml' + index + meta + this.getUrl(type);
|
2006-03-21 16:59:18 -05:00
|
|
|
new Ajax.Request(url ,{method: 'get',onComplete:handler});
|
|
|
|
}
|
2005-03-16 14:56:40 -05:00
|
|
|
};
|
2006-03-23 17:00:38 -05:00
|
|
|
var ResponseHandler = {
|
|
|
|
genreAlbumArtist: function (request) {
|
|
|
|
var type;
|
|
|
|
if (request.responseXML.getElementsByTagName('daap.browsegenrelisting').length > 0) {
|
|
|
|
type = 'genres';
|
|
|
|
}
|
|
|
|
if (request.responseXML.getElementsByTagName('daap.browseartistlisting').length > 0) {
|
|
|
|
type = 'artists';
|
|
|
|
}
|
|
|
|
if (request.responseXML.getElementsByTagName('daap.browsealbumlisting').length > 0) {
|
|
|
|
type = 'albums';
|
|
|
|
}
|
|
|
|
|
|
|
|
var items = $A(request.responseXML.getElementsByTagName('dmap.listingitem'));
|
|
|
|
items = items.collect(function (el) {
|
|
|
|
return Element.textContent(el);
|
|
|
|
}).sort();
|
|
|
|
var select = $(type);
|
|
|
|
Element.removeChildren(select);
|
2005-03-05 19:16:58 -05:00
|
|
|
|
2006-03-23 17:00:38 -05:00
|
|
|
var o = document.createElement('option');
|
|
|
|
o.value = 'all';
|
|
|
|
o.appendChild(document.createTextNode('All (' + items.length + ' ' + type + ')'));
|
|
|
|
select.appendChild(o);
|
2006-03-26 16:14:03 -05:00
|
|
|
var selected = {};
|
|
|
|
Query[type].each(function(item) {
|
|
|
|
selected[item] = true;
|
|
|
|
});
|
|
|
|
Query.clearSelection(type);
|
|
|
|
if (addOptions(type,items,selected)) {
|
|
|
|
select.value='all';
|
|
|
|
}
|
2006-03-23 17:00:38 -05:00
|
|
|
switch (type) {
|
|
|
|
case 'genres':
|
|
|
|
Query.send('artists');
|
|
|
|
break;
|
|
|
|
case 'artists':
|
|
|
|
Query.send('albums');
|
|
|
|
break;
|
|
|
|
case 'albums':
|
|
|
|
Query.send('songs');
|
|
|
|
break;
|
2006-03-26 16:24:20 -05:00
|
|
|
default:
|
|
|
|
alert("Shouldn't happen 3");
|
|
|
|
break;
|
2006-03-23 17:00:38 -05:00
|
|
|
}
|
|
|
|
}
|
2006-03-26 16:24:20 -05:00
|
|
|
};
|
2006-03-26 16:14:03 -05:00
|
|
|
function addOptions(type,options,selected) {
|
|
|
|
el = $(type);
|
|
|
|
var nothingSelected = true;
|
|
|
|
options.each(function (option) {
|
|
|
|
var node;
|
|
|
|
//###FIXME I have no idea why the Builder.node can't create options
|
|
|
|
// with the selected state I want.
|
|
|
|
var o = document.createElement('option');
|
|
|
|
o.value = option;
|
|
|
|
var text = option.truncate(BROWSE_TEXT_LEN);
|
|
|
|
if (option.length != text.length) {
|
|
|
|
o.title = option;
|
|
|
|
o.appendChild(document.createTextNode(text));
|
|
|
|
} else {
|
|
|
|
o.appendChild(document.createTextNode(option));
|
|
|
|
}
|
|
|
|
if (selected[option]) {
|
|
|
|
o.selected = true;
|
|
|
|
nothingSelected = false;
|
|
|
|
Query.addSelection(type,option);
|
|
|
|
} else {
|
|
|
|
o.selected = false;
|
|
|
|
}
|
|
|
|
el.appendChild(o);
|
|
|
|
});
|
|
|
|
return nothingSelected;
|
|
|
|
}
|
2005-03-21 14:53:39 -05:00
|
|
|
|
2006-03-21 16:59:18 -05:00
|
|
|
function rsSource(request) {
|
|
|
|
var items = $A(request.responseXML.getElementsByTagName('dmap.listingitem'));
|
|
|
|
var sourceSelect = $('source');
|
2006-03-23 17:00:38 -05:00
|
|
|
var smartPlaylists = [];
|
|
|
|
var staticPlaylists = [];
|
2006-03-21 16:59:18 -05:00
|
|
|
Element.removeChildren(sourceSelect);
|
2005-03-16 14:56:40 -05:00
|
|
|
|
2006-03-21 16:59:18 -05:00
|
|
|
items.each(function (item,index) {
|
|
|
|
if (0 === index) {
|
|
|
|
// Skip Library
|
2005-03-21 14:53:39 -05:00
|
|
|
return;
|
2006-03-21 16:59:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item.getElementsByTagName('com.apple.itunes.smart-playlist').length > 0) {
|
|
|
|
smartPlaylists.push({name: Element.textContent(item.getElementsByTagName('dmap.itemname')[0]),
|
|
|
|
id: Element.textContent(item.getElementsByTagName('dmap.itemid')[0])});
|
2005-03-21 14:53:39 -05:00
|
|
|
} else {
|
2006-03-21 16:59:18 -05:00
|
|
|
staticPlaylists.push({name: Element.textContent(item.getElementsByTagName('dmap.itemname')[0]),
|
|
|
|
id: Element.textContent(item.getElementsByTagName('dmap.itemid')[0])});
|
2005-03-21 14:53:39 -05:00
|
|
|
}
|
2006-03-21 16:59:18 -05:00
|
|
|
});
|
|
|
|
sourceSelect.appendChild(Builder.node('option',{value: '1'},'Library'));
|
|
|
|
if (smartPlaylists.length > 0) {
|
|
|
|
optgroup = Builder.node('optgroup',{label: 'Smart playlists'});
|
|
|
|
smartPlaylists.each(function (item) {
|
|
|
|
var option = document.createElement('option');
|
|
|
|
optgroup.appendChild(Builder.node('option',{value: item.id},item.name));
|
|
|
|
});
|
|
|
|
sourceSelect.appendChild(optgroup);
|
2005-03-21 14:53:39 -05:00
|
|
|
}
|
2006-03-21 16:59:18 -05:00
|
|
|
if (staticPlaylists.length > 0) {
|
2006-03-27 16:56:26 -05:00
|
|
|
optgroup = Builder.node('optgroup',{label: 'Static playlists',id: 'static_playlists'});
|
2006-03-21 16:59:18 -05:00
|
|
|
staticPlaylists.each(function (item) {
|
|
|
|
var option = document.createElement('option');
|
|
|
|
optgroup.appendChild(Builder.node('option',{value: item.id},item.name));
|
|
|
|
});
|
|
|
|
sourceSelect.appendChild(optgroup);
|
2005-03-21 14:53:39 -05:00
|
|
|
}
|
2006-03-21 16:59:18 -05:00
|
|
|
// Select Library
|
|
|
|
sourceSelect.value = 1;
|
2005-03-21 14:53:39 -05:00
|
|
|
}
|
|
|
|
|
2006-03-21 16:59:18 -05:00
|
|
|
function rsSongs(request) {
|
|
|
|
var items = $A(request.responseXML.getElementsByTagName('dmap.listingitem'));
|
|
|
|
var songsTable = $('songs_data');
|
|
|
|
Element.removeChildren(songsTable);
|
|
|
|
items.each(function (item) {
|
|
|
|
var tr = document.createElement('tr');
|
|
|
|
var time = parseInt(Element.textContent(item.getElementsByTagName('daap.songtime')[0]));
|
|
|
|
time = Math.round(time / 1000);
|
|
|
|
var seconds = time % 60;
|
2005-03-05 19:16:58 -05:00
|
|
|
|
2006-03-21 16:59:18 -05:00
|
|
|
seconds = (seconds < 10) ? '0'+seconds : seconds;
|
|
|
|
timeString = Math.floor(time/60)+ ':' + seconds;
|
2005-03-05 19:16:58 -05:00
|
|
|
|
2006-03-22 03:55:31 -05:00
|
|
|
tr.appendChild(Builder.node('td',{style:'width: 140px;'},Element.textContent(item.getElementsByTagName('dmap.itemname')[0])));
|
2006-03-21 16:59:18 -05:00
|
|
|
tr.appendChild(Builder.node('td',{style:'width: 50px;'},timeString));
|
2006-03-22 03:55:31 -05:00
|
|
|
tr.appendChild(Builder.node('td',{style:'width: 120px;'},Element.textContent(item.getElementsByTagName('daap.songartist')[0])));
|
|
|
|
tr.appendChild(Builder.node('td',{style:'width: 120px;'},Element.textContent(item.getElementsByTagName('daap.songalbum')[0])));
|
2006-03-21 16:59:18 -05:00
|
|
|
tr.appendChild(Builder.node('td',{style:'width: 100px;'},Element.textContent(item.getElementsByTagName('daap.songgenre')[0])));
|
2005-03-05 19:16:58 -05:00
|
|
|
|
2006-03-21 16:59:18 -05:00
|
|
|
songsTable.appendChild(tr);
|
2006-03-24 06:44:50 -05:00
|
|
|
});
|
|
|
|
Query.busy = false;
|
2005-03-05 19:16:58 -05:00
|
|
|
}
|
2006-03-26 16:14:03 -05:00
|
|
|
|
2006-03-21 16:59:18 -05:00
|
|
|
Object.extend(Element, {
|
|
|
|
removeChildren: function(element) {
|
|
|
|
while(element.hasChildNodes()) {
|
|
|
|
element.removeChild(element.firstChild);
|
2005-03-16 14:56:40 -05:00
|
|
|
}
|
2006-03-21 16:59:18 -05:00
|
|
|
},
|
|
|
|
textContent: function(node) {
|
|
|
|
if ((!node) || !node.hasChildNodes()) {
|
|
|
|
// Empty text node
|
|
|
|
return '';
|
2005-03-16 14:56:40 -05:00
|
|
|
} else {
|
2006-03-21 16:59:18 -05:00
|
|
|
if (node.textContent) {
|
|
|
|
// W3C ?
|
|
|
|
return node.textContent;
|
|
|
|
} else if (node.text) {
|
|
|
|
// IE
|
|
|
|
return node.text;
|
2005-03-16 14:56:40 -05:00
|
|
|
}
|
|
|
|
}
|
2006-03-21 16:59:18 -05:00
|
|
|
// We shouldn't end up here;
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
String.prototype.encode = function () {
|
2006-03-26 16:14:03 -05:00
|
|
|
return encodeURIComponent(this).replace(/\'/g,"\\'");
|
2006-03-21 16:59:18 -05:00
|
|
|
};
|
|
|
|
// Stolen from prototype 1.5
|
|
|
|
String.prototype.truncate = function(length, truncation) {
|
|
|
|
length = length || 30;
|
|
|
|
truncation = truncation === undefined ? '...' : truncation;
|
|
|
|
var ret = (this.length > length) ? this.slice(0, length - truncation.length) + truncation : this;
|
|
|
|
return '' + ret;
|
|
|
|
};
|
|
|
|
function add() {
|
|
|
|
alert('add');
|
|
|
|
}
|
|
|
|
/* Detta script finns att hamta pa http://www.jojoxx.net och
|
|
|
|
far anvandas fritt sa lange som dessa rader star kvar. */
|
|
|
|
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+=" "; }
|
|
|
|
if(typeof(obj)=="string"){
|
|
|
|
str+=ind+prefix+"String:\""+obj+"\"\n";
|
|
|
|
} else if(typeof(obj)=="number"){
|
|
|
|
str+=ind+prefix+"Number:"+obj+"\n";
|
|
|
|
} else if(typeof(obj)=="function"){
|
|
|
|
str+=ind+prefix+"Function:"+obj+"\n";
|
|
|
|
} else if(typeof(obj) == 'boolean') {
|
|
|
|
str+=ind+prefix+"Boolean:" + obj + "\n";
|
|
|
|
} else {
|
|
|
|
var type="Array";
|
2006-03-26 16:24:20 -05:00
|
|
|
for(var i in obj){ type=(type=="Array"&&i==parseInt(i))?"Array":"Object"; }
|
2006-03-21 16:59:18 -05:00
|
|
|
str+=ind+prefix+type+"[\n";
|
|
|
|
if(type=="Array"){
|
|
|
|
for(var i in obj){ str+=DataDumper(obj[i],n,i+"=>"); }
|
|
|
|
} else {
|
|
|
|
for(var i in obj){ str+=DataDumper(obj[i],n,i+"=>"); }
|
|
|
|
}
|
|
|
|
str+=ind+"]\n";
|
|
|
|
}
|
|
|
|
return str;
|
2005-03-16 14:56:40 -05:00
|
|
|
}
|