Added voting.
This commit is contained in:
parent
710d41905b
commit
0d3a93ff24
Binary file not shown.
|
@ -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);
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue