RateMyCourse/frontpage/js/load_reviews.js

33 lines
807 B
JavaScript
Raw Permalink Normal View History

2018-09-25 12:26:44 +00:00
var $ = jQuery;
2018-09-27 12:41:34 +00:00
Handlebars.registerHelper('times', function(n, block) {
var accum = '';
for(var i = 0; i < n; ++i)
accum += block.fn(i);
return accum;
});
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");
2018-09-27 12:41:34 +00:00
container.remove(".review_item");
2018-09-25 13:12:45 +00:00
reviews.forEach(function (review) {
var review_html = template(review);
container.append(review_html);
container.append("<hr><br />");
});
2018-09-25 12:26:44 +00:00
}
function loadReviews () {
$.ajax({
2018-09-27 12:41:34 +00:00
url: "/api/postings/",
2018-09-25 12:26:44 +00:00
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();