2018-09-25 12:26:44 +00:00
|
|
|
var $ = jQuery;
|
|
|
|
|
2018-09-25 13:12:45 +00:00
|
|
|
// Load the handlebars template and use it to append all reviews.
|
2018-09-25 12:26:44 +00:00
|
|
|
function displayReviews(reviews) {
|
2018-09-25 13:12:45 +00:00
|
|
|
var template = Handlebars.compile($("#review_item_handlebars").html());
|
|
|
|
var container = $("#review_container");
|
|
|
|
reviews.forEach(function (review) {
|
|
|
|
var review_html = template(review);
|
|
|
|
container.append(review_html);
|
|
|
|
// If a rating is defined, then hide only those rating stars which are higher than the current rating.
|
|
|
|
// TODO: remove this check once this is added to the database.
|
|
|
|
if (typeof(review.rating) !== "undefined") {
|
|
|
|
$(".js_review_rating").each(function (index) {
|
|
|
|
if ((index + 1) > review.rating) {
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
container.append("<hr><br />");
|
|
|
|
});
|
2018-09-25 12:26:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadReviews () {
|
|
|
|
$.ajax({
|
|
|
|
url: "http://localhost:8000/api/postings/",
|
|
|
|
method: "GET"
|
|
|
|
}).done(function (response) {
|
|
|
|
displayReviews(response);
|
|
|
|
}).fail(function (response) {
|
2018-09-25 13:12:45 +00:00
|
|
|
console.log("Could not get postings.");
|
2018-09-25 12:26:44 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
loadReviews();
|