added writeins
This commit is contained in:
parent
1652b23590
commit
6117fbe1e7
|
@ -353,6 +353,36 @@ def vote(socket, data):
|
||||||
socket.send('vote', data)
|
socket.send('vote', data)
|
||||||
|
|
||||||
|
|
||||||
|
def write_in(socket, data):
|
||||||
|
"""
|
||||||
|
Called when a player creates a new write-in.
|
||||||
|
"""
|
||||||
|
post_id = data.get('post_id')
|
||||||
|
option_text = data.get('option_text', '')
|
||||||
|
user = socket.scope['user']
|
||||||
|
|
||||||
|
option_text = option_text.strip()
|
||||||
|
if not option_text:
|
||||||
|
return
|
||||||
|
option_text = "Write in: " + bleach.clean(option_text)
|
||||||
|
if len(option_text) > 200:
|
||||||
|
# error message?
|
||||||
|
return
|
||||||
|
p = Poll.objects.get(post_id=post_id)
|
||||||
|
o = PollOption(
|
||||||
|
poll=p,
|
||||||
|
text=option_text
|
||||||
|
)
|
||||||
|
o.save()
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
data['post_id'] = post_id
|
||||||
|
data['post_type'] = 'poll'
|
||||||
|
data['option_id'] = o.id
|
||||||
|
data['option_text'] = option_text
|
||||||
|
socket.send('update_post', data)
|
||||||
|
|
||||||
|
|
||||||
events = {}
|
events = {}
|
||||||
for obj in dir():
|
for obj in dir():
|
||||||
if type(locals()[obj]) == types.FunctionType:
|
if type(locals()[obj]) == types.FunctionType:
|
||||||
|
|
|
@ -79,12 +79,12 @@
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
{# if post.id == quest.open_post_id and post.id|is_write_in %}
|
{% if post.poll.open and post.poll.allow_writein %}
|
||||||
<div id="writeinContainer">
|
<div id="writeinContainer-{{ post.id }}">
|
||||||
Write-in: <input type="text" id="writeinInput" placeholder="Custom choice..." maxlength="200" /><br />
|
Write-in: <input type="text" id="writeinInput-{{ post.id }}" placeholder="Custom choice..." maxlength="200" /><br />
|
||||||
<input type="submit" id="writeinSubmit" value="Submit" onclick="submitWritein({{ post.id }});"/>
|
<input type="submit" id="writeinSubmit-{{ post.id }}" value="Submit" onclick="submitWritein({{ post.id }});"/>
|
||||||
</div>
|
</div>
|
||||||
{% endif #}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div><br />
|
</div><br />
|
||||||
|
|
|
@ -70,8 +70,8 @@ socket.events['new_post'] = function(data) {
|
||||||
post_str += '</table>';
|
post_str += '</table>';
|
||||||
if (data.allow_writein) {
|
if (data.allow_writein) {
|
||||||
post_str += '<div id="writeinContainer">';
|
post_str += '<div id="writeinContainer">';
|
||||||
post_str += 'Write-in: <input type="text" id="writeinInput" placeholder="Custom choice..." maxlength="200" /><br />';
|
post_str += 'Write-in: <input type="text" id="writeinInput-' + data.post_id + '" placeholder="Custom choice..." maxlength="200" /><br />';
|
||||||
post_str += '<input type="submit" id="writeinSubmit" value="Submit" onclick="submitWritein({{ quest_post[0] }});"/></div>';
|
post_str += '<input type="submit" id="writeinSubmit-' + data.post_id + '" value="Submit" onclick="submitWritein(' + data.post_id + ');"/></div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post_str += '</div></div><br />';
|
post_str += '</div></div><br />';
|
||||||
|
@ -95,16 +95,17 @@ socket.events['close_all_posts'] = function(data) {
|
||||||
}
|
}
|
||||||
socket.events['update_post'] = function(data) {
|
socket.events['update_post'] = function(data) {
|
||||||
let post = document.getElementById('questPostData-' + data.post_id);
|
let post = document.getElementById('questPostData-' + data.post_id);
|
||||||
if (data.post_type === 'text') {
|
if (data.post_type === 'text') { // edit post
|
||||||
post.innerHTML = data.post_text;
|
post.innerHTML = data.post_text;
|
||||||
} else if (data.post_type === 'dice') {
|
} else if (data.post_type === 'dice') { // diceroll
|
||||||
post.innerHTML += '<b>' + data.post_text + '</b><br>';
|
post.innerHTML += '<b>' + data.post_text + '</b><br>';
|
||||||
} else if (data.post_type === 'poll') {
|
} else if (data.post_type === 'poll') { // write-in
|
||||||
let row = post.children[1].insertRow(-1);
|
let row = post.children[1].insertRow(-1);
|
||||||
|
row.id = 'optionRow-' + data.option_id;
|
||||||
let cell = row.insertCell(0);
|
let cell = row.insertCell(0);
|
||||||
cell.className = 'pollCheckBox';
|
cell.className = 'pollCheckBox';
|
||||||
cell.innerHTML = '<input type="checkbox" id="pollInput-' + data.options_id + '" onchange="vote(' + data.post_id + ',' + data.options_id + ')"/>';
|
cell.innerHTML = '<input type="checkbox" id="pollInput-' + data.option_id + '" onchange="vote(' + data.post_id + ',' + data.option_id + ')"/>';
|
||||||
cell.innerHTML += '<label for="pollInput-' + data.options_id + '"></label>';
|
cell.innerHTML += '<label for="pollInput-' + data.option_id + '"></label>';
|
||||||
|
|
||||||
cell = row.insertCell(1);
|
cell = row.insertCell(1);
|
||||||
cell.className = 'option_text';
|
cell.className = 'option_text';
|
||||||
|
@ -141,12 +142,12 @@ function vote(post_id, option_id) {
|
||||||
socket.send('vote', {post_id: post_id, option_id: option_id, polarity: polarity, quest_id: quest_id});
|
socket.send('vote', {post_id: post_id, option_id: option_id, polarity: polarity, quest_id: quest_id});
|
||||||
}
|
}
|
||||||
function submitWritein(post_id) {
|
function submitWritein(post_id) {
|
||||||
let writeinInput = document.getElementById('writeinInput');
|
let writeinInput = document.getElementById('writeinInput-' + post_id);
|
||||||
if (!writeinInput) { return; }
|
if (!writeinInput) { return; }
|
||||||
let option_text = writeinInput.value;
|
let option_text = writeinInput.value;
|
||||||
writeinInput.value = '';
|
writeinInput.value = '';
|
||||||
if (!option_text) { return; }
|
if (!option_text) { return; }
|
||||||
socket.emit('write_in', {option_text: option_text, post_id: post_id, room: room_id});
|
socket.send('write_in', {option_text: option_text, post_id: post_id});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helpers */
|
/* Helpers */
|
||||||
|
@ -201,7 +202,7 @@ function close_post(post_id) {
|
||||||
for (let i = 0; i < boxes.length; i++) {
|
for (let i = 0; i < boxes.length; i++) {
|
||||||
boxes[i].disabled = true;
|
boxes[i].disabled = true;
|
||||||
}
|
}
|
||||||
let writein = document.getElementById('writeinContainer');
|
let writein = document.getElementById('writeinContainer-' + post_id);
|
||||||
if (writein) {
|
if (writein) {
|
||||||
writein.style.display = 'none';
|
writein.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
@ -217,7 +218,7 @@ function open_post(post_id) {
|
||||||
for (let i = 0; i < boxes.length; i++) {
|
for (let i = 0; i < boxes.length; i++) {
|
||||||
boxes[i].disabled = false;
|
boxes[i].disabled = false;
|
||||||
}
|
}
|
||||||
let writein = document.getElementById('writeinContainer');
|
let writein = document.getElementById('writeinContainer-' + post_id);
|
||||||
if (writein) {
|
if (writein) {
|
||||||
writein.style.display = 'initial';
|
writein.style.display = 'initial';
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,8 @@ socket.events['new_post'] = function(data) {
|
||||||
post_str += '</table>';
|
post_str += '</table>';
|
||||||
if (data.allow_writein) {
|
if (data.allow_writein) {
|
||||||
post_str += '<div id="writeinContainer">';
|
post_str += '<div id="writeinContainer">';
|
||||||
post_str += 'Write-in: <input type="text" id="writeinInput" placeholder="Custom choice..." maxlength="200" /><br />';
|
post_str += 'Write-in: <input type="text" id="writeinInput-' + data.post_id + '" placeholder="Custom choice..." maxlength="200" /><br />';
|
||||||
post_str += '<input type="submit" id="writeinSubmit" value="Submit" onclick="submitWritein({{ quest_post[0] }});"/></div>';
|
post_str += '<input type="submit" id="writeinSubmit-' + data.post_id + '" value="Submit" onclick="submitWritein(' + data.post_id + ');"/></div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post_str += '</div></div><br />';
|
post_str += '</div></div><br />';
|
||||||
|
@ -111,7 +111,7 @@ function close_post(post_id) {
|
||||||
for (let i = 0; i < boxes.length; i++) {
|
for (let i = 0; i < boxes.length; i++) {
|
||||||
boxes[i].disabled = true;
|
boxes[i].disabled = true;
|
||||||
}
|
}
|
||||||
let writein = document.getElementById('writeinContainer');
|
let writein = document.getElementById('writeinContainer-' + post_id);
|
||||||
if (writein) {
|
if (writein) {
|
||||||
writein.style.display = 'none';
|
writein.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ function open_post(post_id) {
|
||||||
for (let i = 0; i < boxes.length; i++) {
|
for (let i = 0; i < boxes.length; i++) {
|
||||||
boxes[i].disabled = false;
|
boxes[i].disabled = false;
|
||||||
}
|
}
|
||||||
let writein = document.getElementById('writeinContainer');
|
let writein = document.getElementById('writeinContainer-' + post_id);
|
||||||
if (writein) {
|
if (writein) {
|
||||||
writein.style.display = 'initial';
|
writein.style.display = 'initial';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user