diff --git a/rdio-enhancer.css b/rdio-enhancer.css index d95c363..2f6596b 100644 --- a/rdio-enhancer.css +++ b/rdio-enhancer.css @@ -117,9 +117,39 @@ } .section_header .exportToCSV { - padding: 0 8px; + padding: 0 12px; font-size: 12px; color: #008fd5; float:right; margin-right:5px; +} + +.Dialog.unavailable_dialog .album { + margin: 0; + padding: 10px 0; + line-height: 18px; + border-bottom: 1px solid #e1e4e6; + position: relative; +} +.Dialog.unavailable_dialog .album:last-child { + border: 0; +} +.Dialog.unavailable_dialog .album_name, +.Dialog.unavailable_dialog .album_artist { + max-width: 400px; +} +.Dialog.unavailable_dialog .album_artist a { + color: #94999c; +} +.Dialog.unavailable_dialog .badge { + position: absolute; + right: 0; + top: 50%; + margin: 0; + color: #fff; + cursor: default; + background: rgba(55, 70, 79, 0.6); + border-radius: 3px; + -webkit-transform: translateY(-50%); + transform: translateY(-50%); } \ No newline at end of file diff --git a/rdio-enhancer.js b/rdio-enhancer.js index e027120..56f7887 100644 --- a/rdio-enhancer.js +++ b/rdio-enhancer.js @@ -548,7 +548,7 @@ function injectedJs() { } - if (a == "Profile.Favorites") { + if(a == "Profile.Favorites") { b.orig_onRendered = b.onRendered; b.onRendered = function() { b.orig_onRendered.call(this); @@ -594,7 +594,78 @@ function injectedJs() { } } - if (a== "InfiniteScroll") { + if(a == "Menu") { + b.orig_onRendered = b.onRendered; + b.onRendered = function() { + b.orig_onRendered.call(this); + var menu = this; + + if(menu.$('li:first-child').text().trim() == 'Name') { + + // private scope for this menu component + (function() { + + var item = $('
  • Unavailable Albums
  • '), + spinner = new R.Components.Spinner(); + template = _.template('' + + '
    ' + + '
    <%= name %>
    ' + + '
    <%= artist %>
    ' + + '
    Unavailable
    ' + + '
    ' + ); + + menu.$('ul').append(item); + item.on('click', function(event) { + + R.loader.load(["Dialog"], function() { + + var dialog = new R.Components.Dialog({ + title: 'Unavailable Albums', + width: 550, + extraClassName: 'unavailable_dialog', + closeButton: 'Close' + }); + + dialog.onOpen = function() { + + if(R.enhancer.cache['unavailable_albums']) { + dialog.onLoaded(R.enhancer.cache['unavailable_albums']); + } else { + this.$('.body .container').append(spinner.el); + spinner.spin(); + R.enhancer.getUnavilableAlbums(function(results) { + // caching results of this call as it's unlikely that: + // 1) someone will add an unavailable album to their favorites + // 2) a previously saved album will change to unavailable during their session + R.enhancer.cache['unavailable_albums'] = results; + dialog.onLoaded(results); + }); + } + }; + + dialog.onLoaded = function(data) { + var albums = []; + for(var i = 0, length = data.length, album; i < length; i++) { + // console.debug(data[i]); + albums.push(template(data[i])); + } + spinner.stop(); + this.$('.body .container').html(''); + this.onResize(); + }; + + menu.close(); + dialog.open(); + }); + }); + + })(); + } + } + } + + if(a == "InfiniteScroll") { b.orig_ensureItemsLoaded = b.ensureItemsLoaded; b.ensureItemsLoaded = function() { // When manually filtered (by tagging system) @@ -762,6 +833,27 @@ function injectedJs() { }; }, + getUnavilableAlbums: function(callback) { + R.Api.request({ + method: "getAlbumsInCollection", + content: {}, + success: function(response) { + if(response.status != 'ok') { + R.enhancer.show_message('There was an error getting unavailable albums.', true); + return; + } + var unavailables = []; + $.each(response.result.items, function(index, album) { + if(!album.canStream) unavailables.push(album); + }); + callback(unavailables); + }, + error: function() { + R.enhancer.show_message('There was an error getting unavailable albums.', true); + } + }); + }, + getTracks: function(callback) { R.enhancer.getModels( callback, @@ -1101,6 +1193,9 @@ function injectedJs() { } }; + // cache for storing results of API calls as needed + R.enhancer.cache = {}; + // Call all of the overwrite functions to hook into Rdio R.enhancer.overwrite_playlist(); R.enhancer.overwrite_create();