Browse files

Better unload logic and let isEditable just apply to tracks

  • Loading branch information...
1 parent e3a7989 commit ae3ea05197baedb5e346d4b249a92db66639e167 @jwheare committed Dec 19, 2009
Showing with 13 additions and 26 deletions.
  1. +5 −15 src/js/controllers/playlist.controller.js
  2. +6 −10 src/js/main/models.js
  3. +2 −1 src/js/models/playlist.model.js
View
20 src/js/controllers/playlist.controller.js
@@ -78,10 +78,6 @@ Playlist.prototype = {
create: function () {
// Cancel Playdar
PLAYDAR.cancel_playdar_resolve();
- // Unload current playlist
- if (this.current) {
- this.current.unload();
- }
// Set a new current playlist
this.setCurrent();
// Metadata
@@ -142,6 +138,10 @@ Playlist.prototype = {
// Highlight the current playlist in the sidebar
setCurrent: function (playlist) {
+ // Unload any current playlist
+ if (this.current && this.current != playlist) {
+ this.current.unload();
+ }
var playlistItem;
if (playlist) {
this.current = playlist;
@@ -182,10 +182,6 @@ Playlist.prototype = {
}
// Cancel Playdar
PLAYDAR.cancel_playdar_resolve();
- // Unload the current playlist
- if (this.current) {
- this.current.unload();
- }
// Update the current playlist object
this.setCurrent(playlist);
// Hide add track details
@@ -197,7 +193,7 @@ Playlist.prototype = {
this.loadTracks();
// Show footer and add track form again
this.showFooter();
- if (!playlist.isAlbum()) {
+ if (playlist.isEditable()) {
this.addTrackForm.show();
}
},
@@ -232,9 +228,6 @@ Playlist.prototype = {
this.headerElem.show();
},
buildEditElem: function () {
- if (!this.current.isEditable()) {
- return false;
- }
var that = this;
var editButton = $('<a href="#">')
.append($('<img>')
@@ -312,9 +305,6 @@ Playlist.prototype = {
return field;
},
buildEditForm: function () {
- if (!this.current.isEditable()) {
- return false;
- }
var that = this;
this.editForm = $('<form id="playlistEditForm">').hide().submit(function (e) {
e.preventDefault();
View
16 src/js/main/models.js
@@ -42,10 +42,8 @@
var delete_link = $('<a href="#" class="delete_playlist" title="Delete playlist">').text('');
wrapper.append(delete_link);
// Edit button
- if (this.isEditable()) {
- var edit_link = $('<a href="#" class="edit_playlist">').text(STRINGS.edit_playlist_text);
- wrapper.append(edit_link);
- }
+ var edit_link = $('<a href="#" class="edit_playlist">').text(STRINGS.edit_playlist_text);
+ wrapper.append(edit_link);
// Title
var title = $('<a href="#" class="playlist">')
.attr('title', this.toString())
@@ -57,12 +55,10 @@
}
wrapper.append(title);
// Edit form
- if (this.isEditable()) {
- var edit_form = $('<form style="display: none;" class="edit_playlist_form">')
- .append('<input type="text" name="name" class="playlist_name">')
- .append('<input type="submit" value="save">');
- wrapper.append(edit_form);
- }
+ var edit_form = $('<form style="display: none;" class="edit_playlist_form">')
+ .append('<input type="text" name="name" class="playlist_name">')
+ .append('<input type="submit" value="save">');
+ wrapper.append(edit_form);
return wrapper.html();
};
View
3 src/js/models/playlist.model.js
@@ -147,6 +147,7 @@ Playlist.prototype = {
return elements;
},
unload: function () {
+ // Remove all tracks from the DOM
$.each(this.tracks, function (i, playlist_track) {
playlist_track.unload();
});
@@ -316,7 +317,7 @@ Playlist.prototype = {
},
get_doc: function () {
// Load tracks
- this.load();
+ this.fetchTracks();
var doc = $.extend(this.get_doc_ref(), {
date: this.date.getTime(),
published: this.published,

0 comments on commit ae3ea05

Please sign in to comment.