-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from MaxSiryatov/module4-task1
- Loading branch information
Showing
17 changed files
with
603 additions
and
164 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,29 +1,74 @@ | ||
import SortView from '../view/sort-view.js'; | ||
import EventsListView from '../view/event-list-view.js'; | ||
import CurrentFormView from '../view/point-edit-view.js'; | ||
import SortView from '../view/sort-view.js'; | ||
import PointView from '../view/point-view.js'; | ||
import { render } from '../render.js'; | ||
import OpenFormBtnView from '../view/open-form-button-view.js'; | ||
import { RenderPosition, render, replace } from '../framework/render.js'; | ||
import CloseFormBtnView from '../view/close-form-button-view.js'; | ||
import SaveFormBtnView from '../view/save-form-button-view.js'; | ||
|
||
export default class TripPresenter { | ||
sortFormView = new SortView(); | ||
eventsListView = new EventsListView(); | ||
#sortFormView = new SortView(); | ||
#pointsListView = new EventsListView(); | ||
#container = null; | ||
#pointModel = null; | ||
#formComponent = null; | ||
#tripPoint = []; | ||
|
||
constructor ({container, pointModel}) { | ||
this.container = container; | ||
this.pointModel = pointModel; | ||
this.#container = container; | ||
this.#pointModel = pointModel; | ||
} | ||
|
||
init() { | ||
this.tripPoint = [...this.pointModel.getPoints()]; | ||
this.currentPoint = this.pointModel.getPoint(); | ||
this.#tripPoint = [...this.#pointModel.getPoints()]; | ||
|
||
render(this.#sortFormView, this.#container); | ||
render(this.#pointsListView, this.#container); | ||
|
||
for (let i = 0; i < this.#tripPoint.length; i++) { | ||
this.#renderPoint(this.#tripPoint[i]); | ||
} | ||
} | ||
|
||
render(this.sortFormView, this.container); | ||
render(this.eventsListView, this.container); | ||
#renderPoint (point) { | ||
const escKeyDownBtnHandler = (evt) => { | ||
if (evt.key === 'Escape') { | ||
replacePointToForm(); | ||
document.removeEventListener('keydown', escKeyDownBtnHandler); | ||
} | ||
}; | ||
const pointComponent = new PointView({data: point}); | ||
const formComponent = new CurrentFormView({ | ||
data: point, | ||
onSubmit: () => { | ||
replacePointToForm(); | ||
document.removeEventListener('keydown', escKeyDownBtnHandler); | ||
}}); | ||
const deleteBtn = formComponent.element.querySelector('.event__reset-btn'); | ||
const openBtn = new OpenFormBtnView({ | ||
onClick: () => { | ||
replaceFormToPoint(); | ||
document.addEventListener('keydown', escKeyDownBtnHandler); | ||
}}); | ||
const closeBtn = new CloseFormBtnView({ | ||
onClick: () => { | ||
replacePointToForm(); | ||
document.removeEventListener('keydown', escKeyDownBtnHandler); | ||
}}); | ||
const saveBtn = new SaveFormBtnView(); | ||
|
||
render(new CurrentFormView({point: this.currentPoint}), this.eventsListView.getElement()); | ||
render(pointComponent, this.#pointsListView.element); | ||
render(openBtn, pointComponent.element, RenderPosition.BEFOREEND); | ||
render(saveBtn, deleteBtn, RenderPosition.BEFOREBEGIN); | ||
render(closeBtn, deleteBtn, RenderPosition.AFTEREND); | ||
|
||
function replacePointToForm() { | ||
replace(pointComponent, formComponent); | ||
} | ||
|
||
for (let i = 0; i < this.tripPoint.length; i++) { | ||
render(new PointView({data: this.tripPoint[i]}), this.eventsListView.getElement()); | ||
function replaceFormToPoint() { | ||
replace(formComponent, pointComponent); | ||
} | ||
} | ||
} | ||
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import AbstractView from '../framework/view/abstract-view'; | ||
|
||
function createCloseFormBtn() { | ||
return `<button class="event__rollup-btn" type="button"> | ||
<span class="visually-hidden">Open event</span> | ||
</button>`; | ||
} | ||
|
||
export default class CloseFormBtnView extends AbstractView{ | ||
#handleClick = null; | ||
|
||
constructor ({onClick}) { | ||
super(); | ||
this.#handleClick = onClick; | ||
this.element.addEventListener('click', this.#clickHandler); | ||
} | ||
|
||
get template() { | ||
return createCloseFormBtn(); | ||
} | ||
|
||
#clickHandler = (evt) => { | ||
evt.preventDefault(); | ||
this.#handleClick(); | ||
}; | ||
} |
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,19 +1,8 @@ | ||
import { createEventListTemplate } from '../templates/event-list-template.js'; | ||
import { createElement } from '../render.js'; | ||
import AbstractView from '../framework/view/abstract-view.js'; | ||
|
||
export default class EventsListView { | ||
getTemplate() { | ||
export default class EventListView extends AbstractView{ | ||
get template() { | ||
return createEventListTemplate(); | ||
} | ||
|
||
getElement() { | ||
if (!this.element) { | ||
this.element = createElement(this.getTemplate()); | ||
} | ||
return this.element; | ||
} | ||
|
||
removeElement() { | ||
this.element = null; | ||
} | ||
} |
Oops, something went wrong.