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