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