-
Notifications
You must be signed in to change notification settings - Fork 1
/
stitch-order-element.html
142 lines (128 loc) · 4 KB
/
stitch-order-element.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="stitch-order-request.html">
<link rel="import" href="stitch-order-form.html">
<!--
`stitch-order-element`
Configures an order from Amazon
@demo demo/index.html
-->
<dom-module id="stitch-order-element">
<template>
<style>
:host {
display: block;
}
</style>
<stitch-order-request id="request"
product-url="[[productUrl]]"
product-details="{{details}}">
</stitch-order-request>
<stitch-order-form id="form" product-url="{{productUrl}}" product-details="[[details]]"></stitch-order-form>
<!--
Development guidelines:
- Stick to paper elements if possible for UI widgets
- The mockup shows the element enclosed inside a white page on an off-white background. No need to build that
in; it will be part of the environment in which the element is used.
- This folder contains a mockup.png with a mockup of the approximate element we're looking for. Interpret it as
mostly a guide for what we'd like the layout to look like. We know paper-elements, for example, result in
a different visual style than shown there.
Error handling:
- If a product search turns up no results, or more than one results, we'll need to hide the remainder of the form
and display an error.
- When the URL bar is empty (and thus there are no results), we'll need to hide the form and display a message
saying to copy and paste an amazon product web page URL in there to create an order.
How to read the element below:
- For the most part, design/develop is up to you. I scaffolded out a *few* bits below as a way to explain a few
particular architecture needs that we anticipate in order to integrate with our system.
e.g.: the different userOrder and userOrderForSave objects.
-->
</template>
<script>
Polymer({
is: 'stitch-order-element',
properties: {
/**
* The current product URL.
*/
productUrl: {
type: Object,
notify: true
},
/**
* The current product details retrieved from amazon.
*
* Note that this object will not have the shipping information.
*/
productDetails: {
type: Object,
readOnly: true,
computed: '_detailsChanged(details)',
notify: true
},
/**
* The last product submitted (address, product, options are the 3 objects inside this one).
*
* Note that this object will have the data from the last product submitted
* to access the current product data use `productDetails` instead.
*/
lastProduct: {
type: Object,
readOnly: true,
notify: true
},
/**
* The last product submitted URL.
*
* Note that this URL will be the last product submitted URL
* to access the current product URL use `productUrl` instead.
*/
lastUrl: {
type: String,
readOnly: true,
notify: true
}
},
listeners: {
'request.order-details-request': '_loadingProduct',
'request.order-response': '_orderDataRetrieved',
'request.error': '_errorThrown',
'order-submit': '_save'
},
/**
* Resets the current form data.
*
* This will wipe `productUrl` and `productDetails`.
* `lastProduct` and `lastUrl` will remain unchanged.
*/
reset: function(){
this.$.form.reset();
},
_detailsChanged: function(details){
return details;
},
_loadingProduct: function(e){
this.$.form.reset(null, e.detail.URL);
this.$.form.set('loading', true);
this.$.form.set('loaded', false);
},
_orderDataRetrieved: function(e){
if (e.detail.details) {
this.$.form.set('loaded', true);
}
if (e.detail.options) {
this.$.form.set('loading', false);
}
},
_errorThrown: function(e){
this.$.form.error(e.detail.request.response[0].Error[0]);
},
/**
* Capture the `order-submit` event and set the data into the `lastProduct` Object
*/
_save: function(e){
this._setlastUrl(this.productUrl);
this._setLastProduct(e.detail);
}
});
</script>
</dom-module>