Merge pull request #15 from andrewlalis/al/votes_improv

Added voting.
This commit is contained in:
Andrew Lalis 2018-10-11 11:43:23 +01:00 committed by GitHub
commit 13aa10ff56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 38 deletions

Binary file not shown.

View File

@ -1,38 +1,3 @@
// $(function() {
// var csrftoken = $("#csrf-token input").val();
// $(".vote-up").click(function() {
// var reviewId = $(this).attr("data-review-id");
// var data = {
// 'csrfmiddlewaretoken': csrftoken,
// 'helpful': true
// };
// // Vote up
// $.post(
// '/api/postings/reviews/' + reviewId + '/helpful_vote/',
// data,
// function(result) { console.log(result); }
// );
// // Hide vote buttons
// $("#review-votes-" + reviewId + " .review-vote-buttons").hide();
// });
// $(".vote-down").click(function() {
// var reviewId = $(this).attr("data-review-id");
// var data = {
// 'csrfmiddlewaretoken': csrftoken,
// 'helpful': false
// };
// // Vote down
// $.post(
// '/api/postings/reviews/' + reviewId + '/helpful_vote/',
// data,
// function(result) { console.log(result); }
// );
// // Hide vote buttons
// $("#review-votes-" + reviewId + " .review-vote-buttons").hide();
// });
// });
// Sends either an up- or down-vote for a particular review.
function sendVote (event, is_helpful) {
var csrf_token = $('#csrf-token input').val();
@ -46,7 +11,18 @@ function sendVote (event, is_helpful) {
data,
)
.done(function (response) {
console.log(response);
var selector = '#votes_';
if (is_helpful) {
selector += 'helpful_';
} else {
selector += 'unhelpful_';
}
var $vote_display = $(selector + review_id);
var current_votes = parseInt($vote_display.html());
$vote_display.html(current_votes + 1);
$('#review-votes-' + review_id + ' .review-vote-buttons').hide();
})
.fail(function (response) {
console.log(response);

View File

@ -25,8 +25,8 @@
<a class="btn btn-light btn-sm js_vote_up"><span class="glyphicon glyphicon-thumbs-up"></span> Yes</a>
<a class="btn btn-light btn-sm js_vote_down"><span class="glyphicon glyphicon-thumbs-down"></span> No</a>
</div>
<span title="{{ review.getHelpfulVoteCount }} people found this review helpful"><span class="votes-helpful">{{ review.helpful_vote_count }}</span> <span class="glyphicon glyphicon-thumbs-up"></span></span> /
<span title="{{ review.getUnhelpfulVoteCount }} people found this review unhelpful"><span class="votes-unhelpful">{{ review.unhelpful_vote_count }}</span> <span class="glyphicon glyphicon-thumbs-down"></span></span>
<span title="{{ review.helpful_vote_count }} people found this review helpful"><span id="votes_helpful_{{ review.pk }}">{{ review.helpful_vote_count }}</span> <span class="glyphicon glyphicon-thumbs-up"></span></span> /
<span title="{{ review.helpful_vote_count }} people found this review unhelpful"><span id="votes_unhelpful_{{ review.pk }}">{{ review.unhelpful_vote_count }}</span> <span class="glyphicon glyphicon-thumbs-down"></span></span>
</div>
</div>
</div>