From cc7cf25b5044fe7ef0f9f36c06042cbf7333cf22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=91=D0=BE?= =?UTF-8?q?=D1=80=D0=BE=D0=B4=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Mon, 30 Sep 2024 15:04:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B8=D0=BA=D0=B8=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8?= =?UTF-8?q?=D0=B9=20=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B8=D0=BD=D1=82=D0=B5,?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BA=D1=80=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/presenter/board-presenter.js | 61 ++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/src/presenter/board-presenter.js b/src/presenter/board-presenter.js index e88b7e0..e742871 100644 --- a/src/presenter/board-presenter.js +++ b/src/presenter/board-presenter.js @@ -1,7 +1,7 @@ import TripInfoView from '../view/trip-info-view.js'; //Инфо в шапке про маршрут import PointView from '../view/trip-point-view.js'; //Точка маршрута import OffersView from '../view/trip-edit-point-view.js';//Форма редактирования -import {render} from '../framework/render.js'; +import { render, replace } from '../framework/render.js'; const siteMainElement = document.querySelector('.page-body'); const siteTripInfo = siteMainElement.querySelector('.trip-info'); // Инфо в шапке про маршрут export default class BoardPresenter { @@ -18,22 +18,55 @@ export default class BoardPresenter { this.boardPoints = [...this.#pointsModel.points]; this.boardOffers = [...this.#pointsModel.offers]; - const offersView = new OffersView({ - point: this.boardPoints[0], - allOffers: this.#pointsModel.getOffersByType(this.boardPoints[0].type), - pointDestination: this.#pointsModel.getDestinationsById(this.boardPoints[0].destination), - allDestination: this.#pointsModel.destinations + for (let i = 0; i < this.boardPoints.length; i++) { + this.#renderPoints(this.boardPoints[i]); + } + } + + #renderPoints(point) { //Отображение точки маршрута с обработчиками, форма редактирования внутри!!! + const escKeyDownHandler = (evt) => { + if(evt.key === 'Escape') { + evt.preventDefault(); + replaceFormToPoint(); + document.removeEventListener('keydown', escKeyDownHandler); + } + }; + const onOpenEditButtonClick = () => { + replacePointToForm(); + document.addEventListener('keydown', escKeyDownHandler); + }; + const onCloseEditButtonClick = () => { + replaceFormToPoint(); + document.removeEventListener('keydown', escKeyDownHandler); + }; + const onSubmitButtonClick = () => { + replaceFormToPoint(); + document.removeEventListener('keydown', escKeyDownHandler); + }; + const pointComponent = new PointView({ //Точка маршрута + point, + offers: [...this.#pointsModel.getOffersById(point.type, point.offers)], + destination: this.#pointsModel.getDestinationsById(this.boardPoints[0].destination), + onOpenEditButtonClick }); - render(offersView, this.#container); //Отображение формы редактирования - for (let i = 0; i < this.boardPoints.length; i++) { - const point = new PointView({ - point: this.boardPoints[i], - offers: [...this.#pointsModel.getOffersById(this.boardPoints[i].type, this.boardPoints[i].offers)], - destination: this.#pointsModel.getDestinationsById(this.boardPoints[i].destination) - }); - render(point, this.#container); //Отображение поинтов + const editPointComponent = new OffersView({ //Форма редактирования + point, + allOffers: this.#pointsModel.getOffersByType(point.type), + pointDestination: this.#pointsModel.getDestinationsById(point.destination), + allDestination: this.#pointsModel.destinations, + onCloseEditButtonClick, + onSubmitButtonClick + }); + + function replacePointToForm() { + replace(editPointComponent, pointComponent); + } + + function replaceFormToPoint() { + replace(pointComponent, editPointComponent); } + render(pointComponent, this.#container); } }