Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make albums and subscriptions non editable. Some cleanup

  • Loading branch information...
commit f99309fbeadc08fd36cc87c7ee031d73d02d3a08 1 parent 79e5a32
@jwheare authored
View
14 src/js/controllers/playlist.controller.js
@@ -134,7 +134,7 @@ Playlist.prototype = {
this.albumsSidebarTitleElem.show();
this.albumsSidebarList.append(albumElements);
}
- if (typeof playlists !== 'undefined') {
+ if (playlists === undefined) {
this.fetchAllDone = true;
}
}
@@ -232,6 +232,9 @@ Playlist.prototype = {
this.headerElem.show();
},
buildEditElem: function () {
+ if (!this.current.isEditable()) {
+ return false;
+ }
var that = this;
var editButton = $('<a href="#">')
.append($('<img>')
@@ -309,6 +312,9 @@ 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();
@@ -396,6 +402,12 @@ Playlist.prototype = {
PLAYDAR.updateLoadProgress.call(nowPlayingSound);
}
});
+ // Enable/disable sortable
+ if (this.current.isEditable()) {
+ this.trackListElem.sortable('enable');
+ } else {
+ this.trackListElem.sortable('disable');
+ }
// Resolve tracks with Playdar
PLAYDAR.resolve_current_playlist();
// Show SM2 if the current playing track is in this playlist
View
1  src/js/main/handlers.js
@@ -7,6 +7,7 @@ CONTROLLERS.Playlist.trackListElem.sortable({
opacity: 0.5,
delay: 100,
placeholder: 'placeholder',
+ forcePlaceholderSize: true,
update: function (e, ui) {
var tracks = $.map($('#playlist li'), function (playlist_item, i) {
return $(playlist_item).data('playlist_track');
View
38 src/js/main/models.js
@@ -33,27 +33,37 @@
return wrapper.html();
};
function playlistToHtml () {
+ // Wrap in a div so we can return its innerHTML as a string
+ var wrapper = $('<div>');
+ // Playing indicator
var play_indicator = $('<a href="#" class="playlist_playing" title="Playing">');
+ wrapper.append(play_indicator);
+ // Delete button
var delete_link = $('<a href="#" class="delete_playlist" title="Delete playlist">').text('');
- var edit_link = $('<a href="#" class="edit_playlist">').text(STRINGS.edit_playlist_text);
- var name = $('<a href="#" class="playlist">')
+ 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);
+ }
+ // Title
+ var title = $('<a href="#" class="playlist">')
.attr('title', this.toString())
.append($('<span>').text(UTIL.truncateString(this.toString())));
+ // Album art
if (this.isAlbum()) {
var albumArt = IMPORTERS.LastFm.getAlbumArt(this.artist, this.album);
- name.prepend($('<img width="24" height="24" class="art">').attr('src', albumArt));
+ title.prepend($('<img width="24" height="24" class="art">').attr('src', albumArt));
}
- 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">');
- // Wrap in a div so we can return its innerHTML as a string
- return $('<div>')
- .append(play_indicator)
- .append(delete_link)
- .append(edit_link)
- .append(name)
- .append(edit_form)
- .html();
+ 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);
+ }
+ return wrapper.html();
};
/* Apply to Models */
View
2  src/js/main/playdar.js
@@ -507,8 +507,8 @@ var PLAYDAR = {
var loading = track_item.find('.loading');
var loaded = this.bytesLoaded/this.bytesTotal * 100;
loading.width(loaded + "%");
+ PLAYDAR.updateStreamDuration(this.sID, this.durationEstimate, loaded < 100);
}
- PLAYDAR.updateStreamDuration(this.sID, this.durationEstimate, loaded < 100);
},
updateStreamDuration: function (sid, duration, estimate) {
var track_item = $('#' + sid).data('track_item');
View
12 src/js/models/playlist.model.js
@@ -27,7 +27,7 @@ function Playlist (options) {
}
}
this.date = this.options.date ? new Date(this.options.date) : new Date();
- this.setOption('type');
+ this.setOption('type', 'playlist');
this.setOption('artist');
this.setOption('album');
this.setOption('title');
@@ -46,8 +46,11 @@ function Playlist (options) {
// Override this
Playlist.DefaultOptions = {};
Playlist.prototype = {
- setOption: function (optionName) {
- this[optionName] = this.options[optionName] || '';
+ setOption: function (optionName, defaultValue) {
+ if (defaultValue === undefined) {
+ defaultValue = '';
+ }
+ this[optionName] = this.options[optionName] || defaultValue;
},
addOptions: function (options) {
$.extend(this.options, options);
@@ -82,6 +85,9 @@ Playlist.prototype = {
isSubscription: function () {
return this.type == 'subscription' && this.subscription;
},
+ isEditable: function () {
+ return !this.isAlbum() && !this.isSubscription();
+ },
albumToString: function () {
return this.artist + ' - ' + this.album;
},
View
1  src/js/models/playlisttrack.model.js
@@ -7,7 +7,6 @@ function PlaylistTrack (playlist, track, options) {
this.id = MODELS.next_playlist_track_id++;
this.playlist = playlist;
this.track = track;
- this.set_track_duration(track.duration);
this.options = options || {};
View
2  src/js/models/track.model.js
@@ -20,7 +20,7 @@ function Track (doc) {
};
Track.prototype = {
get_duration_string: function () {
- if (typeof this.duration != 'undefined') {
+ if (this.duration) {
return Playdar.Util.mmss(this.duration);
}
return '';
View
4 src/js/util.js
@@ -9,7 +9,9 @@ var UTIL = {
},
truncateString: function (name, length, truncation) {
length = length || 30;
- truncation = (typeof truncation == 'undefined') ? '' : truncation;
+ if (truncation === undefined) {
+ truncation = '';
+ }
if (name.length > length) {
return name.slice(0, length - truncation.length) + truncation;
}
Please sign in to comment.
Something went wrong with that request. Please try again.