Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 53 additions & 55 deletions debugging/book-library/index.html
Original file line number Diff line number Diff line change
@@ -1,73 +1,68 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<title> </title>
<meta
charset="utf-8"
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<title>Book Library</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
/>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" href="style.css" />
</head>

<body>
<div class="jumbotron text-center">
<div class="header">
<h1>Library</h1>
<p>Add books to your virtual library</p>
<button
id="add-btn"
data-toggle="collapse"
data-target="#demo"
class="btn"
>
Add new book
</button>
</div>

<button data-toggle="collapse" data-target="#demo" class="btn btn-info">
Add new book
</button>

<div id="demo" class="collapse">
<div class="form-group">
<label for="title">Title:</label>
<input
type="title"
class="form-control"
id="title"
name="title"
required
/>
<label for="author">Author: </label>
<input
type="author"
class="form-control"
id="author"
name="author"
required
/>
<label for="pages">Pages:</label>
<input
type="number"
class="form-control"
id="pages"
name="pages"
required
/>
<label class="form-check-label">
<form id="book-form">
<div class="form-group">
<label for="title">Title:</label>
<input
type="checkbox"
class="form-check-input"
id="check"
value=""
/>Read
</label>
<input
type="submit"
value="Submit"
class="btn btn-primary"
onclick="submit();"
/>
</div>
type="text"
class="form-control"
id="title"
name="title"
required
/>
<label for="author">Author: </label>
<input
type="text"
class="form-control"
id="author"
name="author"
required
/>
<label for="pages">Pages:</label>
<input
type="number"
class="form-control"
id="pages"
name="pages"
required
/>
<label for="check" class="form-check-label">
<input
type="checkbox"
class="form-check-input"
id="check"
value=""
/>Read
</label>
<button id="submit-btn" class="btn" type="submit">submit</button>
</div>
</form>
</div>

<table class="table" id="display">
Expand All @@ -92,5 +87,8 @@ <h1>Library</h1>
</table>

<script src="script.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</body>
</html>
22 changes: 15 additions & 7 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ function populateStorage() {
);
myLibrary.push(book1);
myLibrary.push(book2);
render();
}
}

const addBtn = document.getElementById("add-btn");
const title = document.getElementById("title");
const author = document.getElementById("author");
const pages = document.getElementById("pages");
const check = document.getElementById("check");
const bookForm = document.getElementById("book-form");

//
bookForm.addEventListener("submit", function (e) {
e.preventDefault(); // stop page reload
submit(); // call your function
});
//check the right input from forms and if its ok -> add the new book (object in array)
//via Book function and start render function
function submit() {
Expand All @@ -37,9 +43,11 @@ function submit() {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
let book3 = new Book(title.value, author.value, pages.value, check.checked);
myLibrary.push(book3);
render();
bookForm.reset();
document.getElementById("demo").classList.remove("show");
}
}

Expand All @@ -54,7 +62,7 @@ function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
for (let n = rowsNumber - 1; n > 0; n--) {
table.deleteRow(n);
}
//insert updated row and cells
Expand All @@ -76,7 +84,7 @@ function render() {
changeBut.className = "btn btn-success";
wasReadCell.appendChild(changeBut);
let readStatus = "";
if (myLibrary[i].check == false) {
if (myLibrary[i].check === true) {
readStatus = "Yes";
} else {
readStatus = "No";
Expand All @@ -89,12 +97,12 @@ function render() {
});

//add delete button to every row and render again
let delButton = document.createElement("button");
let delBut = document.createElement("button");
delBut.id = i + 5;
deleteCell.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
delBut.addEventListener("click", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
Expand Down
48 changes: 41 additions & 7 deletions debugging/book-library/style.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
html {
scroll-behavior: smooth;
}

.header {
background: #2f2e57;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.header h1 {
color: white;
font-size: 50px;
padding: 20px;
}
.header p {
color: white;
font-size: 30px;
padding: 20px;
}

.form-group {
background-color: #2f2e57;
color: whitesmoke;
width: 400px;
height: 300px;
height: 350px;
align-self: left;
padding-left: 20px;
padding: 20px;
margin: 20px auto;
border-radius: 10px;
gap: 10px;
}

.btn {
display: block;
background-color: skyblue;
display: flex;
margin: 20px auto;
padding: 10px;
border-radius: 10px;
font-size: 20px;
border: none;
outline: none;
}
.btn:focus {
outline: none;
box-shadow: none;
}

.form-check-label {
padding-left: 20px;
margin: 5px 0px 5px 0px;
}

button.btn-info {
margin: 20px;
}
Loading