add 'next page' button to quest page

This commit is contained in:
iou1name 2018-09-24 13:46:46 -04:00
parent 247fc6729a
commit 55cc375aea
5 changed files with 35 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import random
import bleach
from django.db import IntegrityError
from django.utils.timezone import localtime
from django.urls import reverse
from quest.models import *
from quest.tools import handle_img
@ -420,6 +421,12 @@ def new_page(socket, data):
)
p.save()
data = {}
data['page_num'] = p.page_num
data['title'] = title
data['url'] = reverse('quest:quest', args=[socket.quest_id, p.page_num])
socket.send('new_page', data)
events = {}
for obj in dir():

View File

@ -148,6 +148,11 @@
</div>
</div>
{% endif %}
{% if page_num != pages.reverse()[0].page_num %}
<div id="nextPageContainer">
<input type="button" id="nextPage" value="Next Page: {{ pages[page_num].title }}" onclick="window.location.href='{{ url('quest:quest', args=[quest_id, page_num+1]) }}'">
</div>
{% endif %}
</div>
<div id="chatPane" style="display:{% if request.session.get("hide_chat") == True %}none{% else %}flex{% endif %};">
<h1>Chat</h1>

View File

@ -96,6 +96,20 @@ h3 {
width: 100%;
}
#nextPageContainer {
width: 100%;
height: 5em;
padding: 1em;
box-sizing: border-box;
text-align: center;
}
#nextPage {
height: 100%;
width: 100%;
box-sizing: border-box;
}
#chatPane {
height: calc(100% - var(--header-height));
width: 30%;

View File

@ -154,6 +154,11 @@ socket.events['vote'] = function(data) {
socket.events['set_option_box'] = function(data) {
document.getElementById('pollInput-' + data.option_id).checked = data.polarity;
}
socket.events['new_page'] = function(data) {
if (page_num != data.page_num-1) { return; }
let html_str = '<div id="nextPageContainer"><input type="button" id="nextPage" value="Next Page: ' + data.title + '" onclick="window.location.href=\'' + SCRIPT_NAME + data.url + '\'"></div>';
document.getElementById('questPane').innerHTML = document.getElementById('questPane').innerHTML + html_str;
}
/* Websocket send */
function vote(post_id, option_id) {

View File

@ -23,6 +23,10 @@ def quest(request, quest_id, page_num=1):
pages = PageTitle.objects.filter(quest=quest).order_by('page_num')
messages = quest.message_set.all()
posts = quest.post_set.filter(page_num=page_num)
if posts.count() == 0:
page_num = pages.reverse()[0].page_num
return redirect('quest:quest', quest_id=quest.id, page_num=page_num)
# TODO: filter by page_num as well
dice_rolls = DiceRoll.objects.filter(dicecall__post__quest=quest)
poll_options = PollOption.objects.filter(poll__post__quest=quest)
poll_votes = PollVote.objects.filter(option__poll__post__quest=quest)