Add subscription management features
[blerg.git] / www / jssrc / blerg / User.js
index d2d0b83..5bcdbd0 100644 (file)
@@ -14,8 +14,8 @@ enyo.kind({
        components: [
                {classes: "blerg-user-controls", components: [
                        {name: "chatterLink", kind: "blerg.Link", content: "[chatter]"},
-                       {name: "stalkLink", kind: "blerg.Link", content: "[stalk]", showing: false, onclick: "startStalking"},
-                       {name: "unstalkLink", kind: "blerg.Link", content: "[stop stalking]", showing: false, onclick: "stopStalking"},
+                       {name: "stalkLink", kind: "blerg.Link", content: "[stalk]", showing: false, onNavigate: "startStalking"},
+                       {name: "unstalkLink", kind: "blerg.Link", content: "[stop stalking]", showing: false, onNavigate: "stopStalking"},
                        {name: "rssLink", kind: "blerg.Link", components: [
                                {noDom: true, content: "["},
                                {kind: "Image", src: "/images/rss.png", attributes: {width: 16, height: 16}},
@@ -25,7 +25,8 @@ enyo.kind({
                {name: "records"},
                {name: "loadMoreButton", kind: "onyx.Button", onclick: "loadMore", content: "Load More"},
                {name: "api", kind: "blerg.API",
-                onItemsLoaded: "itemsLoaded"}
+                onItemsLoaded: "itemsLoaded",
+                onSubscriptionStatus: "gotStalkStatus"}
        ],
        statics: {
                locationDetect: function(l) {
@@ -82,6 +83,21 @@ enyo.kind({
                        this.$.unstalkLink.hide();
                        return;
                }
-               // Make an API call to determine status
+               this.$.api.getSubscriptionStatus(this.username);
+       },
+       gotStalkStatus: function(inSender, inEvent) {
+               if (inEvent.subscribed) {
+                       this.$.stalkLink.hide();
+                       this.$.unstalkLink.show();
+               } else {
+                       this.$.stalkLink.show();
+                       this.$.unstalkLink.hide();
+               }
+       },
+       startStalking: function() {
+               this.$.api.subscribe(this.username);
+       },
+       stopStalking: function() {
+               this.$.api.unsubscribe(this.username);
        }
 });