-
Notifications
You must be signed in to change notification settings - Fork 1
/
stitch-order-form.html
385 lines (330 loc) · 9.36 KB
/
stitch-order-form.html
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-form/iron-form.html">
<link rel="import" href="../paper-styles/shadow.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../iron-image/iron-image.html">
<link rel="import" href="../paper-spinner/paper-spinner.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../vaadin-combo-box/vaadin-combo-box.html">
<link rel="import" href="font-styles.html">
<link rel="import" href="stitch-order-icons.html">
<dom-module id="stitch-order-form">
<template>
<style include="font-styles">
:host {
display: block;
color: var(--primary-text-color);
background-color: var(--primary-background-color);
margin: 10px;
padding: 22px 25px;
}
.section {
margin-top: 50px;
}
.horizontal {
@apply(--layout-horizontal);
}
[spacer] {
@apply(--layout-flex);
}
.spinner {
margin: 15px auto;
@apply(--layout-horizontal);
@apply(--layout-center-center);
}
#error {
@apply(--layout-horizontal);
@apply(--layout-center-center);
color: var(--primary-error-color, --paper-red-a200);
}
#error[hidden] {
display: none;
}
#error iron-icon {
display: inline-block;
color: var(--primary-error-color, --paper-red-a700);
}
form {
height: 0;
overflow: hidden;
-webkit-transition: height 300ms;
-moz-transition: height 300ms;
-ms-transition: height 300ms;
-o-transition: height 300ms;
transition: height 300ms;
}
form.expanded {
height: auto;
}
form paper-input {
margin: 0 10px;
}
@media (min-width: 768px) {
form paper-input {
margin: 0 25px;
width: 60%;
}
form .horizontal paper-input {
width: 15%;
}
}
#content {
margin: 15px auto;
}
.left iron-image {
display: block;
width: 160px;
height: 160px;
@apply(--shadow-elevation-2dp);
}
.left #primeLogo {
float: right;
margin-top: 7px;
height: 14px;
width: 47px;
background-image: url('https://images-na.ssl-images-amazon.com/images/G/01/da/creatives/prime-2015-04.png');
background-repeat: no-repeat;
color: transparent;
}
#content .right {
padding-left: 10px;
@apply(--layout-flex);
}
#options {
@apply(--layout-vertical);
@apply(--layout-start);
}
iron-icon[prefix] {
color: var(--secondary-text-color);
margin-right: 10px;
}
#invoiceResume :not(h3) {
margin: 0 25px;
}
#buttons {
margin: 50px 0 20px;
@apply(--layout-horizontal-reverse);
}
paper-button:not([disabled]):hover {
font-weight: bold;
}
#submitButton:not([disabled]) {
color: var(--text-primary-color);
background-color: var(--primary-color);
}
#cancelButton:not([disabled]) {
color: var(--accent-color);
}
</style>
<header>
<h1>Order Product</h1>
<paper-input label="[[label]]" placeholder="[[placeholder]]"
value="{{productUrl}}" type="url" required
error-message="Invalid URL" autofocus>
<iron-icon icon="stitch-order:shopping-cart" prefix></iron-icon>
</paper-input>
</header>
<div class="spinner">
<paper-spinner id="formSpinner" alt="Loading product details"></paper-spinner>
</div>
<div id="error" hidden$="[[!fail]]">
<iron-icon icon="stitch-order:error"></iron-icon>
[[failMessage]]
</div>
<form is="iron-form" id="form" method="get" content-type="application/json">
<div id="content" class="horizontal">
<div class="left">
<iron-image sizing="contain" src="[[productDetails.image]]" preload fade></iron-image>
<div id="primeLogo" hidden$="[[!productDetails.prime]]" alt="the Prime Logo">Prime</div>
</div>
<div class="right">
<h2>[[productDetails.title]]</h2>
<h4>Select Options</h4>
<div id="options">
<template is="dom-repeat" items="[[productDetails.options]]" as="option">
<vaadin-combo-box required label="[[option.name]] *"
items="[[option.values]]"
selected-item="{{option.selected}}">
</vaadin-combo-box>
</template>
<div class="spinner">
<paper-spinner id="optionsSpinner" alt="Loading product options"></paper-spinner>
</div>
</div>
</div>
</div>
<div id="shipping" class="section">
<h3>Shipping information</h3>
<paper-input value="{{address.line1}}" required label="Address Line 1 *"></paper-input>
<paper-input value="{{address.line2}}" label="Address Line 2"></paper-input>
<div class="horizontal">
<paper-input value="{{address.city}}" required label="City *"></paper-input>
<paper-input value="{{address.state}}" required label="State *"></paper-input>
<paper-input value="{{address.zip}}" required label="ZIP *" type="number"></paper-input>
</div>
<paper-input value="{{address.email}}" required label="E-Mail *" type="email">
<iron-icon icon="stitch-order:mail" prefix></iron-icon>
</paper-input>
<paper-input value="{{address.phone}}" required label="Phone Number *" type="tel">
<iron-icon icon="stitch-order:phone" prefix></iron-icon>
</paper-input>
</div>
<div id="invoiceResume" class="section">
<h3>Total Cost</h3>
<div>[[productDetails.cost]] + shipping</div>
<p>(Note: shipping is calculated when purchase is made)</p>
</div>
<div id="buttons" class="section">
<paper-button id="submitButton" raised on-tap="_submit">Set up Order</paper-button>
<div spacer></div>
<paper-button id="cancelButton" on-tap="_reset">Cancel</paper-button>
</div>
</form>
</template>
<script>
(function(){
'use strict';
Polymer({
is: 'stitch-order-form',
/**
* Fired when the user submit a valid form.
*
* Note that this event will be fired only if the form is filled (at least the required fields).
*
* All the form information is included as the event.detail object.
*
* @event order-submit
* @event iron-form-submit
*/
/**
* Fired when the user submit a the form but it's invalid.
*
* Note that this event will be fired only when at least one required field of the form is not filled.
*
* @event iron-form-invalid
*/
/**
* Fired when the form is reset
*
* @event iron-form-reset
*/
properties: {
/**
* Label to be set on the URL input.
*/
label: {
type: String,
value: 'Paste the URL of the Amazon page here'
},
/**
* Placeholder for the URL input.
*/
placeholder: {
type: String,
value: 'https://www.amazon.com/...'
},
/**
* The product details and options requests from amazon are on the fly.
*/
loading: Boolean,
/**
* The product details where retrieved from amazon.
*/
loaded: Boolean,
/**
* The product could not be retrieved through the amazon API or another error gets captured.
*/
fail: {
type: Boolean,
readOnly: true,
value: false
},
/**
* The message displayed as the corresponding error.
*/
failMessage: {
type: Boolean,
readOnly: true,
value: false
},
/**
* This value is bind with the UI paper-input.
*
* Note that the main functionality is to pass the value to the stitch-order-request
* and the the `productDetails` value as a result.
*/
productUrl: {
type: String,
value: '',
notify: true
},
/**
* This value contains the result of the amazon API parsed to fit the UI and
* should be provided directly by the stitch-order-request element.
*
* Note that this value doesn't reflect changes and if you need to know the status
* of the order you should listen instead the `order-submit` or `iron-form-submit` event.
*/
productDetails: Object
},
observers: [
'_loadingContent(loading, loaded)'
],
listeners: {
'iron-form-presubmit': '_setAction'
},
attached: function(){
this.reset();
},
reset: function(address, URL){
this.$.form.reset();
this.productUrl = URL || '';
this.address = address || {};
this.loading = this.loaded = false;
this._setFail(false);
this._setFailMessage('');
},
error: function(details){
this.loading = false;
this._errorDetails = details;
this._setFail(true);
this._setFailMessage(details.Message[0]);
},
_loadingContent: function(loading, loaded){
this.$.form.classList.toggle('expanded', loaded);
this.$.formSpinner.set('active', loading && !loaded);
this.$.optionsSpinner.set('active', loading && loaded);
if (loading) {
Polymer.dom(this.root).querySelectorAll('.spinner').forEach(function(spinner){
spinner.style.display = '';
});
} else {
if (loaded) {
Polymer.dom(this.root).querySelectorAll('.spinner').forEach(function(spinner){
spinner.style.display = 'none';
});
}
}
},
_setAction: function(){
var params = this.$.form.request.params;
params.address = this.address;
params.product = this.productDetails;
params.options = this.productDetails.options;
this.fire('order-submit', params);
},
_submit: function(){
if (this._validate()) {
this.$.form.submit();
}
},
_reset: function(){
this.reset();
},
_validate: function(){
return true;
}
});
})();
</script>
</dom-module>