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