8fe0947a51fff9ee10f456071aa64a0855f37bb2
[blerg.git] / www / jssrc / blerg / Record.js
1 enyo.kind({
2     name: "blerg.Record",
3     kind: "Control",
4     classes: "record",
5     published: {
6         data: "",
7         timestamp: 0,
8         author: "",
9         record: null
10     },
11     components: [
12         {name: "data", noDom: true, allowHtml: true},
13         {classes: "info", components: [
14             {noDom: true, content: "Posted "},
15             {name: "date", noDom: true},
16             {noDom: true, content: ". "},
17             {name: "permalink", kind: "blerg.Link", content: "[permalink]"},
18             {noDom: true, content: " "},
19             {name: "reply", kind: "blerg.Link", content: "[reply]", onclick: "postPopup"}
20         ]}
21     ],
22     create: function() {
23         this.inherited(arguments);
24         this.dataChanged();
25         this.timestampChanged();
26         this.updateLinks();
27     },
28     dataChanged: function() {
29         this.$.data.setContent(blerg.Util.blergFormat(this.data));
30     },
31     timestampChanged: function() {
32         this.$.date.setContent(new Date(this.timestamp * 1000).toString());
33     },
34     authorChanged: function() {
35         this.updateLinks();
36     },
37     recordChanged: function() {
38         this.updateLinks();
39     },
40     updateLinks: function() {
41         this.$.permalink.setHref(baseURL + enyo.macroize("/#{$author}/{$record}", this));
42     },
43     postPopup: function() {
44         this.bubble('onPostVisibility', {
45             showing: true,
46             data: enyo.macroize("@{$author}/{$record}", this)
47         });
48         return true;
49     }
50 });
51
52 enyo.kind({
53     name: "blerg.TagRecord",
54     kind: "blerg.Record",
55     components: [
56         {name: "data", noDom: true, allowHtml: true},
57         {classes: "info", components: [
58             {noDom: true, content: "Posted by "},
59             {name: "author", kind: "blerg.Link", classes: "author ref"},
60             {noDom: true, content: " at "},
61             {name: "date", noDom: true},
62             {noDom: true, content: ". "},
63             {name: "permalink", kind: "blerg.Link", content: "[permalink]"},
64             {noDom: true, content: " "},
65             {name: "reply", kind: "blerg.Link", content: "[reply]", onclick: "postPopup"}
66         ]}
67     ],
68     updateLinks: function() {
69         this.inherited(arguments);
70         this.$.author.setContent('@' + this.author);
71         this.$.author.setHref('/#' + this.author);
72     }
73 });
74
75 enyo.kind({
76     name: "blerg.BriefRecord",
77     kind: "blerg.Record",
78     components: [
79         {name: "authorlink", kind: "blerg.Link", classes: "author ref"},
80         {noDom: true, content: " "},
81         {name: "data", noDom: true}
82     ],
83     dataChanged: function() {
84         var d = this.data.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
85         this.$.data.setContent(d);
86     },
87     timestampChanged: function() { },
88     updateLinks: function() {
89         this.$.authorlink.setHref(baseURL + '/#' + this.author);
90         this.$.authorlink.setContent('@' + this.author);
91     },
92 });