-
Notifications
You must be signed in to change notification settings - Fork 2
/
post-list.html
56 lines (52 loc) · 1.58 KB
/
post-list.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
<link rel="import" href="../finished/components/polymer/polymer.html">
<link rel="import" href="../finished/post-service/post-service.html">
<link rel="import" href="post-card.html">
<polymer-element name="post-list" attributes="show">
<template>
<style>
:host {
display: block;
width: 100%;
}
post-card {
margin-bottom: 30px;
}
</style>
<post-service id="service" posts="{{posts}}"></post-service>
<div layout vertical center>
<template repeat="{{post in posts}}">
<post-card
favorite="{{post.favorite}}"
on-favorite-tap="{{handleFavorite}}"
hidden?="{{show == 'favorites' && !post.favorite}}">
<img src="{{post.avatar}}" width="70" height="70">
<h2>{{post.username}}</h2>
<p>{{post.text}}</p>
</post-card>
<core-icon-button icon="star" on-click="{{putJSON}}" layout vertical center></core-icon-button>
<core-ajax id="ajax2"
url="/api/posts.json"
on-core-response="{{getJSON}}"
handleAs="json">
</core-ajax>
</template>
</div>
</template>
<script>
Polymer({
handleFavorite: function(event, detail, sender) {
var post = sender.templateInstance.model.post;
this.$.service.setFavorite(post.uid, post.favorite);
},
getJSON: function(event, detail, sender)
{
console.dir(detail.response);
},
putJSON: function(event, detail, sender)
{
this.posts.push({"username": "Parth"});
console.dir(this.posts);
}
});
</script>
</polymer-element>