Skip to content

Commit

Permalink
[FIX] Prevent playlist with no name
Browse files Browse the repository at this point in the history
* Init UpNext with first player playlist
* if we remove the current track form upnext trigger next
  • Loading branch information
flyingrub committed Mar 30, 2016
1 parent a1e6dd4 commit 2c25aaf
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
8 changes: 1 addition & 7 deletions app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ let Application = Mn.Application.extend({
// All track initialization
let allTracks = new Tracks([], { type: 'all' });

allTracks.fetch({
success: () => { // For now initialize upNext with all track
this.allTracks.get('tracks').each(track => {
this.upNext.get('tracks').add(track);
});
}
});
allTracks.fetch();
this.allTracks = new Playlist({
title: "All Songs",
tracks: allTracks
Expand Down
3 changes: 3 additions & 0 deletions app/styles/header.styl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ div[role='contentinfo']
color: $text-dark
display: inline-block

span
padding: 0 8px

span[contenteditable='true']:hover
background-color: $background-dark

Expand Down
13 changes: 8 additions & 5 deletions app/views/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Header = Mn.ItemView.extend({
'click #reset-upnext': 'resetUpNext',
'click #delete-playlist': 'deletePlaylist',
'keypress @ui.title': 'keypressPlaylistTitle',
'focusout @ui.title' : 'savePlaylistTitle'
'blur @ui.title' : 'savePlaylistTitle'
},

modelEvents: {
Expand All @@ -31,16 +31,19 @@ const Header = Mn.ItemView.extend({

keypressPlaylistTitle(e) {
if (e.key == 'Enter') {
this.savePlaylistTitle();
this.ui.title.blur();
return false;
}
},

savePlaylistTitle(e) {
let currentPlaylist = this.model.get('currentPlaylist');
currentPlaylist.set('title', this.ui.title.html());
currentPlaylist.save();
if (this.ui.title.html() == '') {
setTimeout(() => { this.ui.title.focus() }, 0);
} else {
let currentPlaylist = this.model.get('currentPlaylist');
currentPlaylist.set('title', this.ui.title.html());
currentPlaylist.save();
}
},

serializeData() {
Expand Down
6 changes: 5 additions & 1 deletion app/views/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const Player = Mn.LayoutView.extend({

initialize() {
this.listenTo(application.channel,'reset:UpNext', this.render);
this.listenTo(application.channel, 'player:next', this.next)
this.listenTo(application.appState, 'change:currentTrack',
function(appState, currentTrack) {
if (currentTrack) {
Expand Down Expand Up @@ -80,7 +81,7 @@ const Player = Mn.LayoutView.extend({
onRender() {
let audio = this.ui.player.get(0);
audio.ontimeupdate = this.onTimeUpdate;
audio.onended = this.next;
audio.onended = () => { this.next() };
audio.onvolumechange = this.onVolumeChange;
audio.volume = application.appState.get('currentVolume');
},
Expand Down Expand Up @@ -156,6 +157,9 @@ const Player = Mn.LayoutView.extend({
this.replayCurrent();
}
application.appState.set('currentTrack', upNext.at(0));
} else {
application.appState.set('currentTrack', undefined);
this.render();
}
},

Expand Down
2 changes: 1 addition & 1 deletion app/views/popupPlaylists.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const PopupPlaylists = Mn.CompositeView.extend({
if(e.keyCode == 13) {
let newPlaylist = new Playlist({ title: title });
newPlaylist.addTrack(this.model);
application.allPlaylists.create(newPlaylist);
application.allPlaylists.add(newPlaylist);
this.ui.playlistText.val('');
}
},
Expand Down
10 changes: 10 additions & 0 deletions app/views/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ const TrackView = Mn.LayoutView.extend({
},

play(e) {
// Add current playlist to upNext if no track in UpNext
let tracks = application.appState.get('currentPlaylist').get('tracks');
if (application.upNext.get('tracks').length == 0) {
tracks.each(track => {
application.upNext.get('tracks').add(track);
});
}
application.appState.set('currentTrack', this.model);
},

Expand Down Expand Up @@ -86,6 +93,9 @@ const TrackView = Mn.LayoutView.extend({

deleteFromUpNext(e) {
e.stopPropagation();
if (this.model == application.appState.get('currentTrack')) {
application.channel.trigger('player:next');
}
application.upNext.removeTrack(this.model);
},

Expand Down

0 comments on commit 2c25aaf

Please sign in to comment.