2021-09-17 15:08:07 +00:00
|
|
|
<script>
|
2021-09-25 21:13:52 +00:00
|
|
|
// Voting
|
|
|
|
|
|
|
|
function post_vote(url, callback) {
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("POST", url, true);
|
|
|
|
var form = new FormData()
|
|
|
|
form.append("formkey", formkey());
|
|
|
|
xhr.withCredentials=true;
|
|
|
|
|
|
|
|
xhr.onload = function() {
|
|
|
|
if (xhr.status==204) {}
|
|
|
|
else if (xhr.status >= 200 && xhr.status < 300) {
|
2021-09-26 09:06:17 +00:00
|
|
|
document.getElementById('toast-post-success').toast('dispose');
|
|
|
|
document.getElementById('toast-post-success').toast('show');
|
2021-09-25 21:13:52 +00:00
|
|
|
document.getElementById('toast-post-success-text').innerText = JSON.parse(xhr.response)["message"];
|
|
|
|
callback(xhr)
|
|
|
|
return true
|
|
|
|
|
|
|
|
} else if (xhr.status >= 300 && xhr.status < 400) {
|
|
|
|
window.location.href = JSON.parse(xhr.response)["redirect"]
|
|
|
|
} else {
|
|
|
|
data=JSON.parse(xhr.response);
|
|
|
|
|
2021-09-26 09:06:17 +00:00
|
|
|
document.getElementById('toast-post-error').toast('dispose');
|
|
|
|
document.getElementById('toast-post-error').toast('show');
|
2021-09-25 21:13:52 +00:00
|
|
|
document.getElementById('toast-post-error-text').innerText = data["error"];
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
xhr.send(form);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var upvote = function(event) {
|
|
|
|
|
|
|
|
var type = event.target.dataset.contentType;
|
|
|
|
var id = event.target.dataset.idUp;
|
|
|
|
|
|
|
|
var downvoteButton = document.getElementsByClassName(type + '-' + id + '-down');
|
|
|
|
var upvoteButton = document.getElementsByClassName(type + '-' + id + '-up');
|
|
|
|
var scoreText = document.getElementsByClassName(type + '-score-' + id);
|
|
|
|
|
|
|
|
for (var j = 0; j < upvoteButton.length && j < downvoteButton.length && j < scoreText.length; j++) {
|
|
|
|
|
|
|
|
var thisUpvoteButton = upvoteButton[j];
|
|
|
|
var thisDownvoteButton = downvoteButton[j];
|
|
|
|
var thisScoreText = scoreText[j];
|
|
|
|
var thisScore = Number(thisScoreText.textContent);
|
2021-09-26 09:23:51 +00:00
|
|
|
var voteDirection = "0"
|
2021-09-25 21:13:52 +00:00
|
|
|
|
|
|
|
if (thisUpvoteButton.classList.contains('active')) {
|
|
|
|
thisUpvoteButton.classList.remove('active')
|
|
|
|
thisScoreText.textContent = thisScore - 1
|
|
|
|
voteDirection = "0"
|
|
|
|
} else if (thisDownvoteButton.classList.contains('active')) {
|
|
|
|
thisUpvoteButton.classList.add('active')
|
|
|
|
thisDownvoteButton.classList.remove('active')
|
|
|
|
thisScoreText.textContent = thisScore + 2
|
|
|
|
voteDirection = "1"
|
|
|
|
} else {
|
|
|
|
thisUpvoteButton.classList.add('active')
|
|
|
|
thisScoreText.textContent = thisScore + 1
|
|
|
|
voteDirection = "1"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thisUpvoteButton.classList.contains('active')) {
|
|
|
|
thisScoreText.classList.add('score-up')
|
|
|
|
thisScoreText.classList.remove('score-down')
|
|
|
|
thisScoreText.classList.remove('score')
|
|
|
|
} else if (thisDownvoteButton.classList.contains('active')) {
|
|
|
|
thisScoreText.classList.add('score-down')
|
|
|
|
thisScoreText.classList.remove('score-up')
|
|
|
|
thisScoreText.classList.remove('score')
|
|
|
|
} else {
|
|
|
|
thisScoreText.classList.add('score')
|
|
|
|
thisScoreText.classList.remove('score-up')
|
|
|
|
thisScoreText.classList.remove('score-down')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
post_vote("/vote/" + type + "/" + id + "/" + voteDirection);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var downvote = function(event) {
|
|
|
|
|
|
|
|
var type = event.target.dataset.contentType;
|
|
|
|
var id = event.target.dataset.idDown;
|
|
|
|
|
|
|
|
var downvoteButton = document.getElementsByClassName(type + '-' + id + '-down');
|
|
|
|
var upvoteButton = document.getElementsByClassName(type + '-' + id + '-up');
|
|
|
|
var scoreText = document.getElementsByClassName(type + '-score-' + id);
|
|
|
|
|
|
|
|
for (var j = 0; j < upvoteButton.length && j < downvoteButton.length && j < scoreText.length; j++) {
|
|
|
|
|
|
|
|
var thisUpvoteButton = upvoteButton[j];
|
|
|
|
var thisDownvoteButton = downvoteButton[j];
|
|
|
|
var thisScoreText = scoreText[j];
|
|
|
|
var thisScore = Number(thisScoreText.textContent);
|
2021-09-26 09:23:51 +00:00
|
|
|
var voteDirection = "0"
|
2021-09-25 21:13:52 +00:00
|
|
|
|
|
|
|
if (thisDownvoteButton.classList.contains('active')) {
|
|
|
|
thisDownvoteButton.classList.remove('active')
|
|
|
|
thisScoreText.textContent = thisScore + 1
|
|
|
|
voteDirection = "0"
|
|
|
|
} else if (thisUpvoteButton.classList.contains('active')) {
|
|
|
|
thisDownvoteButton.classList.add('active')
|
|
|
|
thisUpvoteButton.classList.remove('active')
|
|
|
|
thisScoreText.textContent = thisScore - 2
|
|
|
|
voteDirection = "-1"
|
|
|
|
} else {
|
|
|
|
thisDownvoteButton.classList.add('active')
|
|
|
|
thisScoreText.textContent = thisScore - 1
|
|
|
|
voteDirection = "-1"
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thisUpvoteButton.classList.contains('active')) {
|
|
|
|
thisScoreText.classList.add('score-up')
|
|
|
|
thisScoreText.classList.remove('score-down')
|
|
|
|
thisScoreText.classList.remove('score')
|
|
|
|
} else if (thisDownvoteButton.classList.contains('active')) {
|
|
|
|
thisScoreText.classList.add('score-down')
|
|
|
|
thisScoreText.classList.remove('score-up')
|
|
|
|
thisScoreText.classList.remove('score')
|
|
|
|
} else {
|
|
|
|
thisScoreText.classList.add('score')
|
|
|
|
thisScoreText.classList.remove('score-up')
|
|
|
|
thisScoreText.classList.remove('score-down')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
post_vote("/vote/" + type + "/" + id + "/" + voteDirection);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var register_votes = function() {
|
|
|
|
var upvoteButtons = document.getElementsByClassName('upvote-button')
|
|
|
|
|
|
|
|
var downvoteButtons = document.getElementsByClassName('downvote-button')
|
|
|
|
|
|
|
|
var voteDirection = 0
|
|
|
|
|
|
|
|
for (var i = 0; i < upvoteButtons.length; i++) {
|
|
|
|
upvoteButtons[i].addEventListener('click', upvote, false);
|
|
|
|
upvoteButtons[i].addEventListener('keydown', function(event) {
|
|
|
|
if (event.keyCode === 13) {
|
|
|
|
upvote(event)
|
|
|
|
}
|
|
|
|
}, false)
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < downvoteButtons.length; i++) {
|
|
|
|
downvoteButtons[i].addEventListener('click', downvote, false);
|
|
|
|
downvoteButtons[i].addEventListener('keydown', function(event) {
|
|
|
|
if (event.keyCode === 13) {
|
|
|
|
downvote(event)
|
|
|
|
}
|
|
|
|
}, false)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
register_votes()
|
|
|
|
|
|
|
|
// award modal
|
|
|
|
|
|
|
|
function awardModal(link) {
|
|
|
|
var target = document.getElementById("awardTarget");
|
|
|
|
target.action = link;
|
|
|
|
}
|
|
|
|
|
|
|
|
function bruh(kind) {
|
|
|
|
document.getElementById('giveaward').disabled=false;
|
|
|
|
document.getElementById('kind').value=kind;
|
|
|
|
try {document.getElementsByClassName('picked')[0].classList.toggle('picked');} catch(e) {}
|
|
|
|
document.getElementById(kind).classList.toggle('picked')
|
|
|
|
}
|
2021-09-17 15:08:07 +00:00
|
|
|
</script>
|
|
|
|
|
2021-09-17 11:25:14 +00:00
|
|
|
<div class="modal fade" id="awardModal" tabindex="-1" role="dialog" aria-labelledby="awardModalTitle" aria-hidden="true">
|
2021-09-17 14:01:47 +00:00
|
|
|
<div class="modal-dialog modal-dialog-scrollable modal-dialog-centered" role="document">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 class="modal-title">Give Award</h5>
|
2021-09-26 09:04:49 +00:00
|
|
|
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
|
2021-09-17 14:01:47 +00:00
|
|
|
<span aria-hidden="true"><i class="far fa-times"></i></span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div id="awardModalBody" class="modal-body">
|
2021-09-17 15:23:23 +00:00
|
|
|
<form id="awardTarget" class="pt-3 pb-0" action="" method="post">
|
2021-09-17 14:01:47 +00:00
|
|
|
<div class="card-columns awards-wrapper">
|
2021-09-17 14:35:12 +00:00
|
|
|
{% for award in v.user_awards %}
|
2021-09-17 19:26:55 +00:00
|
|
|
{% if award.owned %}
|
|
|
|
<a href="javascript:void(0)" id="{{award.kind}}" class="card" onclick="bruh('{{award.kind}}')">
|
|
|
|
{% else %}
|
|
|
|
<a href="javascript:void(0)" id="{{award.kind}}" class="card disabled">
|
|
|
|
{% endif %}
|
2021-09-17 14:35:12 +00:00
|
|
|
<i class="{{award.icon}} {{award.color}}"></i><br />
|
2021-09-17 14:52:45 +00:00
|
|
|
<span class="d-block pt-2" style="font-weight: bold; font-size: 14px; color:#E1E1E1">{{award.title}}</span>
|
2021-09-17 14:35:12 +00:00
|
|
|
<span class="text-muted">{{award.owned}} owned</span>
|
2021-09-17 14:49:56 +00:00
|
|
|
</a>
|
2021-09-17 14:35:12 +00:00
|
|
|
{% endfor %}
|
2021-09-17 14:13:40 +00:00
|
|
|
</div>
|
|
|
|
<label for="note" class="pt-4">Note (optional):</label>
|
2021-09-17 14:38:19 +00:00
|
|
|
<input id="kind" name="kind" value="" hidden>
|
2021-09-17 14:13:40 +00:00
|
|
|
<textarea id="note" name="note" class="form-control" placeholder="Note to include in award notification"></textarea>
|
2021-09-17 14:24:08 +00:00
|
|
|
<input id="giveaward" class="btn btn-primary" style="float:right" type="submit" value="Give Award" disabled>
|
2021-09-17 14:01:47 +00:00
|
|
|
</form>
|
|
|
|
</div>
|
2021-09-17 15:30:26 +00:00
|
|
|
</div>
|
2021-09-17 14:01:47 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
2021-09-17 14:35:12 +00:00
|
|
|
.awards-wrapper input[type="radio"] {
|
|
|
|
display: none;
|
2021-09-17 14:24:46 +00:00
|
|
|
}
|
2021-09-17 14:35:12 +00:00
|
|
|
|
2021-09-17 14:49:56 +00:00
|
|
|
.awards-wrapper a {
|
2021-09-17 14:01:47 +00:00
|
|
|
cursor: pointer;
|
2021-09-17 14:35:12 +00:00
|
|
|
padding: 15px;
|
|
|
|
text-align: center;
|
|
|
|
text-transform: none!important;
|
2021-09-17 14:01:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 14:49:56 +00:00
|
|
|
.awards-wrapper a i {
|
2021-09-17 14:35:12 +00:00
|
|
|
font-size: 45px;
|
2021-09-17 14:01:47 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 14:49:56 +00:00
|
|
|
.awards-wrapper a.disabled {
|
2021-09-17 14:35:12 +00:00
|
|
|
opacity: 0.6;
|
2021-09-17 14:24:46 +00:00
|
|
|
}
|
2021-09-17 14:35:12 +00:00
|
|
|
|
2021-09-17 15:01:32 +00:00
|
|
|
.awards-wrapper a:hover, .picked {
|
2021-09-17 14:35:12 +00:00
|
|
|
background-color: var(--primary)!important;
|
2021-09-17 14:24:46 +00:00
|
|
|
}
|
2021-09-17 14:35:12 +00:00
|
|
|
|
2021-09-17 14:49:56 +00:00
|
|
|
.awards-wrapper input[type="radio"]:checked+a {
|
2021-09-17 14:35:12 +00:00
|
|
|
background-color: var(--primary)!important;
|
2021-09-17 14:24:46 +00:00
|
|
|
}
|
2021-09-17 14:01:47 +00:00
|
|
|
</style>
|