From 9de533b95030029337eaceaf773486963697907b Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 25 Sep 2018 15:12:45 +0200 Subject: [PATCH] Added handlebars template. --- frontpage/index2.html | 122 +++++------------- frontpage/js/load_reviews.js | 20 ++- frontpage/js/templates/review_item.handlebars | 34 +++++ 3 files changed, 85 insertions(+), 91 deletions(-) create mode 100644 frontpage/js/templates/review_item.handlebars diff --git a/frontpage/index2.html b/frontpage/index2.html index 0b6a5f5..2c47647 100644 --- a/frontpage/index2.html +++ b/frontpage/index2.html @@ -164,94 +164,9 @@

-
-
-
- - -
January 29, 2016
1 day ago
-
-
-
-
- - - - - -
-
Course review 3
-
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley
-
-
-
-
-
- - -
January 29, 2016
1 day ago
-
-
-
- - - - - -
-
Course review 2
-
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley
-
-
-
-
-
- - -
January 29, 2016
1 day ago
-
-
-
- - - - - -
-
Course review 1
-
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley
-
-
+
+ +
@@ -265,7 +180,36 @@ - + + + + + diff --git a/frontpage/js/load_reviews.js b/frontpage/js/load_reviews.js index 3d10447..3902ad8 100644 --- a/frontpage/js/load_reviews.js +++ b/frontpage/js/load_reviews.js @@ -1,7 +1,23 @@ var $ = jQuery; +// Load the handlebars template and use it to append all reviews. function displayReviews(reviews) { - + 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("

"); + }); } function loadReviews () { @@ -11,7 +27,7 @@ function loadReviews () { }).done(function (response) { displayReviews(response); }).fail(function (response) { - console.log(response); + console.log("Could not get postings."); }) } diff --git a/frontpage/js/templates/review_item.handlebars b/frontpage/js/templates/review_item.handlebars new file mode 100644 index 0000000..3ec7b29 --- /dev/null +++ b/frontpage/js/templates/review_item.handlebars @@ -0,0 +1,34 @@ +
+
+ + +
+ {{date_published}} +
+
+
+
+ + + + + +
+
+ {{title}} +
+
+ {{content}} +
+
+
\ No newline at end of file