From bd7288bed32f23345125a62e84145ab07891d3af Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 1 Jun 2013 15:42:08 -0400 Subject: [PATCH] Add user playlist interface --- channel.js | 30 +++++++++++++++++++++++ user.js | 10 ++++++-- www/assets/js/callbacks.js | 18 ++++++++++++++ www/assets/js/client.js | 49 ++++++++++++++++++++++++++++++++++++++ www/assets/js/functions.js | 3 +++ www/channel.html | 41 ++++++++++++++++++++++++------- 6 files changed, 140 insertions(+), 11 deletions(-) diff --git a/channel.js b/channel.js index e12c8a16..14270bef 100644 --- a/channel.js +++ b/channel.js @@ -1079,6 +1079,36 @@ Channel.prototype.tryQueue = function(user, data) { this.enqueue(data, user); } +Channel.prototype.tryQueuePlaylist = function(user, data) { + if(!this.hasPermission(user, "playlistadd")) { + return; + } + + if(typeof data.name != "string" || + typeof data.pos != "string") { + return; + } + + if(data.pos == "next" && !this.hasPermission(user, "playlistnext")) { + return; + } + + var pl = Database.loadUserPlaylist(user.name, data.name); + // Queue in reverse order for qnext + if(data.pos == "next") { + for(var i = pl.length - 1; i >= 0; i--) { + pl[i].pos = "next"; + this.enqueue(pl[i], user); + } + } + else { + for(var i = 0; i < pl.length; i++) { + pl[i].pos = "end"; + this.enqueue(pl[i], user); + } + } +} + Channel.prototype.setTemp = function(idx, temp) { var med = this.queue[idx]; med.temp = temp; diff --git a/user.js b/user.js index 14c87059..275b8d77 100644 --- a/user.js +++ b/user.js @@ -417,7 +417,7 @@ User.prototype.initCallbacks = function() { this.socket.on("listPlaylists", function(data) { if(this.name == "" || this.rank < 1) { - socket.emit("listPlaylists", { + this.socket.emit("listPlaylists", { pllist: [], error: "You must be logged in to manage playlists" }); @@ -425,7 +425,7 @@ User.prototype.initCallbacks = function() { } var list = Database.getUserPlaylists(this.name); - socket.emit("listPlaylists", { + this.socket.emit("listPlaylists", { pllist: list, }); }.bind(this)); @@ -458,6 +458,12 @@ User.prototype.initCallbacks = function() { error: result ? false : "Unknown" }); }.bind(this)); + + this.socket.on("queuePlaylist", function(data) { + if(this.channel != null) { + this.channel.tryQueuePlaylist(this, data); + } + }.bind(this)); } // Handle administration diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index 5ef24636..6852693a 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -750,6 +750,24 @@ Callbacks = { makeAlert("Error", data.error, "alert-error"); } }, + + listPlaylists: function(data) { + if(data.error) { + makeAlert("Error", data.error, "alert-error") + .addClass("span12") + .css("margin-left", "0") + .insertBefore($("#userpl_name").parent()); + } + else { + var pls = data.pllist; + $("#userpl_dropdown").html(""); + for(var i = 0; i < pls.length; i++) { + $("