-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwelcome-greeting.js
More file actions
60 lines (52 loc) · 1.48 KB
/
welcome-greeting.js
File metadata and controls
60 lines (52 loc) · 1.48 KB
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
import {html, PolymerElement} from '@polymer/polymer/polymer-element.js';
import {APIHelper} from './APIHelper.js'
class WelcomeGreeting extends PolymerElement {
static get template() {
return html`
<style>
:host {
display: block;
}
</style>
<div hidden$="[[hide]]">
<h2 id="GreetingMessage" hidden$="[[hideGreeting]]">[[greeting]]</h2>
<button id="NextButton" hidden$="[[hideNextButton]]" on-click="_dispatchNextButtonClicked">Next</button>
</div>
`;
}
_dispatchNextButtonClicked() {
this.dispatchEvent(new CustomEvent('next-button-clicked', {detail : "next button clicked"}));
}
_handleError(errorMessage) {
this.hideGreeting = true;
this.dispatchEvent(new CustomEvent('api-error', {detail: errorMessage}));
}
greet() {
var self = this;
APIHelper.getJsonResponse('/welcome')
.then(function(response) {
self.greeting = response.message;
self.hideGreeting = false;
self.hideNextButton = false;
self.hide = false;
})
.catch(function(err) {
if(err) {
self.hideNextButton = true;
self._handleError(err);
console.log('Fetch Error :-S', err);
}
});
}
init() {
this.hide = true;
this.hideGreeting = true;
this.hideNextButton = true;
this.greeting = '';
}
constructor() {
super();
this.init();
}
}
window.customElements.define('welcome-greeting', WelcomeGreeting);