-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.js
64 lines (51 loc) · 1.7 KB
/
project.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const form = document.getElementById("film-form");
const titleElement = document.querySelector("#title");
const directorElement = document.querySelector("#director");
const urlElement = document.querySelector("#url");
const cardBody = document.querySelectorAll(".card-body")[1];
const clear = document.getElementById("clear-films");
// Tum Eventleri Yukleme
eventListeners();
function eventListeners() {
form.addEventListener("submit", addFilm);
document.addEventListener("DOMContentLoaded", function () {
let films = Storage.getFilmsFromStorage();
UI.loadAllFilms(films);
});
cardBody.addEventListener("click", deleteFilm);
clear.addEventListener("click", clearAllFilms);
}
function addFilm(e) {
const title = titleElement.value;
const director = directorElement.value;
const url = urlElement.value;
if (title === "" || director === "" || url === "") {
// Hata
UI.displayMessages("Tum Alanlari Doldurun", "danger");
} else {
// Yeni Film
const newFilm = new Film(title, director, url);
// Arayuze Film Ekleme
UI.addFilmToUI(newFilm);
// Storage film Ekleme
Storage.addFilmToStorage(newFilm);
UI.displayMessages("Film basariyla eklendi..", "success");
}
UI.clearInputs(titleElement, directorElement, urlElement);
e.preventDefault();
}
function deleteFilm(e) {
if (e.target.id === "delete-film") {
UI.deleteFilmFromUI(e.target);
Storage.deleteFilmFromStorage(
e.target.closest("tr").querySelector("td:nth-child(2)").textContent
);
UI.displayMessages("Silme islemi basarili...", "success");
}
}
function clearAllFilms(e) {
if (confirm("Eminmisiniz ?")) {
UI.clearAllFilmsFromUI();
Storage.clearAllFilmsFromStorage();
}
}