Add RSS links for tags and feed
[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         {classes: "blerg-user-controls", components: [
11             {name: "rssLink", kind: "blerg.Link", components: [
12                 {tag: null, content: "["},
13                 {kind: "Image", src: "/images/rss.png", attributes: {width: 16, height: 16}},
14                 {tag: null, content: "RSS]"}
15             ]}
16         ]},
17         {name: "records"},
18         {name: "spinner", kind: "OldSchoolSpinner", showing: false},
19         {name: "api", kind: "blerg.API",
20          onItemsLoaded: "itemsLoaded"}
21     ],
22     statics: {
23         locationDetect: function(l) {
24             var m = l.hash.match(/^#\/(ref|tag)\/([A-Za-z0-9_-]+)$/);
25             if (m) {
26                 return {
27                     kind: "blerg.Tag",
28                     type: m[1],
29                     tag: m[2]
30                 };
31             }
32         }
33     },
34     create: function() {
35         this.inherited(arguments);
36         this.tagChanged();
37     },
38     tagChanged: function() {
39         switch(this.type) {
40         case 'tag':
41             this.bubble('onSetTitle', {section: '#' + this.tag});
42             break;
43         case 'ref':
44             this.bubble('onSetTitle', {section: 'about @' + this.tag});
45             break;
46         }
47         this.$.rssLink.setHref('/rss/' + this.type + '/' + this.tag);
48         this.$.records.destroyComponents();
49         this.lastRecord = null;
50         this.loadMore();
51     },
52     loadItems: function(from, to) {
53         this.inherited(arguments);
54         this.$.api.loadTagRecords(this.type, this.tag);
55     },
56     itemsLoaded: function(inSender, inEvent) {
57         this.addItems(inEvent.entries);
58     }
59 });