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