From 6d78b2907ac16e23dbe12bbf4c41a696772f9288 Mon Sep 17 00:00:00 2001 From: James Wheare Date: Wed, 16 Dec 2009 19:21:16 +0000 Subject: [PATCH] Fix playlist created dates and title handling. String.trim is not standard --- public/playlick.css | 9 +++++---- src/js/controllers/playlist.controller.js | 21 +++++---------------- src/js/importers.js | 7 ++++--- src/js/importers/lastfm.js | 6 +++--- src/js/importers/spotify.js | 4 ++-- src/js/main.js | 6 +++--- src/js/main/handlers.js | 5 +++-- src/js/main/models.js | 8 +++++++- src/js/models/playlist.model.js | 22 ++++++++++++---------- src/js/util.js | 2 +- 10 files changed, 45 insertions(+), 45 deletions(-) diff --git a/public/playlick.css b/public/playlick.css index ed23c5a..91d3ff8 100644 --- a/public/playlick.css +++ b/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 { diff --git a/src/js/controllers/playlist.controller.js b/src/js/controllers/playlist.controller.js index deb6ed1..badfb06 100644 --- a/src/js/controllers/playlist.controller.js +++ b/src/js/controllers/playlist.controller.js @@ -296,7 +296,7 @@ Playlist.prototype = { this.editForm = $('
').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; } diff --git a/src/js/importers.js b/src/js/importers.js index 059973e..d1d7eb1 100644 --- a/src/js/importers.js +++ b/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), diff --git a/src/js/importers/lastfm.js b/src/js/importers/lastfm.js index e3e4d57..b270db3 100644 --- a/src/js/importers/lastfm.js +++ b/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 = {}; diff --git a/src/js/importers/spotify.js b/src/js/importers/spotify.js index 9b3b9f7..e2eda94 100644 --- a/src/js/importers/spotify.js +++ b/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 }); diff --git a/src/js/main.js b/src/js/main.js index aaa1ec3..3db3351 100644 --- a/src/js/main.js +++ b/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 = $('').text(playlist.name); + var escapedAlbum = $('').text(playlist.toString()); $('#album_name').html(escapedAlbum); $('#album_done').show(); // Register playlist diff --git a/src/js/main/handlers.js b/src/js/main/handlers.js index 6d6c98a..b5721fb 100644 --- a/src/js/main/handlers.js +++ b/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); } }); diff --git a/src/js/main/models.js b/src/js/main/models.js index ff5ac3b..8b31be8 100644 --- a/src/js/main/models.js +++ b/src/js/main/models.js @@ -36,7 +36,13 @@ var play_indicator = $(''); var delete_link = $('').text('╳'); var edit_link = $('').text(STRINGS.edit_playlist_text); - var name = $('').text(UTIL.truncateString(this.toString())); + var name = $('') + .attr('title', this.toString()) + .append($('').text(UTIL.truncateString(this.toString()))); + if (this.isAlbum()) { + var albumArt = IMPORTERS.LastFm.getAlbumArt(this.artist, this.album); + name.prepend($('').attr('src', albumArt)); + } var edit_form = $('') .append('') .append(''); diff --git a/src/js/models/playlist.model.js b/src/js/models/playlist.model.js index 47bea65..96f12ad 100644 --- a/src/js/models/playlist.model.js +++ b/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, diff --git a/src/js/util.js b/src/js/util.js index bd61c23..41fc848 100644 --- a/src/js/util.js +++ b/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(';');