|
1 // //////////////////////////////////////////////////////////////////////////// |
|
2 // (c)2009 Symbian Foundation |
|
3 // //////////////////////////////////////////////////////////////////////////// |
|
4 |
|
5 // Feed presentation classes |
|
6 |
|
7 // Abstract class used to create controls to represent feed entries. |
|
8 function FeedPresenter(rssreader){ |
|
9 if (rssreader) { |
|
10 this.init(rssreader); |
|
11 } |
|
12 } |
|
13 |
|
14 // FeedPresenter "Constructor" |
|
15 FeedPresenter.prototype.init = function(rssreader){ |
|
16 this.rssreader = rssreader; |
|
17 } |
|
18 |
|
19 // Create a control that represents this item and add it to |
|
20 // parent rss reader |
|
21 FeedPresenter.prototype.show = function(item){ |
|
22 } |
|
23 |
|
24 // Create and add controls to be shown before items list. |
|
25 FeedPresenter.prototype.addPreambleItems = function(){ |
|
26 } |
|
27 |
|
28 // No items returned, show "No messages" |
|
29 FeedPresenter.prototype.showNoItems = function(){ |
|
30 var label = new Label(null, null, "No messages"); |
|
31 this.rssreader.addControl(label); |
|
32 } |
|
33 |
|
34 // Implementation of FeedPresenter that shows feed in a |
|
35 // ContentPanel |
|
36 function HtmlFeedPresenter(rssreader) { |
|
37 if (rssreader) { |
|
38 this.init(rssreader); |
|
39 } |
|
40 this.expanded = false; |
|
41 } |
|
42 |
|
43 // HtmlFeedPresenter is a subclass of FeedPresenter |
|
44 HtmlFeedPresenter.prototype = new FeedPresenter(null); |
|
45 |
|
46 // HtmlFeedPresenter "constructor" |
|
47 HtmlFeedPresenter.prototype.init = function(rssreader) { |
|
48 FeedPresenter.prototype.init.call(this, rssreader); |
|
49 } |
|
50 |
|
51 // Create a control that represents this item and add it to |
|
52 // parent rss reader |
|
53 HtmlFeedPresenter.prototype.show = function(item) { |
|
54 // get a feed item control from the pool or create one and |
|
55 // place it in the pool if there aren't enough feed item controls |
|
56 var feedItemControl = new ContentPanel(null, null, null, true); |
|
57 |
|
58 // initialize feed item control |
|
59 feedItemControl.setCaption(item.title); |
|
60 feedItemControl.setContent(this.getContentHTMLForFeedItem(item)); |
|
61 feedItemControl.setExpanded(this.expanded); |
|
62 |
|
63 // add the feed item control to the main view |
|
64 this.rssreader.feedItemControls.push(feedItemControl); |
|
65 this.rssreader.addControl(feedItemControl); |
|
66 } |
|
67 |
|
68 // Returns the content HTML for a feed item. |
|
69 HtmlFeedPresenter.prototype.getContentHTMLForFeedItem = function (item){ |
|
70 var buf = ""; |
|
71 |
|
72 // item date |
|
73 if (item.date != null) { |
|
74 buf += "<div class=\"FeedItemDate\">" ; |
|
75 if ( item.author != null ) { |
|
76 buf += item.author + ", "; |
|
77 } |
|
78 buf += item.date + "</div>"; |
|
79 } |
|
80 |
|
81 // item description |
|
82 if (item.description != null) { |
|
83 buf += "<div class=\"FeedItemDescription\">" + item.description + "</div>"; |
|
84 } |
|
85 |
|
86 if (item.url != null) { |
|
87 // blogs |
|
88 buf += "<div class=\"FeedItemLink\">"; |
|
89 // buf += "<a href=\"JavaScript:void(0)\" onclick=\"openURL('" + item.title + "', '" + item.url + "'); return false;\">"; |
|
90 buf += "<a href=\"JavaScript:void(0)\" onclick=\"openURL('" + item.url + "'); return false;\">"; |
|
91 buf += "Read more..."; |
|
92 buf += "</a>"; |
|
93 buf += "</div>"; |
|
94 } |
|
95 |
|
96 return buf; |
|
97 } |
|
98 |
|
99 |
|
100 // Implementation of FeedPresenter that shows feed as a clickable |
|
101 // button that shows feed entry title as label |
|
102 function ButtonFeedPresenter(rssreader) { |
|
103 if (rssreader) { |
|
104 this.init(rssreader); |
|
105 } |
|
106 this.indexCounter = 0; |
|
107 this.items = []; |
|
108 } |
|
109 |
|
110 // ButtonFeedPresenter is a subclass of FeedPresenter |
|
111 ButtonFeedPresenter.prototype = new FeedPresenter(null); |
|
112 |
|
113 // ButtonFeedPresenter "constructor" |
|
114 ButtonFeedPresenter.prototype.init = function(rssreader) { |
|
115 FeedPresenter.prototype.init.call(this, rssreader); |
|
116 } |
|
117 |
|
118 // Create a control that represents this item and add it to |
|
119 // parent rss reader |
|
120 ButtonFeedPresenter.prototype.show = function(item) { |
|
121 this.items[this.indexCounter] = item; |
|
122 // get a feed item control from the pool or create one and |
|
123 // place it in the pool if there aren't enough feed item controls |
|
124 var feedItemControl = new NavigationButton(this.indexCounter, "right.gif", item.title); |
|
125 |
|
126 // add button press handler |
|
127 var self = this; |
|
128 feedItemControl.addEventListener("ActionPerformed", |
|
129 function(event) { self.feedClicked(event); } ); |
|
130 |
|
131 this.indexCounter++; |
|
132 |
|
133 // add the feed item control to the main view |
|
134 this.rssreader.feedItemControls.push(feedItemControl); |
|
135 this.rssreader.addControl(feedItemControl); |
|
136 } |
|
137 |
|
138 // Handle the button-press |
|
139 ButtonFeedPresenter.prototype.feedClicked = function(event){ |
|
140 var clickedButton = event.source; |
|
141 var id = clickedButton.id; |
|
142 var url = this.items[id].url; |
|
143 |
|
144 if (url.indexOf("/wiki/index.php")) { |
|
145 // hack for printable wiki pages |
|
146 var articleName = url.replace(wikiBaseUrl + "/", ""); |
|
147 url = wikiBaseUrl + "?title=" + articleName + "&action=render"; |
|
148 openURL(url); |
|
149 } |
|
150 else { |
|
151 openURL(url); |
|
152 } |
|
153 } |
|
154 |
|
155 |