diff --git a/channel.js b/channel.js index 8cdb474b..a261fe4d 100644 --- a/channel.js +++ b/channel.js @@ -819,6 +819,21 @@ Channel.prototype.tryMove = function(user, data) { /* REGION Polls */ +Channel.prototype.tryOpenPoll = function(user, data) { + if(!Rank.hasPermission(user, "poll") && this.leader != user) { + return; + } + + if(!data.title || !data.opts) { + return; + } + + var poll = new Poll(user.name, data.title, data.opts); + this.poll = poll; + this.broadcastPoll(); + this.logger.log("*** " + user.name + " Opened Poll: '" + poll.title + "'"); +} + Channel.prototype.tryClosePoll = function(user) { if(!Rank.hasPermission(user, "poll") && this.leader != user) { return; diff --git a/user.js b/user.js index c9de7bf7..d6de6ce2 100644 --- a/user.js +++ b/user.js @@ -101,6 +101,12 @@ User.prototype.initCallbacks = function() { } }.bind(this)); + this.socket.on("newPoll", function(data) { + if(this.channel != null) { + this.channel.tryOpenPoll(this, data); + } + }.bind(this)); + this.socket.on("playerReady", function() { if(this.channel != null) { this.channel.sendMediaUpdate(this); diff --git a/www/assets/js/client.js b/www/assets/js/client.js index 09fe46c3..36342c70 100644 --- a/www/assets/js/client.js +++ b/www/assets/js/client.js @@ -213,9 +213,15 @@ $("#register").click(function() { $("#chatline").keydown(function(ev) { if(ev.keyCode == 13 && $("#chatline").val() != "") { - socket.emit("chatMsg", { - msg: $("#chatline").val() - }); + if($("#chatline").val().trim() == "/poll") { + newPollMenu(); + $("#chatline").val(""); + } + else { + socket.emit("chatMsg", { + msg: $("#chatline").val() + }); + } CHATHIST.push($("#chatline").val()); if(CHATHIST.length > 10) CHATHIST.shift(); diff --git a/www/assets/js/functions.js b/www/assets/js/functions.js index b76fd7bb..2a5c041b 100644 --- a/www/assets/js/functions.js +++ b/www/assets/js/functions.js @@ -730,3 +730,68 @@ function enableBerrymotes() { monkeyPatchChat(); }); } + +function newPollMenu() { + var modal = $("
").addClass("modal hide fade") + .appendTo($("body")); + var head = $("").addClass("modal-header") + .appendTo(modal); + $("").addClass("close") + .attr("data-dismiss", "modal") + .attr("aria-hidden", "true") + .appendTo(head)[0].innerHTML = "×"; + $("").text("New Poll").appendTo(head); + var body = $("").addClass("modal-body").appendTo(modal); + + var form = $("").addClass("form-horizontal") + .appendTo(body); + + var tgroup = $("").addClass("control-group").appendTo(form); + $("").text("Title") + .addClass("control-label") + .attr("for", "polltitle") + .appendTo(tgroup); + $("").attr("type", "text") + .attr("id", "polltitle") + .appendTo($("").addClass("controls").appendTo(tgroup)) + + function addPollOption() { + var g = $("").addClass("control-group").appendTo(form); + var c = $("").addClass("controls").appendTo(g); + $("").attr("type", "text") + .appendTo(c); + } + addPollOption(); + + var footer = $("").addClass("modal-footer").appendTo(modal); + $("").addClass("btn pull-left") + .text("Add Poll Option") + .appendTo(footer) + .click(addPollOption); + + var submit = function() { + var all = form.find("input[type=\"text\"]"); + var title = $(all[0]).val(); + var opts = new Array(all.length - 1); + for(var i = 1; i < all.length; i++) { + opts[i - 1] = $(all[i]).val(); + } + + console.log(title, opts); + socket.emit("newPoll", { + title: title, + opts: opts + }); + } + + $("").addClass("btn btn-primary") + .attr("data-dismiss", "modal") + .attr("aria-hidden", "true") + .text("Open Poll") + .appendTo(footer) + .click(submit); + modal.on("hidden", function() { + modal.remove(); + }); + modal.modal(); +} diff --git a/www/help.html b/www/help.html index 00177850..9822a14e 100644 --- a/www/help.html +++ b/www/help.html @@ -104,6 +104,11 @@ +/poll(no parameters)
There are also some other chat features. When your name appears in a message, the message will be highlighted. If you type the beginning of someone's name in chat, pressing tab will attempt to autocomplete the name.