X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjssrc%2Fblerg%2FUser.js;h=57366fbf71c37e6452d2a6de8fb526001be4b583;hb=3e5f69d01b9488475413d4ecce8161ab7a889ca2;hp=ca0916a3c4f984c7d4584e7562725b5e6ff23713;hpb=9818631aecddd827374a0c01b3ec287e7b018bb1;p=blerg.git diff --git a/www/jssrc/blerg/User.js b/www/jssrc/blerg/User.js index ca0916a..57366fb 100644 --- a/www/jssrc/blerg/User.js +++ b/www/jssrc/blerg/User.js @@ -1,54 +1,125 @@ enyo.kind({ - name: "blerg.User", - kind: "blerg.Pager", - listKind: "blerg.Record", - published: { - username: "", - permalink: false, - firstRecord: null, - }, - statics: { - locationDetect: function(l) { - var m = l.hash.match(/^#([A-Za-z0-9_-]+)(?:\/(p)?(\d+))?$/); - if (m) { - return { - kind: "blerg.User", - username: m[1], - permalink: m[2] != 'p', - firstRecord: parseInt(m[3]) - }; - } - } - }, - create: function() { - this.inherited(arguments); - this.usernameChanged(); - }, - usernameChanged: function() { - this.bubble('onSetTitle', {section: '@' + this.username}); - this.$.records.destroyComponents(); - this.lastRecord = null; - this.loadMore(); - }, - loadItems: function(from, to) { - this.inherited(arguments); + name: "blerg.User", + kind: "blerg.Pager", + listKind: "blerg.Record", + handlers: { + onLogin: "getStalkStatus", + onLogout: "getStalkStatus", + onReload: "usernameChanged" + }, + 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: [ + {tag: null, content: "["}, + {kind: "Image", src: "/images/rss.png", attributes: {width: 16, height: 16}}, + {tag: null, content: "RSS]"} + ]} + ]}, + {name: "records"}, + {name: "spinner", kind: "OldSchoolSpinner", showing: false}, + {name: "emptyAccountMessage", showing: false, content: "Hey, there's nothing here!"}, + {name: "userNotFoundMessage", classes: "blerg-error", showing: false, content: "User not found"}, + {name: "loadMoreButton", kind: "onyx.Button", onclick: "loadMore", content: "Load More"}, + {name: "api", kind: "blerg.API", + onItemsLoaded: "itemsLoaded", + onUserNotFound: "userNotFound", + onAPIError: "apiError", + onSubscriptionStatus: "gotStalkStatus"} + ], + statics: { + locationDetect: function(l) { + var m = l.hash.match(/^#([A-Za-z0-9_-]+)(?:\/(\d+))?$/); + if (m) { + return { + kind: "blerg.User", + username: m[1], + permalink: m[2] != undefined, + record: parseInt(m[2]) + }; + } + } + }, + create: function() { + this.inherited(arguments); + this.usernameChanged(); + }, + usernameChanged: function() { + this.bubble('onSetTitle', {section: '@' + this.username}); + this.$.records.destroyComponents(); + this.lastRecord = null; + this.$.loadMoreButton.hide(); + this.$.chatterLink.setHref('/#/ref/' + this.username); + this.$.rssLink.setHref('/rss/' + this.username); + this.getStalkStatus(); - var url; - if (from != undefined && to != undefined) { - url = baseURL + '/get/' + this.username + '/' + from + '-' + to; - } else { - url = baseURL + '/get/' + this.username; - } + if (this.permalink) { + this.loadItems(this.record, this.record); + } else { + this.loadMore(); + } + }, + loadItems: function(from, to) { + this.inherited(arguments); + this.$.api.loadUserRecords(this.username, from, to); + }, + itemsLoaded: function(inSender, inEvent) { + this.$.userNotFoundMessage.hide(); + if (this.permalink) { + this.$.loadMoreButton.hide(); + } else { + this.$.loadMoreButton.show(); + } - var req = new enyo.Ajax({ - url: url - }); - req.response(function(inSender, inResponse) { - for (var i = 0; i < inResponse.length; i++) { - inResponse[i].author = this.username; - } - this.addItems(inResponse); - }.bind(this)); - req.go(); - } + for (var i = 0; i < inEvent.entries.length; i++) { + inEvent.entries[i].author = this.username; + } + + this.addItems(inEvent.entries); + if (this.lastRecord == 0 || inEvent.entries.length == 0) + this.$.loadMoreButton.hide(); + }, + addItems: function(items) { + this.$.emptyAccountMessage.setShowing(items.length == 0); + this.inherited(arguments); + }, + userNotFound: function() { + this.addItems([]); + this.$.emptyAccountMessage.hide(); + this.$.userNotFoundMessage.show(); + }, + apiError: function() { + this.addItems([]); + alert('Unknown API Error'); + }, + 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); + } });