-
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 #7 from artyomp1506/module6-task1
- Loading branch information
Showing
8 changed files
with
95 additions
and
36 deletions.
There are no files selected for viewing
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,13 +1,16 @@ | ||
import { getRandomNumber, getRandomValue } from '../utils.js'; | ||
import { CITIES, DESCRIPTIONS } from './consts.js'; | ||
export function generateDestination() | ||
import { CITIES, DESCRIPTIONS, DESTINATIONS_COUNT, CITIES_COUNT } from './consts.js'; | ||
export function generateDestinations() | ||
{ | ||
return { | ||
let destinations = [] | ||
for (let i=0; i<DESTINATIONS_COUNT; i++) | ||
destinations.push({ | ||
id: crypto.randomUUID(), | ||
name: getRandomValue(CITIES), | ||
name: CITIES[i%CITIES_COUNT], | ||
description: getRandomValue(DESCRIPTIONS), | ||
pictures: Array.from({length: getRandomNumber(1, 5)}, () => ({ | ||
src: `https://loremflickr.com/248/152?random=${crypto.randomUUID()}`, | ||
description: getRandomValue(DESCRIPTIONS)})) | ||
} | ||
}) | ||
return destinations | ||
} |
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
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,26 +1,69 @@ | ||
import { createElement } from "../render" | ||
import {createEditTemplate} from "../templates/edit-template.js" | ||
import AbstractView from '../framework/view/abstract-view.js' | ||
export default class EditPointView extends AbstractView { | ||
#onFormSubitHandler = null | ||
import AbstractStatefullView from "../framework/view/abstract-stateful-view.js" | ||
import { DestinationModel } from "../model/destination_model.js" | ||
import { CITIES } from "../mocks/consts.js" | ||
export default class EditPointView extends AbstractStatefullView { | ||
#onFormSubmitHandler = null | ||
#onFormCloseHandler = null | ||
#point = null | ||
#destination = null | ||
#offers =null | ||
constructor(point, destination, offers, onFormSubmit) { | ||
#destinations = null | ||
#offers = null | ||
constructor(point, destination, destinations, offers, onFormSubmit, onFormClose) { | ||
super() | ||
this.#point = point | ||
this._setState(EditPointView.parsePointToState({point})) | ||
this.#destination = destination | ||
this.#destinations = destinations | ||
this.#offers = offers | ||
this.#onFormSubitHandler = onFormSubmit | ||
this.element.querySelector('.event__rollup-btn').addEventListener('click', this.#clickSubmitHandle) | ||
this.element.querySelector('form').addEventListener('submit', this.#clickSubmitHandle) | ||
this.#onFormSubmitHandler = onFormSubmit | ||
this.#onFormCloseHandler = onFormClose | ||
this._restoreHandlers() | ||
|
||
} | ||
|
||
get template() { | ||
return createEditTemplate(this.#point, this.#destination, this.#offers) | ||
console.log(this._state) | ||
return createEditTemplate(this._state.point, this.#destinations.find(destination=>destination.id==this._state.point.destinationId), this.#offers) | ||
} | ||
_restoreHandlers() { | ||
this.element.querySelector('.event__rollup-btn').addEventListener('click', this.#clickCloseHandle) | ||
this.element.querySelector('form').addEventListener('submit', this.#clickSubmitHandle) | ||
this.element.querySelector('.event__type-group').addEventListener('change', this.#changeEventTypeHandler) | ||
this.element.querySelector('.event__input--destination').addEventListener('change', this.#changeDestinationHandler) | ||
this.element.querySelector('.event__input--price').addEventListener('change', this.#changePriceHandler) | ||
} | ||
#changeEventTypeHandler = (evt) => { | ||
console.log(this._state) | ||
this.updateElement({point: {...this._state.point, | ||
type: evt.target.value, | ||
offers: [] | ||
}}) | ||
} | ||
#clickSubmitHandle = (evt) => | ||
{ | ||
evt.preventDefault() | ||
this.#onFormSubitHandler(this.#point) | ||
this.#onFormSubmitHandler(this._state.point) | ||
} | ||
#clickCloseHandle = (evt) => | ||
{ | ||
evt.preventDefault() | ||
this.#onFormCloseHandler() | ||
} | ||
#changeDestinationHandler = (evt) => | ||
{ | ||
evt.preventDefault() | ||
console.log(this.#destinations) | ||
let destination = this.#destinations.find((distination)=> distination.name == evt.target.value).id | ||
|
||
this.updateElement({point: {...this._state.point, destinationId: destination} }) | ||
} | ||
#changePriceHandler = (evt) => | ||
{ | ||
evt.preventDefault() | ||
this._state.basePrice = evt.target.value | ||
this.updateElement({point:{...this._state.point, basePrice: this._state.basePrice}} ) | ||
|
||
} | ||
static parsePointToState = (point) => (point) | ||
} |