From 9bbbd471728bdeede39e5274e2d8f87119f76e38 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Thu, 29 Sep 2011 22:54:45 +0100
Subject: [PATCH] add an icon/action for "more like this" search on each song

---
 server/djrandom/frontend/static/js/djr/player.js | 15 +++++++++++++++
 server/djrandom/frontend/templates/_macros.html  |  1 +
 2 files changed, 16 insertions(+)

diff --git a/server/djrandom/frontend/static/js/djr/player.js b/server/djrandom/frontend/static/js/djr/player.js
index f90fdda..534b445 100644
--- a/server/djrandom/frontend/static/js/djr/player.js
+++ b/server/djrandom/frontend/static/js/djr/player.js
@@ -192,6 +192,17 @@ djr.Player.prototype.autoExtendCurrentPlaylist = function(callback) {
   });
 };
 
+// Extend the current playlist with the results of a MoreLikeThis
+// search based on a single selected song.
+djr.Player.prototype.moreLikeThis = function(sha1) {
+  var player = this;
+  var songs = [sha1];
+
+  this.backend.moreLikeThese(songs, function(results) {
+    player.createChunk(results, 'like that');
+  });
+};
+
 djr.Player.prototype.createChunk = function(songs, chunk_title) {
   // Create the new chunk, with unique songs.
   var chunk = this.playlist.createUniqueChunk(songs, chunk_title);
@@ -263,6 +274,10 @@ djr.Player.prototype.setChunkHtml = function(chunk, chunk_id, songs_html) {
     var sha1 = $(this).parent().parent().attr('id').substr(5);
     player.removeSong(sha1);
   });
+  chunk_div.find('.chunk_inner .ctlbox .ctl_love').click(function() {
+    var sha1 = $(this).parent().parent().attr('id').substr(5);
+    player.moreLikeThis(sha1);
+  });
 };
 
 // Start playing a specific song.
diff --git a/server/djrandom/frontend/templates/_macros.html b/server/djrandom/frontend/templates/_macros.html
index 1c25e24..3557ad5 100644
--- a/server/djrandom/frontend/templates/_macros.html
+++ b/server/djrandom/frontend/templates/_macros.html
@@ -1,6 +1,7 @@
 {% macro render_song(mp3) -%}
 <div class="song" id="song_{{ mp3.sha1 }}">
   <div class="ctlbox" style="display:none;">
+    <a id="song_{{ mp3.sha1 }}_mlt" class="ctl_btn ctl_love"></a>
     <a id="song_{{ mp3.sha1 }}_remove" class="ctl_btn ctl_remove"></a>
   </div>
   <a id="play_{{ mp3.sha1 }}" class="song_a">
-- 
GitLab