d885481c41904dd38972e1c922a75663908d613d
[blerg.git] / www / jssrc / blerg / Tag.js
1 enyo.kind({
2     name: "blerg.Tag",
3     kind: "blerg.Pager",
4     listKind: "blerg.TagRecord",
5     published: {
6         type: null,
7         tag: ""
8     },
9     components: [
10         {name: "records"},
11         {name: "api", kind: "blerg.API",
12          onItemsLoaded: "itemsLoaded"}
13     ],
14     statics: {
15         locationDetect: function(l) {
16             var m = l.hash.match(/^#\/(ref|tag)\/([A-Za-z0-9_-]+)$/);
17             if (m) {
18                 return {
19                     kind: "blerg.Tag",
20                     type: m[1],
21                     tag: m[2]
22                 };
23             }
24         }
25     },
26     create: function() {
27         this.inherited(arguments);
28         this.tagChanged();
29     },
30     tagChanged: function() {
31         switch(this.type) {
32         case 'tag':
33             this.bubble('onSetTitle', {section: '#' + this.tag});
34             break;
35         case 'ref':
36             this.bubble('onSetTitle', {section: 'about @' + this.tag});
37             break;
38         }
39         this.$.records.destroyComponents();
40         this.lastRecord = null;
41         this.loadMore();
42     },
43     loadItems: function(from, to) {
44         this.inherited(arguments);
45         this.$.api.loadTagRecords(this.type, this.tag);
46     },
47     itemsLoaded: function(inSender, inEvent) {
48         this.addItems(inEvent.entries);
49     }
50 });