-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
65 lines (55 loc) · 2.22 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html>
<body>
<button onclick="window.print()">Print</button>
<div id="playlists">
</div>
<script>
require(['$api/models', '$api/library'], function(models, library) {
function renderPlaylistFromUri (uri) {
models.Playlist.fromURI(uri)
.load(['name', 'tracks'])
.done(renderPlaylist);
}
function renderPlaylist(p) {
var div = document.createElement('div'),
html = '<h2>' + p.name.decodeForHtml() + '</h2>';
html += '<table><thead><tr><th>Track</th><th>Artists</th></tr></thead>'
models.Promise.join([
p.tracks.snapshot()
]).done(function (result) {
var tracks = result[0].toArray();
for(var i=0; i<tracks.length; i++){
html += '<tr>';
html += '<td>' + tracks[i].name + '</td>';
html += '<td>'
for (var j=0; j<tracks[i].artists.length; j++) {
html += tracks[i].artists[j].name + ' ';
}
html += '</td>';
html += '</tr>';
}
html += '</table>'
div.innerHTML = html;
document.getElementById('playlists').appendChild(div);
});
}
library.Library.forCurrentUser()
.load('playlists')
.done(function (library) {
models.Promise.join([
library.playlists.snapshot()
]).done(function (result) {
var playlists = result[0].toArray();
for (var i = 0; i < playlists.length; i++) {
if (playlists[i] === null) {
break;
}
renderPlaylistFromUri(playlists[i].uri);
};
});
});
});
</script>
</body>
</html>