- first commit
This commit is contained in:
commit
407717d4b5
57 changed files with 5510 additions and 0 deletions
83
client/book-list.html
Normal file
83
client/book-list.html
Normal file
|
@ -0,0 +1,83 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Document</title>
|
||||
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<hr>
|
||||
<h1>List of books</h1>
|
||||
<hr>
|
||||
|
||||
<div>
|
||||
<div class="row" id="books">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="editBookModal" class="modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Edit Book</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<form id="editForm" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="exampleInputPassword1">ISBN</label>
|
||||
<input class="form-control" name="isbn" id="isbn">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="exampleInputPassword1">Title</label>
|
||||
<input class="form-control" name="title" id="title">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="exampleInputPassword1">Author</label>
|
||||
<input class="form-control" name="author" id="author">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="exampleInputPassword1">Published Date</label>
|
||||
<input type="date" class="form-control" name="publish_date" id="publish_date">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="exampleInputPassword1">Publisher</label>
|
||||
<input class="form-control" name="publisher" id="publisher">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="exampleInputPassword1">Number Of Pages</label>
|
||||
<input type="number" class="form-control" name="numOfPages" id="numOfPages">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
|
||||
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
|
||||
|
||||
<script type="text/javascript" src="book-list.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
70
client/book-list.js
Normal file
70
client/book-list.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
const setEditModal = (isbn) => {
|
||||
const xhttp = new XMLHttpRequest();
|
||||
|
||||
xhttp.open("GET", `http://localhost:3000/book/${isbn}`, false);
|
||||
xhttp.send();
|
||||
|
||||
const book = JSON.parse(xhttp.responseText);
|
||||
|
||||
const {
|
||||
title,
|
||||
author,
|
||||
publisher,
|
||||
publish_date,
|
||||
numOfPages
|
||||
} = book;
|
||||
|
||||
document.getElementById('isbn').value = isbn;
|
||||
document.getElementById('title').value = title;
|
||||
document.getElementById('author').value = author;
|
||||
document.getElementById('publisher').value = publisher;
|
||||
document.getElementById('publish_date').value = publish_date;
|
||||
document.getElementById('numOfPages').value = numOfPages;
|
||||
|
||||
// setting up the action url for the book
|
||||
document.getElementById('editForm').action = `http://localhost:3000/book/${isbn}`;
|
||||
}
|
||||
|
||||
const deleteBook = (isbn) => {
|
||||
const xhttp = new XMLHttpRequest();
|
||||
|
||||
xhttp.open("DELETE", `http://localhost:3000/book/${isbn}`, false);
|
||||
xhttp.send();
|
||||
|
||||
location.reload();
|
||||
}
|
||||
|
||||
const loadBooks = () => {
|
||||
const xhttp = new XMLHttpRequest();
|
||||
|
||||
xhttp.open("GET", "http://localhost:3000/books", false);
|
||||
xhttp.send();
|
||||
|
||||
const books = JSON.parse(xhttp.responseText);
|
||||
|
||||
for (let book of books) {
|
||||
const x = `
|
||||
<div class="col-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${book.title}</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">${book.isbn}</h6>
|
||||
<div>Author: ${book.author}</div>
|
||||
<div>Publisher: ${book.publisher}</div>
|
||||
<div>Number Of Pages: ${book.numOfPages}</div>
|
||||
<hr>
|
||||
<button type="button" class="btn btn-danger">Delete</button>
|
||||
<button types="button" class="btn btn-primary" data-toggle="modal"
|
||||
data-target="#editBookModal" onClick="setEditModal(${book.isbn})">
|
||||
Edit
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
||||
document.getElementById('books').innerHTML += x;
|
||||
}
|
||||
}
|
||||
|
||||
loadBooks();
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue