X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FUser.js;h=5bcdbd05f1e1e46834c982bbd32223f8b8b99c74;hb=a579fec94d5058776ea0fb6f47f922ea48ff876f;hp=b977fa032eb3176e61570aa2521f67e7072b4e7f;hpb=65a1f7dc82554486ffa9cc03eac29a7a1642f046;p=blerg.git diff --git a/www/jssrc/blerg/User.js b/www/jssrc/blerg/User.js index b977fa0..5bcdbd0 100644 --- a/www/jssrc/blerg/User.js +++ b/www/jssrc/blerg/User.js @@ -2,11 +2,32 @@ enyo.kind({ name: "blerg.User", kind: "blerg.Pager", listKind: "blerg.Record", + handlers: { + onLogin: "getStalkStatus", + onLogout: "getStalkStatus" + }, published: { username: "", permalink: false, record: null, }, + components: [ + {classes: "blerg-user-controls", components: [ + {name: "chatterLink", kind: "blerg.Link", content: "[chatter]"}, + {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}}, + {noDom: true, content: "RSS]"} + ]} + ]}, + {name: "records"}, + {name: "loadMoreButton", kind: "onyx.Button", onclick: "loadMore", content: "Load More"}, + {name: "api", kind: "blerg.API", + onItemsLoaded: "itemsLoaded", + onSubscriptionStatus: "gotStalkStatus"} + ], statics: { locationDetect: function(l) { var m = l.hash.match(/^#([A-Za-z0-9_-]+)(?:\/(\d+))?$/); @@ -29,6 +50,10 @@ enyo.kind({ this.$.records.destroyComponents(); this.lastRecord = null; this.$.loadMoreButton.hide(); + this.$.chatterLink.setHref('/#/ref/' + this.username); + this.$.rssLink.setHref('/rss/' + this.username); + this.getStalkStatus(); + if (this.permalink) { this.loadItems(this.record, this.record); } else { @@ -37,30 +62,42 @@ enyo.kind({ }, loadItems: function(from, to) { this.inherited(arguments); - - var url; - if (from != undefined && to != undefined) { - url = baseURL + '/get/' + this.username + '/' + from + '-' + to; + this.$.api.loadUserRecords(this.username, from, to); + }, + itemsLoaded: function(inSender, inEvent) { + if (this.permalink) { + this.$.loadMoreButton.hide(); } else { - url = baseURL + '/get/' + this.username; + this.$.loadMoreButton.show(); } - var req = new enyo.Ajax({ - url: url - }); - req.response(function(inSender, inResponse) { - if (this.permalink) { - this.$.loadMoreButton.hide(); - } else { - this.$.loadMoreButton.show(); - } - - for (var i = 0; i < inResponse.length; i++) { - inResponse[i].author = this.username; - } + for (var i = 0; i < inEvent.entries.length; i++) { + inEvent.entries[i].author = this.username; + } - this.addItems(inResponse); - }.bind(this)); - req.go(); + this.addItems(inEvent.entries); + }, + getStalkStatus: function() { + if (!blerg.API.loggedIn) { + this.$.stalkLink.hide(); + this.$.unstalkLink.hide(); + return; + } + 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); } });