-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
65 lines (58 loc) · 2.16 KB
/
main.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
65
import TripPresenter from './presenter/trip-presenter';
import PointModel from './model/point-model';
import DestinationModel from './model/destinations-model';
import OfferModel from './model/offers-model';
import FilterModel from './model/filter-model';
import FilterPresenter from './presenter/filter-presenter';
import NewPointButtonView from './view/new-point-button-view';
import {render} from './framework/render';
import PointsApiService from './api-service/points-api';
import DestinationsApiService from './api-service/destinations-api';
import OffersApiService from './api-service/offers-api';
const AUTHORIZATION = 'Basic hs0NCvhAEPs';
const END_POINT = 'https://21.objects.htmlacademy.pro/big-trip';
const tripContainer = document.querySelector('.trip-events');
const headerContainer = document.querySelector('.trip-main');
const pointsModel = new PointModel({
pointsApiService: new PointsApiService(END_POINT, AUTHORIZATION)
});
const destinationsModel = new DestinationModel({
destinationsApiService: new DestinationsApiService(END_POINT, AUTHORIZATION)
});
const offersModel = new OfferModel({
offersApiService: new OffersApiService(END_POINT, AUTHORIZATION)
});
const filtersModel = new FilterModel();
const tripPresenter = new TripPresenter({
container: tripContainer,
pointsModel: pointsModel,
destinationsModel: destinationsModel,
offersModel: offersModel,
filtersModel: filtersModel,
onNewPointDestroy: newPointCloseHandler
});
const filterPresenter = new FilterPresenter({
filterContainer: headerContainer.querySelector('.trip-controls__filters'),
filterModel: filtersModel,
pointsModel
});
const newPointButtonComponent = new NewPointButtonView({
onClick: NewPointButtonClickHandler
});
function newPointCloseHandler() {
newPointButtonComponent.enableButton();
}
function NewPointButtonClickHandler() {
tripPresenter.createPoint();
newPointButtonComponent.disableButton();
}
render(newPointButtonComponent, headerContainer);
filterPresenter.init();
tripPresenter.init();
offersModel.init().finally(() => {
destinationsModel.init().finally(() => {
pointsModel.init().then(() => {
newPointButtonComponent.enableButton();
});
});
});