-
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 #8 from InsomniaRolodex/module5-task2
- Loading branch information
Showing
8 changed files
with
123 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const SortingType = { | ||
DAY: 'day', | ||
EVENT: 'event', | ||
TIME: 'time', | ||
PRICE: 'price', | ||
OFFERS: 'offers'}; | ||
|
||
export {SortingType}; |
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
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,22 +1,35 @@ | ||
import { SortingType } from '../const.js'; | ||
import AbstractView from '../framework/view/abstract-view.js'; | ||
|
||
const sortingTypes = ['Day', 'Event', 'Time', 'Price', 'Offers']; | ||
|
||
const findCheckedElement = (element) => element === 'Price' ? 'checked' : ''; | ||
import { capitalize } from '../util.js'; | ||
|
||
const createSortingElement = (sortingType) => ` | ||
<div class="trip-sort__item trip-sort__item--${sortingType}"> | ||
<input id="sort-day" class="trip-sort__input visually-hidden" type="radio" name="trip-sort" value="sort-${sortingType}" ${findCheckedElement(sortingType)}> | ||
<label class="trip-sort__btn" for="sort-day">${sortingType}</label> | ||
<input id="sort-${sortingType}" class="trip-sort__input visually-hidden" type="radio" name="trip-sort" value="sort-${sortingType}" | ||
data-sort-type="${sortingType}" | ||
${sortingType === 'event' ? 'disabled' : ''} | ||
${sortingType === 'offers' ? 'disabled' : ''}> | ||
<label class="trip-sort__btn" for="sort-${sortingType}">${capitalize(sortingType)}</label> | ||
</div>`; | ||
|
||
const createSortingTemplate = () => ` | ||
<form class="trip-events__trip-sort trip-sort" action="#" method="get"> | ||
${sortingTypes.map((sortingType) => createSortingElement(sortingType)).join('')} | ||
${Object.values(SortingType).map((sortingType) => createSortingElement(sortingType)).join('')} | ||
</form>`; | ||
|
||
export default class SortingView extends AbstractView{ | ||
#handleSortTypeChange; | ||
|
||
constructor ({onSortTypeChange}) { | ||
super(); | ||
this.#handleSortTypeChange = onSortTypeChange; | ||
this.element.addEventListener('change', this.#sortTypeChangeHandler); | ||
} | ||
|
||
get template () { | ||
return createSortingTemplate(); | ||
} | ||
|
||
#sortTypeChangeHandler = (evt) => { | ||
this.#handleSortTypeChange(evt.target.dataset.sortType); | ||
}; | ||
} |
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