diff --git a/events.py b/events.py
index f80dcbe..ab45b52 100644
--- a/events.py
+++ b/events.py
@@ -346,3 +346,26 @@ def vote(data):
data["option_id"] = option_id
data["polarity"] = polarity
emit("vote", data, room=room)
+
+
+@socketio.on("write_in")
+def write_in(data):
+ """
+ Called when a user submits a write-in option.
+ """
+ room = data.get("room")
+ post_id = data.get("post_id")
+ option_text = data.get("option_text")
+
+ if len(option_text) > 200:
+ return
+ option_text = bleach.clean(option_text)
+ option_text = "Write-in: " + option_text
+ option_id = db.insert_poll_option(post_id, option_text)
+
+ data = {}
+ data["post_id"] = post_id
+ data["post_type"] = "poll"
+ data["option_id"] = option_id
+ data["option_text"] = option_text
+ emit("update_post", data, room=room)
diff --git a/static/anonkunQM.js b/static/anonkunQM.js
index 231c720..4874ae1 100644
--- a/static/anonkunQM.js
+++ b/static/anonkunQM.js
@@ -30,6 +30,7 @@ var tid = setInterval( function () {
post_str += 'pollPost active_post">';
}
post_str += '
';
if (data.post_type == 'text') {
post_str += data.post;
@@ -61,11 +63,24 @@ var tid = setInterval( function () {
socket.on('update_post', function(data) {
let post_id = data.post_id;
let post = document.getElementById('questPostData-' + post_id);
- if (data.post_type == 'text') {
+ if (data.post_type === 'text') {
post.innerHTML = data.post;
- }
- else if (data.post_type == 'dice') {
+ } else if (data.post_type === 'dice') {
post.innerHTML += '
' + data.post + '';
+ } else if (data.post_type === 'poll') {
+ let row = post.children[1].insertRow(-1);
+ let cell = row.insertCell(0);
+ cell.className = 'pollCheckBox';
+ cell.innerHTML = '
';
+ cell.innerHTML += '
';
+
+ cell = row.insertCell(1);
+ cell.className = 'option_text';
+ cell.innerHTML = data.option_text;
+
+ cell = row.insertCell(2);
+ cell.className = "optionVotes";
+ cell.innerHTML = "0";
}
});
socket.on('close_post', function(data) {
@@ -131,6 +146,30 @@ function pollVote(post_id, option_id) {
let polarity = document.getElementById('pollInput-' + option_id).checked;
socket.emit('vote', {post_id: post_id, option_id: option_id, polarity: polarity, room: room_id});
}
+function submitWritein(post_id) {
+ let writeinInput = document.getElementById('writeinInput');
+ if (!writeinInput) { return; }
+ let option_text = writeinInput.value;
+ writeinInput.value = '';
+ if (!option_text) { return; }
+ socket.emit('write_in', {option_text: option_text, post_id: post_id, room: room_id});
+}
+function deactivate_post() {
+ let post = document.getElementsByClassName('active_post');
+ if (post.length == 0) { return; }
+ post = post[0];
+ post.children[1].children[0].textContent = post.children[1].children[0].textContent.replace('Open', 'Closed');
+ post.classList.remove("active_post");
+ /* QM only */
+ post.children[0].children[2].outerHTML = "";
+ post.children[0].children[1].outerHTML = "";
+ /* end QM only */
+ let writein = document.getElementById('writeinContainer');
+ if (writein) {
+ writein.outerHTML = '';
+ }
+}
+/* QM only */
function makePost() {
let qparea = document.getElementById('postTextArea');
let text = qparea.value.trim();
@@ -169,19 +208,6 @@ function close_post(post_id) {
function open_post(post_id) {
socket.emit('open_post', {post_id: post_id, room: room_id});
}
-function deactivate_post() {
- let post = document.getElementsByClassName('active_post');
- if (post.length == 0) { return; }
- post = post[0];
- post.children[1].children[0].textContent = post.children[1].children[0].textContent.replace('Open', 'Closed');
- post.classList.remove("active_post");
- post.children[0].children[2].outerHTML = "";
- post.children[0].children[1].outerHTML = "";
- let writein = document.getElementById('writeinContainer');
- if (writein) {
- writein.outerHTML = '';
- }
-}
function insertPollOption() {
let opts = document.getElementById('pollOptions');
let num = opts.children.length+1;
@@ -210,3 +236,4 @@ function openPostTab(event, modeName) {
document.getElementById(modeName).style.display = "block";
event.currentTarget.className += " active";
}
+/* end QM only */
diff --git a/static/anonkunUser.js b/static/anonkunUser.js
index e7a33fe..c375b84 100644
--- a/static/anonkunUser.js
+++ b/static/anonkunUser.js
@@ -54,11 +54,24 @@ var tid = setInterval( function () {
socket.on('update_post', function(data) {
let post_id = data.post_id;
let post = document.getElementById('questPostData-' + post_id);
- if (data.post_type == 'text') {
+ if (data.post_type === 'text') {
post.innerHTML = data.post;
- }
- else if (data.post_type == 'dice') {
+ } else if (data.post_type === 'dice') {
post.innerHTML += '
' + data.post + '';
+ } else if (data.post_type === 'poll') {
+ let row = post.children[1].insertRow(-1);
+ let cell = row.insertCell(0);
+ cell.className = 'pollCheckBox';
+ cell.innerHTML = '
';
+ cell.innerHTML += '
';
+
+ cell = row.insertCell(1);
+ cell.className = 'option_text';
+ cell.innerHTML = data.option_text;
+
+ cell = row.insertCell(2);
+ cell.className = "optionVotes";
+ cell.innerHTML = "0";
}
});
socket.on('close_post', function(data) {
@@ -124,6 +137,14 @@ function pollVote(post_id, option_id) {
let polarity = document.getElementById('pollInput-' + option_id).checked;
socket.emit('vote', {post_id: post_id, option_id: option_id, polarity: polarity, room: room_id});
}
+function submitWritein(post_id) {
+ let writeinInput = document.getElementById('writeinInput');
+ if (!writeinInput) { return; }
+ let option_text = writeinInput.value;
+ writeinInput.value = '';
+ if (!option_text) { return; }
+ socket.emit('write_in', {option_text: option_text, post_id: post_id, room: room_id});
+}
function deactivate_post() {
let post = document.getElementsByClassName('active_post');
if (post.length == 0) { return; }
diff --git a/templates/quest.html b/templates/quest.html
index 84b44f1..af414ad 100644
--- a/templates/quest.html
+++ b/templates/quest.html
@@ -75,7 +75,8 @@
{% if quest_post[0] == open_post_id and quest_post[0]|is_write_in %}
- Write-in:
+ Write-in:
+
{% endif %}
{% endif %}