From 0d1a2543d0da9c523d68ceef3a31a0c16ff10be9 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sat, 11 Feb 2012 14:18:45 +0000
Subject: [PATCH] add a "skip" button (Next)

---
 server/djrandom/frontend/static/js/djr/backend.js | 11 +++++++++++
 server/djrandom/frontend/static/js/djr/djr.js     |  3 +++
 server/djrandom/frontend/static/js/djr/player.js  |  6 ++++++
 server/djrandom/frontend/templates/index.html     |  3 ++-
 4 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/server/djrandom/frontend/static/js/djr/backend.js b/server/djrandom/frontend/static/js/djr/backend.js
index c2c3514..2bdabd1 100644
--- a/server/djrandom/frontend/static/js/djr/backend.js
+++ b/server/djrandom/frontend/static/js/djr/backend.js
@@ -224,6 +224,17 @@ djr.Backend.prototype.nowPlaying = function(song, old_songs) {
           });
 };
 
+/**
+ * Report that we skipped a song.
+ *
+ * @param {string} song SHA1 hash of the song that was skipped
+djr.Backend.prototype.skipSong = function(song) {
+  $.ajax({url: '/json/skip',
+          data: {'cur': song},
+          type: 'POST'
+          });
+};
+
 /**
   * Request N never played songs
   *
diff --git a/server/djrandom/frontend/static/js/djr/djr.js b/server/djrandom/frontend/static/js/djr/djr.js
index 8f4a902..e95be9e 100644
--- a/server/djrandom/frontend/static/js/djr/djr.js
+++ b/server/djrandom/frontend/static/js/djr/djr.js
@@ -43,6 +43,9 @@ djr.init = function (userid) {
   });
 
   // Add onclick hooks to the playlist controls.
+  $('#skipbtn').click(function() {
+    djr.player().skipSong();
+  });
   $('#playlistClearBtn').click(function() {
     djr.player().clearPlaylist();
   });
diff --git a/server/djrandom/frontend/static/js/djr/player.js b/server/djrandom/frontend/static/js/djr/player.js
index 3f6bbe6..08ae83c 100644
--- a/server/djrandom/frontend/static/js/djr/player.js
+++ b/server/djrandom/frontend/static/js/djr/player.js
@@ -351,6 +351,12 @@ djr.Player.prototype.play = function(song) {
   this.backend.nowPlaying(song, this.old_songs);
 };
 
+// Skip the current song, play the next one.
+djr.Player.prototype.skipSong = function() {
+  this.backend.skipSong(this.cur_song);
+  this.nextSong();
+};
+
 // Start playing the next song.
 djr.Player.prototype.nextSong = function() {
   if (this.auto_extend && this.playlist.isLastSong(this.cur_song)) {
diff --git a/server/djrandom/frontend/templates/index.html b/server/djrandom/frontend/templates/index.html
index 6a50d5f..b1713de 100644
--- a/server/djrandom/frontend/templates/index.html
+++ b/server/djrandom/frontend/templates/index.html
@@ -108,7 +108,8 @@ $(document).ready(function() {
 
         <div id="metasongcontrols" class="buttonbox">
           <br/>
-          <a id="pllistbtn">Playlists</a>
+          <a id="skipbtn"><b>Next</b></a>
+          | <a id="pllistbtn">Playlists</a>
           | <a id="lyricsbtn">Lyrics</a>
           | <a id="wikibtn">Wikipedia</a>
           | <a id="lastfmbtn">Song Info</a>
-- 
GitLab