]>
Commit | Line | Data |
---|---|---|
71af6d36 | 1 | var SCHEMA_VERSION = 10; |
b871dd06 | 2 | |
25d99353 AD |
3 | var offline_mode = false; |
4 | var store = false; | |
5 | var localServer = false; | |
6 | var db = false; | |
79e565a9 AD |
7 | var articles_synced = 0; |
8 | var sync_in_progress = false; | |
206d4967 | 9 | var sync_timer = false; |
25d99353 | 10 | |
4681834e AD |
11 | function view_offline(id, feed_id) { |
12 | try { | |
13 | ||
14 | enableHotkeys(); | |
15 | showArticleInHeadlines(id); | |
16 | ||
1b27261c AD |
17 | db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]); |
18 | ||
19 | var rs = db.execute("SELECT * FROM articles WHERE id = ?", [id]); | |
20 | ||
21 | if (rs.isValidRow()) { | |
22 | ||
23 | var tmp = "<div class=\"postReply\">"; | |
24 | ||
25 | tmp += "<div class=\"postHeader\" onmouseover=\"enable_resize(true)\" "+ | |
26 | "onmouseout=\"enable_resize(false)\">"; | |
27 | ||
28 | tmp += "<div class=\"postDate\">"+rs.fieldByName("updated")+"</div>"; | |
29 | ||
30 | if (rs.fieldByName("link") != "") { | |
31 | tmp += "<div clear='both'><a target=\"_blank\" "+ | |
32 | "href=\"" + rs.fieldByName("link") + "\">" + | |
33 | rs.fieldByName("title") + "</a></div>"; | |
34 | } else { | |
35 | tmp += "<div clear='both'>" + rs.fieldByName("title") + "</div>"; | |
36 | } | |
4681834e | 37 | |
3ab18266 | 38 | /* tmp += "<div style='float : right'> "+ |
1b27261c AD |
39 | "<img src='images/tag.png' class='tagsPic' alt='Tags' title='Tags'>"; |
40 | tmp += rs.fieldByName("tags"); | |
3ab18266 | 41 | tmp += "</div>"; */ |
1b27261c | 42 | |
424fc145 | 43 | /* tmp += "<div clear='both'>"+ |
12aa4007 AD |
44 | "<a target=\"_blank\" "+ |
45 | "href=\"" + rs.fieldByName("comments") + "\">" + | |
424fc145 | 46 | __("comments") + "</a></div>"; */ |
1b27261c AD |
47 | |
48 | tmp += "</div>"; | |
49 | ||
50 | tmp += "<div class=\"postContent\">" | |
51 | tmp += rs.fieldByName("content"); | |
52 | tmp += "</div>"; | |
53 | ||
54 | tmp += "</div>"; | |
55 | ||
56 | render_article(tmp); | |
57 | update_local_feedlist_counters(); | |
58 | } | |
4681834e | 59 | |
03c96380 AD |
60 | rs.close(); |
61 | ||
4681834e AD |
62 | return false; |
63 | ||
64 | } catch (e) { | |
65 | exception_error("view_offline", e); | |
66 | } | |
67 | } | |
68 | ||
69 | function viewfeed_offline(feed_id, subop, is_cat, subop_param, skip_history, offset) { | |
70 | try { | |
71 | notify(''); | |
72 | ||
73 | if (!offset) offset = 0; | |
74 | ||
0e923da4 AD |
75 | if (offset > 0) { |
76 | _feed_cur_page = parseInt(offset); | |
77 | if (_infscroll_request_sent) { | |
78 | return; | |
79 | } | |
80 | } else { | |
81 | _feed_cur_page = 0; | |
82 | _infscroll_disable = 0; | |
83 | } | |
84 | ||
85 | if (getActiveFeedId() != feed_id) { | |
86 | _feed_cur_page = 0; | |
87 | active_post_id = 0; | |
88 | _infscroll_disable = 0; | |
89 | } | |
90 | ||
4681834e AD |
91 | loading_set_progress(100); |
92 | ||
93 | clean_feed_selections(); | |
94 | ||
95 | setActiveFeedId(feed_id, is_cat); | |
96 | ||
97 | if (!is_cat) { | |
acac8448 | 98 | var feedr = $("FEEDR-" + feed_id); |
4681834e AD |
99 | if (feedr && !feedr.className.match("Selected")) { |
100 | feedr.className = feedr.className + "Selected"; | |
101 | } | |
102 | } else { | |
acac8448 | 103 | var feedr = $("FCAT-" + feed_id); |
4681834e AD |
104 | if (feedr && !feedr.className.match("Selected")) { |
105 | feedr.className = feedr.className + "Selected"; | |
106 | } | |
107 | } | |
108 | ||
67625745 AD |
109 | if (subop == "MarkAllRead") { |
110 | catchup_local_feed(feed_id, is_cat); | |
111 | } | |
112 | ||
4681834e AD |
113 | disableContainerChildren("headlinesToolbar", false); |
114 | Form.enable("main_toolbar_form"); | |
115 | ||
acac8448 | 116 | var f = $("headlines-frame"); |
4681834e AD |
117 | try { |
118 | if (reply.offset == 0) { | |
119 | debug("resetting headlines scrollTop"); | |
120 | f.scrollTop = 0; | |
121 | } | |
122 | } catch (e) { }; | |
123 | ||
124 | ||
4681834e | 125 | var tmp = ""; |
046a2e3c | 126 | var feed_title = ""; |
4681834e | 127 | |
046a2e3c AD |
128 | if (is_cat) { |
129 | feed_title = get_local_category_title(feed_id); | |
130 | } else { | |
131 | feed_title = get_local_feed_title(feed_id); | |
132 | } | |
4681834e | 133 | |
88a66534 | 134 | if (feed_title) { |
4681834e AD |
135 | |
136 | if (offset == 0) { | |
137 | tmp += "<div id=\"headlinesContainer\">"; | |
138 | ||
139 | tmp += "<div class=\"headlinesSubToolbar\">"; | |
140 | tmp += "<div id=\"subtoolbar_ftitle\">"; | |
141 | tmp += feed_title; | |
142 | tmp += "</div>"; | |
143 | ||
779ba075 AD |
144 | var sel_all_link; |
145 | var sel_unread_link; | |
146 | var sel_none_link; | |
147 | var sel_inv_link; | |
148 | ||
acac8448 | 149 | if ($("content-frame")) { |
779ba075 AD |
150 | sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)"; |
151 | sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)"; | |
152 | sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)"; | |
153 | sel_inv_link = "javascript:invertHeadlineSelection()"; | |
154 | } else { | |
155 | sel_all_link = "javascript:cdmSelectArticles('all')"; | |
156 | sel_unread_link = "javascript:cdmSelectArticles('unread')"; | |
157 | sel_none_link = "javascript:cdmSelectArticles('none')"; | |
158 | sel_inv_link = "javascript:invertHeadlineSelection()"; | |
159 | } | |
4681834e AD |
160 | |
161 | tmp += __('Select:')+ | |
162 | " <a href=\""+sel_all_link+"\">"+__('All')+"</a>, "+ | |
163 | "<a href=\""+sel_unread_link+"\">"+__('Unread')+"</a>, "+ | |
164 | "<a href=\""+sel_inv_link+"\">"+__('Invert')+"</a>, "+ | |
165 | "<a href=\""+sel_none_link+"\">"+__('None')+"</a>"; | |
166 | ||
167 | tmp += " "; | |
168 | ||
169 | tmp += "</div>"; | |
170 | ||
171 | tmp += "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">"; | |
acac8448 | 172 | if ($("content-frame")) { |
779ba075 AD |
173 | tmp += "<table class=\"headlinesList\" id=\"headlinesList\" cellspacing=\"0\">"; |
174 | } | |
4681834e AD |
175 | |
176 | } | |
177 | ||
4681834e AD |
178 | var limit = 30; |
179 | ||
180 | var toolbar_form = document.forms["main_toolbar_form"]; | |
181 | ||
182 | var limit = toolbar_form.limit[toolbar_form.limit.selectedIndex].value; | |
183 | var view_mode = toolbar_form.view_mode[toolbar_form.view_mode.selectedIndex].value; | |
184 | ||
185 | var limit_qpart = ""; | |
186 | var strategy_qpart = ""; | |
187 | var mode_qpart = ""; | |
e491d06d | 188 | var offset_qpart = ""; |
4681834e AD |
189 | |
190 | if (limit != 0) { | |
191 | limit_qpart = "LIMIT " + limit; | |
192 | } | |
193 | ||
194 | if (view_mode == "all_articles") { | |
195 | mode_qpart = "1"; | |
196 | } else if (view_mode == "adaptive") { | |
046a2e3c AD |
197 | if (is_cat && get_local_category_unread(feed_id) || |
198 | get_local_feed_unread(feed_id) > 0) { | |
199 | mode_qpart = "unread = 1"; | |
4681834e AD |
200 | } else { |
201 | mode_qpart = "1"; | |
202 | } | |
046a2e3c | 203 | |
4681834e AD |
204 | } else if (view_mode == "marked") { |
205 | mode_qpart = "marked = 1"; | |
206 | } else if (view_mode == "unread") { | |
207 | mode_qpart = "unread = 1"; | |
208 | } else { | |
209 | mode_qpart = "1"; | |
210 | } | |
211 | ||
79645416 AD |
212 | var ext_tables_qpart = ""; |
213 | ||
046a2e3c AD |
214 | if (is_cat) { |
215 | if (feed_id >= 0) { | |
216 | strategy_qpart = "cat_id = " + feed_id; | |
217 | } else if (feed_id == -2) { | |
218 | strategy_qpart = "article_labels.id = articles.id"; | |
219 | ext_tables_qpart = ",article_labels"; | |
220 | } | |
221 | } else if (feed_id > 0) { | |
4681834e AD |
222 | strategy_qpart = "feed_id = " + feed_id; |
223 | } else if (feed_id == -1) { | |
224 | strategy_qpart = "marked = 1"; | |
225 | } else if (feed_id == -4) { | |
226 | strategy_qpart = "1"; | |
88a66534 AD |
227 | } else if (feed_id < -10) { |
228 | var label_id = -11 - feed_id; | |
79645416 AD |
229 | strategy_qpart = "article_labels.id = articles.id AND label_id = " + label_id; |
230 | ext_tables_qpart = ",article_labels"; | |
e491d06d AD |
231 | } |
232 | ||
233 | if (offset > 0) { | |
234 | offset_qpart = "OFFSET " + (offset*30); | |
235 | } else { | |
236 | offset_qpart = ""; | |
237 | } | |
4681834e | 238 | |
851ce414 | 239 | var query = "SELECT *,feeds.title AS feed_title "+ |
046a2e3c | 240 | "FROM articles,feeds,categories"+ext_tables_qpart+" "+ |
79645416 | 241 | "WHERE " + |
046a2e3c | 242 | "cat_id = categories.id AND " + |
851ce414 | 243 | "feed_id = feeds.id AND " + |
4681834e AD |
244 | strategy_qpart + |
245 | " AND " + mode_qpart + | |
246 | " ORDER BY updated DESC "+ | |
e491d06d AD |
247 | limit_qpart + " " + |
248 | offset_qpart; | |
4681834e AD |
249 | |
250 | var rs = db.execute(query); | |
251 | ||
e491d06d | 252 | var line_num = offset*30; |
4681834e | 253 | |
851ce414 AD |
254 | var real_feed_id = feed_id; |
255 | ||
4681834e AD |
256 | while (rs.isValidRow()) { |
257 | ||
258 | var id = rs.fieldByName("id"); | |
259 | var feed_id = rs.fieldByName("feed_id"); | |
260 | ||
851ce414 AD |
261 | var entry_feed_title = false; |
262 | ||
046a2e3c | 263 | if (real_feed_id < 0 || is_cat) { |
851ce414 AD |
264 | entry_feed_title = rs.fieldByName("feed_title"); |
265 | } | |
266 | ||
4681834e AD |
267 | var marked_pic; |
268 | ||
269 | var row_class = (line_num % 2) ? "even" : "odd"; | |
270 | ||
271 | if (rs.fieldByName("unread") == "1") { | |
272 | row_class += "Unread"; | |
273 | } | |
6da82466 AD |
274 | |
275 | var labels = get_local_article_labels(id); | |
276 | ||
6da82466 AD |
277 | var labels_str = "<span id=\"HLLCTR-"+id+"\">"; |
278 | labels_str += format_article_labels(labels, id); | |
279 | labels_str += "</span>"; | |
280 | ||
4681834e AD |
281 | if (rs.fieldByName("marked") == "1") { |
282 | marked_pic = "<img id=\"FMPIC-"+id+"\" "+ | |
283 | "src=\"images/mark_set.png\" class=\"markedPic\""+ | |
284 | "alt=\"Unstar article\" onclick='javascript:tMark("+id+")'>"; | |
285 | } else { | |
286 | marked_pic = "<img id=\"FMPIC-"+id+"\" "+ | |
287 | "src=\"images/mark_unset.png\" class=\"markedPic\""+ | |
288 | "alt=\"Star article\" onclick='javascript:tMark("+id+")'>"; | |
289 | } | |
290 | ||
291 | var mouseover_attrs = "onmouseover='postMouseIn($id)' "+ | |
292 | "onmouseout='postMouseOut($id)'"; | |
779ba075 AD |
293 | |
294 | var content_preview = truncate_string(strip_tags(rs.fieldByName("content")), | |
295 | 100); | |
4681834e | 296 | |
acac8448 | 297 | if ($("content-frame")) { |
4681834e | 298 | |
779ba075 AD |
299 | tmp += "<tr class='"+row_class+"' id='RROW-"+id+"' "+mouseover_attrs+">"; |
300 | ||
301 | tmp += "<td class='hlUpdPic'> </td>"; | |
4681834e | 302 | |
779ba075 AD |
303 | tmp += "<td class='hlSelectRow'>"+ |
304 | "<input type=\"checkbox\" onclick=\"tSR(this)\" id=\"RCHK-"+id+"\"></td>"; | |
305 | ||
306 | tmp += "<td class='hlMarkedPic'>"+marked_pic+"</td>"; | |
307 | ||
308 | tmp += "<td onclick='view("+id+","+feed_id+")' "+ | |
309 | "class='hlContent' valign='middle'>"; | |
310 | ||
851ce414 | 311 | tmp += "<a target=\"_blank\" id=\"RTITLE-"+id+"\" href=\"" + |
779ba075 AD |
312 | rs.fieldByName("link") + "\"" + |
313 | "onclick=\"return view("+id+","+feed_id+");\">"+ | |
314 | rs.fieldByName("title"); | |
4681834e | 315 | |
779ba075 AD |
316 | tmp += "<span class=\"contentPreview\"> - "+content_preview+"</span>"; |
317 | ||
318 | tmp += "</a>"; | |
851ce414 | 319 | |
6da82466 AD |
320 | tmp += labels_str; |
321 | ||
851ce414 AD |
322 | if (entry_feed_title) { |
323 | tmp += " <span class=\"hlFeed\">"+ | |
324 | "(<a href='javascript:viewfeed("+feed_id+ | |
325 | ")'>"+entry_feed_title+"</a>)</span>"; | |
326 | } | |
327 | ||
779ba075 | 328 | tmp += "</td>"; |
d07f08e8 | 329 | |
779ba075 | 330 | tmp += "<td class=\"hlUpdated\" onclick='view("+id+","+feed_id+")'>"+ |
d07f08e8 AD |
331 | "<nobr>"+rs.fieldByName("updated").substring(0,16)+ |
332 | "</nobr></td>"; | |
779ba075 AD |
333 | |
334 | tmp += "</tr>"; | |
335 | } else { | |
4681834e | 336 | |
779ba075 AD |
337 | var add_class = ""; |
338 | ||
339 | if (rs.fieldByName("unread") == "1") { | |
340 | add_class = "Unread"; | |
341 | } | |
342 | ||
343 | tmp += "<div class=\"cdmArticle"+add_class+"\" id=\"RROW-"+id+"\" "+ | |
344 | mouseover_attrs+"'>"; | |
345 | ||
d07f08e8 AD |
346 | feed_icon_img = "<img class=\"tinyFeedIcon\" src=\""+ |
347 | getInitParam("icons_url")+"/"+feed_id+".ico\" alt=\"\">"; | |
348 | cdm_feed_icon = "<span style=\"cursor : pointer\" "+ | |
349 | "onclick=\"viewfeed("+feed_id+")\">"+feed_icon_img+"</span>"; | |
350 | ||
779ba075 AD |
351 | tmp += "<div class=\"cdmHeader\">"; |
352 | tmp += "<div class=\"articleUpdated\">"+ | |
d07f08e8 AD |
353 | rs.fieldByName("updated").substring(0,16)+ |
354 | " "+cdm_feed_icon+"</div>"; | |
779ba075 AD |
355 | |
356 | tmp += "<span id=\"RTITLE-"+id+"\" class=\"titleWrap\">"+ | |
357 | "<a class=\"title\" onclick=\"javascript:toggleUnread("+id+", 0)\""+ | |
358 | "target=\"_blank\" href=\""+rs.fieldByName("link")+ | |
359 | "\">"+rs.fieldByName("title")+"</a>"; | |
851ce414 | 360 | |
6da82466 AD |
361 | tmp += labels_str; |
362 | ||
851ce414 AD |
363 | if (entry_feed_title) { |
364 | tmp += " (<a href='javascript:viewfeed("+feed_id+ | |
365 | ")'>"+entry_feed_title+"</a>)"; | |
366 | } | |
367 | ||
779ba075 AD |
368 | tmp += "</span></div>"; |
369 | ||
370 | tmp += "<div class=\"cdmContent\" onclick=\"cdmClicked("+id+")\""+ | |
371 | "id=\"CICD-"+id+"\">"; | |
372 | tmp += rs.fieldByName("content"); | |
373 | tmp += "<br clear='both'>" | |
374 | tmp += "</div>"; | |
375 | ||
376 | tmp += "<div class=\"cdmFooter\"><span class='s0'>"; | |
377 | tmp += __("Select:")+ | |
378 | " <input type=\"checkbox\" "+ | |
379 | "onclick=\"toggleSelectRowById(this, 'RROW-"+id+"')\" "+ | |
380 | "class=\"feedCheckBox\" id=\"RCHK-"+id+"\">"; | |
381 | ||
382 | tmp += "</span><span class='s1'>"+marked_pic+"</span> "; | |
383 | ||
3ab18266 | 384 | /* tmp += "<span class='s1'>"+ |
779ba075 AD |
385 | "<img class='tagsPic' src='images/tag.png' alt='Tags' title='Tags'>"+ |
386 | "<span id=\"ATSTR-"+id+"\">"+rs.fieldByName("tags")+"</span>"+ | |
3ab18266 | 387 | "</span>"; */ |
779ba075 AD |
388 | |
389 | tmp += "<span class='s2'>Toggle: <a class=\"cdmToggleLink\""+ | |
390 | "href=\"javascript:toggleUnread("+id+")\">"+ | |
391 | "Unread</a></span>"; | |
392 | tmp += "</div>"; | |
393 | ||
394 | tmp += "</div>"; | |
395 | } | |
4681834e AD |
396 | |
397 | rs.next(); | |
398 | line_num++; | |
399 | } | |
03c96380 | 400 | |
0e923da4 AD |
401 | if (line_num - offset*30 < 30) { |
402 | _infscroll_disable = 1; | |
403 | } | |
404 | ||
03c96380 | 405 | rs.close(); |
4681834e AD |
406 | |
407 | if (offset == 0) { | |
408 | tmp += "</table>"; | |
76d20f5f AD |
409 | |
410 | if (line_num - offset*30 == 0) { | |
411 | tmp += "<div class='whiteBox'>" + | |
412 | __("No articles found to display.") + | |
413 | "</div>"; | |
414 | } | |
4681834e AD |
415 | tmp += "</div></div>"; |
416 | } | |
417 | ||
418 | if (offset == 0) { | |
acac8448 | 419 | var container = $("headlines-frame"); |
4681834e AD |
420 | container.innerHTML = tmp; |
421 | } else { | |
422 | var ids = getSelectedArticleIds2(); | |
423 | ||
acac8448 | 424 | var container = $("headlinesList"); |
e491d06d | 425 | container.innerHTML = container.innerHTML + tmp; |
4681834e AD |
426 | |
427 | for (var i = 0; i < ids.length; i++) { | |
428 | markHeadline(ids[i]); | |
429 | } | |
430 | } | |
431 | } | |
432 | ||
433 | remove_splash(); | |
434 | ||
0e923da4 | 435 | _infscroll_request_sent = 0; |
4681834e AD |
436 | |
437 | } catch (e) { | |
438 | exception_error("viewfeed_offline", e); | |
439 | } | |
440 | } | |
441 | ||
442 | function render_offline_feedlist() { | |
443 | try { | |
1c980681 | 444 | var cats_enabled = getInitParam("enable_feed_cats") == "1"; |
d6416405 | 445 | |
4681834e AD |
446 | var tmp = "<ul class=\"feedList\" id=\"feedList\">"; |
447 | ||
448 | var unread = get_local_feed_unread(-4); | |
449 | ||
450 | global_unread = unread; | |
451 | updateTitle(); | |
452 | ||
d6416405 | 453 | if (cats_enabled) { |
c2726c96 | 454 | tmp += printCategoryHeader(-1, is_local_cat_collapsed(-1), false); |
d6416405 AD |
455 | } |
456 | ||
4681834e AD |
457 | tmp += printFeedEntry(-4, __("All articles"), "feed", unread, |
458 | "images/tag.png"); | |
459 | ||
460 | var unread = get_local_feed_unread(-1); | |
461 | ||
462 | tmp += printFeedEntry(-1, __("Starred articles"), "feed", unread, | |
463 | "images/mark_set.png"); | |
464 | ||
d6416405 AD |
465 | if (cats_enabled) { |
466 | tmp += "</ul></li>"; | |
467 | } else { | |
468 | tmp += "<li><hr/></li>"; | |
469 | } | |
4681834e | 470 | |
c2726c96 AD |
471 | if (cats_enabled) { |
472 | tmp += printCategoryHeader(-2, is_local_cat_collapsed(-2), false); | |
473 | } | |
474 | ||
475 | var rs = db.execute("SELECT id,caption "+ | |
476 | "FROM labels "+ | |
477 | "ORDER BY caption"); | |
478 | ||
479 | while (rs.isValidRow()) { | |
480 | var id = -11 - parseInt(rs.field(0)); | |
481 | var caption = rs.field(1); | |
482 | var unread = get_local_feed_unread(id); | |
483 | ||
484 | tmp += printFeedEntry(id, caption, "feed", unread, | |
485 | "images/label.png"); | |
486 | ||
487 | rs.next(); | |
488 | } | |
489 | ||
490 | rs.close(); | |
491 | ||
492 | if (cats_enabled) { | |
493 | tmp += "</ul></li>"; | |
494 | } else { | |
495 | tmp += "<li><hr/></li>"; | |
496 | } | |
497 | ||
f4c11347 | 498 | /* var rs = db.execute("SELECT feeds.id,feeds.title,has_icon,COUNT(articles.id) "+ |
4681834e AD |
499 | "FROM feeds LEFT JOIN articles ON (feed_id = feeds.id) "+ |
500 | "WHERE unread = 1 OR unread IS NULL GROUP BY feeds.id "+ | |
f4c11347 AD |
501 | "ORDER BY feeds.title"); */ |
502 | ||
d6416405 AD |
503 | var order_by = "feeds.title"; |
504 | ||
505 | if (cats_enabled) order_by = "categories.title," + order_by; | |
506 | ||
507 | var rs = db.execute("SELECT "+ | |
508 | "feeds.id,feeds.title,has_icon,cat_id,collapsed "+ | |
509 | "FROM feeds,categories WHERE cat_id = categories.id "+ | |
510 | "ORDER BY "+order_by); | |
511 | ||
512 | var tmp_cat_id = -1; | |
4681834e AD |
513 | |
514 | while (rs.isValidRow()) { | |
515 | ||
516 | var id = rs.field(0); | |
517 | var title = rs.field(1); | |
518 | var has_icon = rs.field(2); | |
f4c11347 | 519 | var unread = get_local_feed_unread(id); |
d6416405 AD |
520 | var cat_id = rs.field(3); |
521 | var cat_hidden = rs.field(4); | |
522 | ||
523 | if (cat_id != tmp_cat_id && cats_enabled) { | |
524 | if (tmp_cat_id != -1) { | |
525 | tmp += "</ul></li>"; | |
526 | } | |
046a2e3c | 527 | tmp += printCategoryHeader(cat_id, cat_hidden, true); |
d6416405 AD |
528 | tmp_cat_id = cat_id; |
529 | } | |
4681834e AD |
530 | |
531 | var icon = ""; | |
532 | ||
533 | if (has_icon) { | |
046a2e3c | 534 | icon = getInitParam("icons_url") + "/" + id + ".ico"; |
4681834e AD |
535 | } |
536 | ||
4681834e AD |
537 | var feed_icon = ""; |
538 | ||
539 | var row_class = "feed"; | |
540 | ||
541 | if (unread > 0) { | |
542 | row_class += "Unread"; | |
543 | fctr_class = "feedCtrHasUnread"; | |
544 | } else { | |
545 | fctr_class = "feedCtrNoUnread"; | |
546 | } | |
547 | ||
548 | tmp += printFeedEntry(id, title, "feed", unread, icon); | |
549 | ||
550 | rs.next(); | |
551 | } | |
552 | ||
03c96380 AD |
553 | rs.close(); |
554 | ||
983a6a9c AD |
555 | if (cats_enabled) { |
556 | tmp += "</ul>"; | |
557 | } | |
558 | ||
4681834e AD |
559 | tmp += "</ul>"; |
560 | ||
561 | render_feedlist(tmp); | |
562 | } catch (e) { | |
563 | exception_error("render_offline_feedlist", e); | |
564 | } | |
565 | } | |
566 | ||
567 | function init_offline() { | |
568 | try { | |
569 | offline_mode = true; | |
9ca945a6 | 570 | store.enabled = true; |
4681834e AD |
571 | |
572 | Element.hide("dispSwitchPrompt"); | |
573 | Element.hide("feedBrowserPrompt"); | |
4681834e | 574 | |
69ea0cdd AD |
575 | Element.hide("topLinksOnline"); |
576 | Element.show("topLinksOffline"); | |
577 | ||
acac8448 | 578 | var tb_form = $("main_toolbar_form"); |
80b1c238 AD |
579 | Element.hide(tb_form.update); |
580 | ||
acac8448 | 581 | var chooser = $("quickMenuChooser"); |
3c6d3586 AD |
582 | chooser.disabled = true; |
583 | ||
3034277a AD |
584 | var rs = db.execute("SELECT key, value FROM init_params"); |
585 | ||
586 | while (rs.isValidRow()) { | |
587 | init_params[rs.field(0)] = rs.field(1); | |
588 | rs.next(); | |
589 | } | |
590 | ||
591 | rs.close(); | |
4681834e | 592 | |
b15e516e AD |
593 | var rs = db.execute("SELECT COUNT(*) FROM feeds"); |
594 | ||
595 | var num_feeds = 0; | |
596 | ||
597 | if (rs.isValidRow()) { | |
598 | num_feeds = rs.field(0); | |
599 | } | |
600 | ||
601 | rs.close(); | |
602 | ||
603 | if (num_feeds == 0) { | |
604 | remove_splash(); | |
605 | return fatalError(0, | |
606 | __("Data for offline browsing has not been downloaded yet.")); | |
607 | } | |
608 | ||
4681834e | 609 | render_offline_feedlist(); |
10003c4c | 610 | init_second_stage(); |
b15e516e AD |
611 | window.setTimeout("viewfeed(-4)", 50); |
612 | ||
4681834e AD |
613 | } catch (e) { |
614 | exception_error("init_offline", e); | |
615 | } | |
616 | } | |
617 | ||
618 | function offline_download_parse(stage, transport) { | |
619 | try { | |
620 | if (transport.responseXML) { | |
621 | ||
206d4967 AD |
622 | if (!sync_in_progress) return; |
623 | ||
badac687 AD |
624 | var sync_ok = transport.responseXML.getElementsByTagName("sync-ok"); |
625 | ||
626 | if (sync_ok.length > 0) { | |
627 | for (var i = 0; i < sync_ok.length; i++) { | |
628 | var id = sync_ok[i].getAttribute("id"); | |
629 | if (id) { | |
630 | debug("synced offline info for id " + id); | |
631 | db.execute("UPDATE articles SET modified = '' WHERE id = ?", [id]); | |
632 | } | |
633 | } | |
634 | } | |
635 | ||
4681834e AD |
636 | if (stage == 0) { |
637 | ||
8ca1a0ac AD |
638 | $("offlineModeSyncMsg").innerHTML = __("Synchronizing feeds..."); |
639 | ||
4681834e AD |
640 | var feeds = transport.responseXML.getElementsByTagName("feed"); |
641 | ||
642 | if (feeds.length > 0) { | |
643 | db.execute("DELETE FROM feeds"); | |
644 | } | |
645 | ||
646 | for (var i = 0; i < feeds.length; i++) { | |
647 | var id = feeds[i].getAttribute("id"); | |
648 | var has_icon = feeds[i].getAttribute("has_icon"); | |
649 | var title = feeds[i].firstChild.nodeValue; | |
d8781c91 AD |
650 | var cat_id = feeds[i].getAttribute("cat_id"); |
651 | ||
652 | db.execute("INSERT INTO feeds (id,title,has_icon,cat_id)"+ | |
75aa83ec | 653 | "VALUES (?,?,?,?)", |
d8781c91 | 654 | [id, title, has_icon, cat_id]); |
4681834e | 655 | } |
75aa83ec | 656 | |
8ca1a0ac AD |
657 | $("offlineModeSyncMsg").innerHTML = __("Synchronizing categories..."); |
658 | ||
75aa83ec AD |
659 | var cats = transport.responseXML.getElementsByTagName("category"); |
660 | ||
661 | if (feeds.length > 0) { | |
662 | db.execute("DELETE FROM categories"); | |
663 | } | |
664 | ||
665 | for (var i = 0; i < cats.length; i++) { | |
666 | var id = cats[i].getAttribute("id"); | |
667 | var collapsed = cats[i].getAttribute("collapsed"); | |
668 | var title = cats[i].firstChild.nodeValue; | |
669 | ||
670 | db.execute("INSERT INTO categories (id,title,collapsed)"+ | |
671 | "VALUES (?,?,?)", | |
672 | [id, title, collapsed]); | |
673 | } | |
674 | ||
8ca1a0ac AD |
675 | $("offlineModeSyncMsg").innerHTML = __("Synchronizing labels..."); |
676 | ||
ed22888b AD |
677 | var labels = transport.responseXML.getElementsByTagName("label"); |
678 | ||
679 | if (labels.length > 0) { | |
680 | db.execute("DELETE FROM labels"); | |
681 | } | |
682 | ||
683 | for (var i = 0; i < labels.length; i++) { | |
684 | var id = labels[i].getAttribute("id"); | |
685 | var fg_color = labels[i].getAttribute("fg_color"); | |
686 | var bg_color = labels[i].getAttribute("bg_color"); | |
687 | var caption = labels[i].firstChild.nodeValue; | |
688 | ||
689 | db.execute("INSERT INTO labels (id,caption,fg_color,bg_color)"+ | |
690 | "VALUES (?,?,?,?)", | |
691 | [id, caption, fg_color, bg_color]); | |
692 | } | |
693 | ||
8ca1a0ac AD |
694 | $("offlineModeSyncMsg").innerHTML = __("Synchronizing articles..."); |
695 | ||
696 | sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")", 2*1000); | |
4681834e AD |
697 | } else { |
698 | ||
699 | var articles = transport.responseXML.getElementsByTagName("article"); | |
700 | ||
3e52ab08 AD |
701 | var limit = transport.responseXML.getElementsByTagName("limit")[0]; |
702 | ||
703 | if (limit) { | |
704 | limit = limit.getAttribute("value"); | |
705 | } else { | |
706 | limit = 0; | |
707 | } | |
708 | ||
4681834e AD |
709 | var articles_found = 0; |
710 | ||
711 | for (var i = 0; i < articles.length; i++) { | |
712 | var a = eval("("+articles[i].firstChild.nodeValue+")"); | |
713 | articles_found++; | |
714 | if (a) { | |
715 | ||
4681834e | 716 | db.execute("DELETE FROM articles WHERE id = ?", [a.id]); |
c2726c96 | 717 | |
4681834e AD |
718 | db.execute("INSERT INTO articles "+ |
719 | "(id, feed_id, title, link, guid, updated, content, "+ | |
55852afa AD |
720 | "unread, marked, tags, comments) "+ |
721 | "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | |
4681834e | 722 | [a.id, a.feed_id, a.title, a.link, a.guid, a.updated, |
55852afa | 723 | a.content, a.unread, a.marked, a.tags, |
3034277a | 724 | a.comments]); |
4681834e | 725 | |
c2726c96 AD |
726 | if (a.labels.length > 0) { |
727 | for (var j = 0; j < a.labels.length; j++) { | |
728 | label_local_add_article(a.id, a.labels[j][0]); | |
729 | } | |
730 | } | |
731 | ||
4681834e AD |
732 | } |
733 | } | |
734 | ||
3e52ab08 AD |
735 | debug("downloaded articles: " + articles_found + " limit: " + limit); |
736 | ||
79e565a9 AD |
737 | articles_synced += articles_found; |
738 | ||
b4dc02e2 | 739 | var msg =__("Synchronizing articles (%d)...").replace("%d", articles_synced); |
79e565a9 AD |
740 | |
741 | $("offlineModeSyncMsg").innerHTML = msg; | |
742 | ||
badac687 AD |
743 | var has_sync_data = has_local_sync_data(); |
744 | ||
745 | if (articles_found >= limit || has_sync_data) { | |
206d4967 | 746 | sync_timer = window.setTimeout("update_offline_data("+(stage+1)+")", |
8ca1a0ac | 747 | 3*1000); |
badac687 AD |
748 | debug("<b>update_offline_data: done " + stage + " HSD: " + |
749 | has_sync_data + "</b>"); | |
4681834e | 750 | } else { |
206d4967 | 751 | window.setTimeout("offlineDownloadStart()", 180*1000); |
3e52ab08 | 752 | debug("update_offline_data: finished"); |
4681834e | 753 | |
79e565a9 | 754 | var pic = $("offlineModePic"); |
04870193 AD |
755 | |
756 | if (pic) { | |
757 | pic.src = "images/offline.png"; | |
79e565a9 AD |
758 | |
759 | var rs = db.execute("SELECT value FROM syncdata WHERE key = 'last_online'"); | |
760 | var last_sync = ""; | |
761 | ||
762 | if (rs.isValidRow()) { | |
763 | last_sync = rs.field(0).substring(0,16); | |
764 | } | |
765 | rs.close(); | |
766 | ||
767 | var msg = __("Last sync: %s").replace("%s", last_sync); | |
768 | ||
769 | articles_synced = 0; | |
770 | ||
771 | $("offlineModeSyncMsg").innerHTML = msg; | |
04870193 AD |
772 | } |
773 | ||
8ca1a0ac | 774 | offlineSyncShowHideElems(false); |
79e565a9 AD |
775 | |
776 | sync_in_progress = false; | |
777 | ||
711f9461 AD |
778 | db.execute("DELETE FROM articles WHERE "+ |
779 | "updated < DATETIME('NOW', 'localtime', '-31 days')"); | |
4681834e AD |
780 | |
781 | } | |
782 | } | |
783 | ||
7f4f9f4e | 784 | update_local_sync_data(); |
04870193 | 785 | |
7f4f9f4e | 786 | |
f45c85f9 | 787 | // notify(''); |
b2319311 | 788 | |
b4dc02e2 AD |
789 | } else { |
790 | sync_in_progress = false; | |
791 | ||
792 | var pic = $("offlineModePic"); | |
793 | ||
794 | if (pic) { | |
795 | pic.src = "images/offline.png"; | |
8ca1a0ac | 796 | var msg = __("Last sync: Error receiving data."); |
b4dc02e2 AD |
797 | articles_synced = 0; |
798 | $("offlineModeSyncMsg").innerHTML = msg; | |
799 | } | |
800 | ||
8ca1a0ac | 801 | offlineSyncShowHideElems(false); |
4681834e | 802 | } |
b4dc02e2 | 803 | |
4681834e AD |
804 | } catch (e) { |
805 | exception_error("offline_download_parse", e); | |
806 | } | |
807 | } | |
808 | ||
809 | function update_offline_data(stage) { | |
810 | try { | |
811 | ||
812 | if (!stage) stage = 0; | |
79e565a9 | 813 | |
23e2fb84 | 814 | if (!db || offline_mode || getInitParam("offline_enabled") != "1") return; |
4681834e | 815 | |
f45c85f9 | 816 | // notify_progress("Updating offline data... (" + stage +")", true); |
4681834e | 817 | |
e8080ee9 AD |
818 | var query = "backend.php?op=rpc&subop=download"; |
819 | ||
4681834e | 820 | var rs = db.execute("SELECT MAX(id), MIN(id) FROM articles"); |
03c96380 | 821 | |
4681834e AD |
822 | if (rs.isValidRow() && rs.field(0)) { |
823 | var offline_dl_max_id = rs.field(0); | |
824 | var offline_dl_min_id = rs.field(1); | |
825 | ||
826 | query = query + "&cidt=" + offline_dl_max_id; | |
827 | query = query + "&cidb=" + offline_dl_min_id; | |
e8080ee9 AD |
828 | |
829 | stage = 1; | |
4681834e AD |
830 | } |
831 | ||
03c96380 AD |
832 | rs.close(); |
833 | ||
e8080ee9 AD |
834 | debug("update_offline_data: stage " + stage); |
835 | ||
836 | query = query + "&stage=" + stage; | |
837 | ||
badac687 AD |
838 | var to_sync = prepare_local_sync_data(); |
839 | ||
840 | if (to_sync != "") { | |
841 | to_sync = "?sync=" + param_escape(to_sync); | |
842 | } | |
843 | ||
844 | debug(query + "/" + to_sync); | |
845 | ||
79e565a9 | 846 | var pic = $("offlineModePic"); |
04870193 AD |
847 | |
848 | if (pic) { | |
849 | pic.src = "images/offline-sync.gif"; | |
79e565a9 AD |
850 | if (articles_synced == 0) { |
851 | $("offlineModeSyncMsg").innerHTML = __("Synchronizing..."); | |
852 | } | |
853 | } | |
854 | ||
8ca1a0ac | 855 | offlineSyncShowHideElems(true); |
9ca945a6 | 856 | offlineUpdateStore(); |
79e565a9 | 857 | |
79e565a9 | 858 | sync_in_progress = true; |
04870193 | 859 | |
4681834e | 860 | new Ajax.Request(query, { |
badac687 | 861 | parameters: to_sync, |
4681834e AD |
862 | onComplete: function(transport) { |
863 | offline_download_parse(stage, transport); | |
4681834e AD |
864 | } }); |
865 | ||
866 | } catch (e) { | |
867 | exception_error("initiate_offline_download", e); | |
868 | } | |
869 | } | |
870 | ||
d6416405 | 871 | function set_feedlist_counter(id, ctr, is_cat) { |
4681834e AD |
872 | try { |
873 | ||
acac8448 AD |
874 | var feedctr = $("FEEDCTR-" + id); |
875 | var feedu = $("FEEDU-" + id); | |
876 | var feedr = $("FEEDR-" + id); | |
4681834e | 877 | |
d6416405 | 878 | if (is_cat) { |
acac8448 | 879 | var catctr = $("FCATCTR-" + id); |
d6416405 AD |
880 | if (catctr) { |
881 | catctr.innerHTML = "(" + ctr + ")"; | |
882 | if (ctr > 0) { | |
883 | catctr.className = "catCtrHasUnread"; | |
884 | } else { | |
885 | catctr.className = "catCtrNoUnread"; | |
886 | } | |
887 | } | |
888 | } else if (feedctr && feedu && feedr) { | |
4681834e AD |
889 | |
890 | var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML)); | |
891 | ||
892 | feedu.innerHTML = ctr; | |
893 | ||
894 | if (ctr > 0) { | |
895 | feedctr.className = "feedCtrHasUnread"; | |
896 | if (!feedr.className.match("Unread")) { | |
897 | var is_selected = feedr.className.match("Selected"); | |
898 | ||
899 | feedr.className = feedr.className.replace("Selected", ""); | |
900 | feedr.className = feedr.className.replace("Unread", ""); | |
901 | ||
902 | feedr.className = feedr.className + "Unread"; | |
903 | ||
904 | if (is_selected) { | |
905 | feedr.className = feedr.className + "Selected"; | |
906 | } | |
907 | ||
908 | } | |
909 | ||
910 | if (row_needs_hl) { | |
911 | new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5", | |
912 | queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } ); | |
913 | } | |
914 | } else { | |
915 | feedctr.className = "feedCtrNoUnread"; | |
916 | feedr.className = feedr.className.replace("Unread", ""); | |
917 | } | |
918 | } | |
919 | ||
920 | } catch (e) { | |
921 | exception_error("set_feedlist_counter", e); | |
922 | } | |
923 | } | |
924 | ||
925 | function update_local_feedlist_counters() { | |
926 | try { | |
b7dbf528 | 927 | if (!offline_mode || !db) return; |
4681834e | 928 | |
f4c11347 | 929 | /* var rs = db.execute("SELECT feeds.id,COUNT(articles.id) "+ |
4681834e AD |
930 | "FROM feeds LEFT JOIN articles ON (feed_id = feeds.id) "+ |
931 | "WHERE unread = 1 OR unread IS NULL GROUP BY feeds.id "+ | |
f4c11347 AD |
932 | "ORDER BY feeds.title"); */ |
933 | ||
d6416405 | 934 | var rs = db.execute("SELECT id FROM feeds "+ |
f4c11347 | 935 | "ORDER BY title"); |
4681834e AD |
936 | |
937 | while (rs.isValidRow()) { | |
938 | var id = rs.field(0); | |
f4c11347 | 939 | var ctr = get_local_feed_unread(id); |
d6416405 AD |
940 | set_feedlist_counter(id, ctr, false); |
941 | rs.next(); | |
942 | } | |
4681834e | 943 | |
d6416405 AD |
944 | rs.close(); |
945 | ||
946 | var rs = db.execute("SELECT cat_id,SUM(unread) "+ | |
947 | "FROM articles, feeds WHERE feeds.id = feed_id GROUP BY cat_id"); | |
4681834e | 948 | |
d6416405 AD |
949 | while (rs.isValidRow()) { |
950 | var id = rs.field(0); | |
951 | var ctr = rs.field(1); | |
952 | set_feedlist_counter(id, ctr, true); | |
4681834e AD |
953 | rs.next(); |
954 | } | |
955 | ||
03c96380 AD |
956 | rs.close(); |
957 | ||
c174bcdf AD |
958 | set_feedlist_counter(-2, get_local_category_unread(-2), true); |
959 | ||
4681834e AD |
960 | set_feedlist_counter(-4, get_local_feed_unread(-4)); |
961 | set_feedlist_counter(-1, get_local_feed_unread(-1)); | |
962 | ||
88a66534 AD |
963 | var rs = db.execute("SELECT id FROM labels"); |
964 | ||
965 | while (rs.isValidRow()) { | |
966 | var id = -11 - rs.field(0); | |
967 | var ctr = get_local_feed_unread(id); | |
968 | set_feedlist_counter(id, ctr, false); | |
969 | rs.next(); | |
970 | } | |
971 | ||
972 | rs.close(); | |
973 | ||
4681834e AD |
974 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); |
975 | ||
976 | global_unread = get_local_feed_unread(-4); | |
977 | updateTitle(); | |
978 | ||
979 | } catch (e) { | |
980 | exception_error("update_local_feedlist_counters", e); | |
981 | } | |
982 | } | |
774b8df8 AD |
983 | |
984 | function get_local_feed_unread(id) { | |
985 | try { | |
986 | var rs; | |
987 | ||
988 | if (id == -4) { | |
989 | rs = db.execute("SELECT SUM(unread) FROM articles"); | |
990 | } else if (id == -1) { | |
991 | rs = db.execute("SELECT SUM(unread) FROM articles WHERE marked = 1"); | |
88a66534 | 992 | } else if (id > 0) { |
774b8df8 | 993 | rs = db.execute("SELECT SUM(unread) FROM articles WHERE feed_id = ?", [id]); |
88a66534 AD |
994 | } else if (id < -10) { |
995 | var label_id = -11 - id; | |
996 | rs = db.execute("SELECT SUM(unread) FROM articles,article_labels "+ | |
997 | "WHERE article_labels.id = articles.id AND label_id = ?", [label_id]); | |
774b8df8 AD |
998 | } |
999 | ||
03c96380 AD |
1000 | var a = false; |
1001 | ||
774b8df8 | 1002 | if (rs.isValidRow()) { |
03c96380 | 1003 | a = rs.field(0); |
774b8df8 | 1004 | } else { |
03c96380 | 1005 | a = 0; |
774b8df8 AD |
1006 | } |
1007 | ||
03c96380 AD |
1008 | rs.close(); |
1009 | ||
1010 | return a; | |
1011 | ||
774b8df8 AD |
1012 | } catch (e) { |
1013 | exception_error("get_local_feed_unread", e); | |
1014 | } | |
1015 | } | |
1016 | ||
59b223d7 AD |
1017 | function enable_offline_reading() { |
1018 | try { | |
1019 | ||
23e2fb84 | 1020 | if (db && getInitParam("offline_enabled") == "1") { |
59b223d7 | 1021 | init_local_sync_data(); |
79e565a9 AD |
1022 | Element.show("offlineModePic"); |
1023 | offlineDownloadStart(); | |
59b223d7 AD |
1024 | } |
1025 | ||
1026 | } catch (e) { | |
1027 | exception_error("enable_offline_reading", e); | |
1028 | } | |
1029 | } | |
1030 | ||
25d99353 AD |
1031 | function init_gears() { |
1032 | try { | |
1033 | ||
1034 | if (window.google && google.gears) { | |
8ca1a0ac AD |
1035 | |
1036 | try { | |
1037 | localServer = google.gears.factory.create("beta.localserver"); | |
1038 | } catch (e) { | |
1039 | return; | |
1040 | } | |
1041 | ||
25d99353 | 1042 | store = localServer.createManagedStore("tt-rss"); |
206d4967 | 1043 | store.manifestUrl = "manifest.json.php"; |
9ca945a6 | 1044 | store.enabled = false; |
206d4967 | 1045 | |
25d99353 AD |
1046 | db = google.gears.factory.create('beta.database'); |
1047 | db.open('tt-rss'); | |
1048 | ||
1049 | db.execute("CREATE TABLE IF NOT EXISTS version (schema_version text)"); | |
1050 | ||
1051 | var rs = db.execute("SELECT schema_version FROM version"); | |
1052 | ||
1053 | var version = ""; | |
1054 | ||
1055 | if (rs.isValidRow()) { | |
1056 | version = rs.field(0); | |
1057 | } | |
1058 | ||
3034277a AD |
1059 | rs.close(); |
1060 | ||
25d99353 | 1061 | if (version != SCHEMA_VERSION) { |
3034277a | 1062 | db.execute("DROP TABLE IF EXISTS init_params"); |
b871dd06 AD |
1063 | db.execute("DROP TABLE IF EXISTS cache"); |
1064 | db.execute("DROP TABLE IF EXISTS feeds"); | |
d8781c91 | 1065 | db.execute("DROP TABLE IF EXISTS categories"); |
ed22888b AD |
1066 | db.execute("DROP TABLE IF EXISTS labels"); |
1067 | db.execute("DROP TABLE IF EXISTS article_labels"); | |
b871dd06 | 1068 | db.execute("DROP TABLE IF EXISTS articles"); |
c174bcdf AD |
1069 | db.execute("DROP INDEX IF EXISTS article_labels_label_id_idx"); |
1070 | db.execute("DROP INDEX IF EXISTS articles_unread_idx"); | |
1071 | db.execute("DROP INDEX IF EXISTS articles_feed_id_idx"); | |
badac687 AD |
1072 | db.execute("DROP INDEX IF EXISTS articles_id_idx"); |
1073 | db.execute("DROP INDEX IF EXISTS article_labels_id_idx"); | |
3034277a | 1074 | db.execute("DROP TABLE IF EXISTS version"); |
6b684299 AD |
1075 | db.execute("DROP TRIGGER IF EXISTS articles_update_unread"); |
1076 | db.execute("DROP TRIGGER IF EXISTS articles_update_marked"); | |
5b880817 | 1077 | db.execute("DROP TRIGGER IF EXISTS articles_remove_labelrefs"); |
3034277a | 1078 | db.execute("CREATE TABLE IF NOT EXISTS version (schema_version text)"); |
6b684299 | 1079 | db.execute("DROP TABLE IF EXISTS syncdata"); |
25d99353 AD |
1080 | db.execute("INSERT INTO version (schema_version) VALUES (?)", |
1081 | [SCHEMA_VERSION]); | |
1082 | } | |
1083 | ||
71af6d36 | 1084 | db.execute("CREATE TABLE IF NOT EXISTS init_params (key text, value text)"); |
3034277a | 1085 | |
71af6d36 AD |
1086 | db.execute("CREATE TABLE IF NOT EXISTS cache (id integer, article text, param text, added text)"); |
1087 | db.execute("CREATE TABLE IF NOT EXISTS feeds (id integer, title text, has_icon integer, cat_id integer)"); | |
1088 | db.execute("CREATE TABLE IF NOT EXISTS categories (id integer, title text, collapsed integer)"); | |
1089 | db.execute("CREATE TABLE IF NOT EXISTS labels (id integer, caption text, fg_color text, bg_color text)"); | |
ed22888b | 1090 | db.execute("CREATE TABLE IF NOT EXISTS article_labels (id integer, label_id integer)"); |
55852afa | 1091 | db.execute("CREATE TABLE IF NOT EXISTS articles (id integer, feed_id integer, title text, link text, guid text, updated timestamp, content text, tags text, unread integer, marked integer, added text, modified timestamp, comments text)"); |
c174bcdf AD |
1092 | |
1093 | db.execute("CREATE INDEX IF NOT EXISTS articles_unread_idx ON articles(unread)"); | |
1094 | db.execute("CREATE INDEX IF NOT EXISTS article_labels_label_id_idx ON article_labels(label_id)"); | |
1095 | db.execute("CREATE INDEX IF NOT EXISTS articles_feed_id_idx ON articles(feed_id)"); | |
badac687 AD |
1096 | db.execute("CREATE INDEX IF NOT EXISTS articles_id_idx ON articles(id)"); |
1097 | db.execute("CREATE INDEX IF NOT EXISTS article_labels_id_idx ON article_labels(id)"); | |
779ba075 | 1098 | |
71af6d36 | 1099 | db.execute("CREATE TABLE IF NOT EXISTS syncdata (key integer, value text)"); |
6b684299 | 1100 | |
779ba075 | 1101 | db.execute("DELETE FROM cache WHERE id LIKE 'F:%' OR id LIKE 'C:%'"); |
69ea0cdd | 1102 | |
6b684299 | 1103 | db.execute("CREATE TRIGGER IF NOT EXISTS articles_update_unread "+ |
55852afa AD |
1104 | "UPDATE OF unread ON articles "+ |
1105 | "BEGIN "+ | |
711f9461 | 1106 | "UPDATE articles SET modified = DATETIME('NOW', 'localtime') "+ |
6b684299 AD |
1107 | "WHERE id = OLD.id AND "+ |
1108 | "OLD.unread != NEW.unread;"+ | |
1109 | "END;"); | |
1110 | ||
1111 | db.execute("CREATE TRIGGER IF NOT EXISTS articles_update_marked "+ | |
1112 | "UPDATE OF marked ON articles "+ | |
1113 | "BEGIN "+ | |
1114 | "UPDATE articles SET modified = DATETIME('NOW', 'localtime') "+ | |
1115 | "WHERE id = OLD.id;"+ | |
55852afa AD |
1116 | "END;"); |
1117 | ||
5b880817 AD |
1118 | db.execute("CREATE TRIGGER IF NOT EXISTS articles_remove_labelrefs "+ |
1119 | "DELETE ON articles "+ | |
1120 | "BEGIN "+ | |
1121 | "DELETE FROM article_labels WHERE id = OLD.id; "+ | |
1122 | "END; "); | |
1123 | ||
25d99353 AD |
1124 | } |
1125 | ||
1126 | cache_expire(); | |
1127 | ||
1128 | } catch (e) { | |
1129 | exception_error("init_gears", e); | |
1130 | } | |
1131 | } | |
1132 | ||
69ea0cdd | 1133 | function gotoOffline() { |
206d4967 AD |
1134 | |
1135 | // debug("[Local store] currentVersion = " + store.currentVersion); | |
1136 | ||
8ca1a0ac AD |
1137 | var rs = db.execute("SELECT COUNT(*) FROM articles"); |
1138 | var count = 0; | |
1139 | if (rs.isValidRow()) { | |
1140 | count = rs.field(0); | |
1141 | } | |
1142 | ||
1143 | rs.close(); | |
1144 | ||
1145 | if (count == 0) { | |
1146 | notify_error("You have to synchronize some articles before going into offline mode."); | |
1147 | return; | |
1148 | } | |
1149 | ||
206d4967 AD |
1150 | if (confirm(__("Switch Tiny Tiny RSS into offline mode?"))) { |
1151 | ||
9ca945a6 | 1152 | store.enabled = true; |
206d4967 AD |
1153 | store.checkForUpdate(); |
1154 | ||
80b7fe74 | 1155 | notify_progress("Preparing offline mode...", true); |
206d4967 AD |
1156 | |
1157 | var timerId = window.setInterval(function() { | |
1158 | if (store.currentVersion) { | |
1159 | window.clearInterval(timerId); | |
8ca1a0ac AD |
1160 | debug("[Local store] sync complete: " + store.currentVersion); |
1161 | ||
1162 | //window.location.href = "tt-rss.php"; | |
1163 | ||
1164 | offlineDownloadStop(); | |
8ca1a0ac AD |
1165 | init_offline(); |
1166 | ||
1167 | notify_info("Tiny Tiny RSS is in offline mode."); | |
1168 | ||
206d4967 AD |
1169 | } else if (store.updateStatus == 3) { |
1170 | debug("[Local store] sync error: " + store.lastErrorMessage); | |
8ca1a0ac | 1171 | notify_error(store.lastErrorMessage, true); |
206d4967 AD |
1172 | } }, 500); |
1173 | } | |
69ea0cdd AD |
1174 | } |
1175 | ||
1176 | function gotoOnline() { | |
9ca945a6 AD |
1177 | // if (confirm(__("You won't be able to access offline version of Tiny Tiny RSS until you switch it into offline mode again. Go online?"))) { |
1178 | if (confirm(__("Tiny Tiny RSS will reload. Go online?"))) { | |
1179 | //localServer.removeManagedStore("tt-rss"); | |
206d4967 AD |
1180 | window.location.href = "tt-rss.php"; |
1181 | } | |
69ea0cdd | 1182 | } |
774b8df8 | 1183 | |
c26aa9f0 AD |
1184 | function local_collapse_cat(id) { |
1185 | try { | |
1186 | if (db) { | |
1187 | db.execute("UPDATE categories SET collapsed = NOT collapsed WHERE id = ?", | |
1188 | [id]); | |
1189 | } | |
1190 | } catch (e) { | |
1191 | exception_error("local_collapse_cat", e); | |
1192 | } | |
1193 | } | |
d6416405 AD |
1194 | |
1195 | function get_local_category_title(id) { | |
1196 | try { | |
71af6d36 | 1197 | |
d6416405 AD |
1198 | var rs = db.execute("SELECT title FROM categories WHERE id = ?", [id]); |
1199 | var tmp = ""; | |
1200 | ||
1201 | if (rs.isValidRow()) { | |
1202 | tmp = rs.field(0); | |
1203 | } | |
1204 | ||
1205 | rs.close(); | |
1206 | ||
1207 | return tmp; | |
1208 | ||
1209 | } catch (e) { | |
1210 | exception_error("get_local_category_title", e); | |
1211 | } | |
1212 | } | |
1213 | ||
1214 | function get_local_category_unread(id) { | |
1215 | try { | |
c174bcdf AD |
1216 | var rs = false; |
1217 | ||
1218 | if (id >= 0) { | |
1219 | rs = db.execute("SELECT SUM(unread) FROM articles, feeds "+ | |
1220 | "WHERE feeds.id = feed_id AND cat_id = ?", [id]); | |
1221 | } else if (id == -2) { | |
1222 | rs = db.execute("SELECT SUM(unread) FROM article_labels, articles "+ | |
1223 | "where article_labels.id = articles.id"); | |
1224 | } else { | |
1225 | return 0; | |
1226 | } | |
d6416405 AD |
1227 | |
1228 | var tmp = 0; | |
1229 | ||
1230 | if (rs.isValidRow()) { | |
1231 | tmp = rs.field(0); | |
1232 | } | |
1233 | ||
1234 | rs.close(); | |
1235 | ||
1236 | return tmp; | |
1237 | ||
1238 | } catch (e) { | |
1239 | exception_error("get_local_category_unread", e); | |
1240 | } | |
1241 | } | |
1242 | ||
1243 | function printCategoryHeader(cat_id, hidden, can_browse) { | |
1244 | try { | |
1245 | if (hidden == undefined) hidden = false; | |
1246 | if (can_browse == undefined) can_browse = false; | |
1247 | ||
1248 | var tmp_category = get_local_category_title(cat_id); | |
1249 | var tmp = ""; | |
1250 | ||
1251 | var cat_unread = get_local_category_unread(cat_id); | |
1252 | ||
1253 | var holder_style = ""; | |
1254 | var ellipsis = ""; | |
1255 | ||
1256 | if (hidden) { | |
1257 | holder_style = "display:none;"; | |
1258 | ellipsis = "…"; | |
1259 | } | |
1260 | ||
1261 | var catctr_class = (cat_unread > 0) ? "catCtrHasUnread" : "catCtrNoUnread"; | |
1262 | ||
1263 | var browse_cat_link = ""; | |
1264 | var inner_title_class = "catTitleNL"; | |
1265 | ||
1266 | if (can_browse) { | |
046a2e3c | 1267 | browse_cat_link = "onclick=\"javascript:viewCategory("+cat_id+")\""; |
d6416405 AD |
1268 | inner_title_class = "catTitle"; |
1269 | } | |
1270 | ||
1271 | var cat_class = "feedCat"; | |
1272 | ||
1273 | tmp += "<li class=\""+cat_class+"\" id=\"FCAT-"+cat_id+"\">"+ | |
1274 | "<img onclick=\"toggleCollapseCat("+cat_id+")\" class=\"catCollapse\""+ | |
1275 | " title=\""+__('Click to collapse category')+"\""+ | |
1276 | " src=\"images/cat-collapse.png\"><span class=\""+inner_title_class+"\" "+ | |
1277 | " id=\"FCATN-"+cat_id+"\" "+browse_cat_link+ | |
1278 | "\">"+tmp_category+"</span>"; | |
1279 | ||
1280 | tmp += "<span id=\"FCAP-"+cat_id+"\">"; | |
1281 | ||
1282 | tmp += " <span id=\"FCATCTR-"+cat_id+"\" "+ | |
1283 | "class=\""+catctr_class+"\">("+cat_unread+")</span> "+ellipsis; | |
1284 | ||
1285 | tmp += "</span>"; | |
1286 | ||
1287 | tmp += "<ul class=\"feedCatList\" id=\"FCATLIST-"+cat_id+"\" "+ | |
1288 | "style='"+holder_style+"'>"; | |
1289 | ||
1290 | return tmp; | |
1291 | } catch (e) { | |
1292 | exception_error("printCategoryHeader", e); | |
1293 | } | |
1294 | } | |
1295 | ||
c2726c96 AD |
1296 | function is_local_cat_collapsed(id) { |
1297 | try { | |
1298 | ||
1299 | var rs = db.execute("SELECT collapsed FROM categories WHERE id = ?", [id]); | |
1300 | var cat_hidden = 0; | |
1301 | ||
1302 | if (rs.isValidRow()) { | |
1303 | cat_hidden = rs.field(0); | |
1304 | } | |
1305 | ||
1306 | rs.close(); | |
1307 | ||
1308 | return cat_hidden == "1"; | |
1309 | ||
1310 | } catch (e) { | |
1311 | exception_error("is_local_cat_collapsed", e); | |
1312 | } | |
1313 | } | |
1314 | ||
6da82466 AD |
1315 | function get_local_article_labels(id) { |
1316 | try { | |
1317 | var rs = db.execute("SELECT DISTINCT label_id,caption,fg_color,bg_color "+ | |
1318 | "FROM labels, article_labels "+ | |
1319 | "WHERE labels.id = label_id AND article_labels.id = ?", [id]); | |
1320 | ||
1321 | var tmp = new Array(); | |
1322 | ||
1323 | while (rs.isValidRow()) { | |
1324 | var e = new Array(); | |
1325 | ||
1326 | e[0] = rs.field(0); | |
1327 | e[1] = rs.field(1); | |
1328 | e[2] = rs.field(2); | |
1329 | e[3] = rs.field(3); | |
1330 | ||
1331 | tmp.push(e); | |
1332 | ||
1333 | rs.next(); | |
1334 | } | |
1335 | ||
1336 | return tmp; | |
1337 | ||
1338 | } catch (e) { | |
1339 | exception_error("get_local_article_labels", e); | |
1340 | } | |
1341 | } | |
1342 | ||
c2726c96 AD |
1343 | function label_local_add_article(id, label_id) { |
1344 | try { | |
5b880817 | 1345 | //debug("label_local_add_article " + id + " => " + label_id); |
c2726c96 AD |
1346 | |
1347 | var rs = db.execute("SELECT COUNT(id) FROM article_labels WHERE "+ | |
1348 | "id = ? AND label_id = ?", [id, label_id]); | |
1349 | var check = rs.field(0); | |
1350 | ||
1351 | if (rs.isValidRow()) { | |
1352 | var check = rs.field(0); | |
1353 | } | |
1354 | rs.close(); | |
1355 | ||
1356 | if (check == 0) { | |
1357 | db.execute("INSERT INTO article_labels (id, label_id) VALUES "+ | |
1358 | "(?,?)", [id, label_id]); | |
1359 | } | |
1360 | ||
1361 | } catch (e) { | |
1362 | exception_error("label_local_add_article", e); | |
1363 | } | |
1364 | } | |
88a66534 AD |
1365 | |
1366 | function get_local_feed_title(id) { | |
1367 | try { | |
1368 | ||
1369 | var feed_title = "Unknown feed: " + id; | |
1370 | ||
1371 | if (id > 0) { | |
1372 | var rs = db.execute("SELECT title FROM feeds WHERE id = ?", [id]); | |
1373 | ||
1374 | if (rs.isValidRow()) { | |
1375 | feed_title = rs.field(0); | |
1376 | } | |
1377 | ||
1378 | rs.close(); | |
1379 | } else if (id == -1) { | |
1380 | feed_title = __("Starred articles"); | |
1381 | } else if (id == -4) { | |
1382 | feed_title = __("All articles"); | |
1383 | } else if (id < -10) { | |
1384 | ||
1385 | var label_id = -11 - id; | |
1386 | ||
1387 | var rs = db.execute("SELECT caption FROM labels WHERE id = ?", [label_id]); | |
1388 | ||
1389 | if (rs.isValidRow()) { | |
1390 | feed_title = rs.field(0); | |
1391 | } | |
1392 | ||
1393 | rs.close(); | |
1394 | } | |
1395 | ||
1396 | return feed_title; | |
1397 | ||
1398 | } catch (e) { | |
1399 | exception_error("get_local_feed_title", e); | |
1400 | } | |
1401 | } | |
6da82466 AD |
1402 | |
1403 | function format_article_labels(labels, id) { | |
1404 | try { | |
1405 | ||
1406 | var labels_str = ""; | |
1407 | ||
1408 | if (!labels) return ""; | |
1409 | ||
1410 | for (var i = 0; i < labels.length; i++) { | |
1411 | var l = labels[i]; | |
1412 | ||
1413 | labels_str += "<span class='hlLabelRef' "+ | |
1414 | "style='color : "+l[2]+"; background-color : "+l[3]+"'>"+l[1]+"</span>"; | |
1415 | } | |
1416 | ||
1417 | return labels_str; | |
1418 | ||
1419 | } catch (e) { | |
1420 | exception_error("format_article_labels", e); | |
1421 | } | |
1422 | } | |
1423 | ||
6b684299 AD |
1424 | function init_local_sync_data() { |
1425 | try { | |
23e2fb84 AD |
1426 | |
1427 | if (!db) return; | |
1428 | ||
6b684299 AD |
1429 | var rs = db.execute("SELECT COUNT(*) FROM syncdata WHERE key = 'last_online'"); |
1430 | var has_last_online = 0; | |
1431 | ||
1432 | if (rs.isValidRow()) { | |
1433 | has_last_online = rs.field(0); | |
1434 | } | |
1435 | ||
1436 | rs.close(); | |
1437 | ||
1438 | if (!has_last_online) { | |
1439 | db.execute("INSERT INTO syncdata (key, value) VALUES ('last_online', '')"); | |
1440 | } | |
1441 | ||
1442 | } catch (e) { | |
1443 | exception_error("init_local_sync_data", e); | |
1444 | ||
1445 | } | |
1446 | } | |
1447 | ||
badac687 AD |
1448 | function has_local_sync_data() { |
1449 | try { | |
1450 | ||
1451 | var rs = db.execute("SELECT id FROM articles "+ | |
1452 | "WHERE modified > (SELECT value FROM syncdata WHERE key = 'last_online') "+ | |
1453 | "LIMIT 1"); | |
1454 | ||
1455 | var tmp = 0; | |
1456 | ||
1457 | if (rs.isValidRow()) { | |
1458 | tmp = rs.field(0); | |
1459 | } | |
1460 | ||
1461 | rs.close(); | |
1462 | ||
1463 | return tmp != 0; | |
1464 | ||
1465 | } catch (e) { | |
1466 | exception_error("has_local_sync_data", e); | |
1467 | } | |
1468 | } | |
1469 | ||
1470 | function prepare_local_sync_data() { | |
1471 | try { | |
1472 | var rs = db.execute("SELECT value FROM syncdata WHERE key = 'last_online'"); | |
1473 | ||
1474 | var last_online = ""; | |
1475 | ||
1476 | if (rs.isValidRow()) { | |
1477 | last_online = rs.field(0); | |
1478 | } | |
1479 | ||
1480 | rs.close(); | |
1481 | ||
1482 | var rs = db.execute("SELECT id,unread,marked FROM articles "+ | |
1483 | "WHERE modified > ? LIMIT 200", [last_online]); | |
1484 | ||
1485 | var tmp = last_online + ";"; | |
1486 | ||
1487 | var entries = 0; | |
1488 | ||
1489 | while (rs.isValidRow()) { | |
1490 | var e = new Array(); | |
1491 | ||
1492 | tmp = tmp + rs.field(0) + "," + rs.field(1) + "," + rs.field(2) + ";"; | |
1493 | entries++; | |
1494 | ||
1495 | rs.next(); | |
1496 | } | |
1497 | ||
1498 | rs.close(); | |
1499 | ||
1500 | if (entries > 0) { | |
1501 | return tmp; | |
1502 | } else { | |
1503 | return ''; | |
1504 | } | |
1505 | ||
1506 | } catch (e) { | |
1507 | exception_error("prepare_local_sync_data", e); | |
1508 | } | |
1509 | } | |
1510 | ||
6b684299 AD |
1511 | function update_local_sync_data() { |
1512 | try { | |
1513 | if (db && !offline_mode) { | |
badac687 AD |
1514 | |
1515 | var rs = db.execute("SELECT id FROM articles "+ | |
1516 | "WHERE modified > (SELECT value FROM syncdata WHERE "+ | |
1517 | "key = 'last_online') LIMIT 1") | |
1518 | ||
1519 | var f_id = 0; | |
1520 | ||
1521 | if (rs.isValidRow()) { | |
1522 | f_id = rs.field(0); | |
1523 | } | |
1524 | ||
1525 | rs.close(); | |
1526 | ||
1527 | /* no pending articles to sync */ | |
1528 | ||
1529 | if (f_id == 0) { | |
1530 | db.execute("UPDATE syncdata SET value = DATETIME('NOW', 'localtime') "+ | |
1531 | "WHERE key = 'last_online'"); | |
1532 | } | |
6b684299 AD |
1533 | |
1534 | } | |
1535 | } catch (e) { | |
1536 | exception_error("update_local_sync_data", e); | |
1537 | } | |
1538 | } | |
67625745 AD |
1539 | |
1540 | function catchup_local_feed(id, is_cat) { | |
1541 | try { | |
6161d5cc AD |
1542 | if (!db) return; |
1543 | ||
67625745 AD |
1544 | if (!is_cat) { |
1545 | if (id >= 0) { | |
1546 | db.execute("UPDATE articles SET unread = 0 WHERE feed_id = ?", [id]); | |
1547 | } else if (id == -1) { | |
1548 | db.execute("UPDATE articles SET unread = 0 WHERE marked = 1"); | |
1549 | } else if (id == -4) { | |
1550 | db.execute("UPDATE articles SET unread = 0"); | |
1551 | } else if (id < -10) { | |
1552 | var label_id = -11-id; | |
1553 | ||
1554 | db.execute("UPDATE articles SET unread = 0 WHERE "+ | |
1555 | "(SELECT COUNT(*) FROM article_labels WHERE "+ | |
1556 | "article_labels.id = articles.id AND label_id = ?) > 0", [label_id]); | |
1557 | } | |
1558 | } | |
1559 | ||
1560 | update_local_feedlist_counters(); | |
1561 | ||
1562 | } catch (e) { | |
1563 | exception_error("catchup_local_feed", e); | |
1564 | } | |
1565 | } | |
79e565a9 AD |
1566 | |
1567 | function toggleOfflineModeInfo() { | |
1568 | try { | |
1569 | var e = $('offlineModeDrop'); | |
1570 | var p = $('offlineModePic'); | |
1571 | ||
1572 | if (Element.visible(e)) { | |
1573 | Element.hide(e); | |
1574 | } else { | |
1575 | Element.show(e); | |
1576 | } | |
1577 | ||
1578 | } catch (e) { | |
1579 | exception_error("toggleOfflineModeInfo", e); | |
1580 | } | |
1581 | } | |
1582 | ||
1583 | function offlineDownloadStart() { | |
1584 | try { | |
1585 | if (db && !sync_in_progress && getInitParam("offline_enabled") == "1") { | |
1586 | window.setTimeout("update_offline_data(0)", 100); | |
1587 | } | |
1588 | } catch (e) { | |
1589 | exception_error("offlineDownloadStart", e); | |
1590 | } | |
1591 | } | |
1592 | ||
206d4967 AD |
1593 | function offlineDownloadStop() { |
1594 | try { | |
1595 | if (db && sync_in_progress && getInitParam("offline_enabled") == "1") { | |
8ca1a0ac AD |
1596 | |
1597 | sync_in_progress = false; | |
1598 | ||
1599 | if (sync_timer) { | |
1600 | window.clearTimeout(sync_timer); | |
1601 | sync_timer = false; | |
1602 | } | |
1603 | ||
1604 | var pic = $("offlineModePic"); | |
1605 | ||
1606 | if (pic) { | |
1607 | pic.src = "images/offline.png"; | |
1608 | var msg = __("Last sync: Cancelled."); | |
1609 | articles_synced = 0; | |
1610 | $("offlineModeSyncMsg").innerHTML = msg; | |
1611 | } | |
1612 | ||
1613 | offlineSyncShowHideElems(false); | |
1614 | ||
206d4967 AD |
1615 | } |
1616 | } catch (e) { | |
1617 | exception_error("offlineDownloadStart", e); | |
1618 | } | |
1619 | } | |
1620 | ||
79e565a9 AD |
1621 | function offlineClearData() { |
1622 | try { | |
1623 | if (db) { | |
1624 | ||
b4dc02e2 | 1625 | if (confirm(__("This will remove all offline data stored by Tiny Tiny RSS on this computer. Continue?"))) { |
79e565a9 AD |
1626 | |
1627 | notify_progress("Removing offline data..."); | |
1628 | ||
b4dc02e2 AD |
1629 | localServer.removeManagedStore("tt-rss"); |
1630 | ||
79e565a9 AD |
1631 | db.execute("DELETE FROM articles"); |
1632 | db.execute("DELETE FROM article_labels"); | |
1633 | db.execute("DELETE FROM labels"); | |
1634 | db.execute("DELETE FROM feeds"); | |
8ca1a0ac | 1635 | db.execute("DELETE FROM cache"); |
79e565a9 | 1636 | |
8ca1a0ac | 1637 | notify_info("Local data removed."); |
79e565a9 AD |
1638 | } |
1639 | } | |
1640 | } catch (e) { | |
1641 | exception_error("offlineClearData", e); | |
1642 | } | |
1643 | } | |
206d4967 AD |
1644 | |
1645 | function offlineUpdateStore() { | |
1646 | try { | |
9ca945a6 | 1647 | if (offline_mode || !store) return; |
206d4967 | 1648 | |
9ca945a6 AD |
1649 | store.checkForUpdate(); |
1650 | ||
1651 | var timerId = window.setInterval(function() { | |
1652 | if (store.currentVersion) { | |
1653 | window.clearInterval(timerId); | |
1654 | debug("[Local store] sync complete: " + store.currentVersion); | |
1655 | } else if (store.updateStatus == 3) { | |
1656 | debug("[Local store] sync error: " + store.lastErrorMessage); | |
1657 | } }, 500); | |
206d4967 AD |
1658 | |
1659 | } catch (e) { | |
1660 | exception_error("offlineUpdateStore", e); | |
1661 | } | |
1662 | } | |
8ca1a0ac AD |
1663 | |
1664 | function offlineSyncShowHideElems(syncing) { | |
1665 | try { | |
1666 | ||
1667 | var elems = $$("div.hideWhenSyncing"); | |
1668 | ||
1669 | for (var j = 0; j < elems.length; j++) { | |
1670 | if (syncing) { | |
1671 | Element.hide(elems[j]); | |
1672 | } else { | |
1673 | Element.show(elems[j]); | |
1674 | } | |
1675 | } | |
1676 | ||
1677 | var elems = $$("div.showWhenSyncing"); | |
1678 | ||
1679 | for (var j = 0; j < elems.length; j++) { | |
1680 | if (syncing) { | |
1681 | Element.show(elems[j]); | |
1682 | } else { | |
1683 | Element.hide(elems[j]); | |
1684 | } | |
1685 | } | |
1686 | ||
1687 | } catch (e) { | |
1688 | exception_error("offlineSyncShowHideElems", e); | |
1689 | } | |
1690 | } | |
9ca945a6 AD |
1691 | |
1692 | function offlineConfirmModeChange() { | |
1693 | try { | |
1694 | ||
1695 | if (db) { | |
1696 | var ok = confirm(__("Tiny Tiny RSS has trouble accessing its server. Would you like to go offline?")); | |
1697 | ||
1698 | if (ok) { | |
1699 | init_offline(); | |
1700 | } | |
1701 | } | |
1702 | ||
1703 | } catch (e) { | |
1704 | exception_error("offlineConfirmModeChange", e); | |
1705 | } | |
1706 | } |