Skip to content

Commit

Permalink
Fix playlist created dates and title handling. String.trim is not sta…
Browse files Browse the repository at this point in the history
…ndard
  • Loading branch information
jwheare committed Dec 16, 2009
1 parent fa1bbcd commit 6d78b29
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 45 deletions.
9 changes: 5 additions & 4 deletions public/playlick.css
Expand Up @@ -159,9 +159,9 @@ ul.playlists li {
border-bottom: 1px solid #c0e95b; border-bottom: 1px solid #c0e95b;
line-height: 32px; line-height: 32px;
} }
ul.playlists li img { ul.playlists li img.art {
float: right; float: left;
margin: 7px 0 0 3px; margin: 5px 6px 0 -6px;
vertical-align: middle; vertical-align: middle;
} }
ul.playlists li a.playlist { ul.playlists li a.playlist {
Expand Down Expand Up @@ -520,7 +520,8 @@ form#lastfm_playlists_form input.submit {
p#lastfm_done input { p#lastfm_done input {
} }
ul#lastfm_playlists { ul#lastfm_playlists {
margin-top: -29px; margin-top: -22px;
margin-left: 11px;
list-style-type: none; list-style-type: none;
} }
ul#lastfm_playlists li { ul#lastfm_playlists li {
Expand Down
21 changes: 5 additions & 16 deletions src/js/controllers/playlist.controller.js
Expand Up @@ -296,7 +296,7 @@ Playlist.prototype = {
this.editForm = $('<form id="playlistEditForm">').hide().submit(function (e) { this.editForm = $('<form id="playlistEditForm">').hide().submit(function (e) {
e.preventDefault(); e.preventDefault();
var params = UTIL.serializeForm(this); var params = UTIL.serializeForm(this);
that.current.name = params.title; that.current.title = params.title;
that.current.url = params.url; that.current.url = params.url;
that.current.subtitle = params.subtitle; that.current.subtitle = params.subtitle;
that.current.description = params.description; that.current.description = params.description;
Expand Down Expand Up @@ -404,7 +404,7 @@ Playlist.prototype = {
button.html(STRINGS.cancel_edit_playlist_text); button.html(STRINGS.cancel_edit_playlist_text);
// Update input and select // Update input and select
var edit_input = playlist_item.find('input.playlist_name'); 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 () { setTimeout(function () {
edit_input.focus().select(); edit_input.focus().select();
}); });
Expand All @@ -418,18 +418,7 @@ Playlist.prototype = {
}); });
}, },
updateSidebarTitle: function (playlist) { updateSidebarTitle: function (playlist) {
playlist.element.find('a.playlist').text(UTIL.truncateString(playlist.toString())); playlist.element.find('a.playlist span').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();
}
}, },


addTrack: function (artistName, trackName, albumName, url) { addTrack: function (artistName, trackName, albumName, url) {
Expand All @@ -446,7 +435,7 @@ Playlist.prototype = {
if (artistName) { if (artistName) {
playlistName = artistName + ' - ' + playlistName; playlistName = artistName + ' - ' + playlistName;
} }
this.current.name = playlistName; this.current.title = playlistName;
} }
// Save // Save
this.current.save(); this.current.save();
Expand All @@ -473,7 +462,7 @@ Playlist.prototype = {


/* DELETE */ /* DELETE */
remove: function (playlist) { 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(); playlist.remove();
return true; return true;
} }
Expand Down
7 changes: 4 additions & 3 deletions src/js/importers.js
Expand Up @@ -136,8 +136,9 @@ IMPORTERS = {
} }
var playlist = new MODELS.Playlist({ var playlist = new MODELS.Playlist({
type: metadata.type, type: metadata.type,
name: title, title: title,
artist: metadata.artist, artist: metadata.artist,
album: metadata.album,
image: IMPORTERS.getAbsoluteUrl(metadata.image || jspf.image, source), image: IMPORTERS.getAbsoluteUrl(metadata.image || jspf.image, source),
description: description, description: description,
url: IMPORTERS.getAbsoluteUrl(url, source), url: IMPORTERS.getAbsoluteUrl(url, source),
Expand Down Expand Up @@ -200,7 +201,7 @@ IMPORTERS = {
description = ''; description = '';
} }
var playlist = new MODELS.Playlist({ var playlist = new MODELS.Playlist({
name: IMPORTERS.getStringItem(podcast.title), title: IMPORTERS.getStringItem(podcast.title),
subtitle: subtitle, subtitle: subtitle,
description: description, description: description,
copyright: IMPORTERS.getStringItem(podcast.copyright), copyright: IMPORTERS.getStringItem(podcast.copyright),
Expand Down Expand Up @@ -252,7 +253,7 @@ IMPORTERS = {
})[0]; })[0];
var link = linkObject ? linkObject.href : ''; var link = linkObject ? linkObject.href : '';
var playlist = new MODELS.Playlist({ var playlist = new MODELS.Playlist({
name: IMPORTERS.getStringItem(podcast.title), title: IMPORTERS.getStringItem(podcast.title),
subtitle: subtitle, subtitle: subtitle,
description: description, description: description,
copyright: IMPORTERS.getStringItem(podcast.copyright), copyright: IMPORTERS.getStringItem(podcast.copyright),
Expand Down
6 changes: 3 additions & 3 deletions src/js/importers/lastfm.js
Expand Up @@ -164,7 +164,7 @@ LastFm.lovedTracks = function (user, callback, exceptionHandler) {
} }
// Create the playlist // Create the playlist
var playlist = new MODELS.Playlist({ var playlist = new MODELS.Playlist({
name: 'Loved tracks for ' + json.lovedtracks['@attr'].user title: 'Loved tracks for ' + json.lovedtracks['@attr'].user
}); });
// Load tracks // Load tracks
$.each(trackList, function (i, data) { $.each(trackList, function (i, data) {
Expand Down Expand Up @@ -213,8 +213,8 @@ LastFm.album = function (artist, album, callback, exceptionHandler) {
} }
var metadata = { var metadata = {
type: 'album', type: 'album',
title: json.album.name,
artist: json.album.artist, artist: json.album.artist,
album: json.album.name,
description: description, description: description,
url: json.album.url url: json.album.url
}; };
Expand Down Expand Up @@ -260,7 +260,7 @@ LastFm.generateUsersPlaylist = function (userA, userB, callback, exceptionHandle
var artists = UTIL.shuffle(json.comparison.result.artists.artist); var artists = UTIL.shuffle(json.comparison.result.artists.artist);
// Create the playlist // Create the playlist
var playlist = new MODELS.Playlist({ var playlist = new MODELS.Playlist({
name: userA + ' and ' + userB, title: userA + ' and ' + userB,
description: 'A playlist based on your shared artists' description: 'A playlist based on your shared artists'
}); });
var playlistTracks = {}; var playlistTracks = {};
Expand Down
4 changes: 2 additions & 2 deletions src/js/importers/spotify.js
Expand Up @@ -141,8 +141,8 @@ Spotify.album = function (url, callback, exceptionHandler) {
// Create the playlist // Create the playlist
var playlist = new MODELS.Playlist({ var playlist = new MODELS.Playlist({
type: 'album', type: 'album',
name: album.name,
artist: album.artist.name || album.artist[0].name, artist: album.artist.name || album.artist[0].name,
album: album.name,
url: url, url: url,
source: albumLookupUrl, source: albumLookupUrl,
image: LastFm.getAlbumArt(album.artist.name || album.artist[0].name, album.name, 'large') image: LastFm.getAlbumArt(album.artist.name || album.artist[0].name, album.name, 'large')
Expand Down Expand Up @@ -189,7 +189,7 @@ Spotify.track = function (url, callback, exceptionHandler) {
} }
// Create a playlist // Create a playlist
var playlist = new MODELS.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, url: url,
source: trackLookupUrl source: trackLookupUrl
}); });
Expand Down
6 changes: 3 additions & 3 deletions src/js/main.js
Expand Up @@ -136,7 +136,7 @@ var PLAYLICK = {
function callback (playlist) { function callback (playlist) {
// Update messages // Update messages
$('p.messages').hide(); $('p.messages').hide();
$('#url_title').text(playlist.name); $('#url_title').text(playlist.toString());
$('#url_count').text(playlist.tracks.length); $('#url_count').text(playlist.tracks.length);
$('#url_done').show(); $('#url_done').show();
// Register playlist // Register playlist
Expand Down Expand Up @@ -166,7 +166,7 @@ var PLAYLICK = {
function callback (playlist) { function callback (playlist) {
// Update messages // Update messages
$('p.messages').hide(); $('p.messages').hide();
$('#spotify_title').text(playlist.name); $('#spotify_title').text(playlist.toString());
$('#spotify_done').show(); $('#spotify_done').show();
// Register playlist // Register playlist
CONTROLLERS.Playlist.register(playlist); CONTROLLERS.Playlist.register(playlist);
Expand Down Expand Up @@ -195,7 +195,7 @@ var PLAYLICK = {
function callback (playlist) { function callback (playlist) {
// Update messages // Update messages
$('p.messages').hide(); $('p.messages').hide();
var escapedAlbum = $('<b>').text(playlist.name); var escapedAlbum = $('<b>').text(playlist.toString());
$('#album_name').html(escapedAlbum); $('#album_name').html(escapedAlbum);
$('#album_done').show(); $('#album_done').show();
// Register playlist // Register playlist
Expand Down
5 changes: 3 additions & 2 deletions src/js/main/handlers.js
Expand Up @@ -150,7 +150,7 @@ CONTROLLERS.Playlist.playlistSidebarLists.click(function (e) {
var target = $(e.target); var target = $(e.target);
var playlist_item = target.closest('li.p'); var playlist_item = target.closest('li.p');
// Load the clicked playlist // 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(); e.preventDefault();
target.blur(); target.blur();
CONTROLLERS.Playlist.loadItem(playlist_item); CONTROLLERS.Playlist.loadItem(playlist_item);
Expand Down Expand Up @@ -178,7 +178,8 @@ CONTROLLERS.Playlist.playlistSidebarLists.click(function (e) {
var form = target.parents('form'); var form = target.parents('form');
var params = UTIL.serializeForm(form); var params = UTIL.serializeForm(form);
var playlist = playlist_item.data('playlist'); 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); CONTROLLERS.Playlist.toggleSidebarEditName(playlist_item);
} }
}); });
Expand Down
8 changes: 7 additions & 1 deletion src/js/main/models.js
Expand Up @@ -36,7 +36,13 @@
var play_indicator = $('<a href="#" class="playlist_playing" title="Playing">'); var play_indicator = $('<a href="#" class="playlist_playing" title="Playing">');
var delete_link = $('<a href="#" class="delete_playlist" title="Delete playlist">').text('╳'); 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 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">') var edit_form = $('<form style="display: none;" class="edit_playlist_form">')
.append('<input type="text" name="name" class="playlist_name">') .append('<input type="text" name="name" class="playlist_name">')
.append('<input type="submit" value="save">'); .append('<input type="submit" value="save">');
Expand Down
22 changes: 12 additions & 10 deletions src/js/models/playlist.model.js
Expand Up @@ -27,8 +27,10 @@ function Playlist (options) {
} }
} }
this.type = this.options.type || 'playlist'; 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.artist = this.options.artist || '';
this.album = this.options.album || '';
this.title = this.options.title;
this.image = this.options.image || ''; this.image = this.options.image || '';
this.subtitle = this.options.subtitle || ''; this.subtitle = this.options.subtitle || '';
this.description = this.options.description || ''; this.description = this.options.description || '';
Expand Down Expand Up @@ -70,22 +72,20 @@ Playlist.prototype = {
/** /**
* Playlist management * Playlist management
**/ **/
set_name: function (name) {
this.name = name;
// AUTOSAVE
this.save();
},
isAlbum: function () { isAlbum: function () {
return this.type == 'album'; return this.type == 'album';
}, },
albumToString: function () { albumToString: function () {
return this.artist + ' - ' + this.name; return this.artist + ' - ' + this.album;
}, },
toString: function () { toString: function () {
if (this.title) {
return this.title;
}
if (this.isAlbum()) { if (this.isAlbum()) {
return this.albumToString(); return this.albumToString();
} }
return this.name; return "Playlist: " + this.date.toLocaleString();
}, },
/** /**
* Fetch tracks from Couch * Fetch tracks from Couch
Expand Down Expand Up @@ -167,7 +167,7 @@ Playlist.prototype = {
+ 'track: "' + playlist_track.track.name.replace(/"/g, '\\"') + '"' + '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' + 'tell application "iTunes"\n'
+ ' set new_playlist to (make playlist with properties {name:playlist_name})\n' + ' set new_playlist to (make playlist with properties {name:playlist_name})\n'
+ ' set l to source "Library"\n' + ' set l to source "Library"\n'
Expand Down Expand Up @@ -305,8 +305,10 @@ Playlist.prototype = {
var doc = $.extend(this.get_doc_ref(), { var doc = $.extend(this.get_doc_ref(), {
published: this.published, published: this.published,
type: this.type, type: this.type,
name: this.name, date: this.date.getTime(),
title: this.title,
artist: this.artist, artist: this.artist,
album: this.album,
image: this.image, image: this.image,
subtitle: this.subtitle, subtitle: this.subtitle,
description: this.description, description: this.description,
Expand Down
2 changes: 1 addition & 1 deletion src/js/util.js
Expand Up @@ -25,7 +25,7 @@ var UTIL = {
compareString: function (a, b) { compareString: function (a, b) {
a = a || ''; a = a || '';
b = b || ''; b = b || '';
return a.trim().toUpperCase() == b.trim().toUpperCase(); return a.toUpperCase() == b.toUpperCase();
}, },
getHashParts: function () { getHashParts: function () {
var hash_sections = window.location.hash.replace(/^#(.*)/, '$1').split(';'); var hash_sections = window.location.hash.replace(/^#(.*)/, '$1').split(';');
Expand Down

0 comments on commit 6d78b29

Please sign in to comment.