Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added list playlists view

  • Loading branch information...
commit 7b67ac88625bb6ac02204f0ffa02d9291bec7a43 1 parent 8baf5d7
@stevestreza authored
View
28 MPListPlaylistsView.js
@@ -0,0 +1,28 @@
+var MPListPlaylistsView = window.MPListPlaylistsView = Class.extend({
+ init: function(playlists, element){
+ this._domElement = $(element);
+ this._playlists = playlists;
+
+ var self = this;
+ this._listView = new MPListView(this._domElement, this._playlists, function(thePlaylist){
+ return new MPPlaylistViewItem(thePlaylist, self);
+ });
+ }
+});
+
+var MPPlaylistViewItem = window.MPPlaylistViewItem = MPListViewItem.extend({
+ init: function(playlist, parent){
+ this._super();
+
+ this._titleLabel = $("<div class='MPTitleLabel MPLabel'></div>");
+ this.contentsView().append(this._titleLabel);
+
+ console.log("Setting title label to " + playlist.name());
+ this._titleLabel.text(playlist.name());
+
+ var self = this;
+ $(this.domElement()).bind("click", function(ev){
+ $(parent).trigger("selected", playlist);
+ });
+ }
+})
View
2  MusicPlayer.css
@@ -3,7 +3,7 @@ body{
padding: 0px;
}
-.MPTrackView {
+.MPListViewItem {
width: 100%;
height: 72px;
background-color: #030303;
View
26 MusicPlayer.js
@@ -8,12 +8,21 @@ window.MPHashFromUsernameAndPassword = function(username, password){
};
}
-var MPPlaylist = function(tracks, username, playlistStub){
+var MPPlaylist = function(tracks, username, playlistStub, name){
this._tracks = tracks;
this._username = username;
this._playlistStub = playlistStub;
+ this._name = name;
};
+MPPlaylist.prototype.path = function(){
+ return this._username + "/" + this._playlistStub;
+}
+
+MPPlaylist.prototype.name = function(){
+ return this._name;
+}
+
MPPlaylist.prototype.trackAfter = function(index){
var newIndex = index+1;
if(newIndex >= this._tracks.length || newIndex < 0){
@@ -238,9 +247,20 @@ $(function(){
player.loadTrack(playlist.trackAtIndex(song));
player.play();
}else if(playlists){
- for(var playlistStub in playlists){
- var playlistName = playlists[playlistStub];
+ var username = window.location.hash.match(/\#\!([^\/]+)\/?/)[1];
+
+ element.children().remove();
+ var newPlaylists = [];
+ for(var stub in playlists){
+ var name = playlists[stub];
+ var playlist = new MPPlaylist([], username, stub, name);
+ newPlaylists.push(playlist);
}
+
+ var listPlaylistsView = new MPListPlaylistsView(newPlaylists, element);
+ $(listPlaylistsView).bind("selected", function(ev, playlist){
+ window.location.hash = "#!" + playlist.path();
+ });
}
});
}).trigger("hashchange");
View
1  index.html
@@ -11,6 +11,7 @@
<script src="MPCore.js" type="text/javascript" charset="utf-8"></script>
<script src="MPListView.js" type="text/javascript" charset="utf-8"></script>
<script src="MPPlaylistView.js" type="text/javascript" charset="utf-8"></script>
+ <script src="MPListPlaylistsView.js" type="text/javascript" charset="utf-8"></script>
<script src="MusicPlayer.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="MusicPlayer.css" />
Please sign in to comment.
Something went wrong with that request. Please try again.