-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponents.js
71 lines (66 loc) · 1.96 KB
/
components.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Module of View Components
*/
const Components = (function () {
return {
getDealHtml(deal) {
return `
<div class="result">
<div>
<span class="city-from">${deal.arrival}</span><br/><span class="city-to">${deal.departure}</span>
</div>
<div class="description">
${deal.transport} <b>${deal.reference}</b> for <b>${deal.duration.h}h:${deal.duration.m}m</b>
</div>
<span class="price">${deal.fullPrice} €</span>
</div>
`;
},
getResultsHtml(deals) {
const results = deals.length
? deals.map(deal => this.getDealHtml(deal)).join('')
: this.getErrorHtml('There are no tickets in this direction');
return `
<div class="results">
${results}
<div class="button">
<button class="button-reset">Reset</button>
</div>
`;
},
getSelectHtml(options, className) {
const optionsHtml = options.map(
option => `<option value="${option}">${option}</option>`
).join('');
return `<select class="${className}">${optionsHtml}</select>`;
},
getSearchHtml(arrivalCitiesList, departureCitiesList) {
const departureSelect = this.getSelectHtml(departureCitiesList, 'departure');
const arrivalSelect = this.getSelectHtml(arrivalCitiesList, 'arrival');
return `
<div class="select">
From:
${arrivalSelect}
</div>
<div class="select">
To:
${departureSelect}
</div>
<div class="switcher">
<div class="switcher__item" data-rule="cheapest">
Cheapest
</div>
<div class="switcher__item" data-rule="fastest">
Fastest
</div>
</div>
<div class="button">
<button class="button-search">Search</button>
</div>
`;
},
getErrorHtml(text) {
return `<div class="error">${text}</div>`;
}
};
})();