-
Notifications
You must be signed in to change notification settings - Fork 0
/
restaurant.js
51 lines (40 loc) · 1.57 KB
/
restaurant.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
const restaurantApi = new RestaurantApi('http://localhost:3000/restaurants');
class Restaurant {
constructor({id, name, nationality, rating, city_id}){
this.id = id;
this.name = name;
this.nationality = nationality;
this.rating = rating;
this.cityId = city_id;
};
getRestaurant(){
const restaurantLi = document.createElement('li');
const deleteRes = document.createElement('button');
restaurantLi.innerText = this.name;
restaurantLi.classList.add('restaurant-data', 'restaurant-addition');
const restdata = document.createElement('div');
restdata.className = "hidden-restaurant-data";
restdata.classList.add('hidden');
restdata.innerText = `Rating: ${this.rating}
Nationality: ${this.nationality}`;
restaurantLi.appendChild(restdata);
restaurantLi.addEventListener('click', () => {
if (restdata.classList.contains('hidden')){
console.log("connected click")
restdata.classList.remove('hidden')
} else {
restdata.classList.add('hidden');
console.log("HIDDEN");
}
return restaurantLi;
});
deleteRes.classList.add('delete-btn');
deleteRes.innerText = 'x';
deleteRes.addEventListener('click', () => {
restaurantApi.deleteRestaurant(this.id);
restaurantLi.remove();
});
restaurantLi.appendChild(deleteRes);
return restaurantLi;
};
}