Merge pull request #6 from andrewlalis/al/post_review
Added functionality for mvp.
This commit is contained in:
commit
552a1a526f
|
@ -20,8 +20,8 @@ from django.contrib.staticfiles.views import serve
|
|||
from django.views.generic import RedirectView
|
||||
|
||||
urlpatterns = [
|
||||
# / routes to index2.html
|
||||
url(r'^$', serve, kwargs={'path': 'index2.html'}),
|
||||
# / routes to index.html
|
||||
url(r'^$', serve, kwargs={'path': 'index.html'}),
|
||||
|
||||
# static files (*.css, *.js, *.jpg etc.) served on /
|
||||
# (assuming Django uses /static/ and /media/ for static/media urls)
|
||||
|
|
Binary file not shown.
|
@ -15,8 +15,7 @@ class UniversityReviewSerializer(serializers.ModelSerializer):
|
|||
'content',
|
||||
]
|
||||
read_only_fields =[
|
||||
'pk',
|
||||
'username'
|
||||
'pk'
|
||||
]
|
||||
|
||||
# Serializes the generic Review object.
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.1.1 on 2018-09-27 11:15
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('postings', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='universityreview',
|
||||
name='date_published',
|
||||
field=models.DateTimeField(auto_now_add=True),
|
||||
),
|
||||
]
|
|
@ -50,6 +50,6 @@ class UniversityReview(models.Model):
|
|||
username = models.CharField(max_length=200)
|
||||
rating = models.IntegerField(default=1)
|
||||
title = models.CharField(max_length=200)
|
||||
date_published = models.DateField('date published')
|
||||
date_published = models.DateTimeField(auto_now_add=True)
|
||||
content = models.CharField(max_length=200)
|
||||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
<script src="js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"></script>
|
||||
</head>
|
||||
<body class="box">
|
||||
<body class="box2">
|
||||
<!--[if lt IE 8]>
|
||||
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
|
||||
<![endif]-->
|
||||
|
@ -38,7 +38,7 @@
|
|||
</button>
|
||||
<a class="navbar-brand">RateMyCourse</a>
|
||||
</div>
|
||||
<div id="navbar" class="navbar-collapse collapse">
|
||||
<!-- <div id="navbar" class="navbar-collapse collapse">
|
||||
<form class="navbar-form navbar-right" role="form">
|
||||
<div class="form-group">
|
||||
<input type="text" placeholder="Email" class="form-control">
|
||||
|
@ -47,37 +47,196 @@
|
|||
<input type="password" placeholder="Password" class="form-control">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success">Sign in</button>
|
||||
</form>red
|
||||
</div><!--/.navbar-collapse -->
|
||||
</form>
|
||||
</div> -->
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="fullcontainer">
|
||||
<div class="container vertical center horizontal center">
|
||||
<h1>Find rated courses</h1>
|
||||
<h3>The best course reviews by your fellow students!</h3>
|
||||
<div class="col-md-offset-2 col-md-8">
|
||||
<form action="/action_page.php">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" placeholder="Search" name="search">
|
||||
<div class="input-group-btn">
|
||||
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<h1 class="muted text-center">Software engineering and startups</h1>
|
||||
<h2 class="muted text-center">Rijksuniversiteit Groningen</h2>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<!-- <div class="row">
|
||||
<div class="col-sm-3">
|
||||
<div class="rating-block">
|
||||
<h4>Average user rating</h4>
|
||||
<h2 class="bold padding-bottom-7">3 <small>/ 5</small></h2>
|
||||
<button type="button" class="btn btn-warning btn-sm" aria-label="Left Align">
|
||||
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-warning btn-sm" aria-label="Left Align">
|
||||
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-warning btn-sm" aria-label="Left Align">
|
||||
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-default btn-grey btn-sm" aria-label="Left Align">
|
||||
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-default btn-grey btn-sm" aria-label="Left Align">
|
||||
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<h4>Rating breakdown</h4>
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" style="width:35px; line-height:1;">
|
||||
<div style="height:9px; margin:5px 0;">5 <span class="glyphicon glyphicon-star"></span></div>
|
||||
</div>
|
||||
<div class="pull-left" style="width:180px;">
|
||||
<div class="progress" style="height:9px; margin:8px 0;">
|
||||
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="5" aria-valuemin="0" aria-valuemax="5" style="width: 0%">
|
||||
<span class="sr-only">80% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right" style="margin-left:10px;">0</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" style="width:35px; line-height:1;">
|
||||
<div style="height:9px; margin:5px 0;">4 <span class="glyphicon glyphicon-star"></span></div>
|
||||
</div>
|
||||
<div class="pull-left" style="width:180px;">
|
||||
<div class="progress" style="height:9px; margin:8px 0;">
|
||||
<div class="progress-bar progress-bar-primary" role="progressbar" aria-valuenow="4" aria-valuemin="0" aria-valuemax="5" style="width: 33%">
|
||||
<span class="sr-only">80% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right" style="margin-left:10px;">1</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" style="width:35px; line-height:1;">
|
||||
<div style="height:9px; margin:5px 0;">3 <span class="glyphicon glyphicon-star"></span></div>
|
||||
</div>
|
||||
<div class="pull-left" style="width:180px;">
|
||||
<div class="progress" style="height:9px; margin:8px 0;">
|
||||
<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="3" aria-valuemin="0" aria-valuemax="5" style="width: 33%">
|
||||
<span class="sr-only">80% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right" style="margin-left:10px;">1</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" style="width:35px; line-height:1;">
|
||||
<div style="height:9px; margin:5px 0;">2 <span class="glyphicon glyphicon-star"></span></div>
|
||||
</div>
|
||||
<div class="pull-left" style="width:180px;">
|
||||
<div class="progress" style="height:9px; margin:8px 0;">
|
||||
<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="2" aria-valuemin="0" aria-valuemax="5" style="width: 33%">
|
||||
<span class="sr-only">80% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right" style="margin-left:10px;">1</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" style="width:35px; line-height:1;">
|
||||
<div style="height:9px; margin:5px 0;">1 <span class="glyphicon glyphicon-star"></span></div>
|
||||
</div>
|
||||
<div class="pull-left" style="width:180px;">
|
||||
<div class="progress" style="height:9px; margin:8px 0;">
|
||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="1" aria-valuemin="0" aria-valuemax="5" style="width: 0">
|
||||
<span class="sr-only">80% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right" style="margin-left:10px;">0</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-7">
|
||||
<div class="row" style="margin-top:40px;">
|
||||
<div class="col-md-12">
|
||||
<div class="well-sm">
|
||||
<div class="text-right">
|
||||
<a class="btn btn-success btn-green" href="#reviews-anchor" id="open-review-box">Leave a Review</a>
|
||||
</div>
|
||||
|
||||
<div class="row" id="post-review-box" style="display:none;">
|
||||
<div class="col-md-12">
|
||||
<form id="submit_review_form" accept-charset="UTF-8">
|
||||
<input id="ratings-hidden" name="rating" type="hidden">
|
||||
<input id="university_name_input" name="university_name" type="hidden" value="Rijksuniversiteit Groningen">
|
||||
<p id="post_review_date_display" class="text-right"></p>
|
||||
<div class="form-group">
|
||||
<label for="username_input">Name:</label>
|
||||
<input name="username" type="text" class="form-control" placeholder="Name..." id="username_input">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="title_input">Title:</label>
|
||||
<input id="title_input" class="form-control" placeholder="Title..." name="title">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="content_input">Review:</label>
|
||||
<input id="content_input" class="form-control animated" cols="50" id="new-review" name="content" placeholder="Enter your review here..." rows="5">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="rating_input">Rating:</label>
|
||||
<input name="rating" id="rating_input" class="form-control" type="number" min="1" max="5" step="1">
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<a class="btn btn-danger btn-sm" href="#" id="close-review-box" style="display:none; margin-right: 10px;">
|
||||
<span class="glyphicon glyphicon-remove"></span>Cancel</a>
|
||||
<button id="submit_review_button" class="btn btn-success btn-lg" type="submit">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div id="review_container" class="review-block">
|
||||
<!-- All reviews go in this block. -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- /container -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
|
||||
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.min.js"><\/script>')</script>
|
||||
<script src="js/vendor/bootstrap.min.js"></script>
|
||||
<script src="js/vendor/handlebars-v4.0.12.js"></script>
|
||||
<!-- Handlebars templates -->
|
||||
<!-- TODO: Use a templating engine to automatically include all handlebars templates required for a certain page. -->
|
||||
<script id="review_item_handlebars" type="text/x-handlebars-template">
|
||||
<div class="row review_item" id="{{pk}}">
|
||||
<div class="col-sm-3">
|
||||
<div class="review-block-name"><a href="#">{{username}}</a></div>
|
||||
</div>
|
||||
<div class="col-sm-9">
|
||||
<div class="review-block-rate">
|
||||
{{#times rating}}
|
||||
<span class="glyphicon glyphicon-star js_review_rating" aria-hidden="true"></span>
|
||||
{{/times}}
|
||||
</div>
|
||||
<div class="review-block-title">
|
||||
{{title}}
|
||||
</div>
|
||||
<div class="review-block-description">
|
||||
{{content}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<!-- Custom scripts -->
|
||||
<script src="js/main.js"></script>
|
||||
|
||||
<script src="js/load_reviews.js"></script>
|
||||
<script src="js/post_review.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,255 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang=""> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9" lang=""> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html class="no-js" lang=""> <!--<![endif]-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title></title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="apple-touch-icon" href="apple-touch-icon.png">
|
||||
|
||||
<link rel="stylesheet" href="css/bootstrap.min.css">
|
||||
<style>
|
||||
body {
|
||||
padding-top: 50px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
|
||||
<link rel="stylesheet" href="css/main.css">
|
||||
|
||||
<script src="js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"></script>
|
||||
</head>
|
||||
<body class="box2">
|
||||
<!--[if lt IE 8]>
|
||||
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
|
||||
<![endif]-->
|
||||
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand">RateMyCourse</a>
|
||||
</div>
|
||||
<div id="navbar" class="navbar-collapse collapse">
|
||||
<form class="navbar-form navbar-right" role="form">
|
||||
<div class="form-group">
|
||||
<input type="text" placeholder="Email" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="password" placeholder="Password" class="form-control">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success">Sign in</button>
|
||||
</form>
|
||||
</div><!--/.navbar-collapse -->
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<!--<div class="fullcontainer">
|
||||
<div class="container vertical center horizontal center">
|
||||
|
||||
</div>
|
||||
</div>-->
|
||||
|
||||
|
||||
<div class="container">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<h1 class="muted text-center">Software engineering and startups</h1>
|
||||
<h2 class="muted text-center">Rijksuniversiteit Groningen</h2>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-sm-3">
|
||||
<div class="rating-block">
|
||||
<h4>Average user rating</h4>
|
||||
<h2 class="bold padding-bottom-7">3 <small>/ 5</small></h2>
|
||||
<button type="button" class="btn btn-warning btn-sm" aria-label="Left Align">
|
||||
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-warning btn-sm" aria-label="Left Align">
|
||||
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-warning btn-sm" aria-label="Left Align">
|
||||
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-default btn-grey btn-sm" aria-label="Left Align">
|
||||
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
|
||||
</button>
|
||||
<button type="button" class="btn btn-default btn-grey btn-sm" aria-label="Left Align">
|
||||
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<h4>Rating breakdown</h4>
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" style="width:35px; line-height:1;">
|
||||
<div style="height:9px; margin:5px 0;">5 <span class="glyphicon glyphicon-star"></span></div>
|
||||
</div>
|
||||
<div class="pull-left" style="width:180px;">
|
||||
<div class="progress" style="height:9px; margin:8px 0;">
|
||||
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="5" aria-valuemin="0" aria-valuemax="5" style="width: 0%">
|
||||
<span class="sr-only">80% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right" style="margin-left:10px;">0</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" style="width:35px; line-height:1;">
|
||||
<div style="height:9px; margin:5px 0;">4 <span class="glyphicon glyphicon-star"></span></div>
|
||||
</div>
|
||||
<div class="pull-left" style="width:180px;">
|
||||
<div class="progress" style="height:9px; margin:8px 0;">
|
||||
<div class="progress-bar progress-bar-primary" role="progressbar" aria-valuenow="4" aria-valuemin="0" aria-valuemax="5" style="width: 33%">
|
||||
<span class="sr-only">80% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right" style="margin-left:10px;">1</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" style="width:35px; line-height:1;">
|
||||
<div style="height:9px; margin:5px 0;">3 <span class="glyphicon glyphicon-star"></span></div>
|
||||
</div>
|
||||
<div class="pull-left" style="width:180px;">
|
||||
<div class="progress" style="height:9px; margin:8px 0;">
|
||||
<div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="3" aria-valuemin="0" aria-valuemax="5" style="width: 33%">
|
||||
<span class="sr-only">80% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right" style="margin-left:10px;">1</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" style="width:35px; line-height:1;">
|
||||
<div style="height:9px; margin:5px 0;">2 <span class="glyphicon glyphicon-star"></span></div>
|
||||
</div>
|
||||
<div class="pull-left" style="width:180px;">
|
||||
<div class="progress" style="height:9px; margin:8px 0;">
|
||||
<div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="2" aria-valuemin="0" aria-valuemax="5" style="width: 33%">
|
||||
<span class="sr-only">80% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right" style="margin-left:10px;">1</div>
|
||||
</div>
|
||||
<div class="pull-left">
|
||||
<div class="pull-left" style="width:35px; line-height:1;">
|
||||
<div style="height:9px; margin:5px 0;">1 <span class="glyphicon glyphicon-star"></span></div>
|
||||
</div>
|
||||
<div class="pull-left" style="width:180px;">
|
||||
<div class="progress" style="height:9px; margin:8px 0;">
|
||||
<div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="1" aria-valuemin="0" aria-valuemax="5" style="width: 0">
|
||||
<span class="sr-only">80% Complete (danger)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pull-right" style="margin-left:10px;">0</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-7">
|
||||
<hr/>
|
||||
<div id="review_container" class="review-block">
|
||||
<!-- All reviews go in this block. -->
|
||||
|
||||
|
||||
|
||||
<hr/>
|
||||
<div class="row" style="margin-top:40px;">
|
||||
<div class="col-md-12">
|
||||
<div class="well-sm">
|
||||
<div class="text-right">
|
||||
<a class="btn btn-success btn-green" href="#reviews-anchor" id="open-review-box">Leave a Review</a>
|
||||
</div>
|
||||
|
||||
<div class="row" id="post-review-box" style="display:none;">
|
||||
<div class="col-md-12">
|
||||
|
||||
<form accept-charset="UTF-8" action="" method="post">
|
||||
<input id="ratings-hidden" name="rating" type="hidden">
|
||||
<p class="text-right date"></p>
|
||||
<div class="form-group">
|
||||
<label for="usr">Name:</label>
|
||||
<input type="text" class="form-control" placeholder="Name..." id="usr">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="usr">Review:</label>
|
||||
<input class="form-control animated" cols="50" id="new-review" name="comment" placeholder="Enter your review here..." rows="5">
|
||||
</div>
|
||||
<div class="text-right">
|
||||
|
||||
<div class="stars starrr" data-rating="0"></div>
|
||||
<a class="btn btn-danger btn-sm" href="#" id="close-review-box" style="display:none; margin-right: 10px;">
|
||||
<span class="glyphicon glyphicon-remove"></span>Cancel</a>
|
||||
<button class="btn btn-success btn-lg" type="submit">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div> <!-- /container -->
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
|
||||
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.2.min.js"><\/script>')</script>
|
||||
<script src="js/vendor/bootstrap.min.js"></script>
|
||||
<script src="js/vendor/handlebars-v4.0.12.js"></script>
|
||||
<!-- Handlebars templates -->
|
||||
<!-- TODO: Use a templating engine to automatically include all handlebars templates required for a certain page. -->
|
||||
<script id="review_item_handlebars" type="text/x-handlebars-template">
|
||||
<div class="row" id="{{pk}}">
|
||||
<div class="col-sm-3">
|
||||
<img src="http://dummyimage.com/60x60/666/ffffff&text=No+Image" class="img-rounded">
|
||||
<div class="review-block-name"><a href="#">{{username}}</a></div>
|
||||
<div class="review-block-date">
|
||||
{{date_published}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-9">
|
||||
<div class="review-block-rate">
|
||||
<span class="glyphicon glyphicon-star js_review_rating" aria-hidden="true"></span>
|
||||
<span class="glyphicon glyphicon-star js_review_rating" aria-hidden="true"></span>
|
||||
<span class="glyphicon glyphicon-star js_review_rating" aria-hidden="true"></span>
|
||||
<span class="glyphicon glyphicon-star js_review_rating" aria-hidden="true"></span>
|
||||
<span class="glyphicon glyphicon-star js_review_rating" aria-hidden="true"></span>
|
||||
</div>
|
||||
<div class="review-block-title">
|
||||
{{title}}
|
||||
</div>
|
||||
<div class="review-block-description">
|
||||
{{content}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
<!-- Custom scripts -->
|
||||
<script src="js/main.js"></script>
|
||||
<script src="js/load_reviews.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,28 +1,27 @@
|
|||
var $ = jQuery;
|
||||
|
||||
Handlebars.registerHelper('times', function(n, block) {
|
||||
var accum = '';
|
||||
for(var i = 0; i < n; ++i)
|
||||
accum += block.fn(i);
|
||||
return accum;
|
||||
});
|
||||
|
||||
// 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");
|
||||
container.remove(".review_item");
|
||||
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 />");
|
||||
});
|
||||
}
|
||||
|
||||
function loadReviews () {
|
||||
$.ajax({
|
||||
url: "http://localhost:8000/api/postings/",
|
||||
url: "/api/postings/",
|
||||
method: "GET"
|
||||
}).done(function (response) {
|
||||
displayReviews(response);
|
||||
|
|
|
@ -34,37 +34,4 @@ $(function(){
|
|||
closeReviewBtn.hide();
|
||||
|
||||
});
|
||||
|
||||
$('.starrr').on('starrr:change', function(e, value){
|
||||
ratingsField.val(value);
|
||||
});
|
||||
var i;
|
||||
for(i = 1; i<6; i++) {
|
||||
$(".stars").append("<button value=" + i + " id = \"star" + i +"\" type=\"button\" class=\"btn btn-default btn-grey btn-xs\" aria-label=\"Left Align\">\n" +
|
||||
" <span class=\"glyphicon glyphicon-star\" aria-hidden=\"true\"></span>\n" +
|
||||
" </button>");
|
||||
}
|
||||
$(".stars .btn").click(function(e, value) {
|
||||
$(".starrr").attr("data-rating", this.value);
|
||||
for (let j = 1; j <= this.value; j++) {
|
||||
$("#star" + j).removeClass("btn-default btn-grey").addClass("btn-warning");
|
||||
}
|
||||
for (let g = this.value; g <= 5; g++) {
|
||||
$("#star" + (g+1)).addClass("btn-default btn-grey").removeClass("btn-warning");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var d = new Date();
|
||||
|
||||
var month = d.getMonth()+1;
|
||||
var day = d.getDate();
|
||||
|
||||
var output =
|
||||
|
||||
((''+day).length<2 ? '0' : '') + day + '/' +
|
||||
((''+month).length<2 ? '0' : '') + month + '/' +
|
||||
d.getFullYear();
|
||||
$(".date").append(output);
|
||||
|
||||
});
|
|
@ -0,0 +1,47 @@
|
|||
var $ = jQuery;
|
||||
|
||||
// Sends POST request to api.
|
||||
function postReview (data) {
|
||||
$.ajax({
|
||||
url: "api/postings/",
|
||||
method: "POST",
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json",
|
||||
headers: {
|
||||
'X-CSRFToken': Cookies.get("csrftoken")
|
||||
}
|
||||
}).done(function (response) {
|
||||
var template = Handlebars.compile($("#review_item_handlebars").html());
|
||||
var container = $("#review_container");
|
||||
var review_html = template(response);
|
||||
container.append(review_html);
|
||||
container.append("<hr><br />");
|
||||
}).fail(function (response) {
|
||||
console.log(response);
|
||||
alert("The review could not be sent.");
|
||||
}).always(function () {
|
||||
$("#submit_review_form").trigger("reset");
|
||||
$('#close-review-box').trigger("click");
|
||||
});
|
||||
}
|
||||
|
||||
// What to do when the user clicks submit.
|
||||
function onSubmitReviewClicked () {
|
||||
var serialized_data = $("#submit_review_form").serializeArray();
|
||||
var formatted_data = {};
|
||||
for (var i = 0; i < serialized_data.length; i++) {
|
||||
formatted_data[serialized_data[i]['name']] = serialized_data[i]['value'];
|
||||
}
|
||||
console.log(formatted_data);
|
||||
postReview(formatted_data);
|
||||
}
|
||||
|
||||
// Add a listener for when the user clicks to submit a review.
|
||||
$(document.body)
|
||||
.off("click.submit_review_button")
|
||||
.on("click.submit_review_button",
|
||||
"#submit_review_button",
|
||||
function (event) {
|
||||
event.preventDefault();
|
||||
onSubmitReviewClicked();
|
||||
});
|
Loading…
Reference in New Issue