added opening/closing posts
This commit is contained in:
parent
1c1ed68d7b
commit
5485bf8aa9
|
@ -40,7 +40,7 @@ class QuestConsumer(WebsocketConsumer):
|
|||
return
|
||||
self.events[event](self, data.get('data'))
|
||||
|
||||
def send(self, event, data):
|
||||
def send(self, event, data={}):
|
||||
"""
|
||||
Overridden method. If a dictionary is provided, it is converted
|
||||
to JSON before sending it.
|
||||
|
|
|
@ -154,10 +154,13 @@ def dice_post(socket, data):
|
|||
dice_roll=dice_roll,
|
||||
strict=form['diceStrict'],
|
||||
dice_challenge=form['diceChal'],
|
||||
rolls_taken=form['diceRollsTaken']
|
||||
rolls_taken=form['diceRollsTaken'],
|
||||
open=True,
|
||||
)
|
||||
d.save()
|
||||
|
||||
socket.send('close_all_posts')
|
||||
|
||||
data = {}
|
||||
data['post_text'] = post_text
|
||||
data['post_type'] = 'dice'
|
||||
|
@ -166,6 +169,42 @@ def dice_post(socket, data):
|
|||
socket.send('new_post', data)
|
||||
|
||||
|
||||
def close_post(socket, data):
|
||||
"""
|
||||
Called when the QM closes an open post.
|
||||
"""
|
||||
post_id = data.get('post_id')
|
||||
p = Post.objects.get(id=post_id)
|
||||
if data.get('post_type') == 'dice':
|
||||
p.dicecall.open = False
|
||||
p.dicecall.save()
|
||||
elif data.get('post_type') == 'poll':
|
||||
p.poll.open = False
|
||||
p.poll.save()
|
||||
|
||||
data = {}
|
||||
data['post_id'] = post_id
|
||||
socket.send('close_post', data)
|
||||
|
||||
|
||||
def open_post(socket, data):
|
||||
"""
|
||||
Called when the QM opens a closed post.
|
||||
"""
|
||||
post_id = data.get('post_id')
|
||||
p = Post.objects.get(id=post_id)
|
||||
if data.get('post_type') == 'dice':
|
||||
p.dicecall.open = True
|
||||
p.dicecall.save()
|
||||
elif data.get('post_type') == 'poll':
|
||||
p.poll.open = True
|
||||
p.poll.save()
|
||||
|
||||
data = {}
|
||||
data['post_id'] = post_id
|
||||
socket.send('open_post', data)
|
||||
|
||||
|
||||
events = {}
|
||||
for obj in dir():
|
||||
if type(locals()[obj]) == types.FunctionType:
|
||||
|
|
|
@ -34,9 +34,9 @@
|
|||
{% if post.post_type == "text" %}
|
||||
<div class="questPost textPost">
|
||||
{% elif post.post_type == "dice" %}
|
||||
<div class="questPost dicePost{% if post == posts|last %} activePost{% endif %}">
|
||||
<div class="questPost dicePost{% if post.dicecall.open %} activePost{% endif %}">
|
||||
{% elif post.post_type == "poll" %}
|
||||
<div class="questPost pollPost{% if post == posts|last %} activePost{% endif %}">
|
||||
<div class="questPost pollPost{% if post.poll.open %} activePost{% endif %}">
|
||||
{% endif %}
|
||||
<div class="questPostMeta">
|
||||
{{ localtime(post.timestamp).strftime('%Y-%m-%d %H:%M') }}
|
||||
|
@ -44,9 +44,12 @@
|
|||
{% if post.post_type == "text" %}
|
||||
<br /><a href="javascript:void(0);" id="editPost-{{ post.id }}" onclick="edit_post({{ post.id }})">Edit</a>
|
||||
<a href="javascript:void(0);" id="savePost-{{ post.id }}" onclick="save_post('{{ post.id }}')" style="display:none;">Save</a>
|
||||
{% elif post.post_type in ("dice", "poll") and post == posts|last %}
|
||||
<br /><a href="javascript:void(0);" id="closePost-{{ post.id }}" onclick="close_post({{ post.id }})"{% if post.id != quest.open_post_id %} style="display:none;"{% endif %}>Close</a>
|
||||
<a href="javascript:void(0);" id="openPost-{{ post.id }}" onclick="open_post({{ post.id }})"{% if post.id == quest.open_post_id %} style="display:none;"{% endif %}>Open</a>
|
||||
{% elif post.post_type == "dice" %}
|
||||
<br /><a href="javascript:void(0);" id="closePost-{{ post.id }}" onclick="close_post_send({{ post.id }})"{% if not post.dicecall.open %} style="display:none;"{% endif %}>Close</a>
|
||||
<a href="javascript:void(0);" id="openPost-{{ post.id }}" onclick="open_post_send({{ post.id }})"{% if post.dicecall.open %} style="display:none;"{% endif %}>Open</a>
|
||||
{% elif post.post_type == "poll" %}
|
||||
<br /><a href="javascript:void(0);" id="closePost-{{ post.id }}" onclick="close_post_send({{ post.id }})"{% if not post.poll.open %} style="display:none;"{% endif %}>Close</a>
|
||||
<a href="javascript:void(0);" id="openPost-{{ post.id }}" onclick="open_post_send({{ post.id }})"{% if post.poll.open %} style="display:none;"{% endif %}>Open</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
@ -56,14 +59,14 @@
|
|||
{{ post.post_text }}
|
||||
{% endautoescape %}
|
||||
{% elif post.post_type == "dice" %}
|
||||
<h3>{{ post.post_text }} - {% if post.id == quest.open_post_id %}Open{% else %}Closed{% endif %}</h3>
|
||||
<h3>{{ post.post_text }} - {% if post.dicecall.open %}Open{% else %}Closed{% endif %}</h3>
|
||||
{# for dice_roll in dice_rolls.get(post.id, []) %}
|
||||
<div id="questRollId-{{ dice_roll[0] }}">
|
||||
<b>Rolled {{ dice_roll[4] }} = {{ dice_roll[5] }} ({{ dice_roll[3] }}){% if post.id|dice_chal != 0 %} - {% if dice_roll[5] >= post.id|dice_chal %}Pass{% else %}Fail{% endif %}{% endif %}</b>
|
||||
</div>
|
||||
{% endfor #}
|
||||
{% elif post.post_type == "poll" %}
|
||||
<h3>{{ post.post_text }} - {% if post.id == quest.open_post_id %}Open{% else %}Closed{% endif %}</h3>
|
||||
<h3>{{ post.post_text }} - {% if post.poll.open %}Open{% else %}Closed{% endif %}</h3>
|
||||
<table class="poll" id="poll-{{ post.id }}">
|
||||
{# for option in options.get(post.id, []) %}
|
||||
<tr id="optionRow-{{ option[0] }}">
|
||||
|
|
22
quest/migrations/0008_auto_20180824_0855.py
Normal file
22
quest/migrations/0008_auto_20180824_0855.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 2.1 on 2018-08-24 12:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('quest', '0007_dicecall'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='quest',
|
||||
name='open_post_id',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='dicecall',
|
||||
name='open',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
|
@ -14,7 +14,6 @@ class Quest(models.Model):
|
|||
owner = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE)
|
||||
open_post_id = models.IntegerField(null=True)
|
||||
|
||||
|
||||
class Post(models.Model):
|
||||
|
@ -60,6 +59,7 @@ class DiceCall(models.Model):
|
|||
MinValueValidator(1)
|
||||
]
|
||||
)
|
||||
open = models.BooleanField(default=False)
|
||||
|
||||
|
||||
class PageTitle(models.Model):
|
||||
|
|
|
@ -27,7 +27,7 @@ function load() {
|
|||
});
|
||||
}
|
||||
|
||||
/* Websocket events */
|
||||
/* Websocket receive */
|
||||
socket.events['message'] = function(data) {
|
||||
let msg_str = '<div id="message-' + data.message_id + '" class="message">';
|
||||
msg_str = '<div class="messageHeader"><span class="messageName">' + data.name + '</span> ';
|
||||
|
@ -79,7 +79,18 @@ socket.events['new_post'] = function(data) {
|
|||
post_str += '</div></div><br />';
|
||||
qposts.innerHTML = qposts.innerHTML + post_str;
|
||||
};
|
||||
|
||||
socket.events['close_post'] = function(data) {
|
||||
close_post(data.post_id);
|
||||
}
|
||||
socket.events['open_post'] = function(data) {
|
||||
open_post(data.post_id);
|
||||
}
|
||||
socket.events['close_all_posts'] = function(data) {
|
||||
let posts = document.getElementsByClassName('activePost');
|
||||
for (let i = 0; i < posts.length; i++) {
|
||||
close_post(post.children[1].id.slice(14)); // retreive the number at the end
|
||||
}
|
||||
}
|
||||
|
||||
/* Helpers */
|
||||
function padToTwo(number) {
|
||||
|
@ -93,7 +104,7 @@ function strftime(date) {
|
|||
return date_str;
|
||||
}
|
||||
|
||||
/* User-facing */
|
||||
/* DOM editing */
|
||||
function quote(message_id) {
|
||||
let textbox = document.getElementById('messageTextArea');
|
||||
textbox.value += '>>' + message_id + '\n';
|
||||
|
@ -121,3 +132,33 @@ function scrollToMsg(message_id) {
|
|||
if (!elem) { return; }
|
||||
elem.scrollIntoView();
|
||||
}
|
||||
function close_post(post_id) {
|
||||
let post = document.getElementById('questPostData-' + post_id);
|
||||
post.children[0].textContent = post.children[0].textContent.replace('Open', 'Closed');
|
||||
if (post.parentElement.classList.contains('pollPost')) {
|
||||
let table = document.getElementById('poll-' + post_id);
|
||||
let boxes = table.getElementsByTagName('input');
|
||||
for (let i = 0; i < boxes.length; i++) {
|
||||
boxes[i].disabled = true;
|
||||
}
|
||||
let writein = document.getElementById('writeinContainer');
|
||||
if (writein) {
|
||||
writein.style.display = 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
function open_post(post_id) {
|
||||
let post = document.getElementById('questPostData-' + post_id);
|
||||
post.firstElementChild.textContent = post.firstElementChild.textContent.replace('Closed', 'Open');
|
||||
if (post.parentElement.classList.contains('pollPost')) {
|
||||
let table = document.getElementById('poll-' + post_id);
|
||||
let boxes = table.getElementsByTagName('input');
|
||||
for (let i = 0; i < boxes.length; i++) {
|
||||
boxes[i].disabled = false;
|
||||
}
|
||||
let writein = document.getElementById('writeinContainer');
|
||||
if (writein) {
|
||||
writein.style.display = 'initial';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* Websocket receive */
|
||||
socket.events['new_post'] = function(data) {
|
||||
//deactivate_post();
|
||||
let qposts = document.getElementById('questPosts');
|
||||
|
@ -46,6 +47,7 @@ socket.events['new_post'] = function(data) {
|
|||
qposts.innerHTML = qposts.innerHTML + post_str;
|
||||
};
|
||||
|
||||
/* socket send */
|
||||
function makePost() {
|
||||
let qparea = document.getElementById('postTextArea');
|
||||
let text = qparea.value.trim();
|
||||
|
@ -53,19 +55,6 @@ function makePost() {
|
|||
if (text == '') { return; }
|
||||
socket.send('text_post', {text: text, page_num: page_num, quest_id: quest_id});
|
||||
}
|
||||
|
||||
function openPostTab(event, modeName) {
|
||||
let QMPostTabContent = document.getElementsByClassName("QMPostTabContent");
|
||||
for (let i = 0; i < QMPostTabContent.length; i++) {
|
||||
QMPostTabContent[i].style.display = "none";
|
||||
}
|
||||
let QMPostTab = document.getElementsByClassName("QMPostTab");
|
||||
for (let i = 0; i < QMPostTab.length; i++) {
|
||||
QMPostTab[i].className = QMPostTab[i].className.replace(" active", "");
|
||||
}
|
||||
document.getElementById(modeName).style.display = "block";
|
||||
event.currentTarget.className += " active";
|
||||
}
|
||||
function form_post(form_id, emit_msg) {
|
||||
let formData = new FormData(document.getElementById(form_id));
|
||||
let obj = {};
|
||||
|
@ -77,3 +66,73 @@ function form_post(form_id, emit_msg) {
|
|||
socket.send(emit_msg, obj);
|
||||
document.getElementById(form_id).reset();
|
||||
}
|
||||
function close_post_send(post_id) {
|
||||
let post = document.getElementById('questPostData-' + post_id);
|
||||
if (post.parentElement.classList.contains('dicePost')) {
|
||||
data = {post_type: 'dice', post_id: post_id};
|
||||
} else if (post.parentElement.classList.contains('pollPost')) {
|
||||
data = {post_type: 'poll', post_id: post_id};
|
||||
}
|
||||
socket.send('close_post', data);
|
||||
}
|
||||
function open_post_send(post_id) {
|
||||
let post = document.getElementById('questPostData-' + post_id);
|
||||
if (post.parentElement.classList.contains('dicePost')) {
|
||||
data = {post_type: 'dice', post_id: post_id};
|
||||
} else if (post.parentElement.classList.contains('pollPost')) {
|
||||
data = {post_type: 'poll', post_id: post_id};
|
||||
}
|
||||
socket.send('open_post', data);
|
||||
}
|
||||
|
||||
/* DOM editing */
|
||||
function openPostTab(event, modeName) {
|
||||
let QMPostTabContent = document.getElementsByClassName("QMPostTabContent");
|
||||
for (let i = 0; i < QMPostTabContent.length; i++) {
|
||||
QMPostTabContent[i].style.display = "none";
|
||||
}
|
||||
let QMPostTab = document.getElementsByClassName("QMPostTab");
|
||||
for (let i = 0; i < QMPostTab.length; i++) {
|
||||
QMPostTab[i].className = QMPostTab[i].className.replace(" active", "");
|
||||
}
|
||||
document.getElementById(modeName).style.display = "block";
|
||||
event.currentTarget.className += " active";
|
||||
}
|
||||
function close_post(post_id) {
|
||||
let post = document.getElementById('questPostData-' + post_id);
|
||||
post.children[0].textContent = post.children[0].textContent.replace('Open', 'Closed');
|
||||
/* QM only */
|
||||
document.getElementById('closePost-' + post_id).style.display = 'none';
|
||||
document.getElementById('openPost-' + post_id).style.display = 'initial';
|
||||
/* end QM only */
|
||||
if (post.parentElement.classList.contains('pollPost')) {
|
||||
let table = document.getElementById('poll-' + post_id);
|
||||
let boxes = table.getElementsByTagName('input');
|
||||
for (let i = 0; i < boxes.length; i++) {
|
||||
boxes[i].disabled = true;
|
||||
}
|
||||
let writein = document.getElementById('writeinContainer');
|
||||
if (writein) {
|
||||
writein.style.display = 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
function open_post(post_id) {
|
||||
let post = document.getElementById('questPostData-' + post_id);
|
||||
post.firstElementChild.textContent = post.firstElementChild.textContent.replace('Closed', 'Open');
|
||||
/* QM only */
|
||||
document.getElementById('closePost-' + post_id).style.display = 'initial';
|
||||
document.getElementById('openPost-' + post_id).style.display = 'none';
|
||||
/* end QM only */
|
||||
if (post.parentElement.classList.contains('pollPost')) {
|
||||
let table = document.getElementById('poll-' + post_id);
|
||||
let boxes = table.getElementsByTagName('input');
|
||||
for (let i = 0; i < boxes.length; i++) {
|
||||
boxes[i].disabled = false;
|
||||
}
|
||||
let writein = document.getElementById('writeinContainer');
|
||||
if (writein) {
|
||||
writein.style.display = 'initial';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user