summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-08-23 23:24:32 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-08-23 23:24:32 +0200
commit49c16694118f44d3f02da2e068aff5c3f595be68 (patch)
tree860400845cb69416cda0bbdba0ed73ed1195f1be
parentf48773661a235864a8460e1ca0810f0593ac93be (diff)
Display albums in browser/results.
-rw-r--r--static/player.js55
-rw-r--r--static/style.css4
2 files changed, 34 insertions, 25 deletions
diff --git a/static/player.js b/static/player.js
index b120fe1..eedb943 100644
--- a/static/player.js
+++ b/static/player.js
@@ -108,6 +108,36 @@ function output_link(obj) {
song_links.appendChild(li);
}
+function output_album(album) {
+ var li = document.createElement('li');
+ li.setAttribute('class', 'album');
+ li.appendChild(document.createTextNode(album ? album : '(No album)'));
+
+ var song_links = document.getElementById('song-links');
+ song_links.appendChild(li);
+}
+
+function add_results(json) {
+ var lastalbum = false;
+ for(var i = 0; i < json.length; i++) {
+ var type = json[i]["type"];
+ var path = json[i]["name"];
+ var track = json[i]["track"];
+ var name = path.substring(path.lastIndexOf('/')+1);
+ var cached = type == "file" ? json[i]["cached"] : false;
+ var metadata = json[i]["metadata"];
+
+ if(type == 'file' && metadata.album != lastalbum) {
+ output_album(metadata.album);
+ lastalbum = metadata.album;
+ }
+
+ var l = new MusicListing(type, path, name, track, metadata, cached);
+ output_link(l);
+ }
+ log('add_results: ' + lastalbum);
+}
+
function list(root) {
log('listing ' + root);
var xmlhttp = new XMLHttpRequest();
@@ -124,19 +154,7 @@ function list(root) {
l = new MusicListing('dir', up, '..');
output_link(l);
}
- for(var i = 0; i < json.length; i++) {
- var type = json[i]["type"];
- var path = json[i]["name"];
- var track = json[i]["track"];
- var name = path.substring(path.lastIndexOf('/')+1);
- var cached = type == "file" ? json[i]["cached"] : false;
- var metadata = json[i]["metadata"];
- log(metadata.artist);
- if('artist' in json[i]["metadata"])
- log('got artist');
- var l = new MusicListing(type, path, name, track, metadata, cached);
- output_link(l);
- }
+ add_results(json);
}
}
@@ -155,16 +173,7 @@ function do_search(e) {
var json = JSON.parse(xmlhttp.responseText);
document.getElementById('song-links').innerHTML = '';
output_link(new MusicListing('dir', '/', 'Go to root directory'));
- for(var i = 0; i < json.length; i++) {
- var type = json[i]["type"];
- var path = json[i]["name"];
- var track = json[i]["track"];
- var name = path.substring(path.lastIndexOf('/')+1);
- var cached = type == "file" ? json[i]["cached"] : false;
- var metadata = json[i]["metadata"];
- var l = new MusicListing(type, path, name, track, metadata, cached);
- output_link(l);
- }
+ add_results(json);
}
}
diff --git a/static/style.css b/static/style.css
index 1061c64..5c8336d 100644
--- a/static/style.css
+++ b/static/style.css
@@ -16,8 +16,8 @@ span.list-header { font-size: large; }
ul#song-links { width: 30em; overflow: auto; white-space: nowrap; resize: both; }
a#add-dir { font-size: small; }
span#playlist-span { position: absolute; left: 31em; right: 1em; }
-ul#playlist li.album { border-top: 1px solid; margin-bottom: .2em; color: #666; padding-left: 1em; }
-ul#playlist li.album span { margin-left: 1em; }
+li.album { border-top: 1px solid; margin-bottom: .2em; color: #666; padding-left: 1em; }
+li.album span { margin-left: 1em; }
.right { float: right; }
ul#playlist li div:hover { background: #eee; }
input#search-query { padding-left: 16px; background-repeat: no-repeat; background-image: url('/static/icons/magnifier.png'); }