-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
078b88f
commit 456162e
Showing
12 changed files
with
318 additions
and
136 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import {mockDestinations, mockEvents, mockOffers} from '../mock/event'; | ||
|
||
export default class EventsModel { | ||
getEvents() { | ||
get events() { | ||
return [...mockEvents]; | ||
} | ||
|
||
getDestinations() { | ||
get destinations() { | ||
return [...mockDestinations]; | ||
} | ||
|
||
getOffers() { | ||
get offers() { | ||
return [...mockOffers]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,66 @@ | ||
import {render} from '../render'; | ||
import {render, replace} from '../framework/render'; | ||
import EventItem from '../view/event-item'; | ||
import EventList from '../view/event-list'; | ||
import Filters from '../view/filters'; | ||
import Sorting from '../view/sorting'; | ||
import EditForm from '../view/edit-form'; | ||
|
||
export default class Presenter { | ||
eventListComponent = new EventList(); | ||
eventsContainer = document.querySelector('.trip-events'); | ||
filterContainer = document.querySelector('.trip-controls__filters'); | ||
#eventListComponent = new EventList(); | ||
#eventsContainer = document.querySelector('.trip-events'); | ||
#filterContainer = document.querySelector('.trip-controls__filters'); | ||
#eventsModel = null; | ||
#events = null; | ||
#destinations = null; | ||
#offers = null; | ||
|
||
constructor({eventsModel}) { | ||
this.eventsModel = eventsModel; | ||
this.#eventsModel = eventsModel; | ||
} | ||
|
||
init() { | ||
this.events = this.eventsModel.getEvents(); | ||
this.destinations = this.eventsModel.getDestinations(); | ||
this.offers = this.eventsModel.getOffers(); | ||
this.#events = this.#eventsModel.events; | ||
this.#destinations = this.#eventsModel.destinations; | ||
this.#offers = this.#eventsModel.offers; | ||
|
||
render(new Filters(), this.filterContainer); | ||
render(new Sorting(), this.eventsContainer); | ||
render(this.eventListComponent, this.eventsContainer); | ||
render(new EditForm({event:this.events[0], destinations: this.destinations, offers: this.offers}), this.eventListComponent.getElement()); | ||
render(new Filters(), this.#filterContainer); | ||
render(new Sorting(), this.#eventsContainer); | ||
render(this.#eventListComponent, this.#eventsContainer); | ||
|
||
for (let i = 1; i < this.events.length; i++) { | ||
render(new EventItem({event:this.events[i], destinations: this.destinations, offers: this.offers}), this.eventListComponent.getElement()); | ||
for (let i = 0; i < this.#events.length; i++) { | ||
this.#renderEvent(this.#events[i]); | ||
} | ||
} | ||
|
||
#renderEvent(event) { | ||
const escKeyDownHandler = (evt) => { | ||
if (evt.key === 'Escape') { | ||
evt.preventDefault(); | ||
replaceFromEditToItem(); | ||
document.removeEventListener('keydown', escKeyDownHandler); | ||
} | ||
}; | ||
|
||
const editForm = new EditForm({event, destinations: this.#destinations, offers: this.#offers, submitHandler: () => { | ||
replaceFromEditToItem(); | ||
document.removeEventListener('keydown', escKeyDownHandler); | ||
}, clickHandler: () => { | ||
replaceFromEditToItem(); | ||
document.removeEventListener('keydown', escKeyDownHandler); | ||
}}); | ||
const eventItem = new EventItem({event, destinations: this.#destinations, offers: this.#offers, clickHandler: () => { | ||
replaceFromItemToEdit(); | ||
document.addEventListener('keydown', escKeyDownHandler); | ||
}}); | ||
|
||
function replaceFromEditToItem() { | ||
replace(eventItem, editForm); | ||
} | ||
|
||
function replaceFromItemToEdit() { | ||
replace(editForm,eventItem); | ||
} | ||
|
||
render(eventItem, this.#eventListComponent.element); | ||
} | ||
} |
Oops, something went wrong.