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