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