]>
Commit | Line | Data |
---|---|---|
bb7cface | 1 | var active_post_id = false; |
e08443c1 | 2 | var _catchup_callback_func = false; |
4b6206fa | 3 | var last_article_view = false; |
0b126ac2 AD |
4 | var active_real_feed_id = false; |
5 | ||
6 | var _tag_active_post_id = false; | |
7 | var _tag_active_feed_id = false; | |
13f08f75 | 8 | var _tag_active_cdm = false; |
0b126ac2 | 9 | |
13f08f75 AD |
10 | // FIXME: kludge, to restore scrollTop after tag editor terminates |
11 | var _tag_cdm_scroll = false; | |
12 | ||
13 | // FIXME: kludges, needs proper implementation | |
0b126ac2 | 14 | var _reload_feedlist_after_view = false; |
e08443c1 | 15 | |
ba0978c8 AD |
16 | var _cdm_wd_timeout = false; |
17 | var _cdm_wd_vishist = new Array(); | |
18 | ||
e097e8be AD |
19 | var article_cache = new Array(); |
20 | ||
e08443c1 AD |
21 | function catchup_callback() { |
22 | if (xmlhttp_rpc.readyState == 4) { | |
8f3b99ba AD |
23 | try { |
24 | debug("catchup_callback"); | |
9ec58704 | 25 | notify(""); |
8f3b99ba | 26 | all_counters_callback(); |
af6f8bf2 AD |
27 | if (_catchup_callback_func) { |
28 | setTimeout(_catchup_callback_func, 10); | |
29 | } | |
8f3b99ba AD |
30 | } catch (e) { |
31 | exception_error("catchup_callback", e); | |
32 | } | |
e08443c1 AD |
33 | } |
34 | } | |
f0601b87 | 35 | |
6b4163cb AD |
36 | function headlines_callback() { |
37 | if (xmlhttp.readyState == 4) { | |
38 | debug("headlines_callback"); | |
39 | var f = document.getElementById("headlines-frame"); | |
44cc6f20 | 40 | try { |
ac541432 AD |
41 | if (feed_cur_page == 0) { |
42 | debug("resetting headlines scrollTop"); | |
43 | f.scrollTop = 0; | |
44 | } | |
44cc6f20 | 45 | } catch (e) { }; |
3de0261a AD |
46 | |
47 | if (xmlhttp.responseXML) { | |
48 | var headlines = xmlhttp.responseXML.getElementsByTagName("headlines")[0]; | |
49 | var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0]; | |
961f4c73 | 50 | var articles = xmlhttp.responseXML.getElementsByTagName("article"); |
03c88bdd | 51 | var runtime_info = xmlhttp.responseXML.getElementsByTagName("runtime-info"); |
3de0261a | 52 | |
ac541432 AD |
53 | if (feed_cur_page == 0) { |
54 | if (headlines) { | |
55 | f.innerHTML = headlines.firstChild.nodeValue; | |
56 | } else { | |
57 | debug("headlines_callback: returned no data"); | |
58 | f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>"; | |
59 | ||
60 | } | |
007a38d4 | 61 | } else { |
ac541432 AD |
62 | if (headlines) { |
63 | debug("adding some more headlines..."); | |
64 | ||
65 | var c = document.getElementById("headlinesList"); | |
66 | ||
67 | if (!c) { | |
68 | c = document.getElementById("headlinesInnerContainer"); | |
69 | } | |
70 | ||
71 | c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue; | |
72 | } else { | |
73 | debug("headlines_callback: returned no data"); | |
74 | notify_error("Error while trying to load more headlines"); | |
75 | } | |
007a38d4 AD |
76 | |
77 | } | |
3de0261a | 78 | |
961f4c73 AD |
79 | if (articles) { |
80 | for (var i = 0; i < articles.length; i++) { | |
81 | var a_id = articles[i].getAttribute("id"); | |
82 | debug("found id: " + a_id); | |
83 | cache_inject(a_id, articles[i].firstChild.nodeValue); | |
84 | } | |
007a38d4 AD |
85 | } else { |
86 | debug("no cached articles received"); | |
961f4c73 AD |
87 | } |
88 | ||
3de0261a AD |
89 | if (counters) { |
90 | debug("parsing piggybacked counters: " + counters); | |
91 | parse_counters(counters, false); | |
addb5836 AD |
92 | } else { |
93 | debug("counters container not found in reply"); | |
3de0261a | 94 | } |
03c88bdd AD |
95 | |
96 | if (runtime_info) { | |
97 | debug("parsing runtime info: " + runtime_info[0]); | |
98 | parse_runtime_info(runtime_info[0]); | |
99 | } else { | |
100 | debug("counters container not found in reply"); | |
101 | } | |
102 | ||
3de0261a AD |
103 | } else { |
104 | debug("headlines_callback: returned no XML object"); | |
addb5836 | 105 | f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>"; |
3de0261a AD |
106 | } |
107 | ||
935f235d AD |
108 | if (typeof correctPNG != 'undefined') { |
109 | correctPNG(); | |
110 | } | |
ba0978c8 AD |
111 | |
112 | if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout); | |
113 | ||
ac7bcd71 AD |
114 | if (!document.getElementById("headlinesList") && |
115 | getInitParam("cdm_auto_catchup") == 1) { | |
ba0978c8 AD |
116 | debug("starting CDM watchdog"); |
117 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000); | |
118 | _cdm_wd_vishist = new Array(); | |
ac7bcd71 AD |
119 | } else { |
120 | debug("not in CDM mode or watchdog disabled"); | |
ba0978c8 AD |
121 | } |
122 | ||
13f08f75 AD |
123 | if (_tag_cdm_scroll) { |
124 | try { | |
125 | document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll; | |
126 | _tag_cdm_scroll = false; | |
ac541432 AD |
127 | debug("resetting headlinesInner scrollTop"); |
128 | ||
13f08f75 AD |
129 | } catch (e) { } |
130 | } | |
131 | ||
33b8cab4 | 132 | notify(""); |
6b4163cb AD |
133 | } |
134 | } | |
135 | ||
e097e8be AD |
136 | function render_article(article) { |
137 | try { | |
6b4163cb | 138 | var f = document.getElementById("content-frame"); |
44cc6f20 AD |
139 | try { |
140 | f.scrollTop = 0; | |
141 | } catch (e) { }; | |
e097e8be AD |
142 | |
143 | f.innerHTML = article; | |
144 | ||
145 | } catch (e) { | |
146 | exception_error("render_article", e); | |
147 | } | |
148 | } | |
149 | ||
150 | function article_callback() { | |
151 | if (xmlhttp.readyState == 4) { | |
152 | debug("article_callback"); | |
153 | ||
154 | try { | |
155 | if (xmlhttp.responseXML) { | |
156 | var reply = xmlhttp.responseXML.firstChild.firstChild; | |
157 | ||
158 | var articles = xmlhttp.responseXML.getElementsByTagName("article"); | |
159 | ||
160 | for (var i = 0; i < articles.length; i++) { | |
161 | var a_id = articles[i].getAttribute("id"); | |
162 | ||
163 | debug("found id: " + a_id); | |
164 | ||
165 | if (a_id == active_post_id) { | |
166 | debug("active article, rendering..."); | |
167 | render_article(articles[i].firstChild.nodeValue); | |
168 | } | |
169 | ||
170 | cache_inject(a_id, articles[i].firstChild.nodeValue); | |
171 | } | |
172 | ||
173 | } else { | |
174 | debug("article_callback: returned no XML object"); | |
0d88fd97 AD |
175 | var f = document.getElementById("content-frame"); |
176 | f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>"; | |
e097e8be AD |
177 | } |
178 | } catch (e) { | |
179 | exception_error("article_callback", e); | |
180 | } | |
4b6206fa AD |
181 | |
182 | var date = new Date(); | |
183 | last_article_view = date.getTime() / 1000; | |
184 | ||
935f235d AD |
185 | if (typeof correctPNG != 'undefined') { |
186 | correctPNG(); | |
187 | } | |
0b126ac2 AD |
188 | |
189 | if (_reload_feedlist_after_view) { | |
190 | setTimeout('updateFeedList(false, false)', 50); | |
191 | _reload_feedlist_after_view = false; | |
192 | } else { | |
5a94a953 AD |
193 | var counters = xmlhttp.responseXML.getElementsByTagName("counters")[0]; |
194 | ||
195 | if (counters) { | |
196 | debug("parsing piggybacked counters: " + counters); | |
197 | parse_counters(counters, false); | |
198 | } else { | |
addb5836 | 199 | debug("counters container not found in reply"); |
5a94a953 | 200 | } |
0b126ac2 | 201 | } |
9ec58704 AD |
202 | |
203 | notify(""); | |
6b4163cb AD |
204 | } |
205 | } | |
206 | ||
1dc8dba0 | 207 | function view(id, feed_id, skip_history) { |
ee1f45f4 AD |
208 | |
209 | try { | |
ee1f45f4 | 210 | debug("loading article: " + id + "/" + feed_id); |
1dc8dba0 | 211 | |
0b126ac2 AD |
212 | active_real_feed_id = feed_id; |
213 | ||
e097e8be AD |
214 | var cached_article = cache_find(id); |
215 | ||
216 | debug("cache check result: " + (cached_article != false)); | |
ee1f45f4 | 217 | |
ee1f45f4 AD |
218 | enableHotkeys(); |
219 | ||
1c2d7193 | 220 | //setActiveFeedId(feed_id); |
090e250b | 221 | |
6b4163cb AD |
222 | var query = "backend.php?op=view&id=" + param_escape(id) + |
223 | "&feed=" + param_escape(feed_id); | |
224 | ||
4b6206fa AD |
225 | var date = new Date(); |
226 | ||
227 | if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) { | |
228 | debug("<b>xmlhttp seems to be stuck at view, aborting</b>"); | |
229 | xmlhttp.abort(); | |
c5af7171 | 230 | if (is_safari()) { |
86227583 AD |
231 | debug("trying alternative reset method for Safari"); |
232 | xmlhttp = Ajax.getTransport(); | |
c5af7171 | 233 | } |
4b6206fa AD |
234 | } |
235 | ||
ac162cbe AD |
236 | if (xmlhttp_ready(xmlhttp)) { |
237 | ||
238 | active_post_id = id; | |
4b6206fa AD |
239 | |
240 | cleanSelected("headlinesList"); | |
241 | ||
242 | var crow = document.getElementById("RROW-" + active_post_id); | |
e097e8be AD |
243 | |
244 | var article_is_unread = crow.className.match("Unread"); | |
245 | debug("article is unread: " + article_is_unread); | |
246 | ||
4b6206fa AD |
247 | crow.className = crow.className.replace("Unread", ""); |
248 | ||
249 | var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id); | |
250 | ||
251 | if (upd_img_pic) { | |
252 | upd_img_pic.src = "images/blank_icon.gif"; | |
253 | } | |
254 | ||
255 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); | |
256 | markHeadline(active_post_id); | |
257 | ||
e097e8be AD |
258 | var neighbor_ids = getRelativePostIds(active_post_id); |
259 | ||
260 | /* only request uncached articles */ | |
261 | ||
262 | var cids_to_request = Array(); | |
263 | ||
264 | for (var i = 0; i < neighbor_ids.length; i++) { | |
265 | if (!cache_check(neighbor_ids[i])) { | |
266 | cids_to_request.push(neighbor_ids[i]); | |
267 | } | |
268 | } | |
269 | ||
270 | debug("additional ids: " + cids_to_request.toString()); | |
271 | ||
5a94a953 AD |
272 | /* additional info for piggyback counters */ |
273 | ||
274 | if (tagsAreDisplayed()) { | |
275 | query = query + "&omode=lt"; | |
276 | } else { | |
277 | query = query + "&omode=flc"; | |
278 | } | |
279 | ||
86173d9a AD |
280 | var date = new Date(); |
281 | var timestamp = Math.round(date.getTime() / 1000); | |
9ec58704 AD |
282 | query = query + "&ts=" + timestamp; |
283 | ||
e097e8be AD |
284 | query = query + "&cids=" + cids_to_request.toString(); |
285 | ||
286 | if (!cached_article) { | |
287 | ||
288 | notify_progress("Loading, please wait..."); | |
289 | ||
290 | debug(query); | |
291 | ||
292 | xmlhttp.open("GET", query, true); | |
293 | xmlhttp.onreadystatechange=article_callback; | |
294 | xmlhttp.send(null); | |
295 | } else if (cached_article && article_is_unread) { | |
296 | ||
297 | query = query + "&mode=prefetch"; | |
298 | ||
299 | debug(query); | |
300 | ||
301 | xmlhttp.open("GET", query, true); | |
302 | xmlhttp.onreadystatechange=article_callback; | |
303 | xmlhttp.send(null); | |
304 | ||
305 | render_article(cached_article); | |
306 | ||
307 | } else if (cached_article) { | |
308 | ||
addb5836 AD |
309 | query = query + "&mode=prefetch_old"; |
310 | ||
311 | debug(query); | |
312 | ||
313 | xmlhttp.open("GET", query, true); | |
314 | xmlhttp.onreadystatechange=article_callback; | |
315 | xmlhttp.send(null); | |
316 | ||
e097e8be AD |
317 | render_article(cached_article); |
318 | ||
319 | } | |
320 | ||
321 | cache_expire(); | |
86173d9a | 322 | |
6b4163cb AD |
323 | } else { |
324 | debug("xmlhttp busy (@view)"); | |
f88e0a5d | 325 | printLockingError(); |
6b4163cb AD |
326 | } |
327 | ||
ee1f45f4 AD |
328 | } catch (e) { |
329 | exception_error("view", e); | |
330 | } | |
f0601b87 AD |
331 | } |
332 | ||
67343d9f AD |
333 | function tMark(id) { |
334 | return toggleMark(id); | |
335 | } | |
336 | ||
e4f4b46f AD |
337 | function tPub(id) { |
338 | return togglePub(id); | |
339 | } | |
340 | ||
341 | ||
9932fb06 | 342 | function toggleMark(id) { |
f0601b87 AD |
343 | |
344 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
345 | printLockingError(); | |
346 | return; | |
347 | } | |
348 | ||
f0601b87 AD |
349 | var query = "backend.php?op=rpc&id=" + id + "&subop=mark"; |
350 | ||
67343d9f | 351 | var mark_img = document.getElementById("FMPIC-" + id); |
0feab655 | 352 | var vfeedu = document.getElementById("FEEDU--1"); |
7ba176d2 | 353 | var crow = document.getElementById("RROW-" + id); |
254e0e4b | 354 | |
9932fb06 | 355 | if (mark_img.alt != "Reset mark") { |
f0601b87 AD |
356 | mark_img.src = "images/mark_set.png"; |
357 | mark_img.alt = "Reset mark"; | |
f0601b87 | 358 | query = query + "&mark=1"; |
254e0e4b | 359 | |
7ba176d2 AD |
360 | if (vfeedu && crow.className.match("Unread")) { |
361 | vfeedu.innerHTML = (+vfeedu.innerHTML) + 1; | |
362 | } | |
363 | ||
f0601b87 AD |
364 | } else { |
365 | mark_img.src = "images/mark_unset.png"; | |
366 | mark_img.alt = "Set mark"; | |
f0601b87 | 367 | query = query + "&mark=0"; |
254e0e4b | 368 | |
7ba176d2 AD |
369 | if (vfeedu && crow.className.match("Unread")) { |
370 | vfeedu.innerHTML = (+vfeedu.innerHTML) - 1; | |
371 | } | |
254e0e4b AD |
372 | |
373 | } | |
374 | ||
0feab655 AD |
375 | var vfeedctr = document.getElementById("FEEDCTR--1"); |
376 | var vfeedr = document.getElementById("FEEDR--1"); | |
254e0e4b AD |
377 | |
378 | if (vfeedu && vfeedctr) { | |
379 | if ((+vfeedu.innerHTML) > 0) { | |
7ba176d2 | 380 | if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) { |
8add756a | 381 | vfeedr.className = vfeedr.className + "Unread"; |
7ba176d2 | 382 | vfeedctr.className = "odd"; |
8add756a | 383 | } |
254e0e4b AD |
384 | } else { |
385 | vfeedctr.className = "invisible"; | |
8add756a | 386 | vfeedr.className = vfeedr.className.replace("Unread", ""); |
254e0e4b | 387 | } |
f0601b87 AD |
388 | } |
389 | ||
772bc83b AD |
390 | debug("toggle starred for aid " + id); |
391 | ||
392 | new Ajax.Request(query); | |
f0601b87 AD |
393 | |
394 | } | |
395 | ||
e4f4b46f AD |
396 | function togglePub(id) { |
397 | ||
398 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
399 | printLockingError(); | |
400 | return; | |
401 | } | |
402 | ||
403 | var query = "backend.php?op=rpc&id=" + id + "&subop=publ"; | |
404 | ||
405 | var mark_img = document.getElementById("FPPIC-" + id); | |
406 | var vfeedu = document.getElementById("FEEDU--2"); | |
407 | var crow = document.getElementById("RROW-" + id); | |
408 | ||
409 | if (mark_img.alt != "Unpublish") { | |
410 | mark_img.src = "images/pub_set.png"; | |
411 | mark_img.alt = "Unpublish"; | |
412 | query = query + "&pub=1"; | |
413 | ||
414 | if (vfeedu && crow.className.match("Unread")) { | |
415 | vfeedu.innerHTML = (+vfeedu.innerHTML) + 1; | |
416 | } | |
417 | ||
418 | } else { | |
419 | mark_img.src = "images/pub_unset.png"; | |
420 | mark_img.alt = "Publish"; | |
421 | query = query + "&pub=0"; | |
422 | ||
423 | if (vfeedu && crow.className.match("Unread")) { | |
424 | vfeedu.innerHTML = (+vfeedu.innerHTML) - 1; | |
425 | } | |
426 | ||
427 | } | |
428 | ||
429 | var vfeedctr = document.getElementById("FEEDCTR--2"); | |
430 | var vfeedr = document.getElementById("FEEDR--2"); | |
431 | ||
432 | if (vfeedu && vfeedctr) { | |
433 | if ((+vfeedu.innerHTML) > 0) { | |
434 | if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) { | |
435 | vfeedr.className = vfeedr.className + "Unread"; | |
436 | vfeedctr.className = "odd"; | |
437 | } | |
438 | } else { | |
439 | vfeedctr.className = "invisible"; | |
440 | vfeedr.className = vfeedr.className.replace("Unread", ""); | |
441 | } | |
442 | } | |
443 | ||
444 | debug("toggle published for aid " + id); | |
445 | ||
446 | new Ajax.Request(query); | |
447 | ||
448 | } | |
449 | ||
ac162cbe AD |
450 | function correctHeadlinesOffset(id) { |
451 | ||
452 | try { | |
453 | ||
454 | var hlist = document.getElementById("headlinesList"); | |
455 | var container = document.getElementById("headlinesInnerContainer"); | |
456 | var row = document.getElementById("RROW-" + id); | |
457 | ||
458 | var viewport = container.offsetHeight; | |
459 | ||
460 | var rel_offset_top = row.offsetTop - container.scrollTop; | |
461 | var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; | |
462 | ||
463 | debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); | |
464 | debug("Vport: " + viewport); | |
a5e46e0f | 465 | |
ac162cbe AD |
466 | if (rel_offset_top <= 0 || rel_offset_top > viewport) { |
467 | container.scrollTop = row.offsetTop; | |
468 | } else if (rel_offset_bottom > viewport) { | |
a5e46e0f AD |
469 | |
470 | /* doesn't properly work with Opera in some cases because | |
471 | Opera fucks up element scrolling */ | |
472 | ||
ac162cbe AD |
473 | container.scrollTop = row.offsetTop + row.offsetHeight - viewport; |
474 | } | |
475 | ||
476 | } catch (e) { | |
477 | exception_error("correctHeadlinesOffset", e); | |
478 | } | |
479 | ||
480 | } | |
481 | ||
bb7cface | 482 | function moveToPost(mode) { |
f0601b87 | 483 | |
4e51dd2b AD |
484 | // check for combined mode |
485 | if (!document.getElementById("headlinesList")) | |
486 | return; | |
487 | ||
bb7cface AD |
488 | var rows = getVisibleHeadlineIds(); |
489 | ||
ac162cbe AD |
490 | var prev_id = false; |
491 | var next_id = false; | |
bb7cface | 492 | |
d4eec882 AD |
493 | if (!document.getElementById('RROW-' + active_post_id)) { |
494 | active_post_id = false; | |
495 | } | |
496 | ||
bb7cface AD |
497 | if (active_post_id == false) { |
498 | next_id = getFirstVisibleHeadlineId(); | |
499 | prev_id = getLastVisibleHeadlineId(); | |
500 | } else { | |
501 | for (var i = 0; i < rows.length; i++) { | |
502 | if (rows[i] == active_post_id) { | |
503 | prev_id = rows[i-1]; | |
504 | next_id = rows[i+1]; | |
505 | } | |
506 | } | |
507 | } | |
508 | ||
509 | if (mode == "next") { | |
ac162cbe AD |
510 | if (next_id) { |
511 | correctHeadlinesOffset(next_id); | |
86741347 | 512 | view(next_id, getActiveFeedId()); |
bb7cface AD |
513 | } |
514 | } | |
515 | ||
516 | if (mode == "prev") { | |
ac162cbe AD |
517 | if (prev_id) { |
518 | correctHeadlinesOffset(prev_id); | |
86741347 | 519 | view(prev_id, getActiveFeedId()); |
bb7cface AD |
520 | } |
521 | } | |
522 | } | |
523 | ||
5f51022a AD |
524 | function toggleUnread(id, cmode) { |
525 | try { | |
526 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
527 | printLockingError(); | |
528 | return; | |
529 | } | |
530 | ||
531 | var row = document.getElementById("RROW-" + id); | |
532 | if (row) { | |
533 | var nc = row.className; | |
534 | nc = nc.replace("Unread", ""); | |
535 | nc = nc.replace("Selected", ""); | |
536 | ||
537 | if (row.className.match("Unread")) { | |
538 | row.className = nc; | |
539 | } else { | |
540 | row.className = nc + "Unread"; | |
541 | } | |
542 | ||
543 | if (!cmode) cmode = 2; | |
544 | ||
545 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
546 | param_escape(id) + "&cmode=" + param_escape(cmode); | |
547 | ||
9ec58704 AD |
548 | notify_progress("Loading, please wait..."); |
549 | ||
5f51022a AD |
550 | xmlhttp_rpc.open("GET", query, true); |
551 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
552 | xmlhttp_rpc.send(null); | |
553 | ||
554 | } | |
555 | ||
556 | ||
557 | } catch (e) { | |
558 | exception_error("toggleUnread", e); | |
559 | } | |
560 | } | |
561 | ||
2228d0e4 | 562 | function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) { |
1572afe5 AD |
563 | try { |
564 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
565 | printLockingError(); | |
566 | return; | |
567 | } | |
568 | ||
386cbf27 AD |
569 | var rows; |
570 | ||
571 | if (cdm_mode) { | |
572 | rows = cdmGetSelectedArticles(); | |
573 | } else { | |
574 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
575 | } | |
1572afe5 | 576 | |
2228d0e4 | 577 | if (rows.length == 0 && !no_error) { |
9cc600d1 AD |
578 | alert(__("No articles are selected.")); |
579 | return; | |
580 | } | |
581 | ||
1572afe5 | 582 | for (i = 0; i < rows.length; i++) { |
f1f2db64 AD |
583 | var row = document.getElementById("RROW-" + rows[i]); |
584 | if (row) { | |
585 | var nc = row.className; | |
586 | nc = nc.replace("Unread", ""); | |
587 | nc = nc.replace("Selected", ""); | |
588 | ||
589 | if (row.className.match("Unread")) { | |
590 | row.className = nc + "Selected"; | |
591 | } else { | |
592 | row.className = nc + "UnreadSelected"; | |
593 | } | |
594 | } | |
1572afe5 AD |
595 | } |
596 | ||
597 | if (rows.length > 0) { | |
598 | ||
b47b5af7 AD |
599 | var cmode = ""; |
600 | ||
601 | if (set_state == undefined) { | |
602 | cmode = "2"; | |
603 | } else if (set_state == true) { | |
604 | cmode = "1"; | |
605 | } else if (set_state == false) { | |
606 | cmode = "0"; | |
607 | } | |
608 | ||
1572afe5 | 609 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + |
b47b5af7 | 610 | param_escape(rows.toString()) + "&cmode=" + cmode; |
1572afe5 | 611 | |
e08443c1 AD |
612 | _catchup_callback_func = callback_func; |
613 | ||
9ec58704 AD |
614 | notify_progress("Loading, please wait..."); |
615 | ||
1572afe5 | 616 | xmlhttp_rpc.open("GET", query, true); |
e08443c1 | 617 | xmlhttp_rpc.onreadystatechange=catchup_callback; |
1572afe5 AD |
618 | xmlhttp_rpc.send(null); |
619 | ||
620 | } | |
621 | ||
622 | } catch (e) { | |
83f043bb | 623 | exception_error("selectionToggleUnread", e); |
1572afe5 AD |
624 | } |
625 | } | |
626 | ||
386cbf27 | 627 | function selectionToggleMarked(cdm_mode) { |
1572afe5 AD |
628 | try { |
629 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
630 | printLockingError(); | |
631 | return; | |
632 | } | |
633 | ||
386cbf27 AD |
634 | var rows; |
635 | ||
636 | if (cdm_mode) { | |
637 | rows = cdmGetSelectedArticles(); | |
638 | } else { | |
639 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
640 | } | |
1572afe5 | 641 | |
9cc600d1 AD |
642 | if (rows.length == 0) { |
643 | alert(__("No articles are selected.")); | |
644 | return; | |
645 | } | |
646 | ||
1572afe5 AD |
647 | for (i = 0; i < rows.length; i++) { |
648 | var row = document.getElementById("RROW-" + rows[i]); | |
e4f4b46f | 649 | var mark_img = document.getElementById("FMPIC-" + rows[i]); |
1572afe5 AD |
650 | |
651 | if (row && mark_img) { | |
652 | ||
653 | if (mark_img.alt == "Set mark") { | |
654 | mark_img.src = "images/mark_set.png"; | |
655 | mark_img.alt = "Reset mark"; | |
656 | mark_img.setAttribute('onclick', | |
657 | 'javascript:toggleMark('+rows[i]+', false)'); | |
658 | ||
659 | } else { | |
660 | mark_img.src = "images/mark_unset.png"; | |
661 | mark_img.alt = "Set mark"; | |
662 | mark_img.setAttribute('onclick', | |
663 | 'javascript:toggleMark('+rows[i]+', true)'); | |
664 | } | |
665 | } | |
666 | } | |
667 | ||
668 | if (rows.length > 0) { | |
669 | ||
670 | var query = "backend.php?op=rpc&subop=markSelected&ids=" + | |
671 | param_escape(rows.toString()) + "&cmode=2"; | |
672 | ||
673 | xmlhttp_rpc.open("GET", query, true); | |
674 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
675 | xmlhttp_rpc.send(null); | |
676 | ||
677 | } | |
678 | ||
679 | } catch (e) { | |
83f043bb | 680 | exception_error("selectionToggleMarked", e); |
1572afe5 AD |
681 | } |
682 | } | |
683 | ||
e4f4b46f AD |
684 | function selectionTogglePublished(cdm_mode) { |
685 | try { | |
686 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
687 | printLockingError(); | |
688 | return; | |
689 | } | |
690 | ||
691 | var rows; | |
692 | ||
693 | if (cdm_mode) { | |
694 | rows = cdmGetSelectedArticles(); | |
695 | } else { | |
696 | rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK"); | |
697 | } | |
698 | ||
699 | if (rows.length == 0) { | |
700 | alert(__("No articles are selected.")); | |
701 | return; | |
702 | } | |
703 | ||
704 | for (i = 0; i < rows.length; i++) { | |
705 | var row = document.getElementById("RROW-" + rows[i]); | |
706 | var mark_img = document.getElementById("FPPIC-" + rows[i]); | |
707 | ||
708 | if (row && mark_img) { | |
709 | ||
710 | if (mark_img.alt == "Publish") { | |
711 | mark_img.src = "images/pub_set.png"; | |
712 | mark_img.alt = "Unpublish"; | |
713 | mark_img.setAttribute('onclick', | |
714 | 'javascript:togglePub('+rows[i]+', false)'); | |
715 | ||
716 | } else { | |
717 | mark_img.src = "images/pub_unset.png"; | |
718 | mark_img.alt = "Publish"; | |
719 | mark_img.setAttribute('onclick', | |
720 | 'javascript:togglePub('+rows[i]+', true)'); | |
721 | } | |
722 | } | |
723 | } | |
724 | ||
725 | if (rows.length > 0) { | |
726 | ||
727 | var query = "backend.php?op=rpc&subop=publishSelected&ids=" + | |
728 | param_escape(rows.toString()) + "&cmode=2"; | |
729 | ||
730 | xmlhttp_rpc.open("GET", query, true); | |
731 | xmlhttp_rpc.onreadystatechange=all_counters_callback; | |
732 | xmlhttp_rpc.send(null); | |
733 | ||
734 | } | |
735 | ||
736 | } catch (e) { | |
737 | exception_error("selectionToggleMarked", e); | |
738 | } | |
739 | } | |
740 | ||
386cbf27 AD |
741 | function cdmGetSelectedArticles() { |
742 | var sel_articles = new Array(); | |
b2128f01 | 743 | var container = document.getElementById("headlinesInnerContainer"); |
386cbf27 AD |
744 | |
745 | for (i = 0; i < container.childNodes.length; i++) { | |
746 | var child = container.childNodes[i]; | |
747 | ||
748 | if (child.id.match("RROW-") && child.className.match("Selected")) { | |
749 | var c_id = child.id.replace("RROW-", ""); | |
750 | sel_articles.push(c_id); | |
751 | } | |
752 | } | |
753 | ||
754 | return sel_articles; | |
755 | } | |
756 | ||
757 | // mode = all,none,unread | |
758 | function cdmSelectArticles(mode) { | |
b2128f01 | 759 | var container = document.getElementById("headlinesInnerContainer"); |
386cbf27 AD |
760 | |
761 | for (i = 0; i < container.childNodes.length; i++) { | |
762 | var child = container.childNodes[i]; | |
763 | ||
764 | if (child.id.match("RROW-")) { | |
06d1a1c1 AD |
765 | var aid = child.id.replace("RROW-", ""); |
766 | ||
767 | var cb = document.getElementById("RCHK-" + aid); | |
768 | ||
386cbf27 AD |
769 | if (mode == "all") { |
770 | if (!child.className.match("Selected")) { | |
771 | child.className = child.className + "Selected"; | |
06d1a1c1 | 772 | cb.checked = true; |
386cbf27 AD |
773 | } |
774 | } else if (mode == "unread") { | |
775 | if (child.className.match("Unread") && !child.className.match("Selected")) { | |
776 | child.className = child.className + "Selected"; | |
06d1a1c1 | 777 | cb.checked = true; |
386cbf27 AD |
778 | } |
779 | } else { | |
780 | child.className = child.className.replace("Selected", ""); | |
06d1a1c1 | 781 | cb.checked = false; |
386cbf27 AD |
782 | } |
783 | } | |
784 | } | |
785 | } | |
786 | ||
98bea1b1 | 787 | function catchupPage() { |
b47b5af7 | 788 | |
8a5b4579 AD |
789 | var fn = getFeedName(getActiveFeedId(), active_feed_is_cat); |
790 | ||
791 | var str = "Mark all visible articles in " + fn + " as read?"; | |
792 | ||
793 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
794 | return; | |
795 | } | |
796 | ||
b47b5af7 AD |
797 | if (document.getElementById("headlinesList")) { |
798 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true); | |
2228d0e4 | 799 | selectionToggleUnread(false, false, 'viewCurrentFeed()', true); |
b47b5af7 AD |
800 | selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false); |
801 | } else { | |
802 | cdmSelectArticles('all'); | |
2228d0e4 | 803 | selectionToggleUnread(true, false, 'viewCurrentFeed()', true) |
b47b5af7 AD |
804 | cdmSelectArticles('none'); |
805 | } | |
98bea1b1 AD |
806 | } |
807 | ||
88040f57 AD |
808 | function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) { |
809 | ||
810 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
811 | printLockingError(); | |
812 | } | |
813 | ||
814 | var title = prompt("Please enter label title:", ""); | |
815 | ||
816 | if (title) { | |
817 | ||
818 | var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) + | |
819 | "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) + | |
820 | "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) + | |
821 | "&title=" + param_escape(title); | |
822 | ||
823 | debug("LFS: " + query); | |
824 | ||
825 | xmlhttp_rpc.open("GET", query, true); | |
0feab655 | 826 | xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback; |
88040f57 AD |
827 | xmlhttp_rpc.send(null); |
828 | } | |
829 | ||
830 | } | |
831 | ||
13f08f75 | 832 | function editArticleTags(id, feed_id, cdm_enabled) { |
0b126ac2 AD |
833 | _tag_active_post_id = id; |
834 | _tag_active_feed_id = feed_id; | |
13f08f75 | 835 | _tag_active_cdm = cdm_enabled; |
b07b61da AD |
836 | |
837 | cache_invalidate(id); | |
838 | ||
13f08f75 AD |
839 | try { |
840 | _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop; | |
841 | } catch (e) { } | |
0b126ac2 AD |
842 | displayDlg('editArticleTags', id); |
843 | } | |
844 | ||
845 | ||
846 | function tag_saved_callback() { | |
847 | if (xmlhttp_rpc.readyState == 4) { | |
848 | try { | |
849 | debug("in tag_saved_callback"); | |
850 | ||
851 | closeInfoBox(); | |
852 | notify(""); | |
853 | ||
854 | if (tagsAreDisplayed()) { | |
855 | _reload_feedlist_after_view = true; | |
856 | } | |
857 | ||
13f08f75 AD |
858 | if (!_tag_active_cdm) { |
859 | if (active_post_id == _tag_active_post_id) { | |
860 | debug("reloading current article"); | |
861 | view(_tag_active_post_id, _tag_active_feed_id); | |
862 | } | |
863 | } else { | |
864 | debug("reloading current feed"); | |
865 | viewCurrentFeed(); | |
866 | } | |
0b126ac2 AD |
867 | |
868 | } catch (e) { | |
869 | exception_error("catchup_callback", e); | |
870 | } | |
871 | } | |
872 | } | |
873 | ||
874 | function editTagsSave() { | |
875 | ||
876 | if (!xmlhttp_ready(xmlhttp_rpc)) { | |
877 | printLockingError(); | |
878 | } | |
879 | ||
42c32916 | 880 | notify_progress("Saving article tags..."); |
88040f57 | 881 | |
0b126ac2 AD |
882 | var form = document.forms["tag_edit_form"]; |
883 | ||
884 | var query = Form.serialize("tag_edit_form"); | |
885 | ||
14b6c54b AD |
886 | query = "backend.php?op=rpc&subop=setArticleTags&" + query; |
887 | ||
888 | debug(query); | |
889 | ||
890 | xmlhttp_rpc.open("GET", query, true); | |
0b126ac2 AD |
891 | xmlhttp_rpc.onreadystatechange=tag_saved_callback; |
892 | xmlhttp_rpc.send(null); | |
893 | ||
894 | } | |
d62a3b63 AD |
895 | |
896 | function editTagsInsert() { | |
897 | try { | |
898 | ||
899 | var form = document.forms["tag_edit_form"]; | |
900 | ||
901 | var found_tags = form.found_tags; | |
902 | var tags_str = form.tags_str; | |
903 | ||
904 | var tag = found_tags[found_tags.selectedIndex].value; | |
905 | ||
906 | if (tags_str.value.length > 0 && | |
907 | tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) { | |
908 | ||
909 | tags_str.value = tags_str.value + ", "; | |
910 | } | |
911 | ||
912 | tags_str.value = tags_str.value + tag + ", "; | |
913 | ||
914 | found_tags.selectedIndex = 0; | |
915 | ||
916 | } catch (e) { | |
917 | exception_error(e, "editTagsInsert"); | |
918 | } | |
919 | } | |
ba0978c8 AD |
920 | |
921 | function cdmWatchdog() { | |
922 | ||
923 | try { | |
924 | ||
925 | var ctr = document.getElementById("headlinesInnerContainer"); | |
926 | ||
9acd22e8 AD |
927 | if (!ctr) return; |
928 | ||
ba0978c8 AD |
929 | var ids = new Array(); |
930 | ||
931 | var e = ctr.firstChild; | |
932 | ||
933 | while (e) { | |
934 | if (e.className && e.className == "cdmArticleUnread" && e.id && | |
935 | e.id.match("RROW-")) { | |
936 | ||
937 | // article fits in viewport OR article is longer than viewport and | |
938 | // its bottom is visible | |
939 | ||
940 | if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <= | |
941 | ctr.scrollTop + ctr.offsetHeight) { | |
942 | ||
943 | // debug(e.id + " is visible " + e.offsetTop + "." + | |
944 | // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." + | |
945 | // (ctr.scrollTop + ctr.offsetHeight)); | |
946 | ||
947 | ids.push(e.id.replace("RROW-", "")); | |
948 | ||
949 | } else if (e.offsetHeight > ctr.offsetHeight && | |
950 | e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
951 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) { | |
952 | ||
953 | ids.push(e.id.replace("RROW-", "")); | |
954 | ||
955 | } | |
956 | ||
c50e2b30 AD |
957 | // method 2: article bottom is visible and is in upper 1/2 of the viewport |
958 | ||
959 | /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop && | |
960 | e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) { | |
961 | ||
962 | ids.push(e.id.replace("RROW-", "")); | |
963 | ||
964 | } */ | |
965 | ||
ba0978c8 AD |
966 | } |
967 | ||
968 | e = e.nextSibling; | |
969 | } | |
970 | ||
971 | debug("cdmWatchdog, ids= " + ids.toString()); | |
972 | ||
973 | if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) { | |
974 | ||
975 | for (var i = 0; i < ids.length; i++) { | |
976 | var e = document.getElementById("RROW-" + ids[i]); | |
977 | if (e) { | |
978 | e.className = e.className.replace("Unread", ""); | |
979 | } | |
980 | } | |
981 | ||
982 | var query = "backend.php?op=rpc&subop=catchupSelected&ids=" + | |
983 | param_escape(ids.toString()) + "&cmode=0"; | |
984 | ||
f8e47112 | 985 | xmlhttp_rpc.open("GET", query, true); |
ba0978c8 | 986 | xmlhttp_rpc.onreadystatechange=all_counters_callback; |
c50e2b30 | 987 | xmlhttp_rpc.send(null); |
ba0978c8 AD |
988 | |
989 | } | |
990 | ||
c50e2b30 | 991 | _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000); |
ba0978c8 AD |
992 | |
993 | } catch (e) { | |
994 | exception_error(e, "cdmWatchdog"); | |
995 | } | |
996 | ||
997 | } | |
e097e8be AD |
998 | |
999 | ||
1000 | function cache_inject(id, article) { | |
fed4387d | 1001 | if (!cache_check(id)) { |
e097e8be AD |
1002 | debug("cache_article: miss: " + id); |
1003 | ||
1004 | var cache_obj = new Array(); | |
1005 | ||
fed4387d | 1006 | cache_obj["id"] = id; |
e097e8be AD |
1007 | cache_obj["data"] = article; |
1008 | ||
fed4387d | 1009 | article_cache.push(cache_obj); |
e097e8be AD |
1010 | |
1011 | } else { | |
1012 | debug("cache_article: hit: " + id); | |
1013 | } | |
1014 | } | |
1015 | ||
1016 | function cache_find(id) { | |
fed4387d AD |
1017 | for (var i = 0; i < article_cache.length; i++) { |
1018 | if (article_cache[i]["id"] == id) { | |
fed4387d AD |
1019 | return article_cache[i]["data"]; |
1020 | } | |
e097e8be | 1021 | } |
fed4387d | 1022 | return false; |
e097e8be AD |
1023 | } |
1024 | ||
1025 | function cache_check(id) { | |
fed4387d AD |
1026 | for (var i = 0; i < article_cache.length; i++) { |
1027 | if (article_cache[i]["id"] == id) { | |
1028 | return true; | |
1029 | } | |
1030 | } | |
1031 | return false; | |
e097e8be AD |
1032 | } |
1033 | ||
1034 | function cache_expire() { | |
7289eacf | 1035 | while (article_cache.length > 20) { |
fed4387d AD |
1036 | article_cache.shift(); |
1037 | } | |
e097e8be | 1038 | } |
b07b61da AD |
1039 | |
1040 | function cache_invalidate(id) { | |
1041 | var i = 0 | |
c1b18749 AD |
1042 | |
1043 | try { | |
1044 | ||
1045 | while (i < article_cache.length) { | |
1046 | if (article_cache[i]["id"] == id) { | |
1047 | debug("cache_invalidate: removed id " + id); | |
1048 | article_cache.splice(i, 1); | |
1049 | return true; | |
1050 | } | |
1051 | i++; | |
b07b61da | 1052 | } |
c1b18749 AD |
1053 | debug("cache_invalidate: id not found: " + id); |
1054 | return false; | |
1055 | } catch (e) { | |
1056 | exception_error("cache_invalidate", e); | |
b07b61da | 1057 | } |
b07b61da | 1058 | } |
298f3f78 AD |
1059 | |
1060 | function getActiveArticleId() { | |
1061 | return active_post_id; | |
1062 | } | |
e4914b62 AD |
1063 | |
1064 | function cdmMouseIn(elem) { | |
1065 | try { | |
1066 | if (elem.id && elem.id.match("RROW-")) { | |
1067 | var id = elem.id.replace("RROW-", ""); | |
1068 | active_post_id = id; | |
1069 | } | |
1070 | } catch (e) { | |
1071 | exception_error("cdmMouseIn", e); | |
1072 | } | |
1073 | ||
1074 | } | |
1075 | ||
1076 | function cdmMouseOut(elem) { | |
1077 | active_post_id = false; | |
1078 | } | |
ac541432 AD |
1079 | |
1080 | function headlines_scroll_handler() { | |
1081 | try { | |
1082 | ||
1083 | var e = document.getElementById("headlinesInnerContainer"); | |
1084 | ||
a219fec5 | 1085 | if (e.scrollTop + e.offsetHeight > e.scrollHeight - 300) { |
ac541432 AD |
1086 | debug("more cowbell!"); |
1087 | ||
1088 | viewNextFeedPage(); | |
1089 | } | |
1090 | ||
1091 | } catch (e) { | |
1092 | exception_error("headlines_scroll_handler", e); | |
1093 | } | |
1094 | } |