-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtours-users.html
More file actions
73 lines (72 loc) · 1.72 KB
/
tours-users.html
File metadata and controls
73 lines (72 loc) · 1.72 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
61
62
63
64
65
66
67
68
69
70
71
72
73
<dom-module id="tours-users">
<template>
<style>
:host {
display: block;
}
[odd] {
background: rgba(0,0,0,0.05);
}
.item {
padding: 10px 15px;
position: relative;
font-family: Tahoma, Geneva, sans-serif;
}
.name {
font-weight: bold;
}
.link a {
color: #0c8ec8;
text-decoration: none;
cursor: pointer;
}
</style>
<foo class="bar">[[foo.email]]</foo>
<template id='foo' is="dom-repeat" items="[[users]]" >
<div class="item" odd$="[[isEven(index)]]">
<div class="name">
[[item.name]]
</div>
<div class="link">
<a href="[[item.email]]">[[item.email]]</a>
</div>
</div>
</template>
</template>
<script>
class ToursUsers extends Polymer.Element {
static get is() { return 'tours-users'; }
static get properties() {
return {
users: {
type: Array,
value: []
}
};
}
ready() {
super.ready();
this.updateUsers();
}
updateUsers() {
let xhr = new XMLHttpRequest();
let _this = this;
xhr.open('GET', '/api/users');
xhr.send(null);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status == 200) {
_this.setUsers.apply(_this, [xhr.responseText])
}
};
}
setUsers(json) {
this.set('users', JSON.parse(json).users);
this.set('foo', this.users[0]);
}
isEven(index) {
return (index % 2) === 0;
}
}
window.customElements.define(ToursUsers.is, ToursUsers);
</script>
</dom-module>