]>
Commit | Line | Data |
---|---|---|
bb7cface | 1 | var active_post_id = false; |
4b6206fa | 2 | var last_article_view = false; |
0b126ac2 AD |
3 | var active_real_feed_id = false; |
4 | ||
13f08f75 | 5 | // FIXME: kludges, needs proper implementation |
0b126ac2 | 6 | var _reload_feedlist_after_view = false; |
e08443c1 | 7 | |
ba0978c8 AD |
8 | var _cdm_wd_timeout = false; |
9 | var _cdm_wd_vishist = new Array(); | |
10 | ||
e097e8be AD |
11 | var article_cache = new Array(); |
12 | ||
081e527d | 13 | var vgroup_last_feed = false; |
314fcd2b | 14 | var post_under_pointer = false; |
081e527d | 15 | |
022d9e9e AD |
16 | var last_requested_article = false; |
17 | ||
c7e51de1 AD |
18 | function toggle_published_callback(transport) { |
19 | try { | |
20 | if (transport.responseXML) { | |
21 | ||
22 | all_counters_callback2(transport); | |
23 | ||
24 | var note = transport.responseXML.getElementsByTagName("note")[0]; | |
25 | ||
26 | if (note) { | |
27 | var note_id = note.getAttribute("id"); | |
28 | var note_size = note.getAttribute("size"); | |
29 | var note_content = note.firstChild.nodeValue; | |
30 | ||
31 | var container = $('POSTNOTE-' + note_id); | |
32 | ||
33 | cache_invalidate(note_id); | |
34 | ||
35 | if (container) { | |
36 | if (note_size == "0") { | |
37 | Element.hide(container); | |
38 | } else { | |
39 | container.innerHTML = note_content; | |
40 | Element.show(container); | |
41 | } | |
42 | } | |
43 | } | |
44 | } | |
45 | ||
46 | } catch (e) { | |
47 | exception_error("toggle_published_callback", e, transport); | |
48 | } | |
49 | } | |
50 | ||
1341ea0d AD |
51 | function catchup_callback2(transport, callback) { |
52 | try { | |
53 | debug("catchup_callback2 " + transport + ", " + callback); | |
54 | notify(""); | |
55 | all_counters_callback2(transport); | |
56 | if (callback) { | |
57 | setTimeout(callback, 10); | |
58 | } | |
59 | } catch (e) { | |
273d1e29 | 60 | exception_error("catchup_callback2", e, transport); |
1341ea0d AD |
61 | } |
62 | } | |
63 | ||
e19c1824 | 64 | function clean_feed_selections() { |
a49f5e05 | 65 | try { |
acac8448 | 66 | var feeds = $("feedList").getElementsByTagName("LI"); |
a49f5e05 | 67 | |
6c3b0198 AD |
68 | for (var i = 0; i < feeds.length; i++) { |
69 | if (feeds[i].id && feeds[i].id.match("FEEDR-")) { | |
70 | feeds[i].className = feeds[i].className.replace("Selected", ""); | |
71 | } | |
5ee9816c AD |
72 | if (feeds[i].id && feeds[i].id.match("FCAT-")) { |
73 | feeds[i].className = feeds[i].className.replace("Selected", ""); | |
74 | } | |
6c3b0198 | 75 | } |
e19c1824 AD |
76 | } catch (e) { |
77 | exception_error("clean_feed_selections", e); | |
78 | } | |
79 | } | |
80 | ||
3d72bbdb | 81 | function headlines_callback2(transport, feed_cur_page) { |
e19c1824 AD |
82 | try { |
83 | ||
9ca945a6 AD |
84 | if (!transport.responseText && db) { |
85 | offlineConfirmModeChange(); | |
86 | return; | |
87 | } | |
88 | ||
730dbf19 AD |
89 | loading_set_progress(100); |
90 | ||
e19c1824 AD |
91 | debug("headlines_callback2 [page=" + feed_cur_page + "]"); |
92 | ||
2184738a AD |
93 | if (!transport_error_check(transport)) return; |
94 | ||
e19c1824 | 95 | clean_feed_selections(); |
3d72bbdb AD |
96 | |
97 | var is_cat = false; | |
98 | var feed_id = false; | |
ac541432 | 99 | |
3d72bbdb AD |
100 | if (transport.responseXML) { |
101 | var headlines = transport.responseXML.getElementsByTagName("headlines")[0]; | |
102 | if (headlines) { | |
103 | is_cat = headlines.getAttribute("is_cat"); | |
104 | feed_id = headlines.getAttribute("id"); | |
105 | setActiveFeedId(feed_id, is_cat); | |
106 | } | |
6c3b0198 | 107 | } |
f46192bb | 108 | |
6e35a862 AD |
109 | var ll = $('FLL-' + feed_id); |
110 | ||
6c3b0198 | 111 | if (!is_cat) { |
acac8448 | 112 | var feedr = $("FEEDR-" + feed_id); |
6c3b0198 AD |
113 | if (feedr && !feedr.className.match("Selected")) { |
114 | feedr.className = feedr.className + "Selected"; | |
115 | } | |
6e35a862 | 116 | if (feedr && ll) feedr.removeChild(ll); |
5ee9816c | 117 | } else { |
acac8448 | 118 | var feedr = $("FCAT-" + feed_id); |
5ee9816c AD |
119 | if (feedr && !feedr.className.match("Selected")) { |
120 | feedr.className = feedr.className + "Selected"; | |
121 | } | |
b7665618 AD |
122 | |
123 | var fcap = $("FCAP-" + feed_id); | |
124 | if (fcap && ll) fcap.removeChild(ll); | |
6e35a862 | 125 | |
6c3b0198 | 126 | } |
6e35a862 | 127 | |
105b61b7 AD |
128 | var img = $('FIMG-' + feed_id); |
129 | ||
130 | if (img && !is_cat) { | |
131 | img.src = img.alt; | |
132 | img.alt = ''; | |
133 | } | |
134 | ||
acac8448 | 135 | var f = $("headlines-frame"); |
6c3b0198 AD |
136 | try { |
137 | if (feed_cur_page == 0) { | |
138 | debug("resetting headlines scrollTop"); | |
139 | f.scrollTop = 0; | |
a49f5e05 | 140 | } |
6c3b0198 AD |
141 | } catch (e) { }; |
142 | ||
143 | if (transport.responseXML) { | |
144 | var headlines = transport.responseXML.getElementsByTagName("headlines")[0]; | |
145 | var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0]; | |
e19c1824 | 146 | var headlines_unread_obj = transport.responseXML.getElementsByTagName("headlines-unread")[0]; |
52d7e7da | 147 | var disable_cache_obj = transport.responseXML.getElementsByTagName("disable-cache")[0]; |
e19c1824 | 148 | |
081e527d AD |
149 | var vgroup_last_feed_obj = transport.responseXML.getElementsByTagName("vgroup-last-feed")[0]; |
150 | ||
6c3b0198 | 151 | var headlines_count = headlines_count_obj.getAttribute("value"); |
e19c1824 | 152 | var headlines_unread = headlines_unread_obj.getAttribute("value"); |
52d7e7da | 153 | var disable_cache = disable_cache_obj.getAttribute("value") != "0"; |
e19c1824 | 154 | |
081e527d AD |
155 | vgroup_last_feed = vgroup_last_feed_obj.getAttribute("value"); |
156 | ||
587bef10 AD |
157 | if (headlines_count == 0) { |
158 | _infscroll_disable = 1; | |
159 | } else { | |
160 | _infscroll_disable = 0; | |
161 | } | |
162 | ||
6c3b0198 AD |
163 | var counters = transport.responseXML.getElementsByTagName("counters")[0]; |
164 | var articles = transport.responseXML.getElementsByTagName("article"); | |
165 | var runtime_info = transport.responseXML.getElementsByTagName("runtime-info"); | |
166 | ||
167 | if (feed_cur_page == 0) { | |
168 | if (headlines) { | |
169 | f.innerHTML = headlines.firstChild.nodeValue; | |
e19c1824 | 170 | |
dd5865d4 AD |
171 | var cache_prefix = ""; |
172 | ||
173 | if (is_cat) { | |
174 | cache_prefix = "C:"; | |
175 | } else { | |
176 | cache_prefix = "F:"; | |
177 | } | |
178 | ||
3d72bbdb | 179 | cache_invalidate(cache_prefix + feed_id); |
7e8832b3 | 180 | |
52d7e7da | 181 | if (!disable_cache) { |
3d72bbdb | 182 | cache_inject(cache_prefix + feed_id, |
52d7e7da AD |
183 | headlines.firstChild.nodeValue, headlines_unread); |
184 | } | |
e19c1824 | 185 | |
6c3b0198 AD |
186 | } else { |
187 | debug("headlines_callback: returned no data"); | |
188 | f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>"; | |
189 | ||
190 | } | |
191 | } else { | |
192 | if (headlines) { | |
193 | if (headlines_count > 0) { | |
194 | debug("adding some more headlines..."); | |
195 | ||
acac8448 | 196 | var c = $("headlinesList"); |
6c3b0198 AD |
197 | |
198 | if (!c) { | |
acac8448 | 199 | c = $("headlinesInnerContainer"); |
6c3b0198 | 200 | } |
c32cd48a AD |
201 | |
202 | var ids = getSelectedArticleIds2(); | |
6c3b0198 AD |
203 | |
204 | c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue; | |
c32cd48a AD |
205 | |
206 | debug("restore selected ids: " + ids); | |
207 | ||
208 | for (var i = 0; i < ids.length; i++) { | |
209 | markHeadline(ids[i]); | |
210 | } | |
211 | ||
6c3b0198 AD |
212 | } else { |
213 | debug("no new headlines received"); | |
29dfb258 | 214 | } |
29dfb258 | 215 | } else { |
6c3b0198 AD |
216 | debug("headlines_callback: returned no data"); |
217 | notify_error("Error while trying to load more headlines"); | |
218 | } | |
730dbf19 | 219 | |
6c3b0198 AD |
220 | } |
221 | ||
222 | if (articles) { | |
223 | for (var i = 0; i < articles.length; i++) { | |
224 | var a_id = articles[i].getAttribute("id"); | |
225 | debug("found id: " + a_id); | |
226 | cache_inject(a_id, articles[i].firstChild.nodeValue); | |
ac541432 | 227 | } |
007a38d4 | 228 | } else { |
6c3b0198 | 229 | debug("no cached articles received"); |
961f4c73 | 230 | } |
6c3b0198 AD |
231 | |
232 | if (counters) { | |
233 | debug("parsing piggybacked counters: " + counters); | |
234 | parse_counters(counters, false); | |
235 | } else { | |
5aaf9b34 AD |
236 | debug("counters container not found in reply, requesting..."); |
237 | request_counters(); | |
6c3b0198 AD |
238 | } |
239 | ||
240 | if (runtime_info) { | |
241 | debug("parsing runtime info: " + runtime_info[0]); | |
242 | parse_runtime_info(runtime_info[0]); | |
243 | } else { | |
244 | debug("counters container not found in reply"); | |
03c88bdd | 245 | } |
6c3b0198 | 246 | |
3de0261a | 247 | } else { |
6c3b0198 AD |
248 | debug("headlines_callback: returned no XML object"); |
249 | f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>"; | |
3de0261a | 250 | } |
6c3b0198 AD |
251 | |
252 | if (typeof correctPNG != 'undefined') { | |
253 | correctPNG(); | |
935f235d | 254 | } |
6c3b0198 AD |
255 | |
256 | if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout); | |
257 | ||
acac8448 | 258 | if (!$("headlinesList") && |
a969b30b | 259 | getActiveFeedId() != -3 && |
6c3b0198 AD |
260 | getInitParam("cdm_auto_catchup") == 1) { |
261 | debug("starting CDM watchdog"); | |
262 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000); | |
263 | _cdm_wd_vishist = new Array(); | |
ac7bcd71 | 264 | } else { |
6c3b0198 | 265 | debug("not in CDM mode or watchdog disabled"); |
ba0978c8 | 266 | } |
6c3b0198 | 267 | |
6c3b0198 | 268 | _feed_cur_page = feed_cur_page; |
82764a41 AD |
269 | _infscroll_request_sent = 0; |
270 | ||
6c3b0198 | 271 | notify(""); |
730dbf19 AD |
272 | |
273 | remove_splash(); | |
274 | ||
6c3b0198 | 275 | } catch (e) { |
273d1e29 | 276 | exception_error("headlines_callback2", e, transport); |
6b4163cb AD |
277 | } |
278 | } | |
279 | ||
e097e8be AD |
280 | function render_article(article) { |
281 | try { | |
acac8448 | 282 | var f = $("content-frame"); |
44cc6f20 AD |
283 | try { |
284 | f.scrollTop = 0; | |
285 | } catch (e) { }; | |
e097e8be | 286 | |
acac8448 | 287 | var fi = $("content-insert"); |
17042fc0 | 288 | |
e5ebee09 AD |
289 | try { |
290 | fi.scrollTop = 0; | |
291 | } catch (e) { }; | |
95f67d2e | 292 | |
17042fc0 | 293 | fi.innerHTML = article; |
95f67d2e | 294 | |
51682b23 | 295 | // article.evalScripts(); |
e097e8be AD |
296 | |
297 | } catch (e) { | |
298 | exception_error("render_article", e); | |
299 | } | |
300 | } | |
301 | ||
71d277de | 302 | function showArticleInHeadlines(id) { |
e097e8be | 303 | |
868d0ed2 | 304 | try { |
e097e8be | 305 | |
868d0ed2 | 306 | cleanSelected("headlinesList"); |
71d277de | 307 | |
acac8448 | 308 | var crow = $("RROW-" + id); |
76283a4c AD |
309 | |
310 | if (!crow) return; | |
311 | ||
868d0ed2 AD |
312 | var article_is_unread = crow.className.match("Unread"); |
313 | ||
314 | crow.className = crow.className.replace("Unread", ""); | |
fdcdf2de AD |
315 | |
316 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); | |
fdcdf2de | 317 | |
acac8448 | 318 | var upd_img_pic = $("FUPDPIC-" + id); |
ebda016b | 319 | |
fdcdf2de | 320 | var cache_prefix = ""; |
ebda016b | 321 | |
fdcdf2de AD |
322 | if (activeFeedIsCat()) { |
323 | cache_prefix = "C:"; | |
324 | } else { | |
325 | cache_prefix = "F:"; | |
326 | } | |
11063ec6 AD |
327 | |
328 | var view_mode = false; | |
329 | ||
330 | try { | |
331 | view_mode = document.forms['main_toolbar_form'].view_mode; | |
332 | view_mode = view_mode[view_mode.selectedIndex].value; | |
333 | } catch (e) { | |
273d1e29 | 334 | // |
11063ec6 AD |
335 | } |
336 | ||
784ac51f AD |
337 | if (upd_img_pic && (upd_img_pic.src.match("updated.png") || |
338 | upd_img_pic.src.match("fresh_sign.png"))) { | |
339 | ||
fdcdf2de | 340 | upd_img_pic.src = "images/blank_icon.gif"; |
ebda016b AD |
341 | |
342 | cache_invalidate(cache_prefix + getActiveFeedId()); | |
ce411c4b AD |
343 | |
344 | cache_inject(cache_prefix + getActiveFeedId(), | |
acac8448 | 345 | $("headlines-frame").innerHTML, |
ce411c4b | 346 | get_feed_unread(getActiveFeedId())); |
fdcdf2de | 347 | |
11063ec6 | 348 | } else if (article_is_unread && view_mode == "all_articles") { |
fdcdf2de AD |
349 | |
350 | cache_invalidate(cache_prefix + getActiveFeedId()); | |
351 | ||
352 | cache_inject(cache_prefix + getActiveFeedId(), | |
acac8448 | 353 | $("headlines-frame").innerHTML, |
fdcdf2de AD |
354 | get_feed_unread(getActiveFeedId())-1); |
355 | ||
3de99e6b AD |
356 | } else if (article_is_unread) { |
357 | cache_invalidate(cache_prefix + getActiveFeedId()); | |
868d0ed2 | 358 | } |
e097e8be | 359 | |
4c009c78 AD |
360 | markHeadline(id); |
361 | ||
868d0ed2 AD |
362 | } catch (e) { |
363 | exception_error("showArticleInHeadlines", e); | |
364 | } | |
71d277de | 365 | } |
e097e8be | 366 | |
71d277de AD |
367 | function article_callback2(transport, id, feed_id) { |
368 | try { | |
369 | debug("article_callback2 " + id); | |
e097e8be | 370 | |
9ca945a6 AD |
371 | if (!transport.responseText && db) { |
372 | offlineConfirmModeChange(); | |
373 | return; | |
374 | } | |
375 | ||
71d277de | 376 | if (transport.responseXML) { |
e097e8be | 377 | |
2184738a AD |
378 | if (!transport_error_check(transport)) return; |
379 | ||
6e35a862 AD |
380 | var ll = $('LL-' + id); |
381 | var content = $('HLC-' + id); | |
382 | ||
383 | if (ll && content) content.removeChild(ll); | |
384 | ||
385 | if (id != last_requested_article) { | |
386 | debug("requested article id is out of sequence, aborting"); | |
387 | return; | |
388 | } | |
389 | ||
390 | active_real_feed_id = feed_id; | |
391 | active_post_id = id; | |
392 | ||
fbcabe1e | 393 | debug("looking for articles to cache..."); |
71d277de AD |
394 | |
395 | var articles = transport.responseXML.getElementsByTagName("article"); | |
396 | ||
397 | for (var i = 0; i < articles.length; i++) { | |
398 | var a_id = articles[i].getAttribute("id"); | |
399 | ||
400 | debug("found id: " + a_id); | |
401 | ||
402 | if (a_id == active_post_id) { | |
403 | debug("active article, rendering..."); | |
404 | render_article(articles[i].firstChild.nodeValue); | |
e097e8be | 405 | } |
71d277de AD |
406 | |
407 | cache_inject(a_id, articles[i].firstChild.nodeValue); | |
e097e8be | 408 | } |
fbcabe1e | 409 | |
fbcabe1e AD |
410 | |
411 | showArticleInHeadlines(id); | |
412 | ||
2f71f07b AD |
413 | if (db) { |
414 | db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]); | |
415 | } | |
416 | ||
fbcabe1e | 417 | var reply = transport.responseXML.firstChild.firstChild; |
71d277de AD |
418 | |
419 | } else { | |
420 | debug("article_callback: returned no XML object"); | |
acac8448 | 421 | //var f = $("content-frame"); |
17042fc0 | 422 | //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>"; |
e097e8be | 423 | } |
4b6206fa AD |
424 | |
425 | var date = new Date(); | |
426 | last_article_view = date.getTime() / 1000; | |
427 | ||
935f235d AD |
428 | if (typeof correctPNG != 'undefined') { |
429 | correctPNG(); | |
430 | } | |
0b126ac2 AD |
431 | |
432 | if (_reload_feedlist_after_view) { | |
433 | setTimeout('updateFeedList(false, false)', 50); | |
434 | _reload_feedlist_after_view = false; | |
435 | } else { | |
d63170bf AD |
436 | if (transport.responseXML) { |
437 | var counters = transport.responseXML.getElementsByTagName("counters")[0]; | |
5a94a953 | 438 | |
d63170bf AD |
439 | if (counters) { |
440 | debug("parsing piggybacked counters: " + counters); | |
441 | parse_counters(counters, false); | |
442 | } else { | |
443 | debug("counters container not found in reply, requesting..."); | |
444 | request_counters(); | |
445 | } | |
5a94a953 | 446 | } |
0b126ac2 | 447 | } |
9ec58704 AD |
448 | |
449 | notify(""); | |
71d277de | 450 | } catch (e) { |
273d1e29 | 451 | exception_error("article_callback2", e, transport); |
6b4163cb AD |
452 | } |
453 | } | |
454 | ||
1dc8dba0 | 455 | function view(id, feed_id, skip_history) { |
ee1f45f4 AD |
456 | |
457 | try { | |
ee1f45f4 | 458 | debug("loading article: " + id + "/" + feed_id); |
45a6446d AD |
459 | |
460 | if (offline_mode) return view_offline(id, feed_id); | |
461 | ||
e097e8be AD |
462 | var cached_article = cache_find(id); |
463 | ||
464 | debug("cache check result: " + (cached_article != false)); | |
ee1f45f4 | 465 | |
ee1f45f4 AD |
466 | enableHotkeys(); |
467 | ||
1c2d7193 | 468 | //setActiveFeedId(feed_id); |
090e250b | 469 | |
6b4163cb AD |
470 | var query = "backend.php?op=view&id=" + param_escape(id) + |
471 | "&feed=" + param_escape(feed_id); | |
472 | ||
4b6206fa AD |
473 | var date = new Date(); |
474 | ||
71d277de | 475 | var neighbor_ids = getRelativePostIds(active_post_id); |
e097e8be | 476 | |
71d277de | 477 | /* only request uncached articles */ |
e097e8be | 478 | |
71d277de | 479 | var cids_to_request = Array(); |
5a94a953 | 480 | |
71d277de AD |
481 | for (var i = 0; i < neighbor_ids.length; i++) { |
482 | if (!cache_check(neighbor_ids[i])) { | |
483 | cids_to_request.push(neighbor_ids[i]); | |
5a94a953 | 484 | } |
71d277de | 485 | } |
5a94a953 | 486 | |
71d277de | 487 | debug("additional ids: " + cids_to_request.toString()); |
e097e8be | 488 | |
71d277de | 489 | /* additional info for piggyback counters */ |
e097e8be | 490 | |
71d277de AD |
491 | if (tagsAreDisplayed()) { |
492 | query = query + "&omode=lt"; | |
493 | } else { | |
494 | query = query + "&omode=flc"; | |
495 | } | |
e097e8be | 496 | |
71d277de AD |
497 | var date = new Date(); |
498 | var timestamp = Math.round(date.getTime() / 1000); | |
499 | query = query + "&ts=" + timestamp; | |
e097e8be | 500 | |
71d277de | 501 | query = query + "&cids=" + cids_to_request.toString(); |
e097e8be | 502 | |
acac8448 | 503 | var crow = $("RROW-" + id); |
71d277de | 504 | var article_is_unread = crow.className.match("Unread"); |
e097e8be | 505 | |
6cc1fab3 AD |
506 | if (!async_counters_work) { |
507 | query = query + "&csync=true"; | |
508 | } | |
509 | ||
3f70f90f AD |
510 | showArticleInHeadlines(id); |
511 | ||
71d277de | 512 | if (!cached_article) { |
e097e8be | 513 | |
6e35a862 AD |
514 | // notify_progress("Loading, please wait...", true); |
515 | ||
516 | var content = $('HLC-' + id); | |
517 | ||
518 | if (content && !$('LL-' + id)) { | |
519 | var ll = document.createElement('img'); | |
520 | ||
521 | ll.src = 'images/indicator_tiny.gif'; | |
522 | ll.className = 'hlLoading'; | |
523 | ll.id = 'LL-' + id; | |
524 | ||
525 | content.appendChild(ll); | |
526 | ||
527 | } | |
e097e8be | 528 | |
71d277de | 529 | } else if (cached_article && article_is_unread) { |
addb5836 | 530 | |
71d277de | 531 | query = query + "&mode=prefetch"; |
addb5836 | 532 | |
71d277de | 533 | render_article(cached_article); |
addb5836 | 534 | |
71d277de | 535 | } else if (cached_article) { |
e097e8be | 536 | |
71d277de AD |
537 | query = query + "&mode=prefetch_old"; |
538 | render_article(cached_article); | |
997d9d7c | 539 | |
71d277de | 540 | } |
e097e8be | 541 | |
71d277de | 542 | cache_expire(); |
86173d9a | 543 | |
022d9e9e AD |
544 | last_requested_article = id; |
545 | ||
71d277de AD |
546 | new Ajax.Request(query, { |
547 | onComplete: function(transport) { | |
548 | article_callback2(transport, id, feed_id); | |
549 | } }); | |
6b4163cb | 550 | |
a7764e51 AD |
551 | return false; |
552 | ||
ee1f45f4 AD |
553 | } catch (e) { |
554 | exception_error("view", e); | |
555 | } | |
f0601b87 AD |
556 | } |
557 | ||
67343d9f AD |
558 | function tMark(id) { |
559 | return toggleMark(id); | |
560 | } | |
561 | ||
e4f4b46f AD |
562 | function tPub(id) { |
563 | return togglePub(id); | |
564 | } | |
565 | ||
6b0f49f9 AD |
566 | function tMark_afh_off(effect) { |
567 | try { | |
568 | var elem = effect.effects[0].element; | |
569 | ||
570 | debug("tMark_afh_off : " + elem.id); | |
571 | ||
572 | if (elem) { | |
f5e0338d AD |
573 | elem.src = elem.src.replace("mark_set", "mark_unset"); |
574 | elem.alt = __("Star article"); | |
6b0f49f9 AD |
575 | Element.show(elem); |
576 | } | |
577 | ||
578 | } catch (e) { | |
579 | exception_error("tMark_afh_off", e); | |
580 | } | |
581 | } | |
582 | ||
583 | function tPub_afh_off(effect) { | |
584 | try { | |
585 | var elem = effect.effects[0].element; | |
586 | ||
587 | debug("tPub_afh_off : " + elem.id); | |
588 | ||
589 | if (elem) { | |
f5e0338d AD |
590 | elem.src = elem.src.replace("pub_set", "pub_unset"); |
591 | elem.alt = __("Publish article"); | |
6b0f49f9 AD |
592 | Element.show(elem); |
593 | } | |
594 | ||
595 | } catch (e) { | |
596 | exception_error("tPub_afh_off", e); | |
597 | } | |
598 | } | |
e4f4b46f | 599 | |
f5e0338d | 600 | function toggleMark(id, client_only, no_effects) { |
f0601b87 | 601 | |
b685ba25 | 602 | try { |
254e0e4b | 603 | |
b685ba25 AD |
604 | var query = "backend.php?op=rpc&id=" + id + "&subop=mark"; |
605 | ||
606 | query = query + "&afid=" + getActiveFeedId(); | |
607 | ||
608 | if (tagsAreDisplayed()) { | |
609 | query = query + "&omode=tl"; | |
610 | } else { | |
611 | query = query + "&omode=flc"; | |
7ba176d2 | 612 | } |
b685ba25 | 613 | |
acac8448 | 614 | var mark_img = $("FMPIC-" + id); |
56ff7564 AD |
615 | |
616 | if (!mark_img) return; | |
617 | ||
acac8448 AD |
618 | var vfeedu = $("FEEDU--1"); |
619 | var crow = $("RROW-" + id); | |
b685ba25 | 620 | |
f5e0338d AD |
621 | if (mark_img.src.match("mark_unset")) { |
622 | mark_img.src = mark_img.src.replace("mark_unset", "mark_set"); | |
623 | mark_img.alt = __("Unstar article"); | |
b685ba25 | 624 | query = query + "&mark=1"; |
ee8768db | 625 | |
2f71f07b AD |
626 | if (db) { |
627 | db.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id]); | |
628 | } | |
629 | ||
b685ba25 AD |
630 | } else { |
631 | //mark_img.src = "images/mark_unset.png"; | |
f5e0338d | 632 | mark_img.alt = __("Please wait..."); |
b685ba25 AD |
633 | query = query + "&mark=0"; |
634 | ||
acac8448 | 635 | if ($("headlinesList") && !no_effects) { |
b685ba25 AD |
636 | Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off}); |
637 | } else { | |
f5e0338d AD |
638 | mark_img.src = mark_img.src.replace("mark_set", "mark_unset"); |
639 | mark_img.alt = __("Star article"); | |
b685ba25 | 640 | } |
2f71f07b AD |
641 | |
642 | if (db) { | |
643 | db.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id]); | |
644 | } | |
645 | ||
ace1a6da | 646 | } |
772bc83b | 647 | |
46b84d29 | 648 | if (!no_effects) update_local_feedlist_counters(); |
c8a9fe5b | 649 | |
f5e0338d AD |
650 | if (!client_only) { |
651 | debug(query); | |
36e05046 | 652 | |
1341ea0d AD |
653 | new Ajax.Request(query, { |
654 | onComplete: function(transport) { | |
655 | all_counters_callback2(transport); | |
656 | } }); | |
657 | ||
f5e0338d | 658 | } |
f0601b87 | 659 | |
b685ba25 AD |
660 | } catch (e) { |
661 | exception_error("toggleMark", e); | |
662 | } | |
f0601b87 AD |
663 | } |
664 | ||
c7e51de1 | 665 | function togglePub(id, client_only, no_effects, note) { |
e4f4b46f | 666 | |
2bc2147f | 667 | try { |
e4f4b46f | 668 | |
2bc2147f AD |
669 | var query = "backend.php?op=rpc&id=" + id + "&subop=publ"; |
670 | ||
671 | query = query + "&afid=" + getActiveFeedId(); | |
c7e51de1 AD |
672 | |
673 | if (note != undefined) { | |
674 | query = query + "¬e=" + param_escape(note); | |
675 | } else { | |
676 | query = query + "¬e=undefined"; | |
677 | } | |
2bc2147f AD |
678 | |
679 | if (tagsAreDisplayed()) { | |
680 | query = query + "&omode=tl"; | |
681 | } else { | |
682 | query = query + "&omode=flc"; | |
e4f4b46f | 683 | } |
2bc2147f | 684 | |
acac8448 | 685 | var mark_img = $("FPPIC-" + id); |
56ff7564 AD |
686 | |
687 | if (!mark_img) return; | |
688 | ||
acac8448 AD |
689 | var vfeedu = $("FEEDU--2"); |
690 | var crow = $("RROW-" + id); | |
2bc2147f | 691 | |
c7e51de1 | 692 | if (mark_img.src.match("pub_unset") || note != undefined) { |
f5e0338d AD |
693 | mark_img.src = mark_img.src.replace("pub_unset", "pub_set"); |
694 | mark_img.alt = __("Unpublish article"); | |
2bc2147f | 695 | query = query + "&pub=1"; |
ee8768db | 696 | |
e4f4b46f | 697 | } else { |
6b0f49f9 | 698 | //mark_img.src = "images/pub_unset.png"; |
f5e0338d | 699 | mark_img.alt = __("Please wait..."); |
2bc2147f AD |
700 | query = query + "&pub=0"; |
701 | ||
acac8448 | 702 | if ($("headlinesList") && !no_effects) { |
ace1a6da AD |
703 | Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off}); |
704 | } else { | |
f5e0338d AD |
705 | mark_img.src = mark_img.src.replace("pub_set", "pub_unset"); |
706 | mark_img.alt = __("Publish article"); | |
ace1a6da | 707 | } |
e4f4b46f | 708 | } |
b685ba25 | 709 | |
f5e0338d | 710 | if (!client_only) { |
1341ea0d AD |
711 | new Ajax.Request(query, { |
712 | onComplete: function(transport) { | |
c7e51de1 | 713 | toggle_published_callback(transport); |
1341ea0d | 714 | } }); |
f5e0338d | 715 | } |
b685ba25 | 716 | |
2bc2147f | 717 | } catch (e) { |
e4f4b46f | 718 | |
2bc2147f AD |
719 | exception_error("togglePub", e); |
720 | } | |
e4f4b46f AD |
721 | } |
722 | ||
ac162cbe AD |
723 | function correctHeadlinesOffset(id) { |
724 | ||
725 | try { | |
726 | ||
acac8448 AD |
727 | var hlist = $("headlinesList"); |
728 | var container = $("headlinesInnerContainer"); | |
729 | var row = $("RROW-" + id); | |
ac162cbe AD |
730 | |
731 | var viewport = container.offsetHeight; | |
732 | ||
733 | var rel_offset_top = row.offsetTop - container.scrollTop; | |
734 | var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; | |
735 | ||
736 | debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); | |
737 | debug("Vport: " + viewport); | |
a5e46e0f | 738 | |
ac162cbe AD |
739 | if (rel_offset_top <= 0 || rel_offset_top > viewport) { |
740 | container.scrollTop = row.offsetTop; | |
741 | } else if (rel_offset_bottom > viewport) { | |
a5e46e0f AD |
742 | |
743 | /* doesn't properly work with Opera in some cases because | |
744 | Opera fucks up element scrolling */ | |
745 | ||
ac162cbe AD |
746 | container.scrollTop = row.offsetTop + row.offsetHeight - viewport; |
747 | } | |
748 | ||
749 | } catch (e) { | |
750 | exception_error("correctHeadlinesOffset", e); | |
751 | } | |
752 | ||
753 | } | |
754 | ||
bb7cface | 755 | function moveToPost(mode) { |
f0601b87 | 756 | |
b8e6acea AD |
757 | try { |
758 | ||
5ad9d132 AD |
759 | var rows; |
760 | ||
761 | if (isCdmMode()) { | |
762 | rows = cdmGetVisibleArticles(); | |
763 | } else { | |
764 | rows = getVisibleHeadlineIds(); | |
765 | } | |
b8e6acea | 766 | |
5ad9d132 AD |
767 | var prev_id = false; |
768 | var next_id = false; | |
b8e6acea | 769 | |
acac8448 | 770 | if (!$('RROW-' + active_post_id)) { |
5ad9d132 AD |
771 | active_post_id = false; |
772 | } | |
b8e6acea | 773 | |
5ad9d132 AD |
774 | if (active_post_id == false) { |
775 | next_id = getFirstVisibleHeadlineId(); | |
776 | prev_id = getLastVisibleHeadlineId(); | |
777 | } else { | |
778 | for (var i = 0; i < rows.length; i++) { | |
779 | if (rows[i] == active_post_id) { | |
780 | prev_id = rows[i-1]; | |
781 | next_id = rows[i+1]; | |
b8e6acea AD |
782 | } |
783 | } | |
5ad9d132 | 784 | } |
b8e6acea | 785 | |
5ad9d132 AD |
786 | if (mode == "next") { |
787 | if (next_id) { | |
788 | if (isCdmMode()) { | |
789 | ||
790 | if (!cdmArticleIsActuallyVisible(next_id)) { | |
791 | cdmScrollToArticleId(next_id); | |
792 | } | |
793 | cdmSelectArticles("none"); | |
794 | toggleUnread(next_id, 0, true); | |
795 | toggleSelected(next_id); | |
796 | ||
797 | } else { | |
b8e6acea AD |
798 | correctHeadlinesOffset(next_id); |
799 | view(next_id, getActiveFeedId()); | |
800 | } | |
801 | } | |
5ad9d132 | 802 | } |
b8e6acea | 803 | |
5ad9d132 AD |
804 | if (mode == "prev") { |
805 | if (prev_id) { | |
806 | if (isCdmMode()) { | |
807 | cdmScrollToArticleId(prev_id); | |
808 | cdmSelectArticles("none"); | |
809 | toggleUnread(prev_id, 0, true); | |
810 | toggleSelected(prev_id); | |
811 | } else { | |
b8e6acea AD |
812 | correctHeadlinesOffset(prev_id); |
813 | view(prev_id, getActiveFeedId()); | |
814 | } | |
5ad9d132 AD |
815 | } |
816 | } | |
817 | ||
b8e6acea | 818 | } catch (e) { |
438f2ce9 | 819 | exception_error("moveToPost", e); |
bb7cface | 820 | } |
b8e6acea AD |
821 | } |
822 | ||
823 | function toggleSelected(id) { | |
824 | try { | |
825 | ||
acac8448 | 826 | var cb = $("RCHK-" + id); |
5ad9d132 | 827 | |
acac8448 | 828 | var row = $("RROW-" + id); |
b8e6acea AD |
829 | if (row) { |
830 | var nc = row.className; | |
831 | ||
832 | if (!nc.match("Selected")) { | |
833 | nc = nc + "Selected"; | |
5ad9d132 AD |
834 | if (cb) { |
835 | cb.checked = true; | |
836 | } | |
837 | ||
838 | // In CDM basically last selected article == active article | |
839 | if (isCdmMode()) active_post_id = id; | |
b8e6acea AD |
840 | } else { |
841 | nc = nc.replace("Selected", ""); | |
5ad9d132 AD |
842 | if (cb) { |
843 | cb.checked = false; | |
844 | } | |
845 | ||
b8e6acea | 846 | } |
bb7cface | 847 | |
b8e6acea | 848 | row.className = nc; |
bb7cface | 849 | } |
b8e6acea | 850 | } catch (e) { |
438f2ce9 | 851 | exception_error("toggleSelected", e); |
b8e6acea | 852 | } |
bb7cface AD |
853 | } |
854 | ||
0df009c3 | 855 | function toggleUnread_afh(effect) { |
b8e6acea AD |
856 | try { |
857 | ||
858 | var elem = effect.element; | |
0df009c3 | 859 | elem.style.backgroundColor = ""; |
b8e6acea | 860 | |
b8e6acea | 861 | } catch (e) { |
438f2ce9 | 862 | exception_error("toggleUnread_afh", e); |
b8e6acea | 863 | } |
0df009c3 | 864 | } |
b8e6acea AD |
865 | |
866 | function toggleUnread(id, cmode, effect) { | |
5f51022a | 867 | try { |
5f51022a | 868 | |
acac8448 | 869 | var row = $("RROW-" + id); |
5f51022a AD |
870 | if (row) { |
871 | var nc = row.className; | |
93f66472 | 872 | var is_selected = row.className.match("Selected"); |
5f51022a AD |
873 | nc = nc.replace("Unread", ""); |
874 | nc = nc.replace("Selected", ""); | |
875 | ||
b8e6acea AD |
876 | // since we are removing selection from the object, uncheck |
877 | // corresponding checkbox | |
878 | ||
acac8448 | 879 | var cb = $("RCHK-" + id); |
b8e6acea AD |
880 | if (cb) { |
881 | cb.checked = false; | |
882 | } | |
883 | ||
884 | // NOTE: I'm not sure that resetting selection here is a feature -fox | |
885 | ||
a70ab740 AD |
886 | if (cmode == undefined || cmode == 2) { |
887 | if (row.className.match("Unread")) { | |
888 | row.className = nc; | |
b8e6acea | 889 | |
0df009c3 | 890 | if (effect) { |
b8e6acea AD |
891 | new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5", |
892 | afterFinish: toggleUnread_afh, | |
893 | queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } ); | |
0df009c3 | 894 | } |
b8e6acea | 895 | |
a70ab740 AD |
896 | } else { |
897 | row.className = nc + "Unread"; | |
898 | } | |
1a003258 AD |
899 | |
900 | if (db) { | |
901 | db.execute("UPDATE articles SET unread = not unread "+ | |
902 | "WHERE id = ?", [id]); | |
903 | } | |
904 | ||
a70ab740 | 905 | } else if (cmode == 0) { |
5f51022a | 906 | row.className = nc; |
b8e6acea | 907 | |
54eb7d20 | 908 | if (effect) { |
b8e6acea | 909 | new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5", |
54eb7d20 | 910 | afterFinish: toggleUnread_afh, |
b8e6acea | 911 | queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } ); |
54eb7d20 | 912 | } |
1a003258 AD |
913 | |
914 | if (db) { | |
915 | db.execute("UPDATE articles SET unread = 0 "+ | |
916 | "WHERE id = ?", [id]); | |
917 | } | |
918 | ||
a70ab740 | 919 | } else if (cmode == 1) { |
5f51022a | 920 | row.className = nc + "Unread"; |
1a003258 AD |
921 | |
922 | if (db) { | |
923 | db.execute("UPDATE articles SET unread = 1 "+ | |
924 | "WHERE id = ?", [id]); | |
925 | } | |
926 | ||
5f51022a AD |
927 | } |
928 | ||
1a003258 AD |
929 | update_local_feedlist_counters(); |
930 | ||
93f66472 AD |
931 | // Disable unmarking as selected for the time being (16.05.08) -fox |
932 | if (is_selected) row.className = row.className + "Selected"; | |
933 | ||
a70ab740 | 934 | if (cmode == undefined) cmode = 2; |
5f51022a | 935 | |
2855ee88 AD |
936 | var query = "backend.php?op=rpc&subop=catchupSelected" + |
937 | "&cmode=" + param_escape(cmode); | |
938 | ||
939 | var ids = "?ids=" + param_escape(id); | |
5f51022a | 940 | |
1341ea0d | 941 | // notify_progress("Loading, please wait..."); |
9ec58704 | 942 | |
1341ea0d | 943 | new Ajax.Request(query, { |
2855ee88 | 944 | parameters: ids, |
1341ea0d AD |
945 | onComplete: function(transport) { |
946 | all_counters_callback2(transport); | |
947 | } }); | |
5f51022a AD |
948 | |
949 | } | |
950 | ||
5f51022a AD |
951 | } catch (e) { |
952 | exception_error("toggleUnread", e); | |
953 | } | |
954 | } | |
955 | ||
933ba4ee AD |
956 | function selectionRemoveLabel(id) { |
957 | try { | |
958 | ||
959 | var ids = getSelectedArticleIds2(); | |
960 | ||
961 | if (ids.length == 0) { | |
962 | alert(__("No articles are selected.")); | |
963 | return; | |
964 | } | |
965 | ||
37843d70 | 966 | // var ok = confirm(__("Remove selected articles from label?")); |
933ba4ee | 967 | |
37843d70 | 968 | // if (ok) { |
933ba4ee AD |
969 | |
970 | var query = "backend.php?op=rpc&subop=removeFromLabel&ids=" + | |
971 | param_escape(ids.toString()) + "&lid=" + param_escape(id); | |
972 | ||
973 | // notify_progress("Loading, please wait..."); | |
974 | ||
898e8562 AD |
975 | cache_invalidate("F:" + (-11 - id)); |
976 | ||
933ba4ee AD |
977 | new Ajax.Request(query, { |
978 | onComplete: function(transport) { | |
1c9c6025 AD |
979 | show_labels_in_headlines(transport); |
980 | all_counters_callback2(transport); | |
933ba4ee AD |
981 | } }); |
982 | ||
37843d70 | 983 | // } |
933ba4ee AD |
984 | |
985 | } catch (e) { | |
986 | exception_error("selectionAssignLabel", e); | |
987 | ||
988 | } | |
989 | } | |
990 | ||
b8a637f3 AD |
991 | function selectionAssignLabel(id) { |
992 | try { | |
993 | ||
994 | var ids = getSelectedArticleIds2(); | |
995 | ||
996 | if (ids.length == 0) { | |
997 | alert(__("No articles are selected.")); | |
998 | return; | |
999 | } | |
1000 | ||
37843d70 | 1001 | // var ok = confirm(__("Assign selected articles to label?")); |
b8a637f3 | 1002 | |
37843d70 | 1003 | // if (ok) { |
b8a637f3 | 1004 | |
898e8562 AD |
1005 | cache_invalidate("F:" + (-11 - id)); |
1006 | ||
b8a637f3 AD |
1007 | var query = "backend.php?op=rpc&subop=assignToLabel&ids=" + |
1008 | param_escape(ids.toString()) + "&lid=" + param_escape(id); | |
1009 | ||
1010 | // notify_progress("Loading, please wait..."); | |
1011 | ||
1012 | new Ajax.Request(query, { | |
1013 | onComplete: function(transport) { | |
f9247195 AD |
1014 | show_labels_in_headlines(transport); |
1015 | all_counters_callback2(transport); | |
b8a637f3 AD |
1016 | } }); |
1017 | ||
37843d70 | 1018 | // } |
b8a637f3 AD |
1019 | |
1020 | } catch (e) { | |
1021 | exception_error("selectionAssignLabel", e); | |
1022 | ||
1023 | } | |
1024 | } | |
1025 | ||
2228d0e4 | 1026 | function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) { |
1572afe5 | 1027 | try { |
386cbf27 AD |
1028 | var rows; |
1029 | ||
1030 | if (cdm_mode) { | |
1031 | rows = cdmGetSelectedArticles(); | |
1032 | } else { | |
1033 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
1034 | } | |
1572afe5 | 1035 | |
2228d0e4 | 1036 | if (rows.length == 0 && !no_error) { |
9cc600d1 AD |
1037 | alert(__("No articles are selected.")); |
1038 | return; | |
1039 | } | |
1040 | ||
1572afe5 | 1041 | for (i = 0; i < rows.length; i++) { |
acac8448 | 1042 | var row = $("RROW-" + rows[i]); |
f1f2db64 AD |
1043 | if (row) { |
1044 | var nc = row.className; | |
1045 | nc = nc.replace("Unread", ""); | |
1046 | nc = nc.replace("Selected", ""); | |
1047 | ||
a5ae125a AD |
1048 | if (set_state == undefined) { |
1049 | if (row.className.match("Unread")) { | |
1050 | row.className = nc + "Selected"; | |
1051 | } else { | |
1052 | row.className = nc + "UnreadSelected"; | |
1053 | } | |
46b84d29 AD |
1054 | if (db) { |
1055 | db.execute("UPDATE articles SET unread = NOT unread WHERE id = ?", | |
1056 | [rows[i]]); | |
1057 | } | |
a5ae125a AD |
1058 | } |
1059 | ||
1060 | if (set_state == false) { | |
f1f2db64 | 1061 | row.className = nc + "Selected"; |
46b84d29 AD |
1062 | if (db) { |
1063 | db.execute("UPDATE articles SET unread = 0 WHERE id = ?", | |
1064 | [rows[i]]); | |
1065 | } | |
a5ae125a AD |
1066 | } |
1067 | ||
1068 | if (set_state == true) { | |
f1f2db64 | 1069 | row.className = nc + "UnreadSelected"; |
46b84d29 AD |
1070 | if (db) { |
1071 | db.execute("UPDATE articles SET unread = 1 WHERE id = ?", | |
1072 | [rows[i]]); | |
1073 | } | |
f1f2db64 AD |
1074 | } |
1075 | } | |
1572afe5 AD |
1076 | } |
1077 | ||
1078 | if (rows.length > 0) { | |
1079 | ||
46b84d29 AD |
1080 | update_local_feedlist_counters(); |
1081 | ||
b47b5af7 AD |
1082 | var cmode = ""; |
1083 | ||
1084 | if (set_state == undefined) { | |
1085 | cmode = "2"; | |
1086 | } else if (set_state == true) { | |
1087 | cmode = "1"; | |
1088 | } else if (set_state == false) { | |
1089 | cmode = "0"; | |
1090 | } | |
1091 | ||
2855ee88 AD |
1092 | var query = "backend.php?op=rpc&subop=catchupSelected" + |
1093 | "&cmode=" + cmode; | |
1094 | ||
1095 | var ids = "?ids=" + param_escape(rows.toString()); | |
1572afe5 | 1096 | |
9ec58704 AD |
1097 | notify_progress("Loading, please wait..."); |
1098 | ||
1341ea0d | 1099 | new Ajax.Request(query, { |
2855ee88 | 1100 | parameters: ids, |
1341ea0d AD |
1101 | onComplete: function(transport) { |
1102 | catchup_callback2(transport, callback_func); | |
1103 | } }); | |
1572afe5 AD |
1104 | |
1105 | } | |
1106 | ||
1107 | } catch (e) { | |
83f043bb | 1108 | exception_error("selectionToggleUnread", e); |
1572afe5 AD |
1109 | } |
1110 | } | |
1111 | ||
386cbf27 | 1112 | function selectionToggleMarked(cdm_mode) { |
1572afe5 | 1113 | try { |
1572afe5 | 1114 | |
386cbf27 AD |
1115 | var rows; |
1116 | ||
1117 | if (cdm_mode) { | |
1118 | rows = cdmGetSelectedArticles(); | |
1119 | } else { | |
1120 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
1121 | } | |
1572afe5 | 1122 | |
9cc600d1 AD |
1123 | if (rows.length == 0) { |
1124 | alert(__("No articles are selected.")); | |
1125 | return; | |
1126 | } | |
1127 | ||
1572afe5 | 1128 | for (i = 0; i < rows.length; i++) { |
f5e0338d | 1129 | toggleMark(rows[i], true, true); |
1572afe5 AD |
1130 | } |
1131 | ||
46b84d29 AD |
1132 | update_local_feedlist_counters(); |
1133 | ||
1572afe5 AD |
1134 | if (rows.length > 0) { |
1135 | ||
1136 | var query = "backend.php?op=rpc&subop=markSelected&ids=" + | |
1137 | param_escape(rows.toString()) + "&cmode=2"; | |
1138 | ||
2bc2147f AD |
1139 | query = query + "&afid=" + getActiveFeedId(); |
1140 | ||
1341ea0d | 1141 | /* if (tagsAreDisplayed()) { |
2bc2147f AD |
1142 | query = query + "&omode=tl"; |
1143 | } else { | |
1144 | query = query + "&omode=flc"; | |
1341ea0d AD |
1145 | } */ |
1146 | ||
1147 | query = query + "&omode=lc"; | |
2bc2147f | 1148 | |
1341ea0d AD |
1149 | new Ajax.Request(query, { |
1150 | onComplete: function(transport) { | |
1151 | all_counters_callback2(transport); | |
1152 | } }); | |
1572afe5 AD |
1153 | |
1154 | } | |
1155 | ||
1156 | } catch (e) { | |
83f043bb | 1157 | exception_error("selectionToggleMarked", e); |
1572afe5 AD |
1158 | } |
1159 | } | |
1160 | ||
e4f4b46f AD |
1161 | function selectionTogglePublished(cdm_mode) { |
1162 | try { | |
e4f4b46f AD |
1163 | |
1164 | var rows; | |
1165 | ||
1166 | if (cdm_mode) { | |
1167 | rows = cdmGetSelectedArticles(); | |
1168 | } else { | |
1169 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
1170 | } | |
1171 | ||
1172 | if (rows.length == 0) { | |
1173 | alert(__("No articles are selected.")); | |
1174 | return; | |
1175 | } | |
1176 | ||
1177 | for (i = 0; i < rows.length; i++) { | |
f5e0338d | 1178 | togglePub(rows[i], true, true); |
e4f4b46f AD |
1179 | } |
1180 | ||
1181 | if (rows.length > 0) { | |
1182 | ||
1183 | var query = "backend.php?op=rpc&subop=publishSelected&ids=" + | |
1184 | param_escape(rows.toString()) + "&cmode=2"; | |
1185 | ||
2bc2147f AD |
1186 | query = query + "&afid=" + getActiveFeedId(); |
1187 | ||
1341ea0d | 1188 | /* if (tagsAreDisplayed()) { |
2bc2147f AD |
1189 | query = query + "&omode=tl"; |
1190 | } else { | |
1191 | query = query + "&omode=flc"; | |
1341ea0d AD |
1192 | } */ |
1193 | ||
1194 | query = query + "&omode=lc"; | |
2bc2147f | 1195 | |
1341ea0d AD |
1196 | new Ajax.Request(query, { |
1197 | onComplete: function(transport) { | |
1198 | all_counters_callback2(transport); | |
1199 | } }); | |
e4f4b46f AD |
1200 | |
1201 | } | |
1202 | ||
1203 | } catch (e) { | |
1204 | exception_error("selectionToggleMarked", e); | |
1205 | } | |
1206 | } | |
1207 | ||
386cbf27 AD |
1208 | function cdmGetSelectedArticles() { |
1209 | var sel_articles = new Array(); | |
acac8448 | 1210 | var container = $("headlinesInnerContainer"); |
386cbf27 AD |
1211 | |
1212 | for (i = 0; i < container.childNodes.length; i++) { | |
1213 | var child = container.childNodes[i]; | |
1214 | ||
02895941 | 1215 | if (child.id && child.id.match("RROW-") && child.className.match("Selected")) { |
386cbf27 AD |
1216 | var c_id = child.id.replace("RROW-", ""); |
1217 | sel_articles.push(c_id); | |
1218 | } | |
1219 | } | |
1220 | ||
1221 | return sel_articles; | |
1222 | } | |
1223 | ||
8be83f42 AD |
1224 | function cdmGetVisibleArticles() { |
1225 | var sel_articles = new Array(); | |
acac8448 | 1226 | var container = $("headlinesInnerContainer"); |
8be83f42 | 1227 | |
3a40e8a2 AD |
1228 | if (!container) return sel_articles; |
1229 | ||
8be83f42 AD |
1230 | for (i = 0; i < container.childNodes.length; i++) { |
1231 | var child = container.childNodes[i]; | |
1232 | ||
02895941 | 1233 | if (child.id && child.id.match("RROW-")) { |
8be83f42 AD |
1234 | var c_id = child.id.replace("RROW-", ""); |
1235 | sel_articles.push(c_id); | |
1236 | } | |
1237 | } | |
1238 | ||
1239 | return sel_articles; | |
1240 | } | |
1241 | ||
1242 | function cdmGetUnreadArticles() { | |
1243 | var sel_articles = new Array(); | |
acac8448 | 1244 | var container = $("headlinesInnerContainer"); |
8be83f42 AD |
1245 | |
1246 | for (i = 0; i < container.childNodes.length; i++) { | |
1247 | var child = container.childNodes[i]; | |
1248 | ||
02895941 | 1249 | if (child.id && child.id.match("RROW-") && child.className.match("Unread")) { |
8be83f42 AD |
1250 | var c_id = child.id.replace("RROW-", ""); |
1251 | sel_articles.push(c_id); | |
1252 | } | |
1253 | } | |
1254 | ||
1255 | return sel_articles; | |
1256 | } | |
1257 | ||
1258 | ||
386cbf27 AD |
1259 | // mode = all,none,unread |
1260 | function cdmSelectArticles(mode) { | |
acac8448 | 1261 | var container = $("headlinesInnerContainer"); |
386cbf27 AD |
1262 | |
1263 | for (i = 0; i < container.childNodes.length; i++) { | |
1264 | var child = container.childNodes[i]; | |
1265 | ||
02895941 | 1266 | if (child.id && child.id.match("RROW-")) { |
06d1a1c1 AD |
1267 | var aid = child.id.replace("RROW-", ""); |
1268 | ||
acac8448 | 1269 | var cb = $("RCHK-" + aid); |
06d1a1c1 | 1270 | |
386cbf27 AD |
1271 | if (mode == "all") { |
1272 | if (!child.className.match("Selected")) { | |
1273 | child.className = child.className + "Selected"; | |
06d1a1c1 | 1274 | cb.checked = true; |
386cbf27 AD |
1275 | } |
1276 | } else if (mode == "unread") { | |
1277 | if (child.className.match("Unread") && !child.className.match("Selected")) { | |
1278 | child.className = child.className + "Selected"; | |
06d1a1c1 | 1279 | cb.checked = true; |
386cbf27 AD |
1280 | } |
1281 | } else { | |
1282 | child.className = child.className.replace("Selected", ""); | |
06d1a1c1 | 1283 | cb.checked = false; |
386cbf27 AD |
1284 | } |
1285 | } | |
1286 | } | |
1287 | } | |
1288 | ||
98bea1b1 | 1289 | function catchupPage() { |
b47b5af7 | 1290 | |
3d72bbdb | 1291 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); |
8a5b4579 | 1292 | |
a5ae125a AD |
1293 | var str = __("Mark all visible articles in %s as read?"); |
1294 | ||
1295 | str = str.replace("%s", fn); | |
8a5b4579 AD |
1296 | |
1297 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1298 | return; | |
1299 | } | |
1300 | ||
acac8448 | 1301 | if ($("headlinesList")) { |
b47b5af7 | 1302 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true); |
2228d0e4 | 1303 | selectionToggleUnread(false, false, 'viewCurrentFeed()', true); |
b47b5af7 AD |
1304 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); |
1305 | } else { | |
1306 | cdmSelectArticles('all'); | |
2228d0e4 | 1307 | selectionToggleUnread(true, false, 'viewCurrentFeed()', true) |
b47b5af7 AD |
1308 | cdmSelectArticles('none'); |
1309 | } | |
98bea1b1 AD |
1310 | } |
1311 | ||
a5ae125a AD |
1312 | function catchupSelection() { |
1313 | ||
1314 | try { | |
1315 | ||
1316 | var rows; | |
1317 | ||
acac8448 | 1318 | if ($("headlinesList")) { |
a5ae125a AD |
1319 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); |
1320 | } else { | |
1321 | rows = cdmGetSelectedArticles(); | |
1322 | } | |
1323 | ||
1324 | if (rows.length == 0) { | |
1325 | alert(__("No articles are selected.")); | |
1326 | return; | |
1327 | } | |
1328 | ||
1329 | ||
3d72bbdb | 1330 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); |
a5ae125a | 1331 | |
ba5fac1b | 1332 | var str = __("Mark %d selected articles in %s as read?"); |
a5ae125a | 1333 | |
ba5fac1b | 1334 | str = str.replace("%d", rows.length); |
a5ae125a AD |
1335 | str = str.replace("%s", fn); |
1336 | ||
1337 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1338 | return; | |
1339 | } | |
1340 | ||
acac8448 | 1341 | if ($("headlinesList")) { |
a5ae125a AD |
1342 | selectionToggleUnread(false, false, 'viewCurrentFeed()', true); |
1343 | // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); | |
1344 | } else { | |
1345 | selectionToggleUnread(true, false, 'viewCurrentFeed()', true) | |
1346 | // cdmSelectArticles('none'); | |
1347 | } | |
1348 | ||
1349 | } catch (e) { | |
1350 | exception_error("catchupSelection", e); | |
1351 | } | |
1352 | } | |
1353 | ||
13f08f75 | 1354 | function editArticleTags(id, feed_id, cdm_enabled) { |
0b126ac2 AD |
1355 | displayDlg('editArticleTags', id); |
1356 | } | |
1357 | ||
1358 | ||
2ef1af84 AD |
1359 | function tag_saved_callback(transport) { |
1360 | try { | |
1361 | debug("in tag_saved_callback"); | |
0b126ac2 | 1362 | |
2ef1af84 AD |
1363 | closeInfoBox(); |
1364 | notify(""); | |
0b126ac2 | 1365 | |
2ef1af84 AD |
1366 | if (tagsAreDisplayed()) { |
1367 | _reload_feedlist_after_view = true; | |
1368 | } | |
0b126ac2 | 1369 | |
307d187c AD |
1370 | |
1371 | if (transport.responseXML) { | |
1372 | var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0]; | |
1373 | ||
1374 | if (tags_str) { | |
1375 | var id = tags_str.getAttribute("id"); | |
1376 | ||
1377 | if (id) { | |
acac8448 | 1378 | var tags = $("ATSTR-" + id); |
307d187c AD |
1379 | if (tags) { |
1380 | tags.innerHTML = tags_str.firstChild.nodeValue; | |
1381 | } | |
1382 | } | |
13f08f75 | 1383 | } |
0b126ac2 | 1384 | } |
2ef1af84 AD |
1385 | |
1386 | } catch (e) { | |
307d187c | 1387 | exception_error("tag_saved_callback", e); |
0b126ac2 AD |
1388 | } |
1389 | } | |
1390 | ||
1391 | function editTagsSave() { | |
1392 | ||
42c32916 | 1393 | notify_progress("Saving article tags..."); |
88040f57 | 1394 | |
0b126ac2 AD |
1395 | var form = document.forms["tag_edit_form"]; |
1396 | ||
1397 | var query = Form.serialize("tag_edit_form"); | |
1398 | ||
14b6c54b AD |
1399 | query = "backend.php?op=rpc&subop=setArticleTags&" + query; |
1400 | ||
1401 | debug(query); | |
1402 | ||
2ef1af84 AD |
1403 | new Ajax.Request(query, { |
1404 | onComplete: function(transport) { | |
1405 | tag_saved_callback(transport); | |
1406 | } }); | |
0b126ac2 AD |
1407 | |
1408 | } | |
d62a3b63 AD |
1409 | |
1410 | function editTagsInsert() { | |
1411 | try { | |
1412 | ||
1413 | var form = document.forms["tag_edit_form"]; | |
1414 | ||
1415 | var found_tags = form.found_tags; | |
1416 | var tags_str = form.tags_str; | |
1417 | ||
1418 | var tag = found_tags[found_tags.selectedIndex].value; | |
1419 | ||
1420 | if (tags_str.value.length > 0 && | |
1421 | tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) { | |
1422 | ||
1423 | tags_str.value = tags_str.value + ", "; | |
1424 | } | |
1425 | ||
1426 | tags_str.value = tags_str.value + tag + ", "; | |
1427 | ||
1428 | found_tags.selectedIndex = 0; | |
1429 | ||
1430 | } catch (e) { | |
438f2ce9 | 1431 | exception_error("editTagsInsert", e); |
d62a3b63 AD |
1432 | } |
1433 | } | |
ba0978c8 | 1434 | |
587bef10 AD |
1435 | function cdmScrollViewport(where) { |
1436 | debug("cdmScrollViewport: " + where); | |
1437 | ||
acac8448 | 1438 | var ctr = $("headlinesInnerContainer"); |
587bef10 AD |
1439 | |
1440 | if (!ctr) return; | |
1441 | ||
1442 | if (where == "bottom") { | |
1443 | ctr.scrollTop = ctr.scrollHeight; | |
1444 | } else { | |
1445 | ctr.scrollTop = where; | |
1446 | } | |
1447 | } | |
1448 | ||
b8e6acea AD |
1449 | function cdmArticleIsBelowViewport(id) { |
1450 | try { | |
acac8448 AD |
1451 | var ctr = $("headlinesInnerContainer"); |
1452 | var e = $("RROW-" + id); | |
b8e6acea AD |
1453 | |
1454 | if (!e || !ctr) return; | |
1455 | ||
1456 | // article starts below viewport | |
1457 | ||
1458 | if (ctr.scrollTop < e.offsetTop) { | |
1459 | return true; | |
1460 | } else { | |
1461 | return false; | |
1462 | } | |
1463 | ||
1464 | } catch (e) { | |
438f2ce9 | 1465 | exception_error("cdmArticleIsVisible", e); |
b8e6acea AD |
1466 | } |
1467 | } | |
1468 | ||
1469 | function cdmArticleIsAboveViewport(id) { | |
1470 | try { | |
acac8448 AD |
1471 | var ctr = $("headlinesInnerContainer"); |
1472 | var e = $("RROW-" + id); | |
b8e6acea AD |
1473 | |
1474 | if (!e || !ctr) return; | |
1475 | ||
1476 | // article starts above viewport | |
1477 | ||
1478 | if (ctr.scrollTop > e.offsetTop + e.offsetHeight) { | |
1479 | return true; | |
1480 | } else { | |
1481 | return false; | |
1482 | } | |
1483 | ||
1484 | } catch (e) { | |
438f2ce9 | 1485 | exception_error("cdmArticleIsVisible", e); |
b8e6acea AD |
1486 | } |
1487 | } | |
1488 | ||
1489 | function cdmScrollToArticleId(id) { | |
1490 | try { | |
acac8448 AD |
1491 | var ctr = $("headlinesInnerContainer"); |
1492 | var e = $("RROW-" + id); | |
b8e6acea AD |
1493 | |
1494 | if (!e || !ctr) return; | |
1495 | ||
1496 | ctr.scrollTop = e.offsetTop; | |
1497 | ||
1498 | } catch (e) { | |
438f2ce9 | 1499 | exception_error("cdmScrollToArticleId", e); |
b8e6acea AD |
1500 | } |
1501 | } | |
1502 | ||
1503 | function cdmArticleIsActuallyVisible(id) { | |
1504 | try { | |
acac8448 AD |
1505 | var ctr = $("headlinesInnerContainer"); |
1506 | var e = $("RROW-" + id); | |
b8e6acea AD |
1507 | |
1508 | if (!e || !ctr) return; | |
1509 | ||
1510 | // article fits in viewport OR article is longer than viewport and | |
1511 | // its bottom is visible | |
1512 | ||
1513 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
1514 | ctr.scrollTop + ctr.offsetHeight) { | |
1515 | ||
1516 | return true; | |
1517 | ||
1518 | } else if (e.offsetHeight > ctr.offsetHeight && | |
1519 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1520 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
1521 | ||
1522 | return true; | |
1523 | ||
1524 | } | |
1525 | ||
1526 | return false; | |
1527 | ||
1528 | } catch (e) { | |
438f2ce9 | 1529 | exception_error("cdmArticleIsVisible", e); |
b8e6acea AD |
1530 | } |
1531 | } | |
1532 | ||
ba0978c8 AD |
1533 | function cdmWatchdog() { |
1534 | ||
1535 | try { | |
1536 | ||
acac8448 | 1537 | var ctr = $("headlinesInnerContainer"); |
ba0978c8 | 1538 | |
9acd22e8 AD |
1539 | if (!ctr) return; |
1540 | ||
ba0978c8 AD |
1541 | var ids = new Array(); |
1542 | ||
1543 | var e = ctr.firstChild; | |
1544 | ||
1545 | while (e) { | |
1546 | if (e.className && e.className == "cdmArticleUnread" && e.id && | |
1547 | e.id.match("RROW-")) { | |
1548 | ||
1549 | // article fits in viewport OR article is longer than viewport and | |
1550 | // its bottom is visible | |
1551 | ||
1552 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
1553 | ctr.scrollTop + ctr.offsetHeight) { | |
1554 | ||
1555 | // debug(e.id + " is visible " + e.offsetTop + "." + | |
1556 | // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." + | |
1557 | // (ctr.scrollTop + ctr.offsetHeight)); | |
1558 | ||
1559 | ids.push(e.id.replace("RROW-", "")); | |
1560 | ||
1561 | } else if (e.offsetHeight > ctr.offsetHeight && | |
1562 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1563 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
1564 | ||
1565 | ids.push(e.id.replace("RROW-", "")); | |
1566 | ||
1567 | } | |
1568 | ||
c50e2b30 AD |
1569 | // method 2: article bottom is visible and is in upper 1/2 of the viewport |
1570 | ||
1571 | /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
1572 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) { | |
1573 | ||
1574 | ids.push(e.id.replace("RROW-", "")); | |
1575 | ||
1576 | } */ | |
1577 | ||
ba0978c8 AD |
1578 | } |
1579 | ||
1580 | e = e.nextSibling; | |
1581 | } | |
1582 | ||
1583 | debug("cdmWatchdog, ids= " + ids.toString()); | |
1584 | ||
1341ea0d | 1585 | if (ids.length > 0) { |
ba0978c8 AD |
1586 | |
1587 | for (var i = 0; i < ids.length; i++) { | |
acac8448 | 1588 | var e = $("RROW-" + ids[i]); |
ba0978c8 AD |
1589 | if (e) { |
1590 | e.className = e.className.replace("Unread", ""); | |
1591 | } | |
1592 | } | |
1593 | ||
2855ee88 AD |
1594 | var query = "backend.php?op=rpc&subop=catchupSelected" + |
1595 | "&cmode=0"; | |
1596 | ||
1597 | var ids = "?ids=" + param_escape(ids.toString()); | |
ba0978c8 | 1598 | |
1341ea0d | 1599 | new Ajax.Request(query, { |
2855ee88 | 1600 | parameters: ids, |
1341ea0d AD |
1601 | onComplete: function(transport) { |
1602 | all_counters_callback2(transport); | |
1603 | } }); | |
ba0978c8 AD |
1604 | |
1605 | } | |
1606 | ||
c50e2b30 | 1607 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000); |
ba0978c8 AD |
1608 | |
1609 | } catch (e) { | |
438f2ce9 | 1610 | exception_error("cdmWatchdog", e); |
ba0978c8 AD |
1611 | } |
1612 | ||
1613 | } | |
e097e8be AD |
1614 | |
1615 | ||
e19c1824 | 1616 | function cache_inject(id, article, param) { |
fb456d28 AD |
1617 | try { |
1618 | if (!cache_check_param(id, param)) { | |
1619 | debug("cache_article: miss: " + id + " [p=" + param + "]"); | |
1620 | ||
1621 | ||
1622 | if (db) { | |
e097e8be | 1623 | |
fb456d28 AD |
1624 | var date = new Date(); |
1625 | var ts = Math.round(date.getTime() / 1000); | |
e097e8be | 1626 | |
fb456d28 AD |
1627 | db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)", |
1628 | [id, article, param, ts]); | |
1629 | } else { | |
1630 | ||
1631 | var cache_obj = new Array(); | |
1632 | ||
1633 | cache_obj["id"] = id; | |
1634 | cache_obj["data"] = article; | |
1635 | cache_obj["param"] = param; | |
1636 | ||
1637 | article_cache.push(cache_obj); | |
1638 | } | |
1639 | ||
1640 | } else { | |
1641 | debug("cache_article: hit: " + id + " [p=" + param + "]"); | |
1642 | } | |
1643 | } catch (e) { | |
1644 | exception_error("cache_inject", e); | |
e097e8be AD |
1645 | } |
1646 | } | |
1647 | ||
1648 | function cache_find(id) { | |
fb456d28 AD |
1649 | |
1650 | if (db) { | |
31234407 | 1651 | var rs = db.execute("SELECT article FROM cache WHERE id = ?", [id]); |
03c96380 | 1652 | var a = false; |
31234407 AD |
1653 | |
1654 | if (rs.isValidRow()) { | |
03c96380 | 1655 | var a = rs.field(0); |
31234407 | 1656 | } |
fb456d28 | 1657 | |
03c96380 AD |
1658 | rs.close(); |
1659 | ||
1660 | return a; | |
1661 | ||
fb456d28 AD |
1662 | } else { |
1663 | for (var i = 0; i < article_cache.length; i++) { | |
1664 | if (article_cache[i]["id"] == id) { | |
1665 | return article_cache[i]["data"]; | |
1666 | } | |
fed4387d | 1667 | } |
e097e8be | 1668 | } |
fed4387d | 1669 | return false; |
e097e8be AD |
1670 | } |
1671 | ||
5d17ead9 | 1672 | function cache_find_param(id, param) { |
fb456d28 AD |
1673 | |
1674 | if (db) { | |
1675 | var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?", | |
1676 | [id, param]); | |
03c96380 | 1677 | var a = false; |
fb456d28 AD |
1678 | |
1679 | if (rs.isValidRow()) { | |
03c96380 | 1680 | a = rs.field(0); |
fb456d28 AD |
1681 | } |
1682 | ||
03c96380 AD |
1683 | rs.close(); |
1684 | ||
1685 | return a; | |
1686 | ||
fb456d28 AD |
1687 | } else { |
1688 | for (var i = 0; i < article_cache.length; i++) { | |
1689 | if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) { | |
1690 | return article_cache[i]["data"]; | |
1691 | } | |
e19c1824 AD |
1692 | } |
1693 | } | |
1694 | return false; | |
1695 | } | |
1696 | ||
e097e8be | 1697 | function cache_check(id) { |
fb456d28 AD |
1698 | |
1699 | if (db) { | |
1700 | var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?", | |
1701 | [id]); | |
03c96380 | 1702 | var a = false; |
fb456d28 AD |
1703 | |
1704 | if (rs.isValidRow()) { | |
03c96380 | 1705 | a = rs.field(0) != "0"; |
fb456d28 AD |
1706 | } |
1707 | ||
03c96380 AD |
1708 | rs.close(); |
1709 | ||
1710 | return a; | |
1711 | ||
fb456d28 AD |
1712 | } else { |
1713 | for (var i = 0; i < article_cache.length; i++) { | |
1714 | if (article_cache[i]["id"] == id) { | |
1715 | return true; | |
1716 | } | |
fed4387d AD |
1717 | } |
1718 | } | |
1719 | return false; | |
e097e8be AD |
1720 | } |
1721 | ||
e19c1824 | 1722 | function cache_check_param(id, param) { |
5d17ead9 | 1723 | |
fb456d28 AD |
1724 | if (db) { |
1725 | var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?", | |
1726 | [id, param]); | |
03c96380 | 1727 | var a = false; |
5d17ead9 | 1728 | |
fb456d28 | 1729 | if (rs.isValidRow()) { |
03c96380 | 1730 | a = rs.field(0) != "0"; |
fb456d28 AD |
1731 | } |
1732 | ||
03c96380 AD |
1733 | rs.close(); |
1734 | ||
1735 | return a; | |
1736 | ||
fb456d28 AD |
1737 | } else { |
1738 | for (var i = 0; i < article_cache.length; i++) { | |
1739 | if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) { | |
1740 | return true; | |
1741 | } | |
e19c1824 AD |
1742 | } |
1743 | } | |
1744 | return false; | |
1745 | } | |
1746 | ||
e097e8be | 1747 | function cache_expire() { |
31234407 AD |
1748 | if (db) { |
1749 | var date = new Date(); | |
1750 | var ts = Math.round(date.getTime() / 1000); | |
1751 | ||
e0999d95 AD |
1752 | db.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts]); |
1753 | db.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts]); | |
1754 | db.execute("DELETE FROM cache WHERE added < ? - 86400", [ts]); | |
1755 | ||
31234407 AD |
1756 | |
1757 | } else { | |
fb456d28 AD |
1758 | while (article_cache.length > 25) { |
1759 | article_cache.shift(); | |
1760 | } | |
fed4387d | 1761 | } |
e097e8be | 1762 | } |
b07b61da | 1763 | |
3c2d7945 AD |
1764 | function cache_empty() { |
1765 | article_cache = new Array(); | |
1766 | } | |
1767 | ||
b07b61da | 1768 | function cache_invalidate(id) { |
c1b18749 AD |
1769 | try { |
1770 | ||
fb456d28 AD |
1771 | if (db) { |
1772 | rs = db.execute("DELETE FROM cache WHERE id = ?", [id]); | |
1773 | return rs.rowsAffected != 0; | |
1774 | } else { | |
1775 | ||
1776 | var i = 0 | |
1777 | ||
1778 | while (i < article_cache.length) { | |
1779 | if (article_cache[i]["id"] == id) { | |
1780 | debug("cache_invalidate: removed id " + id); | |
1781 | article_cache.splice(i, 1); | |
1782 | return true; | |
1783 | } | |
1784 | i++; | |
c1b18749 | 1785 | } |
b07b61da | 1786 | } |
fb456d28 | 1787 | |
c1b18749 AD |
1788 | debug("cache_invalidate: id not found: " + id); |
1789 | return false; | |
1790 | } catch (e) { | |
1791 | exception_error("cache_invalidate", e); | |
b07b61da | 1792 | } |
b07b61da | 1793 | } |
298f3f78 AD |
1794 | |
1795 | function getActiveArticleId() { | |
1796 | return active_post_id; | |
1797 | } | |
e4914b62 | 1798 | |
3cd4239a | 1799 | function cdmClicked(id) { |
e4914b62 | 1800 | try { |
acac8448 | 1801 | var elem = $("RROW-" + id); |
3cd4239a AD |
1802 | |
1803 | if (elem) { | |
e4914b62 AD |
1804 | var id = elem.id.replace("RROW-", ""); |
1805 | active_post_id = id; | |
5ad9d132 | 1806 | |
96f8322d | 1807 | // cdmSelectArticles("none"); |
b61cf20c | 1808 | toggleUnread(id, 0, true); |
96f8322d | 1809 | // toggleSelected(id); |
5ad9d132 | 1810 | |
e4914b62 AD |
1811 | } |
1812 | } catch (e) { | |
ee8768db | 1813 | exception_error("cdmClicked", e); |
5ad9d132 AD |
1814 | } |
1815 | } | |
e4914b62 | 1816 | |
aa0fa9df AD |
1817 | function preload_article_callback(transport) { |
1818 | try { | |
1819 | if (transport.responseXML) { | |
1820 | var articles = transport.responseXML.getElementsByTagName("article"); | |
1821 | ||
1822 | for (var i = 0; i < articles.length; i++) { | |
1823 | var id = articles[i].getAttribute("id"); | |
b2bb787c | 1824 | if (!cache_check(id)) { |
aa0fa9df AD |
1825 | cache_inject(id, articles[i].firstChild.nodeValue); |
1826 | debug("preloaded article: " + id); | |
1827 | } | |
1828 | } | |
1829 | } | |
1830 | } catch (e) { | |
1831 | exception_error("preload_article_callback", e); | |
1832 | } | |
1833 | } | |
1834 | ||
1835 | function preloadArticleUnderPointer(id) { | |
1836 | try { | |
a598370d AD |
1837 | if (getInitParam("bw_limit") == "1") return; |
1838 | ||
b2bb787c | 1839 | if (post_under_pointer == id && !cache_check(id)) { |
aa0fa9df AD |
1840 | |
1841 | debug("trying to preload article " + id); | |
1842 | ||
1843 | var neighbor_ids = getRelativePostIds(id, 1); | |
1844 | ||
1845 | /* only request uncached articles */ | |
1846 | ||
1847 | var cids_to_request = Array(); | |
1848 | ||
1849 | for (var i = 0; i < neighbor_ids.length; i++) { | |
1850 | if (!cache_check(neighbor_ids[i])) { | |
1851 | cids_to_request.push(neighbor_ids[i]); | |
1852 | } | |
1853 | } | |
1854 | debug("additional ids: " + cids_to_request.toString()); | |
1855 | ||
1856 | cids_to_request.push(id); | |
1857 | ||
1858 | var query = "backend.php?op=rpc&subop=getArticles&ids=" + | |
1859 | cids_to_request.toString(); | |
1860 | new Ajax.Request(query, { | |
1861 | onComplete: function(transport) { | |
1862 | preload_article_callback(transport); | |
1863 | } }); | |
1864 | } | |
1865 | } catch (e) { | |
1866 | exception_error("preloadArticleUnderPointer", e); | |
1867 | } | |
1868 | } | |
1869 | ||
314fcd2b AD |
1870 | function postMouseIn(id) { |
1871 | try { | |
aa0fa9df AD |
1872 | if (post_under_pointer != id) { |
1873 | post_under_pointer = id; | |
1874 | if (!isCdmMode()) { | |
1875 | window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250); | |
1876 | } | |
1877 | } | |
1878 | ||
314fcd2b AD |
1879 | } catch (e) { |
1880 | exception_error("postMouseIn", e); | |
1881 | } | |
1882 | } | |
1883 | ||
1884 | function postMouseOut(id) { | |
1885 | try { | |
1886 | post_under_pointer = false; | |
1887 | } catch (e) { | |
1888 | exception_error("postMouseOut", e); | |
1889 | } | |
1890 | } | |
1891 | ||
ac541432 AD |
1892 | function headlines_scroll_handler() { |
1893 | try { | |
1894 | ||
acac8448 | 1895 | var e = $("headlinesInnerContainer"); |
ac541432 | 1896 | |
4764c27e AD |
1897 | // don't do infinite scrolling when Limit == All |
1898 | ||
1899 | var toolbar_form = document.forms["main_toolbar_form"]; | |
1900 | ||
1901 | var limit = toolbar_form.limit[toolbar_form.limit.selectedIndex]; | |
1902 | if (limit.value != 0) { | |
587bef10 AD |
1903 | |
1904 | debug((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " + | |
1905 | _infscroll_disable); | |
1906 | ||
1907 | if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) { | |
4764c27e AD |
1908 | if (!_infscroll_disable) { |
1909 | debug("more cowbell!"); | |
1910 | viewNextFeedPage(); | |
1911 | } | |
29dfb258 | 1912 | } |
ac541432 AD |
1913 | } |
1914 | ||
1915 | } catch (e) { | |
1916 | exception_error("headlines_scroll_handler", e); | |
1917 | } | |
1918 | } | |
8be83f42 AD |
1919 | |
1920 | function catchupRelativeToArticle(below) { | |
1921 | ||
1922 | try { | |
1923 | ||
49fd1e94 | 1924 | |
8be83f42 AD |
1925 | if (!getActiveArticleId()) { |
1926 | alert(__("No article is selected.")); | |
1927 | return; | |
1928 | } | |
1929 | ||
1930 | var visible_ids; | |
1931 | ||
acac8448 | 1932 | if ($("headlinesList")) { |
8be83f42 AD |
1933 | visible_ids = getVisibleHeadlineIds(); |
1934 | } else { | |
1935 | visible_ids = cdmGetVisibleArticles(); | |
1936 | } | |
1937 | ||
1938 | var ids_to_mark = new Array(); | |
1939 | ||
1940 | if (!below) { | |
1941 | for (var i = 0; i < visible_ids.length; i++) { | |
1942 | if (visible_ids[i] != getActiveArticleId()) { | |
acac8448 | 1943 | var e = $("RROW-" + visible_ids[i]); |
8be83f42 AD |
1944 | |
1945 | if (e && e.className.match("Unread")) { | |
1946 | ids_to_mark.push(visible_ids[i]); | |
1947 | } | |
1948 | } else { | |
1949 | break; | |
1950 | } | |
1951 | } | |
1952 | } else { | |
1953 | for (var i = visible_ids.length-1; i >= 0; i--) { | |
1954 | if (visible_ids[i] != getActiveArticleId()) { | |
acac8448 | 1955 | var e = $("RROW-" + visible_ids[i]); |
8be83f42 AD |
1956 | |
1957 | if (e && e.className.match("Unread")) { | |
1958 | ids_to_mark.push(visible_ids[i]); | |
1959 | } | |
1960 | } else { | |
1961 | break; | |
1962 | } | |
1963 | } | |
1964 | } | |
1965 | ||
1966 | if (ids_to_mark.length == 0) { | |
1967 | alert(__("No articles found to mark")); | |
1968 | } else { | |
1969 | var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length); | |
1970 | ||
1971 | if (confirm(msg)) { | |
1972 | ||
1973 | for (var i = 0; i < ids_to_mark.length; i++) { | |
acac8448 | 1974 | var e = $("RROW-" + ids_to_mark[i]); |
8be83f42 AD |
1975 | e.className = e.className.replace("Unread", ""); |
1976 | } | |
1977 | ||
2855ee88 AD |
1978 | var query = "backend.php?op=rpc&subop=catchupSelected" + |
1979 | "&cmode=0"; | |
1980 | ||
1981 | var ids = "?ids=" + param_escape(ids_to_mark.toString()); | |
8be83f42 | 1982 | |
5fe7767c | 1983 | new Ajax.Request(query, { |
2855ee88 | 1984 | parameters: ids, |
5fe7767c AD |
1985 | onComplete: function(transport) { |
1986 | catchup_callback2(transport); | |
1987 | } }); | |
1988 | ||
8be83f42 AD |
1989 | } |
1990 | } | |
1991 | ||
1992 | } catch (e) { | |
1993 | exception_error("catchupRelativeToArticle", e); | |
1994 | } | |
1995 | } | |
a04c8e8d AD |
1996 | |
1997 | function cdmExpandArticle(a_id) { | |
1998 | try { | |
1999 | var id = 'CICD-' + a_id; | |
2000 | ||
3cd4239a AD |
2001 | try { |
2002 | Element.hide("CEXC-" + a_id); | |
2003 | } catch (e) { } | |
2004 | ||
a04c8e8d AD |
2005 | Effect.Appear(id, {duration : 0.5, |
2006 | beforeStart: function(effect) { | |
2007 | var h_id = 'CICH-' + a_id; | |
acac8448 | 2008 | var h_elem = $(h_id); |
a04c8e8d AD |
2009 | if (h_elem) { h_elem.style.display = "none"; } |
2010 | ||
2011 | toggleUnread(a_id, 0); | |
2012 | }}); | |
2013 | ||
2014 | ||
2015 | } catch (e) { | |
2016 | exception_error("appearBlockElementF", e); | |
2017 | } | |
2018 | ||
2019 | } | |
2020 | ||
3818a89b AD |
2021 | function fixHeadlinesOrder(ids) { |
2022 | try { | |
2023 | for (var i = 0; i < ids.length; i++) { | |
acac8448 | 2024 | var e = $("RROW-" + ids[i]); |
3818a89b AD |
2025 | |
2026 | if (e) { | |
2027 | if (i % 2 == 0) { | |
2028 | e.className = e.className.replace("even", "odd"); | |
2029 | } else { | |
2030 | e.className = e.className.replace("odd", "even"); | |
2031 | } | |
2032 | } | |
2033 | } | |
2034 | } catch (e) { | |
2035 | exception_error("fixHeadlinesOrder", e); | |
2036 | } | |
2037 | } | |
2038 | ||
df485d4f AD |
2039 | function hideReadHeadlines() { |
2040 | try { | |
2041 | ||
2042 | var ids = false; | |
2043 | var vis_ids = new Array(); | |
2044 | ||
acac8448 | 2045 | if ($("headlinesList")) { |
df485d4f AD |
2046 | ids = getVisibleHeadlineIds(); |
2047 | } else { | |
2048 | ids = cdmGetVisibleArticles(); | |
2049 | } | |
2050 | ||
004523dd AD |
2051 | var read_headlines_visible = true; |
2052 | ||
df485d4f | 2053 | for (var i = 0; i < ids.length; i++) { |
acac8448 | 2054 | var row = $("RROW-" + ids[i]); |
df485d4f AD |
2055 | |
2056 | if (row && row.className) { | |
2057 | if (read_headlines_visible) { | |
2058 | if (row.className.match("Unread") || row.className.match("Selected")) { | |
2059 | Element.show(row); | |
2060 | vis_ids.push(ids[i]); | |
2061 | } else { | |
2062 | //Effect.Fade(row, {duration : 0.3}); | |
2063 | Element.hide(row); | |
2064 | } | |
2065 | } else { | |
2066 | Element.show(row); | |
2067 | vis_ids.push(ids[i]); | |
2068 | } | |
2069 | } | |
2070 | } | |
2071 | ||
2072 | fixHeadlinesOrder(vis_ids); | |
2073 | ||
2074 | read_headlines_visible = !read_headlines_visible; | |
2075 | ||
2076 | } catch (e) { | |
2077 | exception_error("hideReadHeadlines", e); | |
2078 | } | |
2079 | } | |
2080 | ||
e75d70b5 AD |
2081 | function invertHeadlineSelection() { |
2082 | try { | |
2083 | var rows = new Array(); | |
2084 | var r = false; | |
2085 | ||
2086 | if (!isCdmMode()) { | |
2087 | r = document.getElementsByTagName("TR"); | |
2088 | } else { | |
2089 | r = document.getElementsByTagName("DIV"); | |
2090 | } | |
2091 | ||
2092 | for (var i = 0; i < r.length; i++) { | |
2093 | if (r[i].id && r[i].id.match("RROW-")) { | |
2094 | rows.push(r[i]); | |
2095 | } | |
2096 | } | |
2097 | ||
2098 | for (var i = 0; i < rows.length; i++) { | |
2099 | var nc = rows[i].className; | |
2100 | var id = rows[i].id.replace("RROW-", ""); | |
acac8448 | 2101 | var cb = $("RCHK-" + id); |
e75d70b5 AD |
2102 | |
2103 | if (!rows[i].className.match("Selected")) { | |
2104 | nc = nc + "Selected"; | |
2105 | cb.checked = true; | |
2106 | } else { | |
2107 | nc = nc.replace("Selected", ""); | |
2108 | cb.checked = false; | |
2109 | } | |
2110 | ||
2111 | rows[i].className = nc; | |
2112 | ||
2113 | } | |
2114 | ||
2115 | } catch (e) { | |
2116 | exception_error("invertHeadlineSelection", e); | |
2117 | } | |
2118 | } | |
2119 | ||
314fcd2b AD |
2120 | function getArticleUnderPointer() { |
2121 | return post_under_pointer; | |
7a822893 | 2122 | } |
eedfb635 AD |
2123 | |
2124 | function zoomToArticle(id) { | |
2125 | try { | |
2126 | var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id), | |
2127 | "ttrss_zoom_" + id, | |
2128 | "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0"); | |
2129 | ||
2130 | } catch (e) { | |
2131 | exception_error("zoomToArticle", e); | |
2132 | } | |
2133 | } | |
a411875b | 2134 | |
4710e3dc AD |
2135 | function showOriginalArticleInline(id) { |
2136 | try { | |
2137 | ||
2138 | var query = "backend.php?op=rpc&subop=getArticleLink&id=" + id; | |
2139 | ||
2140 | notify_progress("Loading, please wait...", true); | |
2141 | ||
2142 | new Ajax.Request(query, { | |
2143 | onComplete: function(transport) { | |
2144 | ||
2145 | if (transport.responseXML) { | |
2146 | ||
2147 | var link = transport.responseXML.getElementsByTagName("link")[0]; | |
2148 | var id = transport.responseXML.getElementsByTagName("id")[0]; | |
2149 | ||
2150 | notify(""); | |
2151 | ||
2152 | if (link && id) { | |
2153 | link = link.firstChild.nodeValue; | |
2154 | ||
acac8448 | 2155 | var ci = $("content-insert"); |
4710e3dc AD |
2156 | |
2157 | var tmp = "<iframe id=\"inline_orig_article\" width=\""+ci.offsetWidth+"\" height=\""+ci.offsetHeight+"\" style=\"border-width : 0px;\" src=\""+link+"\"></iframe>"; | |
2158 | ||
2159 | render_article(tmp); | |
2160 | ||
2161 | } | |
2162 | } | |
2163 | } }); | |
2164 | ||
2165 | } catch (e) { | |
2166 | exception_error("showOriginalArticleInline", e); | |
2167 | } | |
2168 | } | |
2169 | ||
2170 | ||
a411875b AD |
2171 | function scrollArticle(offset) { |
2172 | try { | |
2173 | if (!isCdmMode()) { | |
acac8448 | 2174 | var ci = $("content-insert"); |
a411875b AD |
2175 | if (ci) { |
2176 | ci.scrollTop += offset; | |
2177 | } | |
2178 | } else { | |
acac8448 | 2179 | var hi = $("headlinesInnerContainer"); |
a411875b AD |
2180 | if (hi) { |
2181 | hi.scrollTop += offset; | |
2182 | } | |
2183 | ||
2184 | } | |
2185 | } catch (e) { | |
2186 | exception_error("scrollArticle", e); | |
2187 | } | |
2188 | } | |
f9247195 AD |
2189 | |
2190 | function show_labels_in_headlines(transport) { | |
2191 | try { | |
2192 | if (transport.responseXML) { | |
2193 | var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0]; | |
2194 | ||
2195 | var elems = info.getElementsByTagName("entry"); | |
2196 | ||
2197 | for (var l = 0; l < elems.length; l++) { | |
2198 | var e_id = elems[l].getAttribute("id"); | |
2199 | ||
2200 | if (e_id) { | |
2201 | ||
acac8448 | 2202 | var ctr = $("HLLCTR-" + e_id); |
f9247195 AD |
2203 | |
2204 | if (ctr) { | |
2205 | ctr.innerHTML = elems[l].firstChild.nodeValue; | |
2206 | } | |
2207 | } | |
2208 | ||
2209 | } | |
2210 | ||
2211 | } | |
2212 | } catch (e) { | |
2213 | exception_error("show_labels_in_headlines", e); | |
2214 | ||
2215 | } | |
2216 | } | |
bf3c9838 AD |
2217 | |
2218 | function toggleHeadlineActions() { | |
2219 | try { | |
acac8448 AD |
2220 | var e = $("headlineActionsBody"); |
2221 | var p = $("headlineActionsDrop"); | |
bf3c9838 AD |
2222 | |
2223 | if (!Element.visible(e)) { | |
2224 | Element.show(e); | |
2225 | } else { | |
2226 | Element.hide(e); | |
2227 | } | |
2228 | ||
b62f6ff4 | 2229 | e.scrollTop = 0; |
bf3c9838 | 2230 | e.style.left = (p.offsetLeft + 1) + "px"; |
b4dc02e2 | 2231 | e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px"; |
bf3c9838 AD |
2232 | |
2233 | } catch (e) { | |
2234 | exception_error("toggleHeadlineActions", e); | |
2235 | } | |
2236 | } | |
c7e51de1 AD |
2237 | |
2238 | function publishWithNote(id, def_note) { | |
2239 | try { | |
2240 | if (!def_note) def_note = ''; | |
2241 | ||
2242 | var note = prompt(__("Please enter a note for this article:"), def_note); | |
2243 | ||
2244 | if (note != undefined) { | |
2245 | togglePub(id, false, false, note); | |
2246 | } | |
2247 | ||
2248 | } catch (e) { | |
2249 | exception_error("publishWithNote", e); | |
2250 | } | |
2251 | } |