Make Account Center only usable when logged in
[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          onClearStatus: "clearStatus"}
22     ],
23     statics: {
24         locationDetect: function(l) {
25             var m = l.hash.match(/^#\/(ref|tag)\/([A-Za-z0-9_-]+)$/);
26             if (m) {
27                 return {
28                     kind: "blerg.Tag",
29                     type: m[1],
30                     tag: m[2]
31                 };
32             }
33         }
34     },
35     create: function() {
36         this.inherited(arguments);
37         this.tagChanged();
38     },
39     tagChanged: function() {
40         switch(this.type) {
41         case 'tag':
42             this.bubble('onSetTitle', {section: '#' + this.tag});
43             break;
44         case 'ref':
45             this.bubble('onSetTitle', {section: 'about @' + this.tag});
46             break;
47         }
48         this.$.rssLink.setHref('/rss/' + this.type + '/' + this.tag);
49         this.$.records.destroyComponents();
50         this.lastRecord = null;
51         this.loadMore();
52     },
53     loadItems: function(from, to) {
54         this.inherited(arguments);
55         this.$.api.loadTagRecords(this.type, this.tag);
56     },
57     itemsLoaded: function(inSender, inEvent) {
58         this.addItems(inEvent.entries);
59         if (this.type == 'ref' && blerg.API.loggedIn && blerg.API.username == this.tag) {
60             this.$.api.clearStatus('mentioned');
61         }
62     },
63     clearStatus: function(inSender, inEvent) {
64         if (inEvent.type == 'mentioned' && inEvent.status == 'success') {
65             enyo.Signals.send('onClearNotification', {type: inEvent.type});
66         }
67     }
68 });