only one dicecall may be open a time

This commit is contained in:
iou1name 2018-08-24 18:24:25 -04:00
parent 5485bf8aa9
commit 3e015e75d9
3 changed files with 19 additions and 5 deletions

View File

@ -191,9 +191,16 @@ def open_post(socket, data):
"""
Called when the QM opens a closed post.
"""
# TODO: only posts on last page can be opened
post_id = data.get('post_id')
p = Post.objects.get(id=post_id)
if data.get('post_type') == 'dice':
posts = Post.objects.filter(post_type='dice', dicecall__open=True)
for post in posts:
post.dicecall.open = False
post.dicecall.save()
socket.send('close_all_posts', {'post_type': 'dice'})
p.dicecall.open = True
p.dicecall.save()
elif data.get('post_type') == 'poll':

View File

@ -86,9 +86,13 @@ socket.events['open_post'] = function(data) {
open_post(data.post_id);
}
socket.events['close_all_posts'] = function(data) {
let posts = document.getElementsByClassName('activePost');
let class_set = '';
if (data.post_type == 'dice') { class_set = 'dicePost activePost'; }
else if (data.post_type == 'poll') { class_set = 'pollPost activePost'; }
else { class_set = 'activePost'; }
let posts = document.getElementsByClassName(class_set);
for (let i = 0; i < posts.length; i++) {
close_post(post.children[1].id.slice(14)); // retreive the number at the end
close_post(posts[i].children[1].id.slice(14)); // retreive the id number at the end
}
}
@ -150,6 +154,8 @@ function close_post(post_id) {
function open_post(post_id) {
let post = document.getElementById('questPostData-' + post_id);
post.firstElementChild.textContent = post.firstElementChild.textContent.replace('Closed', 'Open');
post.parentElement.className += ' activePost';
console.log(post.parentElement.className);
if (post.parentElement.classList.contains('pollPost')) {
let table = document.getElementById('poll-' + post_id);
let boxes = table.getElementsByTagName('input');

View File

@ -47,7 +47,7 @@ socket.events['new_post'] = function(data) {
qposts.innerHTML = qposts.innerHTML + post_str;
};
/* socket send */
/* Websocket send */
function makePost() {
let qparea = document.getElementById('postTextArea');
let text = qparea.value.trim();
@ -55,7 +55,7 @@ function makePost() {
if (text == '') { return; }
socket.send('text_post', {text: text, page_num: page_num, quest_id: quest_id});
}
function form_post(form_id, emit_msg) {
function form_post(form_id, event) {
let formData = new FormData(document.getElementById(form_id));
let obj = {};
formData.forEach(function(value, key) {
@ -63,7 +63,7 @@ function form_post(form_id, emit_msg) {
});
obj.quest_id = quest_id;
obj.page_num = page_num;
socket.send(emit_msg, obj);
socket.send(event, obj);
document.getElementById(form_id).reset();
}
function close_post_send(post_id) {
@ -120,6 +120,7 @@ function close_post(post_id) {
function open_post(post_id) {
let post = document.getElementById('questPostData-' + post_id);
post.firstElementChild.textContent = post.firstElementChild.textContent.replace('Closed', 'Open');
post.parentElement.className += ' activePost';
/* QM only */
document.getElementById('closePost-' + post_id).style.display = 'initial';
document.getElementById('openPost-' + post_id).style.display = 'none';