Skip to content
Browse files

Fix playlist created dates and title handling. String.trim is not sta…

…ndard
  • Loading branch information...
1 parent fa1bbcd commit 6d78b2907ac16e23dbe12bbf4c41a696772f9288 @jwheare committed Dec 16, 2009
View
9 public/playlick.css
@@ -159,9 +159,9 @@ ul.playlists li {
border-bottom: 1px solid #c0e95b;
line-height: 32px;
}
-ul.playlists li img {
- float: right;
- margin: 7px 0 0 3px;
+ul.playlists li img.art {
+ float: left;
+ margin: 5px 6px 0 -6px;
vertical-align: middle;
}
ul.playlists li a.playlist {
@@ -520,7 +520,8 @@ form#lastfm_playlists_form input.submit {
p#lastfm_done input {
}
ul#lastfm_playlists {
- margin-top: -29px;
+ margin-top: -22px;
+ margin-left: 11px;
list-style-type: none;
}
ul#lastfm_playlists li {
View
21 src/js/controllers/playlist.controller.js
@@ -296,7 +296,7 @@ Playlist.prototype = {
this.editForm = $('<form id="playlistEditForm">').hide().submit(function (e) {
e.preventDefault();
var params = UTIL.serializeForm(this);
- that.current.name = params.title;
+ that.current.title = params.title;
that.current.url = params.url;
that.current.subtitle = params.subtitle;
that.current.description = params.description;
@@ -404,7 +404,7 @@ Playlist.prototype = {
button.html(STRINGS.cancel_edit_playlist_text);
// Update input and select
var edit_input = playlist_item.find('input.playlist_name');
- edit_input.val(playlist_item.data('playlist').name);
+ edit_input.val(playlist_item.data('playlist').toString());
setTimeout(function () {
edit_input.focus().select();
});
@@ -418,18 +418,7 @@ Playlist.prototype = {
});
},
updateSidebarTitle: function (playlist) {
- playlist.element.find('a.playlist').text(UTIL.truncateString(playlist.toString()));
- },
- updateCopyright: function (playlist, copyright) {
- // Update playlist copyright
- if (copyright) {
- playlist.copyright = copyright;
- playlist.save();
- }
- // Update current copyright
- if (this.current == playlist) {
- this.loadCopyright();
- }
+ playlist.element.find('a.playlist span').text(UTIL.truncateString(playlist.toString()));
},
addTrack: function (artistName, trackName, albumName, url) {
@@ -446,7 +435,7 @@ Playlist.prototype = {
if (artistName) {
playlistName = artistName + ' - ' + playlistName;
}
- this.current.name = playlistName;
+ this.current.title = playlistName;
}
// Save
this.current.save();
@@ -473,7 +462,7 @@ Playlist.prototype = {
/* DELETE */
remove: function (playlist) {
- if (confirm('Are you sure you want to delete this playlist:\n\n' + playlist.name)) {
+ if (confirm('Are you sure you want to delete this playlist:\n\n' + playlist.toString())) {
playlist.remove();
return true;
}
View
7 src/js/importers.js
@@ -136,8 +136,9 @@ IMPORTERS = {
}
var playlist = new MODELS.Playlist({
type: metadata.type,
- name: title,
+ title: title,
artist: metadata.artist,
+ album: metadata.album,
image: IMPORTERS.getAbsoluteUrl(metadata.image || jspf.image, source),
description: description,
url: IMPORTERS.getAbsoluteUrl(url, source),
@@ -200,7 +201,7 @@ IMPORTERS = {
description = '';
}
var playlist = new MODELS.Playlist({
- name: IMPORTERS.getStringItem(podcast.title),
+ title: IMPORTERS.getStringItem(podcast.title),
subtitle: subtitle,
description: description,
copyright: IMPORTERS.getStringItem(podcast.copyright),
@@ -252,7 +253,7 @@ IMPORTERS = {
})[0];
var link = linkObject ? linkObject.href : '';
var playlist = new MODELS.Playlist({
- name: IMPORTERS.getStringItem(podcast.title),
+ title: IMPORTERS.getStringItem(podcast.title),
subtitle: subtitle,
description: description,
copyright: IMPORTERS.getStringItem(podcast.copyright),
View
6 src/js/importers/lastfm.js
@@ -164,7 +164,7 @@ LastFm.lovedTracks = function (user, callback, exceptionHandler) {
}
// Create the playlist
var playlist = new MODELS.Playlist({
- name: 'Loved tracks for ' + json.lovedtracks['@attr'].user
+ title: 'Loved tracks for ' + json.lovedtracks['@attr'].user
});
// Load tracks
$.each(trackList, function (i, data) {
@@ -213,8 +213,8 @@ LastFm.album = function (artist, album, callback, exceptionHandler) {
}
var metadata = {
type: 'album',
- title: json.album.name,
artist: json.album.artist,
+ album: json.album.name,
description: description,
url: json.album.url
};
@@ -260,7 +260,7 @@ LastFm.generateUsersPlaylist = function (userA, userB, callback, exceptionHandle
var artists = UTIL.shuffle(json.comparison.result.artists.artist);
// Create the playlist
var playlist = new MODELS.Playlist({
- name: userA + ' and ' + userB,
+ title: userA + ' and ' + userB,
description: 'A playlist based on your shared artists'
});
var playlistTracks = {};
View
4 src/js/importers/spotify.js
@@ -141,8 +141,8 @@ Spotify.album = function (url, callback, exceptionHandler) {
// Create the playlist
var playlist = new MODELS.Playlist({
type: 'album',
- name: album.name,
artist: album.artist.name || album.artist[0].name,
+ album: album.name,
url: url,
source: albumLookupUrl,
image: LastFm.getAlbumArt(album.artist.name || album.artist[0].name, album.name, 'large')
@@ -189,7 +189,7 @@ Spotify.track = function (url, callback, exceptionHandler) {
}
// Create a playlist
var playlist = new MODELS.Playlist({
- name: (trackData.artist.name || trackData.artist[0].name) + ' - ' + trackData.name,
+ title: (trackData.artist.name || trackData.artist[0].name) + ' - ' + trackData.name,
url: url,
source: trackLookupUrl
});
View
6 src/js/main.js
@@ -136,7 +136,7 @@ var PLAYLICK = {
function callback (playlist) {
// Update messages
$('p.messages').hide();
- $('#url_title').text(playlist.name);
+ $('#url_title').text(playlist.toString());
$('#url_count').text(playlist.tracks.length);
$('#url_done').show();
// Register playlist
@@ -166,7 +166,7 @@ var PLAYLICK = {
function callback (playlist) {
// Update messages
$('p.messages').hide();
- $('#spotify_title').text(playlist.name);
+ $('#spotify_title').text(playlist.toString());
$('#spotify_done').show();
// Register playlist
CONTROLLERS.Playlist.register(playlist);
@@ -195,7 +195,7 @@ var PLAYLICK = {
function callback (playlist) {
// Update messages
$('p.messages').hide();
- var escapedAlbum = $('<b>').text(playlist.name);
+ var escapedAlbum = $('<b>').text(playlist.toString());
$('#album_name').html(escapedAlbum);
$('#album_done').show();
// Register playlist
View
5 src/js/main/handlers.js
@@ -150,7 +150,7 @@ CONTROLLERS.Playlist.playlistSidebarLists.click(function (e) {
var target = $(e.target);
var playlist_item = target.closest('li.p');
// Load the clicked playlist
- if (target.is('li.p a.playlist')) {
+ if (target.is('li.p a.playlist, li.p a.playlist span, li.p a.playlist img')) {
e.preventDefault();
target.blur();
CONTROLLERS.Playlist.loadItem(playlist_item);
@@ -178,7 +178,8 @@ CONTROLLERS.Playlist.playlistSidebarLists.click(function (e) {
var form = target.parents('form');
var params = UTIL.serializeForm(form);
var playlist = playlist_item.data('playlist');
- playlist_item.data('playlist').set_name(params.name);
+ playlist_item.data('playlist').title = params.name;
+ playlist_item.data('playlist').save();
CONTROLLERS.Playlist.toggleSidebarEditName(playlist_item);
}
});
View
8 src/js/main/models.js
@@ -36,7 +36,13 @@
var play_indicator = $('<a href="#" class="playlist_playing" title="Playing">');
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">').text(UTIL.truncateString(this.toString()));
+ var name = $('<a href="#" class="playlist">')
+ .attr('title', this.toString())
+ .append($('<span>').text(UTIL.truncateString(this.toString())));
+ if (this.isAlbum()) {
+ var albumArt = IMPORTERS.LastFm.getAlbumArt(this.artist, this.album);
+ name.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">');
View
22 src/js/models/playlist.model.js
@@ -27,8 +27,10 @@ function Playlist (options) {
}
}
this.type = this.options.type || 'playlist';
- this.name = this.options.name || "Playlist: " + new Date().toLocaleString();
+ this.date = this.options.date ? new Date(this.options.date) : new Date();
this.artist = this.options.artist || '';
+ this.album = this.options.album || '';
+ this.title = this.options.title;
this.image = this.options.image || '';
this.subtitle = this.options.subtitle || '';
this.description = this.options.description || '';
@@ -70,22 +72,20 @@ Playlist.prototype = {
/**
* Playlist management
**/
- set_name: function (name) {
- this.name = name;
- // AUTOSAVE
- this.save();
- },
isAlbum: function () {
return this.type == 'album';
},
albumToString: function () {
- return this.artist + ' - ' + this.name;
+ return this.artist + ' - ' + this.album;
},
toString: function () {
+ if (this.title) {
+ return this.title;
+ }
if (this.isAlbum()) {
return this.albumToString();
}
- return this.name;
+ return "Playlist: " + this.date.toLocaleString();
},
/**
* Fetch tracks from Couch
@@ -167,7 +167,7 @@ Playlist.prototype = {
+ 'track: "' + playlist_track.track.name.replace(/"/g, '\\"') + '"'
+ '}';
});
- var applescript = 'set playlist_name to "' + this.name + '"\n'
+ var applescript = 'set playlist_name to "' + this.toString() + '"\n'
+ 'tell application "iTunes"\n'
+ ' set new_playlist to (make playlist with properties {name:playlist_name})\n'
+ ' set l to source "Library"\n'
@@ -305,8 +305,10 @@ Playlist.prototype = {
var doc = $.extend(this.get_doc_ref(), {
published: this.published,
type: this.type,
- name: this.name,
+ date: this.date.getTime(),
+ title: this.title,
artist: this.artist,
+ album: this.album,
image: this.image,
subtitle: this.subtitle,
description: this.description,
View
2 src/js/util.js
@@ -25,7 +25,7 @@ var UTIL = {
compareString: function (a, b) {
a = a || '';
b = b || '';
- return a.trim().toUpperCase() == b.trim().toUpperCase();
+ return a.toUpperCase() == b.toUpperCase();
},
getHashParts: function () {
var hash_sections = window.location.hash.replace(/^#(.*)/, '$1').split(';');

0 comments on commit 6d78b29

Please sign in to comment.
Something went wrong with that request. Please try again.