Skip to content
Snippets Groups Projects
Commit 8d7f39ad authored by Adylan Roaffa Ilmy's avatar Adylan Roaffa Ilmy
Browse files

Merge branch 'habibi_book' into 'master'

Add Create Review

See merge request !7
parents 2d121dc2 242472ce
Branches
1 merge request!7Add Create Review
<?php
class Review {
function __construct(){
}
}
?>
\ No newline at end of file
......@@ -3,7 +3,7 @@
"db" => array(
"host" => "localhost",
"user" => "root",
"password" => "rahasiailahi",
"password" => "06071998",
"db_name" => "tayo_book_store"
),
"base_url" => "http://localhost:4000/",
......
......@@ -25,4 +25,46 @@
margin-left: 5px;
margin-right: 5px;
}
\ No newline at end of file
}
.review-comment {
width: 100%;
}
textarea {
font-size: 20px;
}
.review-back {
margin-top: 40px;
margin-bottom: 20px;
background-color: white;
border: 3px solid;
border-color: #d9534f;
border-radius: 10px;
width: 150px;
height: 60px;
}
.review-back span {
font-size: 30px;
color: #d9534f;
}
.review-submit {
margin-top: 40px;
margin-bottom: 20px;
background-color: #0094cc;
border: 3px solid;
border-color: #0094cc;
border-radius: 10px;
width: 150px;
height: 60px;
}
.review-submit span {
font-size: 30px;
color: white;
}
......@@ -4,9 +4,9 @@
<div class="row justify-content-between">
<div class="review-title">
<div class="title">
<h1>Nota Hidup</h1>
<h1 id="review-title">Nota Hidup</h1>
</div>
<h2>Light R.D.B</h2>
<h2 id="review-author">Light R.D.B</h2>
</div>
<img
src="/static/img/contoh_buku.png"
......@@ -45,6 +45,31 @@
<div class="review-header">
<h1>Add Comment</h1>
</div>
<textarea
name="comment"
id="review-comment"
rows="10"
class="review-comment"
>
</textarea>
<div class="justify-content-between">
<a href="/history/">
<button
class='review-back'
id='review-back'
>
<span>Back</span>
</button>
</a>
<button
class='review-submit'
id='review-submit'
>
<span>Submit</span>
</button>
</div>
</div>
<script src="/static/js/review.js"></script>
\ No newline at end of file
......@@ -6,11 +6,28 @@ for(i = 0; i < 5; i++) {
stars.push(star);
}
const submitButton = document.getElementById('review-submit');
const getBookContent = function() {
let url_string = window.location.href;
let url = new URL(url_string);
let book_id = url.searchParams.get("book_id");
let book_title = document.getElementById("review-title");
let book_author = document.getElementById("review-author");
doAjax(`/api/book/${book_id}/`, "GET", null, function(response) {
const book = response.data[0];
book_title.innerHTML = book.title;
book_author.innerHTML = book.author;
});
}
const onRatingMouseOver = function() {
const key = this.getAttribute("key")
for(i = 0; i < parseInt(key) + 1; i++) {
console.log(i);
stars[i].src="/static/img/full_star.png";
}
for(i = parseInt(key) + 1; i< 5; i++) {
......@@ -35,10 +52,37 @@ const onRatingClick = function() {
}
}
const submitComment = function() {
let url_string = window.location.href;
let url = new URL(url_string);
let book_id = url.searchParams.get("book_id");
const user_id = getCookie("user_id");
const content = document.getElementById("review-comment").value;
let payload = {
"user_id": parseInt(user_id),
"book_id": parseInt(book_id),
"content": content,
"rating": rating
}
console.log(payload);
console.log('HAI KAMu');
doAjax('/api/review/', "POST", payload, function(response) {
window.location.replace('http://localhost:4000/history/')
})
}
window.onload = function() {
getBookContent();
for (i = 0; i < 5; i++) {
stars[i].onmouseover = onRatingMouseOver;
stars[i].onmouseout = onRatingMouseOut;
stars[i].onclick = onRatingClick;
}
submitButton.onclick = submitComment;
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment