|
1 // //////////////////////////////////////////////////////////////////////////// |
|
2 // (c)2009 Symbian Foundation |
|
3 // //////////////////////////////////////////////////////////////////////////// |
|
4 |
|
5 |
|
6 /////////////////////////////////////////////////////////////////////////////// |
|
7 // A widget for accessing developer.symbian.org forums |
|
8 |
|
9 |
|
10 // Reference to the WRTKit user interface manager and main view. |
|
11 var uiManager; |
|
12 |
|
13 // Global settings / URLs and such |
|
14 |
|
15 // Symbian.org web site base URL |
|
16 //var symbianOrgBaseUrl = "http://staging.foundationhost.org"; |
|
17 //var symbianOrgBaseUrlSsl = "https://staging.foundationhost.org"; |
|
18 var symbianOrgBaseUrl = "http://developer.symbian.org"; |
|
19 var symbianOrgBaseUrlSsl = "https://developer.symbian.org"; |
|
20 var registrationURL = symbianOrgBaseUrl + "/main/user_profile/register.php"; |
|
21 var blogFeedName = "Symbian Blog"; |
|
22 var blogFeedUrl = "http://blog.symbian.org/feed/"; |
|
23 |
|
24 // FORUM vars and settings |
|
25 var symbianOrgNewThreadUrl = symbianOrgBaseUrl+"/forum/newthread.php?"; |
|
26 var symbianOrgNewReplyUrl = symbianOrgBaseUrl+"/forum/newreply.php?"; |
|
27 var symbianOrgLoginUrl = symbianOrgBaseUrlSsl+"/main/user_profile/login.php"; |
|
28 var symbianOrgLoginUsernameField = "username"; |
|
29 var symbianOrgLoginPasswordField = "password"; |
|
30 var forumUsername = null ; |
|
31 var forumPassword = null; |
|
32 |
|
33 // Feed name, URL etc for forums |
|
34 var forumFeedName = "Symbian.org Forums"; |
|
35 var forumFeedURL = symbianOrgBaseUrl+ "/forum/external.php?type=rss2"; //&fulldesc=1&lastpost=1 |
|
36 var forumsForumSpecQuery = "&forumid="; |
|
37 var forumFeedUpdateFrequency = -1; |
|
38 |
|
39 var forumGroupsUrl = symbianOrgBaseUrl+ "/rss/forum.php?type=groups"; |
|
40 var forumsListUrl = symbianOrgBaseUrl+ "/rss/forum.php?type=forums&group="; |
|
41 var forumThreadUrl = symbianOrgBaseUrl+ "/rss/forum.php?type=threadmsgs&threadid="; |
|
42 |
|
43 // Wiki url etc |
|
44 var wikiFeedName = "New on Symbian.org Wiki"; |
|
45 var wikiFeedUrl = symbianOrgBaseUrl+"/wiki/index.php?title=Special:NewPages&feed=rss"; |
|
46 var wikiBaseUrl = symbianOrgBaseUrl+"/wiki/index.php"; |
|
47 |
|
48 // Update variables |
|
49 var myversion = "1.0rc3"; |
|
50 var versionWikiPageUrl = wikiBaseUrl + "/Symbian.org_WRT_Widget"; |
|
51 var versionWikiPageString = "Current widget version is ["; |
|
52 var downloadUrl = symbianOrgBaseUrl + "/wiki/images/c/c5/Symbian.org.wgz"; |
|
53 |
|
54 // UI elements |
|
55 |
|
56 // blog / forum instances |
|
57 // all are SOScreen subclasses |
|
58 var home; // home screen |
|
59 var blog; // RSSReader showing blog |
|
60 var wiki; // RSSReader showing wiki |
|
61 var bugzila; // RSSReader showing bugzilla feeds |
|
62 var forumGroups; // RSSReader showing list of forum groups |
|
63 var settings; |
|
64 var about; |
|
65 |
|
66 // currently showing SOScreen |
|
67 var currentScreen = null; |
|
68 |
|
69 // Controls for the settings view |
|
70 var forumUsernameControl; |
|
71 var forumPasswordControl; |
|
72 |
|
73 // Constants for menu item identifiers. |
|
74 var MENU_ITEM_SETTINGS = 0; |
|
75 var MENU_ITEM_REFRESH = 1; |
|
76 var MENU_ITEM_ABOUT = 2; |
|
77 var MENU_ITEM_CHECK_UPDATE = 3; |
|
78 |
|
79 // Flag indicating weather the web site login has been initiated |
|
80 var loginInitiated = false; |
|
81 var loginInitiatedCallback = null; |
|
82 |
|
83 |
|
84 var widgetHomepage = symbianOrgBaseUrl + "/wiki/index.php?title=Symbian.org_WRT_Widget&action=render"; |
|
85 var aboutText = "<strong>Symbian.org "+myversion+"</strong><br>" |
|
86 + "Symbian.org WRT Widget is a Web Runtime application which allows mobile " |
|
87 + "access to Symbian Foundation Forums, Blog, Wiki and Bugzilla. <br>" |
|
88 + "For more information and updates check <div class=FeedItemLink>" |
|
89 + "<a href=\"JavaScript:void(0)\" onclick=\"openURL('" |
|
90 + widgetHomepage |
|
91 + "'); return false;\">" |
|
92 +" Symbian.org Widget Homepage </a> </div><p>" |
|
93 + "Credits: Ivan Litovski, Ryan Grentz, James Mentz"; |
|
94 |
|
95 |
|
96 // Called from the onload event handler to initialize the widget. |
|
97 function init() { |
|
98 |
|
99 // set tab-navigation mode and show softkeys |
|
100 // (only if we are in the WRT environment) |
|
101 if (window.widget) { |
|
102 widget.setNavigationEnabled(false); |
|
103 window.menu.showSoftkeys(); |
|
104 // create menu |
|
105 var settingsMenuItem = new MenuItem("Settings", MENU_ITEM_SETTINGS); |
|
106 settingsMenuItem.onSelect = menuItemSelected; |
|
107 menu.append(settingsMenuItem); |
|
108 var refreshMenuItem = new MenuItem("Refresh", MENU_ITEM_REFRESH); |
|
109 refreshMenuItem.onSelect = menuItemSelected; |
|
110 menu.append(refreshMenuItem); |
|
111 var aboutMenuItem = new MenuItem("About", MENU_ITEM_ABOUT); |
|
112 aboutMenuItem.onSelect = menuItemSelected; |
|
113 menu.append(aboutMenuItem); |
|
114 var updateMenuItem = new MenuItem("Check for updates", MENU_ITEM_CHECK_UPDATE); |
|
115 updateMenuItem.onSelect = menuItemSelected; |
|
116 menu.append(updateMenuItem); |
|
117 } |
|
118 |
|
119 // load prefs |
|
120 if (!forumUsername || !forumPassword) { |
|
121 loadPreferences(); |
|
122 } |
|
123 |
|
124 // create UI manager |
|
125 uiManager = new UIManager(); |
|
126 |
|
127 // Create the home view |
|
128 home = new ListView(null, "<img src=logo.png>"); |
|
129 |
|
130 // add forums button |
|
131 var forumsButton = new NavigationButton(1, "right.gif", "Forums") |
|
132 forumsButton.addEventListener("ActionPerformed", function(){forumGroups.show();}); |
|
133 home.addControl(forumsButton); |
|
134 |
|
135 // add blogs button |
|
136 var blogsButton = new NavigationButton(2, "right.gif", "Blogs") |
|
137 blogsButton.addEventListener("ActionPerformed", function(){blog.show();}); |
|
138 home.addControl(blogsButton); |
|
139 |
|
140 // add wiki button |
|
141 var wikiButton = new NavigationButton(3, "right.gif", "Wiki") |
|
142 wikiButton.addEventListener("ActionPerformed", function(){wiki.show();}); |
|
143 home.addControl(wikiButton); |
|
144 |
|
145 // add bugzilla button |
|
146 var bugzillaButton = new NavigationButton(3, "right.gif", "Bugzilla") |
|
147 bugzillaButton.addEventListener("ActionPerformed", function(){login(function(){bugzilla.show();});}); |
|
148 home.addControl(bugzillaButton); |
|
149 |
|
150 // soft keys |
|
151 home.setupSoftKeys = function() { |
|
152 if (window.widget) { |
|
153 menu.setRightSoftkeyLabel("Exit", function(){window.close();}); |
|
154 } |
|
155 } |
|
156 |
|
157 // create blog screen |
|
158 blog = new RssReader(blogFeedName, blogFeedUrl, null, home, null); |
|
159 |
|
160 // create wiki screen |
|
161 wiki = new RssReader(wikiFeedName, wikiFeedUrl, new ButtonFeedPresenter(null), home, null); |
|
162 |
|
163 // wiki feed contains full article text for many articles |
|
164 // this takes up a _lot_ of memory. Also we don't |
|
165 // really want the full text at the stage when we want a list |
|
166 // of recent articles. |
|
167 wiki.ignoreContent = true; |
|
168 |
|
169 wiki.maxItems = 20; |
|
170 |
|
171 bugzilla = new BugzillaSearchPanel(home); |
|
172 |
|
173 // create the top level forums screen - list of forum groups |
|
174 // forumsGroup, forum and thread screens are dynamically generated by forumGroups |
|
175 forumGroups = new RssReader("Forums", forumGroupsUrl, new ForumGroupsFeedPresenter(null), home, forumGroupsResponseParser); |
|
176 |
|
177 // create settings view |
|
178 settings = new ListView(null, createCaption("Settings")); |
|
179 settings.previousView = home; |
|
180 |
|
181 var settingsIntroLabel = new Label(null, null, |
|
182 "In order to access all site features, you must login. " |
|
183 + "If you have not registered yet, please click the 'Register' button below."); |
|
184 |
|
185 settings.addControl(settingsIntroLabel); |
|
186 // forum username control |
|
187 forumUsernameControl = new TextField('forumUsername', "Symbian.org username", forumUsername?forumUsername:""); |
|
188 settings.addControl(forumUsernameControl); |
|
189 |
|
190 // forum password control |
|
191 forumPasswordControl = new TextField('forumPassword', "Symbian.org password", forumPassword?forumPassword:"", true); |
|
192 settings.addControl(forumPasswordControl); |
|
193 |
|
194 // save settings button |
|
195 settingsSaveButton = new FormButton(null, "Save"); |
|
196 settingsSaveButton.addEventListener("ActionPerformed", saveSettingsClicked); |
|
197 settings.addControl(settingsSaveButton); |
|
198 |
|
199 |
|
200 // cancel settings button |
|
201 var settingsRegisterButton = new FormButton(null, "Register"); |
|
202 settingsRegisterButton.addEventListener("ActionPerformed", function(){openURL(registrationURL);}); |
|
203 settings.addControl(settingsRegisterButton); |
|
204 |
|
205 // cancel settings button |
|
206 settingsCancelButton = new FormButton(null, "Cancel"); |
|
207 settingsCancelButton.addEventListener("ActionPerformed", function(){settings.goBack();}); |
|
208 settings.addControl(settingsCancelButton); |
|
209 |
|
210 //Create about view |
|
211 about = new ListView(null, createCaption("Symbian.org")); |
|
212 about.previousView = home; |
|
213 // About label control |
|
214 aboutLabel = new ContentPanel(null, null, null, true); |
|
215 aboutLabel.setCaption("About this Widget"); |
|
216 aboutLabel.setContent(aboutText); |
|
217 aboutLabel.setExpanded(true); |
|
218 about.addControl(aboutLabel); |
|
219 |
|
220 home.show(); |
|
221 login(null); |
|
222 } |
|
223 |
|
224 // Callback for when menu items are selected. |
|
225 function menuItemSelected(id) { |
|
226 var currentView = uiManager.getView(); |
|
227 switch (id) { |
|
228 case MENU_ITEM_SETTINGS: |
|
229 if ( currentView == settings || currentView == about) { |
|
230 settings.previousView = home; |
|
231 } else { |
|
232 settings.previousView = currentView; |
|
233 } |
|
234 uiManager.hideNotification(); |
|
235 settings.show(); |
|
236 break; |
|
237 case MENU_ITEM_REFRESH: |
|
238 currentView.update(true); |
|
239 break; |
|
240 case MENU_ITEM_CHECK_UPDATE: |
|
241 checkForUpdates(); |
|
242 break; |
|
243 case MENU_ITEM_ABOUT: |
|
244 if ( currentView == settings || currentView == about) { |
|
245 about.previousView = home; |
|
246 } else { |
|
247 about.previousView = currentView; |
|
248 } |
|
249 about.show(); |
|
250 break; |
|
251 } |
|
252 } |
|
253 |
|
254 // Loads widget preferences. |
|
255 function loadPreferences() { |
|
256 if (window.widget) { |
|
257 // load settings from widget preferences store |
|
258 forumUsername = widget.preferenceForKey("forumUsername"); |
|
259 forumPassword = widget.preferenceForKey("forumPassword"); |
|
260 } |
|
261 } |
|
262 |
|
263 // Loads widget preferences. |
|
264 function savePreferences() { |
|
265 if (window.widget) { |
|
266 // save settings in widget preferences store |
|
267 widget.setPreferenceForKey(forumUsername, "forumUsername"); |
|
268 widget.setPreferenceForKey(forumPassword, "forumPassword"); |
|
269 } |
|
270 } |
|
271 |
|
272 // Callback for settings view save button. |
|
273 function saveSettingsClicked() { |
|
274 forumUsername = forumUsernameControl.getText(); |
|
275 forumPassword = forumPasswordControl.getText(); |
|
276 |
|
277 // save preferences |
|
278 savePreferences(); |
|
279 |
|
280 settings.goBack(); |
|
281 |
|
282 if ( loginInitiated ) { |
|
283 login(loginInitiatedCallback); |
|
284 } |
|
285 } |
|
286 |
|
287 // Opens a URL in a separate browser window |
|
288 function openURL(url) { |
|
289 if (window.widget) { |
|
290 // in WRT |
|
291 widget.openURL(url); |
|
292 } else { |
|
293 // outside WRT |
|
294 window.open(url, "NewWindow"); |
|
295 } |
|
296 } |
|
297 |
|
298 var updatePageAjax = null; |
|
299 |
|
300 function checkForUpdates() { |
|
301 uiManager.showNotification(-1, "wait", "Checking for updates...", -1); |
|
302 updatePageAjax = new Ajax(); |
|
303 updatePageAjax.onreadystatechange = checkForUpdatesStage2; |
|
304 updatePageAjax.open('GET', versionWikiPageUrl, true); |
|
305 updatePageAjax.send(null); |
|
306 } |
|
307 |
|
308 function checkForUpdatesStage2() { |
|
309 if (updatePageAjax.readyState == 4) { |
|
310 // extract version number |
|
311 var content = updatePageAjax.responseText; |
|
312 var ind = content.indexOf(versionWikiPageString); |
|
313 if ( ind == -1 ) { |
|
314 uiManager.showNotification(3000, "warning", "Update failed, check manually."); |
|
315 return; |
|
316 } |
|
317 ind += versionWikiPageString.length; |
|
318 var ind2 = content.indexOf("]",ind); |
|
319 if ( ind2 == -1 || (ind2-ind) > 10 ) { |
|
320 uiManager.showNotification(3000, "warning", "Update failed, check manually."); |
|
321 return; |
|
322 } |
|
323 var version = content.substring(ind,ind2); |
|
324 // compare to this version |
|
325 if ( version != myversion ) { |
|
326 var answer = confirm("Install new version " + version + "?"); |
|
327 if (answer) { |
|
328 // ok, we have the update |
|
329 uiManager.hideNotification(); |
|
330 openURL(downloadUrl); |
|
331 } else { |
|
332 uiManager.showNotification(3000, "info", "Update cancelled."); |
|
333 } |
|
334 } else { |
|
335 uiManager.showNotification(3000, "info", "Up to date!"); |
|
336 } |
|
337 } |
|
338 } |
|
339 |
|
340 function createCaption(caption) { |
|
341 if (caption.length > 30) { |
|
342 caption = caption.substring(0, 30) + "..."; |
|
343 } |
|
344 return "<table border=0>" |
|
345 + "<tr><td><img src=titlebar.png style=\"{vertical-align:middle}\" > </td></td><td>" |
|
346 + "<p class=ListViewCaptionText>"+ caption +"</p>" |
|
347 + "</td></tr></table>"; |
|
348 } |