http://angularjs.org/Cookbook:Resources
[angular-mojolicious.git] / templates / Cookbook / 7-Resources.html.ep
diff --git a/templates/Cookbook/7-Resources.html.ep b/templates/Cookbook/7-Resources.html.ep
new file mode 100644 (file)
index 0000000..38fe3f6
--- /dev/null
@@ -0,0 +1,41 @@
+<script>
+angular.service('myApplication', function($resource){
+ this.Activity = $resource(
+  'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
+  {alt:'json', callback:'JSON_CALLBACK'},
+  { get:     {method:'JSON', params:{visibility:'@self'}},
+   replies: {method:'JSON', params:{visibility:'@self', comments:'@comments'}}
+  });
+}, {inject:['$resource']});
+
+function BuzzController(){}
+BuzzController.prototype = {
+ fetch: function(){
+  this.activities = this.Activity.get({userId:this.userId});
+ },
+ expandReplies: function(activity) {
+  activity.replies = 
+   this.Activity.replies({userId:this.userId, activityId:activity.id});
+ }
+};
+</script>
+<div ng:controller="BuzzController">
+ <input name="userId" value="googlebuzz"/>
+ <button ng:click="fetch()">fetch</button>
+ <hr/>
+ <div ng:repeat="item in activities.data.items">
+  <h1 style="font-size: 15px;">
+   <img src="{{item.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
+   <a href="{{item.actor.profileUrl}}">{{item.actor.name}}</a>
+   <a href="#" ng:click="expandReplies(item)" style="float: right;">
+    Expand replies: {{item.links.replies[0].count}}
+   </a>
+  </h1>
+  {{item.object.content | html}}
+  <div ng:repeat="reply in item.replies.data.items" style="margin-left: 20px;">
+   <img src="{{reply.actor.thumbnailUrl}}" style="max-height:30px;max-width:30px;"/>
+   <a href="{{reply.actor.profileUrl}}">{{reply.actor.name}}</a>:
+   {{reply.content | html}}
+  </div>
+ </div>
+</div>