Add User, port simplified paging
[blerg.git] / www / jssrc / blerg / User.js
diff --git a/www/jssrc/blerg/User.js b/www/jssrc/blerg/User.js
new file mode 100644 (file)
index 0000000..ca0916a
--- /dev/null
@@ -0,0 +1,54 @@
+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);
+
+               var url;
+               if (from != undefined && to != undefined) {
+                       url = baseURL +  '/get/' + this.username + '/' + from + '-' + to;
+               } else {
+                       url = baseURL +  '/get/' + this.username;
+               }
+
+               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();
+       }
+});