-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
29 lines (26 loc) · 1.05 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Event: Raamatute ekraanile lisamine
document.addEventListener('DOMContentLoaded', UI.displayBooks)
//Event: Raamatu lisamine listi
document.querySelector('#book-form').addEventListener('submit', (e) => {
e.preventDefault()
const title = document.querySelector('#title').value
const author = document.querySelector('#author').value
const isbn = document.querySelector('#isbn').value
// Kontrollime, et väljad on täidetud
let book;
if (title === '' || author === '' || isbn === '') {
UI.alertUser('Täida kõik väljad ära', 'danger')
} else {
book = new Book(title, author, isbn)
UI.addBookToList(book)
Storage.addBook(book)
UI.alertUser('Raamat on edukalt lisatud', 'success')
UI.clearFields()
}
})
//Event: Raamtu kustutamine listist
document.querySelector('#book-list').addEventListener('click', (e) => {
UI.deleteBookFromList(e.target)
Storage.deleteBook(e.target.parentElement.previousElementSibling.textContent)
UI.alertUser('Raamat on edukalt lisatud', 'success')
})