-
Notifications
You must be signed in to change notification settings - Fork 3
/
map-google-input.js
74 lines (59 loc) · 1.44 KB
/
map-google-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
import xin from 'xin';
import './css/map-google-input.css';
class MapGoogleInput extends xin.Component {
get template () {
return String(`
<p class="text">[[valueText]]</p>
<div class="cover" (click)="_coverClicked(evt)"></div>
`);
}
get props () {
return {
value: {
type: Object,
notify: true,
},
valueText: {
type: String,
computed: '_computeValueText(value)',
},
selectViewUri: {
type: String,
value: '/map',
},
selectViewComponent: {
type: String,
value: 'map-google-view',
},
};
}
_coverClicked (evt) {
evt.stopImmediatePropagation();
this.present();
}
async present () {
return await new Promise((resolve, reject) => {
// Select Location
// let referer = this.__app.getFragment();
this.__app.once('navigated', evt => {
let view = document.querySelector(`${this.selectViewComponent}`);
if (!view) {
throw new Error('Select view not found');
}
view.set('callback', (result) => {
this.set('value', result);
this.fire('change');
});
});
this.__app.navigate(this.selectViewUri);
});
}
_computeValueText (value) {
if (!value || !value.address) {
return '';
}
return value.address;
}
}
xin.define('map-google-input', MapGoogleInput);
export default MapGoogleInput;