Add poll editor

Implements the suggestion from Issue #34
This commit is contained in:
calzoneman 2013-04-18 11:42:07 -05:00
parent 9338905519
commit 5350fa2e93
5 changed files with 100 additions and 3 deletions

View File

@ -819,6 +819,21 @@ Channel.prototype.tryMove = function(user, data) {
/* REGION Polls */ /* 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) { Channel.prototype.tryClosePoll = function(user) {
if(!Rank.hasPermission(user, "poll") && this.leader != user) { if(!Rank.hasPermission(user, "poll") && this.leader != user) {
return; return;

View File

@ -101,6 +101,12 @@ User.prototype.initCallbacks = function() {
} }
}.bind(this)); }.bind(this));
this.socket.on("newPoll", function(data) {
if(this.channel != null) {
this.channel.tryOpenPoll(this, data);
}
}.bind(this));
this.socket.on("playerReady", function() { this.socket.on("playerReady", function() {
if(this.channel != null) { if(this.channel != null) {
this.channel.sendMediaUpdate(this); this.channel.sendMediaUpdate(this);

View File

@ -213,9 +213,15 @@ $("#register").click(function() {
$("#chatline").keydown(function(ev) { $("#chatline").keydown(function(ev) {
if(ev.keyCode == 13 && $("#chatline").val() != "") { if(ev.keyCode == 13 && $("#chatline").val() != "") {
socket.emit("chatMsg", { if($("#chatline").val().trim() == "/poll") {
msg: $("#chatline").val() newPollMenu();
}); $("#chatline").val("");
}
else {
socket.emit("chatMsg", {
msg: $("#chatline").val()
});
}
CHATHIST.push($("#chatline").val()); CHATHIST.push($("#chatline").val());
if(CHATHIST.length > 10) if(CHATHIST.length > 10)
CHATHIST.shift(); CHATHIST.shift();

View File

@ -730,3 +730,68 @@ function enableBerrymotes() {
monkeyPatchChat(); monkeyPatchChat();
}); });
} }
function newPollMenu() {
var modal = $("<div/>").addClass("modal hide fade")
.appendTo($("body"));
var head = $("<div/>").addClass("modal-header")
.appendTo(modal);
$("<button/>").addClass("close")
.attr("data-dismiss", "modal")
.attr("aria-hidden", "true")
.appendTo(head)[0].innerHTML = "&times;";
$("<h3/>").text("New Poll").appendTo(head);
var body = $("<div/>").addClass("modal-body").appendTo(modal);
var form = $("<form/>").addClass("form-horizontal")
.appendTo(body);
var tgroup = $("<div/>").addClass("control-group").appendTo(form);
$("<label/>").text("Title")
.addClass("control-label")
.attr("for", "polltitle")
.appendTo(tgroup);
$("<input/>").attr("type", "text")
.attr("id", "polltitle")
.appendTo($("<div/>").addClass("controls").appendTo(tgroup))
function addPollOption() {
var g = $("<div/>").addClass("control-group").appendTo(form);
var c = $("<div/>").addClass("controls").appendTo(g);
$("<input/>").attr("type", "text")
.appendTo(c);
}
addPollOption();
var footer = $("<div/>").addClass("modal-footer").appendTo(modal);
$("<button/>").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
});
}
$("<button/>").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();
}

View File

@ -104,6 +104,11 @@
</div> </div>
</td> </td>
</tr> </tr>
<tr>
<td><pre>/poll</pre> (no parameters)</td>
<td>Moderators</td>
<td>A poll editor is popped up allowing for easy creation of the poll, and allowing commas in the poll title and options</td>
</tr>
</table> </table>
<p>There are also some other chat features. When your name appears in a message, <span class="nick-highlight">the message will be highlighted.</span> If you type the beginning of someone's name in chat, pressing tab will attempt to autocomplete the name.</p> <p>There are also some other chat features. When your name appears in a message, <span class="nick-highlight">the message will be highlighted.</span> If you type the beginning of someone's name in chat, pressing tab will attempt to autocomplete the name.</p>