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