ca0916a3c4f984c7d4584e7562725b5e6ff23713
[blerg.git] / www / jssrc / blerg / User.js
1 enyo.kind({
2         name: "blerg.User",
3         kind: "blerg.Pager",
4         listKind: "blerg.Record",
5         published: {
6                 username: "",
7                 permalink: false,
8                 firstRecord: null,
9         },
10         statics: {
11                 locationDetect: function(l) {
12                         var m = l.hash.match(/^#([A-Za-z0-9_-]+)(?:\/(p)?(\d+))?$/);
13                         if (m) {
14                                 return {
15                                         kind: "blerg.User",
16                                         username: m[1],
17                                         permalink: m[2] != 'p',
18                                         firstRecord: parseInt(m[3])
19                                 };
20                         }
21                 }
22         },
23         create: function() {
24                 this.inherited(arguments);
25                 this.usernameChanged();
26         },
27         usernameChanged: function() {
28                 this.bubble('onSetTitle', {section: '@' + this.username});
29                 this.$.records.destroyComponents();
30                 this.lastRecord = null;
31                 this.loadMore();
32         },
33         loadItems: function(from, to) {
34                 this.inherited(arguments);
35
36                 var url;
37                 if (from != undefined && to != undefined) {
38                         url = baseURL +  '/get/' + this.username + '/' + from + '-' + to;
39                 } else {
40                         url = baseURL +  '/get/' + this.username;
41                 }
42
43                 var req = new enyo.Ajax({
44                         url: url
45                 });
46                 req.response(function(inSender, inResponse) {
47                         for (var i = 0; i < inResponse.length; i++) {
48                                 inResponse[i].author = this.username;
49                         }
50                         this.addItems(inResponse);
51                 }.bind(this));
52                 req.go();
53         }
54 });