/
input.js
199 lines (172 loc) · 5.38 KB
/
input.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const {
Button, CheckBox, Composite, TextView, TextInput, Picker, RadioButton, ScrollView, Slider, Switch, contentView
} = require('tabris');
const scrollView = new ScrollView({left: 0, top: 0, right: 0, bottom: 0}).appendTo(contentView);
const COUNTRIES = ['Germany', 'Canada', 'USA', 'Bulgaria'];
const CLASSES = ['Business', 'Economy', 'Economy Plus'];
new TextView({
id: 'nameLabel',
alignment: 'left',
text: 'Name:'
}).appendTo(scrollView);
new TextInput({
id: 'nameInput',
message: 'Full Name'
}).appendTo(scrollView);
new TextView({
id: 'flyerNumberLabel',
text: 'Flyer Number:'
}).appendTo(scrollView);
new TextInput({
id: 'flyerNumberInput',
keyboard: 'number',
message: 'Flyer Number'
}).appendTo(scrollView);
new TextView({
id: 'passphraseLabel',
text: 'Passphrase:'
}).appendTo(scrollView);
new TextInput({
id: 'passphraseInput',
type: 'password',
message: 'Passphrase'
}).appendTo(scrollView);
new TextView({
id: 'countryLabel',
text: 'Country:'
}).appendTo(scrollView);
new Picker({
id: 'countryPicker',
itemCount: COUNTRIES.length,
itemText: index => COUNTRIES[index]
}).appendTo(scrollView);
new TextView({
id: 'classLabel',
text: 'Class:'
}).appendTo(scrollView);
new Picker({
id: 'classPicker',
itemCount: CLASSES.length,
itemText: index => CLASSES[index]
}).appendTo(scrollView);
new TextView({
id: 'seatLabel',
text: 'Seat:'
}).appendTo(scrollView);
new RadioButton({
id: 'windowSeat',
text: 'Window'
}).appendTo(scrollView);
new RadioButton({
id: 'aisleSeat',
text: 'Aisle'
}).appendTo(scrollView);
new RadioButton({
id: 'anySeat',
text: "Don't care",
checked: true
}).appendTo(scrollView);
new Composite({
id: 'luggagePanel'
}).append(
new TextView({
id: 'luggageLabel',
text: 'Luggage:'
})
).append(
new TextView({
id: 'luggageWeight',
text: '0 Kg'
})
).append(
new Slider({
id: 'luggageSlider'
}).on('selectionChanged', ({value}) => {
scrollView.find('#luggageWeight').set({text: value + ' Kg'});
})
).appendTo(scrollView);
new CheckBox({
id: 'veggieChoice',
text: 'Vegetarian'
}).appendTo(scrollView);
new Composite({
id: 'milesPanel'
}).append(
new TextView({
id: 'milesLabel',
text: 'Redeem miles:'
})
).append(
new Switch({
id: 'milesSwitch'
})
).appendTo(scrollView);
new Button({
id: 'reservationButton',
text: 'Place Reservation',
background: '#8b0000',
textColor: 'white'
}).on('select', () => {
updateMessage();
}).appendTo(scrollView);
const message = new TextView({
left: 10, right: 10, top: '#reservationButton 10'
}).appendTo(scrollView);
scrollView.apply({
'#nameLabel': {left: 10, top: 18, width: 120},
'#nameInput': {left: '#nameLabel 10', right: 10, baseline: '#nameLabel'},
'#flyerNumberLabel': {left: 10, top: '#nameLabel 18', width: 120},
'#flyerNumberInput': {left: '#flyerNumberLabel 10', right: 10, baseline: '#flyerNumberLabel'},
'#passphraseLabel': {left: 10, top: '#flyerNumberLabel 18', width: 120},
'#passphraseInput': {left: '#passphraseLabel 10', right: 10, baseline: '#passphraseLabel'},
'#countryLabel': {left: 10, top: '#passphraseLabel 18', width: 120},
'#countryPicker': {left: '#countryLabel 10', right: 10, baseline: '#countryLabel'},
'#seatLabel': {left: 10, top: '#classLabel 18', width: 120},
'#windowSeat': {left: '#seatLabel 10', right: 10, baseline: '#seatLabel'},
'#aisleSeat': {left: '#seatLabel 10', right: 10, top: '#seatLabel 10'},
'#classLabel': {left: 10, top: '#countryLabel 18', width: 120},
'#classPicker': {left: '#classLabel 10', right: 10, baseline: '#classLabel'},
'#anySeat': {left: '#seatLabel 10', right: 10, top: '#aisleSeat 10'},
'#luggagePanel': {left: 10, top: '#anySeat 18', right: 10},
'#luggageLabel': {left: 0, centerY: 0, width: 120},
'#luggageWeight': {right: 10, centerY: 0, width: 50},
'#luggageSlider': {left: '#luggageLabel 10', right: '#luggageWeight 10', centerY: 0},
'#veggieChoice': {left: '#seatLabel 10', right: 10, top: '#luggagePanel 10'},
'#milesPanel': {left: 10, top: '#veggieChoice 10', right: 10},
'#milesLabel': {left: 0, centerY: 0, width: 120},
'#milesSwitch': {left: '#milesLabel 10', centerY: 0},
'#reservationButton': {left: 10, right: 10, top: '#milesPanel 18'}
});
function updateMessage() {
message.text = [
'Flight booked for: ' + scrollView.children('#nameInput').first().text,
'Destination: ' + COUNTRIES[scrollView.children('#countryPicker').first().selectionIndex],
'Seating: ' + createSeating(),
'Luggage: ' + createWeight(),
'Meal: ' + createMeal(),
'Redeem miles: ' + createFrequentFlyerInfo()
].join('\n') + '\n';
}
function createSeating() {
let seating = 'Anywhere';
scrollView.children('RadioButton').forEach((button) => {
if (button.checked) {
seating = button.text;
}
});
seating += ', ' + CLASSES[scrollView.children('#classPicker').first().selectionIndex];
return seating;
}
function createWeight() {
const panel = scrollView.children('#luggagePanel');
return panel.children('#luggageSlider').first().selection + ' kg';
}
function createMeal() {
return scrollView.children('#veggieChoice').first().checked ? 'Vegetarian' : 'Standard';
}
function createFrequentFlyerInfo() {
const panel = scrollView.children('#milesPanel');
let info = panel.children('#milesSwitch').first().checked ? 'Yes' : 'No';
info += ', acct: ' + scrollView.children('#flyerNumberInput').first().text;
return info;
}