2018-06-18 22:13:49 -04:00
|
|
|
{% extends "base.html" %}
|
|
|
|
{% block title %}{{ quest_title }}{% endblock %}
|
|
|
|
{% block head %}
|
2018-06-14 19:15:51 -04:00
|
|
|
<script type="text/javascript" src="/static/socket.io.slim.js"></script>
|
|
|
|
<script>
|
2018-06-21 22:49:25 -04:00
|
|
|
document.execCommand("defaultParagraphSeparator", false, "br");
|
2018-06-20 22:21:22 -04:00
|
|
|
var socket;
|
|
|
|
var tid = setInterval( function () {
|
|
|
|
if ( document.readyState !== 'complete' ) return;
|
|
|
|
clearInterval( tid );
|
2018-06-25 15:52:10 -04:00
|
|
|
|
|
|
|
document.getElementById('chatWindow').scrollTop = document.getElementById('chatWindow').scrollHeight;
|
2018-06-20 22:21:22 -04:00
|
|
|
socket = io.connect('https://' + document.domain + ':' + location.port);
|
|
|
|
socket.on('connect', function() {
|
|
|
|
socket.emit('joined', {room: {{ room_id }}});
|
|
|
|
});
|
|
|
|
socket.on('message', function(data) {
|
2018-07-04 17:20:47 -04:00
|
|
|
let msg_str = '<div class="messageHeader"><span class="messageName">' + data.name + '</span> ';
|
|
|
|
msg_str += '<span class="messageDate">' + strftime(data.date) + '</span></div>';
|
|
|
|
msg_str += '<div class="message">' + data.message + '</div><hr>';
|
2018-06-14 19:15:51 -04:00
|
|
|
|
2018-07-02 16:10:50 -04:00
|
|
|
let mbox = document.getElementById('chatWindow');
|
2018-06-20 22:21:22 -04:00
|
|
|
mbox.innerHTML = mbox.innerHTML + msg_str;
|
|
|
|
mbox.scrollTop = mbox.scrollHeight;
|
|
|
|
});
|
|
|
|
socket.on('new_post', function(data) {
|
2018-07-08 20:19:19 -04:00
|
|
|
deactivate_post();
|
2018-07-02 16:10:50 -04:00
|
|
|
let qposts = document.getElementById('questPosts');
|
2018-07-08 20:19:19 -04:00
|
|
|
let post_str = '<div class="questPost ';
|
|
|
|
if (data.post_type == 'text') {
|
|
|
|
post_str += 'textPost">';
|
|
|
|
} else if (data.post_type == 'dice') {
|
|
|
|
post_str += 'dicePost active_post">';
|
|
|
|
}
|
|
|
|
post_str += '<div class="questPostMeta">' + strftime(data.date);
|
2018-07-04 17:20:47 -04:00
|
|
|
{% if session.get("user_id") == owner_id %}
|
2018-07-07 13:43:58 -04:00
|
|
|
if (data.post_type == 'text') {
|
2018-07-04 17:20:47 -04:00
|
|
|
post_str += '<br /><a href="javascript:void(0);" onclick="edit_post(\'' + data.post_id + '\')">Edit</a>';
|
|
|
|
post_str += '<a href="javascript:void(0);" id="savePost-' + data.post_id + '" onclick="save_post(\'' + data.post_id + '\')" style="display:none;">Save</a>';
|
2018-07-08 20:19:19 -04:00
|
|
|
} else if (data.post_type == 'dice') {
|
2018-07-08 17:50:54 -04:00
|
|
|
post_str += '<br /><a href="javascript:void(0);" id="close_dc-' + data.post_id + '" onclick="close_dice_call(' + data.post_id + ')">Close</a>';
|
|
|
|
post_str += '<a href="javascript:void(0);" id="open_dc-' + data.post_id + '" onclick="open_dice_call(' + data.post_id + ')" style="display:none;">Open</a>'
|
|
|
|
}
|
2018-07-04 17:20:47 -04:00
|
|
|
{% endif %}
|
2018-07-08 17:50:54 -04:00
|
|
|
post_str += '</div><div class="questPostData" id="questPostData-' + data.post_id + '">';
|
|
|
|
if (data.post_type == 'text') {
|
|
|
|
post_str += data.post;
|
2018-07-08 20:19:19 -04:00
|
|
|
} else if (data.post_type == 'dice') {
|
2018-07-08 17:50:54 -04:00
|
|
|
post_str += '<h3>' + data.post + ' - Open</h3>';
|
|
|
|
}
|
|
|
|
post_str += '</div></div><br />';
|
2018-07-04 17:20:47 -04:00
|
|
|
qposts.innerHTML = qposts.innerHTML + post_str;
|
2018-06-20 22:21:22 -04:00
|
|
|
});
|
2018-06-21 20:44:43 -04:00
|
|
|
socket.on('update_post', function(data) {
|
2018-07-02 16:10:50 -04:00
|
|
|
let post_id = data.post_id;
|
2018-07-07 19:18:08 -04:00
|
|
|
let post = document.getElementById('questPostData-' + post_id);
|
|
|
|
if (data.post_type == 'text') {
|
|
|
|
post.innerHTML = data.post;
|
|
|
|
}
|
|
|
|
else if (data.post_type == 'dice') {
|
|
|
|
post.innerHTML += '<b>' + data.post + '</b><br />';
|
|
|
|
}
|
2018-06-21 20:44:43 -04:00
|
|
|
});
|
2018-07-08 17:50:54 -04:00
|
|
|
socket.on('close_dice_call', function(data) {
|
|
|
|
let post = document.getElementById('questPostData-' + data.post_id);
|
2018-07-08 20:19:19 -04:00
|
|
|
post.children[0].textContent = post.children[0].textContent.replace('Open', 'Closed');
|
2018-07-08 17:50:54 -04:00
|
|
|
});
|
|
|
|
socket.on('open_dice_call', function(data) {
|
|
|
|
let post = document.getElementById('questPostData-' + data.post_id);
|
|
|
|
post.firstElementChild.textContent = post.firstElementChild.textContent.replace('Closed', 'Open');
|
|
|
|
});
|
2018-07-02 16:10:50 -04:00
|
|
|
let mtarea = document.getElementById('messageTextArea');
|
2018-06-20 22:21:22 -04:00
|
|
|
mtarea.addEventListener('keypress', function(event) {
|
|
|
|
if (event.key == 'Enter' && !event.shiftKey) {
|
2018-07-02 16:10:50 -04:00
|
|
|
let text = mtarea.value.trim();
|
2018-06-20 22:21:22 -04:00
|
|
|
mtarea.value = '';
|
|
|
|
if (text == '') { return; }
|
|
|
|
socket.emit('message', {message: text, name: 'Anonymous', room: {{ room_id }}});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 100 );
|
2018-06-19 11:54:51 -04:00
|
|
|
</script>
|
|
|
|
<script>
|
2018-06-20 22:21:22 -04:00
|
|
|
function padToTwo(number) {
|
|
|
|
if (number<=99) { number = ("0"+number).slice(-2); }
|
|
|
|
return number;
|
|
|
|
}
|
2018-07-04 17:20:47 -04:00
|
|
|
function strftime(date) {
|
|
|
|
date = new Date(date * 1000);
|
|
|
|
let date_str = date.getFullYear() + '-' + padToTwo(date.getMonth()+1) + '-' + padToTwo(date.getDate()) + ' ';
|
|
|
|
date_str += padToTwo(date.getHours()) + ':' + padToTwo(date.getMinutes()) + ':' + padToTwo(date.getSeconds());
|
|
|
|
return date_str;
|
|
|
|
}
|
2018-06-14 19:15:51 -04:00
|
|
|
</script>
|
2018-06-20 13:07:11 -04:00
|
|
|
{% if session.get("user_id") == owner_id %}
|
|
|
|
<script>
|
|
|
|
function makePost() {
|
2018-07-02 16:10:50 -04:00
|
|
|
let qparea = document.getElementById('postTextArea');
|
|
|
|
let text = qparea.value.trim();
|
2018-06-20 13:07:11 -04:00
|
|
|
qparea.value = '';
|
|
|
|
if (text == '') { return; }
|
2018-06-20 22:21:22 -04:00
|
|
|
socket.emit('new_post', {post: text, room: {{ room_id }}});
|
2018-06-20 13:07:11 -04:00
|
|
|
}
|
2018-06-21 20:44:43 -04:00
|
|
|
function edit_post(post_id) {
|
|
|
|
document.getElementById('questPostData-' + post_id).contentEditable = 'true';
|
2018-06-21 22:49:25 -04:00
|
|
|
document.execCommand("defaultParagraphSeparator", false, "br");
|
|
|
|
document.getElementById('questPostData-' + post_id).style.border = '1px solid #ccc';
|
2018-06-21 20:44:43 -04:00
|
|
|
document.getElementById('savePost-' + post_id).style.display = 'initial';
|
2018-07-08 17:50:54 -04:00
|
|
|
document.getElementById('editPost-' + post_id).style.display = 'none';
|
2018-06-21 20:44:43 -04:00
|
|
|
}
|
|
|
|
function save_post(post_id) {
|
|
|
|
document.getElementById('questPostData-' + post_id).contentEditable = 'false';
|
|
|
|
document.getElementById('questPostData-' + post_id).style.border = null;
|
2018-07-02 16:10:50 -04:00
|
|
|
let text = document.getElementById('questPostData-' + post_id).innerHTML;
|
2018-06-21 20:44:43 -04:00
|
|
|
socket.emit('update_post', {post_id: post_id, post: text, room: {{ room_id }}});
|
|
|
|
document.getElementById('savePost-' + post_id).style.display = 'none';
|
2018-07-08 17:50:54 -04:00
|
|
|
document.getElementById('editPost-' + post_id).style.display = 'initial';
|
2018-06-21 20:44:43 -04:00
|
|
|
}
|
2018-07-02 16:10:50 -04:00
|
|
|
function dice_post() {
|
|
|
|
let formData = new FormData(document.getElementById('QMDicePostForm'));
|
|
|
|
let obj = {};
|
|
|
|
formData.forEach(function(value, key) {
|
|
|
|
obj[key] = value;
|
|
|
|
});
|
2018-07-04 17:20:47 -04:00
|
|
|
obj.room = {{ room_id }};
|
2018-07-02 16:10:50 -04:00
|
|
|
socket.emit('dice_post', obj);
|
|
|
|
document.getElementById('QMDicePostForm').reset();
|
|
|
|
}
|
2018-07-08 17:50:54 -04:00
|
|
|
function close_dice_call(post_id) {
|
|
|
|
document.getElementById('close_dc-' + post_id).style.display = 'none';
|
|
|
|
document.getElementById('open_dc-' + post_id).style.display = 'initial';
|
|
|
|
socket.emit('close_dice_call', {post_id: post_id, room: {{ room_id }}});
|
|
|
|
}
|
|
|
|
function open_dice_call(post_id) {
|
|
|
|
document.getElementById('close_dc-' + post_id).style.display = 'initial';
|
|
|
|
document.getElementById('open_dc-' + post_id).style.display = 'none';
|
|
|
|
socket.emit('open_dice_call', {post_id: post_id, room: {{ room_id }}});
|
|
|
|
}
|
2018-07-08 20:19:19 -04:00
|
|
|
function deactivate_post() {
|
|
|
|
let post = document.getElementsByClassName('active_post');
|
|
|
|
if (post.length == 0) { return; }
|
|
|
|
post = post[0];
|
|
|
|
if (post.classList.contains('dicePost')) {
|
|
|
|
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 = "";
|
|
|
|
}
|
|
|
|
}
|
2018-06-20 13:07:11 -04:00
|
|
|
</script>
|
2018-06-27 08:43:00 -04:00
|
|
|
<script>
|
|
|
|
function openPostTab(event, modeName) {
|
2018-07-02 16:10:50 -04:00
|
|
|
let i, QMPostTabContent, QMPostTab;
|
2018-06-27 08:43:00 -04:00
|
|
|
|
|
|
|
QMPostTabContent = document.getElementsByClassName("QMPostTabContent");
|
|
|
|
for (i = 0; i < QMPostTabContent.length; i++) {
|
|
|
|
QMPostTabContent[i].style.display = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
QMPostTab = document.getElementsByClassName("QMPostTab");
|
|
|
|
for (i = 0; i < QMPostTab.length; i++) {
|
|
|
|
QMPostTab[i].className = QMPostTab[i].className.replace(" active", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById(modeName).style.display = "block";
|
|
|
|
event.currentTarget.className += " active";
|
|
|
|
}
|
|
|
|
</script>
|
2018-06-20 13:07:11 -04:00
|
|
|
{% endif %}
|
|
|
|
{% endblock %}
|
|
|
|
{% block header %}
|
|
|
|
{% if session.get("user_id") == owner_id %}
|
2018-06-25 10:11:43 -04:00
|
|
|
<li><a href="{{ url_for('.quest', quest_title=ident_title + '/edit_quest') }}">Edit Quest</a></li>
|
2018-06-20 13:07:11 -04:00
|
|
|
{% endif %}
|
2018-06-18 22:13:49 -04:00
|
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
|
|
<div id="questContainer">
|
2018-06-26 00:29:10 -04:00
|
|
|
<div id="questPane">
|
|
|
|
<center><h1>{{ quest_title }}</h1></center>
|
2018-06-27 08:43:00 -04:00
|
|
|
<div id="questPosts">
|
|
|
|
{% for quest_post in quest_posts %}
|
2018-07-08 20:19:19 -04:00
|
|
|
{% if quest_post[2] == "text" %}
|
|
|
|
<div class="questPost textPost">
|
|
|
|
{% elif quest_post[2] == "dice" %}
|
|
|
|
<div class="questPost dicePost{% if quest_post == quest_posts|last %} active_post{% endif %}">
|
|
|
|
{% endif %}
|
2018-06-27 08:43:00 -04:00
|
|
|
<div class="questPostMeta">
|
2018-07-07 13:43:58 -04:00
|
|
|
{{ quest_post[4] | strftime }}
|
2018-06-27 08:43:00 -04:00
|
|
|
{% if session.get("user_id") == owner_id %}
|
2018-07-07 13:43:58 -04:00
|
|
|
{% if quest_post[2] == "text" %}
|
2018-07-08 17:50:54 -04:00
|
|
|
<br /><a href="javascript:void(0);" id="editPost-{{ quest_post[0] }}" onclick="edit_post({{ quest_post[0] }})">Edit</a>
|
2018-06-27 08:43:00 -04:00
|
|
|
<a href="javascript:void(0);" id="savePost-{{ quest_post[0] }}" onclick="save_post('{{ quest_post[0] }}')" style="display:none;">Save</a>
|
2018-07-08 17:50:54 -04:00
|
|
|
{% elif quest_post[2] == "dice" and quest_post == quest_posts|last %}
|
|
|
|
{% if quest_post[0] == dice_call %}
|
|
|
|
<br /><a href="javascript:void(0);" id="close_dc-{{ quest_post[0] }}" onclick="close_dice_call({{ quest_post[0] }})">Close</a>
|
|
|
|
<a href="javascript:void(0);" id="open_dc-{{ quest_post[0] }}" onclick="open_dice_call({{ quest_post[0] }})" style="display:none;">Open</a>
|
|
|
|
{% else %}
|
|
|
|
<br /><a href="javascript:void(0);" id="close_dc-{{ quest_post[0] }}" onclick="close_dice_call({{ quest_post[0] }})" style="display:none;">Close</a>
|
|
|
|
<a href="javascript:void(0);" id="open_dc-{{ quest_post[0] }}" onclick="open_dice_call({{ quest_post[0] }})">Open</a>
|
|
|
|
{% endif %}
|
2018-06-27 08:43:00 -04:00
|
|
|
{% endif %}
|
2018-07-07 13:43:58 -04:00
|
|
|
{% endif %}
|
2018-06-27 08:43:00 -04:00
|
|
|
</div>
|
|
|
|
<div class="questPostData" id="questPostData-{{ quest_post[0] }}">
|
2018-07-08 17:50:54 -04:00
|
|
|
{% if quest_post[2] == "text" %}
|
2018-06-27 08:43:00 -04:00
|
|
|
{% autoescape false %}
|
2018-07-07 13:43:58 -04:00
|
|
|
{{ quest_post[3] }}
|
2018-06-27 08:43:00 -04:00
|
|
|
{% endautoescape %}
|
2018-07-08 17:50:54 -04:00
|
|
|
{% elif quest_post[2] == "dice" %}
|
|
|
|
<h3>{{ quest_post[3] }} - {% if quest_post[0] == dice_call %}Open{% else %}Closed{% endif %}</h3>
|
2018-07-07 19:18:08 -04:00
|
|
|
{% for quest_roll in quest_rolls %}
|
|
|
|
{% if quest_roll[2] == quest_post[0] %}
|
2018-07-08 17:50:54 -04:00
|
|
|
<div id="questRollId-{{ quest_roll[0] }}">
|
|
|
|
<b>Rolled {{ quest_roll[4] }} ({{ quest_roll[3] }})</b>
|
|
|
|
</div>
|
2018-07-07 19:18:08 -04:00
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2018-06-27 08:43:00 -04:00
|
|
|
</div>
|
|
|
|
</div><br />
|
|
|
|
{% endfor %}
|
|
|
|
</div>
|
|
|
|
{% if session.get("user_id") == owner_id %}
|
|
|
|
<div id="QMPostPane">
|
|
|
|
<div>
|
|
|
|
<ul id="QMPostTabs">
|
|
|
|
<li><a class="QMPostTab active" href="javascript:void(0);" onclick="openPostTab(event, 'QMPostText')">Text</a></li>
|
|
|
|
<li><a class="QMPostTab" href="javascript:void(0);" onclick="openPostTab(event, 'QMPostDice')">Dice</a></li>
|
|
|
|
<li><a class="QMPostTab" href="javascript:void(0);" onclick="openPostTab(event, 'QMPostPoll')">Poll</a></li>
|
|
|
|
</ul>
|
2018-06-26 00:29:10 -04:00
|
|
|
</div>
|
2018-06-27 08:43:00 -04:00
|
|
|
<div id="QMPostText" class="QMPostTabContent" style="display:initial;">
|
|
|
|
<textarea id="postTextArea"></textarea><br />
|
|
|
|
<input type="submit" name="newPost" value="Post" onclick="makePost();"/>
|
|
|
|
</div>
|
|
|
|
<div id="QMPostDice" class="QMPostTabContent" style="display:none;">
|
2018-07-02 16:10:50 -04:00
|
|
|
Dice for the dice god.<br />
|
|
|
|
<form id="QMDicePostForm" action="javascript:void(0);" onsubmit="dice_post();">
|
2018-07-06 02:09:55 -04:00
|
|
|
Dice: <input type="number" name="diceNum" min="1" max="99" required/>
|
|
|
|
d <input type="number" name="diceSides" min="1" max="99" required/>
|
2018-07-02 16:10:50 -04:00
|
|
|
±<input type="number" name="diceMod" min="-999" max="999"/>
|
|
|
|
<input type="checkbox" name="diceStrict"/>
|
|
|
|
<span class="tooltip" title="Only take matching rolls.">Strict</span><br />
|
|
|
|
<input type="checkbox" onclick="document.getElementById('diceChal').disabled=!this.checked;"/>
|
|
|
|
<span class="tooltip" title="Dice challenge">DC:</span>
|
|
|
|
<input type="number" name="diceChal" id="diceChal" min="1" max="99" disabled/><br />
|
|
|
|
<input type="checkbox" onclick="document.getElementById('diceRolls').disabled=!this.checked;"/>
|
|
|
|
<span class="tooltip" title="Automatically close the dice call after this many rolls have been made.">Rolls Taken:</span>
|
|
|
|
<input type="number" name="diceRolls" id="diceRolls" min="1" max="99" disabled/><br />
|
|
|
|
<input type="submit" name="submit" value="Roll 'em"/>
|
|
|
|
</form>
|
2018-06-27 08:43:00 -04:00
|
|
|
</div>
|
|
|
|
<div id="QMPostPoll" class="QMPostTabContent" style="display:none;">
|
|
|
|
The polls are rigged.
|
2018-06-26 00:29:10 -04:00
|
|
|
</div>
|
2018-06-20 13:07:11 -04:00
|
|
|
</div>
|
|
|
|
{% endif %}
|
2018-06-14 22:09:14 -04:00
|
|
|
</div>
|
2018-06-27 08:43:00 -04:00
|
|
|
<br />
|
|
|
|
<br />
|
2018-06-18 22:13:49 -04:00
|
|
|
<div id="chatPane">
|
|
|
|
<h1>Chat</h1>
|
|
|
|
<div id="chatWindow">
|
|
|
|
{% autoescape false %}
|
|
|
|
{% for message in messages %}
|
|
|
|
<div class="message">
|
|
|
|
<div class="messageHeader">
|
2018-07-07 19:18:08 -04:00
|
|
|
<span class="messageName">Anonymous</span> <span class="messageDate">{{ message[3] | strftime }}</span>
|
2018-06-18 22:13:49 -04:00
|
|
|
</div>
|
|
|
|
<div class="messageMessage">{{ message[4] }}</div>
|
|
|
|
</div>
|
2018-07-02 16:10:50 -04:00
|
|
|
<hr>
|
2018-06-18 22:13:49 -04:00
|
|
|
{% endfor %}
|
|
|
|
{% endautoescape %}
|
|
|
|
</div>
|
2018-06-20 13:07:11 -04:00
|
|
|
<div id="messageTextDiv"><textarea id="messageTextArea"></textarea></div>
|
2018-06-14 19:15:51 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-06-18 22:13:49 -04:00
|
|
|
{% endblock %}
|