From 0d3a93ff24b040a6e4c262f4c1dc17eb8415b48c Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Thu, 11 Oct 2018 12:41:42 +0200 Subject: [PATCH] Added voting. --- backend/db.sqlite3 | Bin 78848 -> 78848 bytes backend/postings/static/postings/js/voting.js | 48 +++++------------- .../templates/postings/frontend/review.html | 4 +- 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/backend/db.sqlite3 b/backend/db.sqlite3 index 91e430b96410eec80e276b9062d8d29e416670bc..12660632d67f786a8c70789e3eeb3b6bc96d9b24 100644 GIT binary patch delta 793 zcmXBQJ!lhg7{~G4|9f|s3qqT=Y11Tan!Y4$)ATLrOX45|9K^*=4x$d?AQT+LMIpsO zbdd^z=wMxRa?vc}AP5d36a~RSbWj8Xih_s|LGk~8p5^o93EW-yZFT&uj=!DpcCKZc z-p+#)ml9s1{W+1V9xa=0%yi8^d^&vO9dCHW3!d?WM?B;{_qapEAAa(UTU_TVm$}FV z&T)p*oa7is*x(Qc*iW4*6-pGylA@>G>)$jjpSafu@H|s@vhEDmoYAVdBG$yJxGXM- zi{gSfFIL1ku`JGtGvc&Z5{m&X`@CdCPHTr7xVV%`~!iX&o9%!(OtSWJsU;-Huk z2gH7{&lx4H?cdG4U+v7hF}nQV3!ivzM}En3p7NNso%k-dxxqG9?6BuK%Ojj>Q>JL>wavHN3iCuFj#e0 z6s))_3Tm3FW?8eOS=20O<~0?~oTjXq)y!z7TiTMQsF~7CY9=(}nu2Cblh=&8KNm2qvw;q$!xx2a}p$QW;Fjf=O|P&F`GW-T>`-&A|MV`4jVN=IPiW(5`Cc z_$06{hG+;C0-+#QGq^!`_7KVfLK#9REeHj%nn4E0V-;dy;AG@t6=Y%H08#>A9sqWq BETsSd diff --git a/backend/postings/static/postings/js/voting.js b/backend/postings/static/postings/js/voting.js index 26a6a6c..0098c99 100644 --- a/backend/postings/static/postings/js/voting.js +++ b/backend/postings/static/postings/js/voting.js @@ -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); diff --git a/backend/postings/templates/postings/frontend/review.html b/backend/postings/templates/postings/frontend/review.html index 0cbb7d6..ab4f843 100644 --- a/backend/postings/templates/postings/frontend/review.html +++ b/backend/postings/templates/postings/frontend/review.html @@ -25,8 +25,8 @@ Yes No - {{ review.helpful_vote_count }} / - {{ review.unhelpful_vote_count }} + {{ review.helpful_vote_count }} / + {{ review.unhelpful_vote_count }} \ No newline at end of file -- 2.34.1