]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
do not schedule catchup batch request when infscroll request is in progress
[tt-rss.git] / tt-rss.js
1 var total_unread = 0;
2 var global_unread = -1;
3 var firsttime_update = true;
4 var _active_feed_id = 0;
5 var _active_feed_is_cat = false;
6 var hotkey_prefix = false;
7 var hotkey_prefix_pressed = false;
8 var init_params = {};
9 var _force_scheduled_update = false;
10 var last_scheduled_update = false;
11
12 var _rpc_seq = 0;
13
14 function next_seq() {
15 _rpc_seq += 1;
16 return _rpc_seq;
17 }
18
19 function get_seq() {
20 return _rpc_seq;
21 }
22
23 function activeFeedIsCat() {
24 return _active_feed_is_cat;
25 }
26
27 function getActiveFeedId() {
28 try {
29 //console.log("gAFID: " + _active_feed_id);
30 return _active_feed_id;
31 } catch (e) {
32 exception_error("getActiveFeedId", e);
33 }
34 }
35
36 function setActiveFeedId(id, is_cat) {
37 try {
38 _active_feed_id = id;
39
40 if (is_cat != undefined) {
41 _active_feed_is_cat = is_cat;
42 }
43
44 selectFeed(id, is_cat);
45
46 } catch (e) {
47 exception_error("setActiveFeedId", e);
48 }
49 }
50
51
52 function updateFeedList() {
53 try {
54
55 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
56 // __("Loading, please wait...") + "</div>";
57
58 Element.show("feedlistLoading");
59
60 if (dijit.byId("feedTree")) {
61 dijit.byId("feedTree").destroyRecursive();
62 }
63
64 var store = new dojo.data.ItemFileWriteStore({
65 url: "backend.php?op=feeds"});
66
67 var treeModel = new fox.FeedStoreModel({
68 store: store,
69 query: {
70 "type": "feed"
71 },
72 rootId: "root",
73 rootLabel: "Feeds",
74 childrenAttrs: ["items"]
75 });
76
77 var tree = new fox.FeedTree({
78 persist: false,
79 model: treeModel,
80 onOpen: function (item, node) {
81 var id = String(item.id);
82 var cat_id = id.substr(id.indexOf(":")+1);
83
84 new Ajax.Request("backend.php",
85 { parameters: "backend.php?op=feeds&subop=collapse&cid=" +
86 param_escape(cat_id) + "&mode=0" } );
87 },
88 onClose: function (item, node) {
89 var id = String(item.id);
90 var cat_id = id.substr(id.indexOf(":")+1);
91
92 new Ajax.Request("backend.php",
93 { parameters: "backend.php?op=feeds&subop=collapse&cid=" +
94 param_escape(cat_id) + "&mode=1" } );
95
96 },
97 onClick: function (item, node) {
98 var id = String(item.id);
99 var is_cat = id.match("^CAT:");
100 var feed = id.substr(id.indexOf(":")+1);
101 viewfeed(feed, '', is_cat);
102 return false;
103 },
104 openOnClick: false,
105 showRoot: false,
106 id: "feedTree",
107 }, "feedTree");
108
109 /* var menu = new dijit.Menu({id: 'feedMenu'});
110
111 menu.addChild(new dijit.MenuItem({
112 label: "Simple menu item"
113 }));
114
115 // menu.bindDomNode(tree.domNode); */
116
117 var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) {
118 console.log(dijit.getEnclosingWidget(event.target));
119 dojo.disconnect(tmph);
120 });
121
122 $("feeds-holder").appendChild(tree.domNode);
123
124 var tmph = dojo.connect(tree, 'onLoad', function() {
125 dojo.disconnect(tmph);
126 Element.hide("feedlistLoading");
127
128 tree.collapseHiddenCats();
129
130 feedlist_init();
131
132 // var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
133 // menu.bindDomNode(node);
134
135 loading_set_progress(25);
136 });
137
138 tree.startup();
139
140 } catch (e) {
141 exception_error("updateFeedList", e);
142 }
143 }
144
145 function catchupAllFeeds() {
146
147 var str = __("Mark all articles as read?");
148
149 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
150
151 var query_str = "backend.php?op=feeds&subop=catchupAll";
152
153 notify_progress("Marking all feeds as read...");
154
155 //console.log("catchupAllFeeds Q=" + query_str);
156
157 new Ajax.Request("backend.php", {
158 parameters: query_str,
159 onComplete: function(transport) {
160 feedlist_callback2(transport);
161 } });
162
163 global_unread = 0;
164 updateTitle("");
165 }
166 }
167
168 function viewCurrentFeed(subop) {
169
170 if (getActiveFeedId() != undefined) {
171 viewfeed(getActiveFeedId(), subop, activeFeedIsCat());
172 }
173 return false; // block unneeded form submits
174 }
175
176 function timeout() {
177 if (getInitParam("bw_limit") == "1") return;
178
179 try {
180 var date = new Date();
181 var ts = Math.round(date.getTime() / 1000);
182
183 if (ts - last_scheduled_update > 10 || _force_scheduled_update) {
184
185 //console.log("timeout()");
186
187 window.clearTimeout(counter_timeout_id);
188
189 var query_str = "?op=rpc&subop=getAllCounters&seq=" + next_seq();
190
191 var omode;
192
193 if (firsttime_update && !navigator.userAgent.match("Opera")) {
194 firsttime_update = false;
195 omode = "T";
196 } else {
197 omode = "flc";
198 }
199
200 query_str = query_str + "&omode=" + omode;
201
202 if (!_force_scheduled_update)
203 query_str = query_str + "&last_article_id=" + getInitParam("last_article_id");
204
205 //console.log("[timeout]" + query_str);
206
207 new Ajax.Request("backend.php", {
208 parameters: query_str,
209 onComplete: function(transport) {
210 handle_rpc_json(transport, !_force_scheduled_update);
211 _force_scheduled_update = false;
212 } });
213
214 last_scheduled_update = ts;
215 }
216
217 } catch (e) {
218 exception_error("timeout", e);
219 }
220
221 setTimeout("timeout()", 3000);
222 }
223
224 function search() {
225 var query = "backend.php?op=dlg&id=search&param=" +
226 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
227
228 if (dijit.byId("searchDlg"))
229 dijit.byId("searchDlg").destroyRecursive();
230
231 dialog = new dijit.Dialog({
232 id: "searchDlg",
233 title: __("Search"),
234 style: "width: 600px",
235 execute: function() {
236 if (this.validate()) {
237 _search_query = dojo.objectToQuery(this.attr('value'));
238 this.hide();
239 viewCurrentFeed();
240 }
241 },
242 href: query});
243
244 dialog.show();
245 }
246
247 function updateTitle() {
248 var tmp = "Tiny Tiny RSS";
249
250 if (global_unread > 0) {
251 tmp = tmp + " (" + global_unread + ")";
252 }
253
254 if (window.fluid) {
255 if (global_unread > 0) {
256 window.fluid.dockBadge = global_unread;
257 } else {
258 window.fluid.dockBadge = "";
259 }
260 }
261
262 document.title = tmp;
263 }
264
265 function genericSanityCheck() {
266 setCookie("ttrss_test", "TEST");
267
268 if (getCookie("ttrss_test") != "TEST") {
269 return fatalError(2);
270 }
271
272 return true;
273 }
274
275 function init() {
276 try {
277 dojo.registerModulePath("fox", "../..");
278
279 dojo.require("fox.FeedTree");
280
281 if (typeof themeBeforeLayout == 'function') {
282 themeBeforeLayout();
283 }
284
285 dojo.parser.parse();
286
287 dojo.addOnLoad(function() {
288 updateFeedList();
289 closeArticlePanel();
290
291 if (typeof themeAfterLayout == 'function') {
292 themeAfterLayout();
293 }
294
295 });
296
297 if (!genericSanityCheck())
298 return false;
299
300 loading_set_progress(20);
301
302 var hasAudio = !!((myAudioTag = document.createElement('audio')).canPlayType);
303
304 new Ajax.Request("backend.php", {
305 parameters: {op: "rpc", subop: "sanityCheck", hasAudio: hasAudio},
306 onComplete: function(transport) {
307 backend_sanity_check_callback(transport);
308 } });
309
310 } catch (e) {
311 exception_error("init", e);
312 }
313 }
314
315 function init_second_stage() {
316
317 try {
318
319 delCookie("ttrss_test");
320
321 var toolbar = document.forms["main_toolbar_form"];
322
323 dijit.getEnclosingWidget(toolbar.view_mode).attr('value',
324 getInitParam("default_view_mode"));
325
326 dijit.getEnclosingWidget(toolbar.order_by).attr('value',
327 getInitParam("default_view_order_by"));
328
329 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
330
331 loading_set_progress(30);
332
333 if (has_local_storage())
334 sessionStorage.clear();
335
336 console.log("second stage ok");
337
338 } catch (e) {
339 exception_error("init_second_stage", e);
340 }
341 }
342
343 function quickMenuGo(opid) {
344 try {
345 if (opid == "qmcPrefs") {
346 gotoPreferences();
347 }
348
349 if (opid == "qmcTagCloud") {
350 displayDlg("printTagCloud");
351 }
352
353 if (opid == "qmcSearch") {
354 search();
355 return;
356 }
357
358 if (opid == "qmcAddFeed") {
359 quickAddFeed();
360 return;
361 }
362
363 if (opid == "qmcDigest") {
364 window.location.href = "digest.php";
365 return;
366 }
367
368 if (opid == "qmcEditFeed") {
369 if (activeFeedIsCat())
370 alert(__("You can't edit this kind of feed."));
371 else
372 editFeed(getActiveFeedId());
373 return;
374 }
375
376 if (opid == "qmcRemoveFeed") {
377 var actid = getActiveFeedId();
378
379 if (activeFeedIsCat()) {
380 alert(__("You can't unsubscribe from the category."));
381 return;
382 }
383
384 if (!actid) {
385 alert(__("Please select some feed first."));
386 return;
387 }
388
389 var fn = getFeedName(actid);
390
391 var pr = __("Unsubscribe from %s?").replace("%s", fn);
392
393 if (confirm(pr)) {
394 unsubscribeFeed(actid);
395 }
396
397 return;
398 }
399
400 if (opid == "qmcCatchupAll") {
401 catchupAllFeeds();
402 return;
403 }
404
405 if (opid == "qmcShowOnlyUnread") {
406 toggleDispRead();
407 return;
408 }
409
410 if (opid == "qmcAddFilter") {
411 quickAddFilter();
412 return;
413 }
414
415 if (opid == "qmcAddLabel") {
416 addLabel();
417 return;
418 }
419
420 if (opid == "qmcRescoreFeed") {
421 rescoreCurrentFeed();
422 return;
423 }
424
425 if (opid == "qmcHKhelp") {
426 //Element.show("hotkey_help_overlay");
427 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
428 }
429
430 if (opid == "qmcAbout") {
431 dialog = new dijit.Dialog({
432 title: __("About..."),
433 style: "width: 400px",
434 href: "backend.php?op=dlg&id=about",
435 });
436
437 dialog.show();
438 }
439
440 } catch (e) {
441 exception_error("quickMenuGo", e);
442 }
443 }
444
445 function toggleDispRead() {
446 try {
447
448 var hide = !(getInitParam("hide_read_feeds") == "1");
449
450 hideOrShowFeeds(hide);
451
452 var query = "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
453 param_escape(hide);
454
455 setInitParam("hide_read_feeds", hide);
456
457 new Ajax.Request("backend.php", {
458 parameters: query,
459 onComplete: function(transport) {
460 } });
461
462 } catch (e) {
463 exception_error("toggleDispRead", e);
464 }
465 }
466
467 function parse_runtime_info(data) {
468
469 //console.log("parsing runtime info...");
470
471 for (k in data) {
472 var v = data[k];
473
474 // console.log("RI: " + k + " => " + v);
475
476 if (k == "new_version_available") {
477 var icon = $("newVersionIcon");
478 if (icon) {
479 if (v == "1") {
480 icon.style.display = "inline";
481 } else {
482 icon.style.display = "none";
483 }
484 }
485 return;
486 }
487
488 var error_flag;
489
490 if (k == "daemon_is_running" && v != 1) {
491 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
492 return;
493 }
494
495 if (k == "daemon_stamp_ok" && v != 1) {
496 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
497 return;
498 }
499
500 if (k == "max_feed_id" || k == "num_feeds") {
501 if (init_params[k] != v) {
502 console.log("feed count changed, need to reload feedlist.");
503 updateFeedList();
504 }
505 }
506
507 init_params[k] = v;
508 notify('');
509 }
510 }
511
512 function catchupCurrentFeed() {
513
514 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
515
516 var str = __("Mark all articles in %s as read?").replace("%s", fn);
517
518 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
519 return viewCurrentFeed('MarkAllRead')
520 }
521 }
522
523 function catchupFeedInGroup(id) {
524
525 try {
526
527 var title = getFeedName(id);
528
529 var str = __("Mark all articles in %s as read?").replace("%s", title);
530
531 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
532 return viewCurrentFeed('MarkAllReadGR:' + id)
533 }
534
535 } catch (e) {
536 exception_error("catchupFeedInGroup", e);
537 }
538 }
539
540 function collapse_feedlist() {
541 try {
542
543 if (!Element.visible('feeds-holder')) {
544 Element.show('feeds-holder');
545 Element.show('feeds-holder_splitter');
546 $("collapse_feeds_btn").innerHTML = "&lt;&lt;";
547 } else {
548 Element.hide('feeds-holder');
549 Element.hide('feeds-holder_splitter');
550 $("collapse_feeds_btn").innerHTML = "&gt;&gt;";
551 }
552
553 dijit.byId("main").resize();
554
555 query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
556 new Ajax.Request("backend.php", { parameters: query });
557
558 } catch (e) {
559 exception_error("collapse_feedlist", e);
560 }
561 }
562
563 function viewModeChanged() {
564 cache_flush();
565 return viewCurrentFeed('')
566 }
567
568 function viewLimitChanged() {
569 cache_flush();
570 return viewCurrentFeed('')
571 }
572
573 /* function adjustArticleScore(id, score) {
574 try {
575
576 var pr = prompt(__("Assign score to article:"), score);
577
578 if (pr != undefined) {
579 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
580
581 new Ajax.Request("backend.php", {
582 parameters: query,
583 onComplete: function(transport) {
584 viewCurrentFeed();
585 } });
586
587 }
588 } catch (e) {
589 exception_error("adjustArticleScore", e);
590 }
591 } */
592
593 function rescoreCurrentFeed() {
594
595 var actid = getActiveFeedId();
596
597 if (activeFeedIsCat() || actid < 0) {
598 alert(__("You can't rescore this kind of feed."));
599 return;
600 }
601
602 if (!actid) {
603 alert(__("Please select some feed first."));
604 return;
605 }
606
607 var fn = getFeedName(actid);
608 var pr = __("Rescore articles in %s?").replace("%s", fn);
609
610 if (confirm(pr)) {
611 notify_progress("Rescoring articles...");
612
613 var query = "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid;
614
615 new Ajax.Request("backend.php", {
616 parameters: query,
617 onComplete: function(transport) {
618 viewCurrentFeed();
619 } });
620 }
621 }
622
623 function hotkey_handler(e) {
624 try {
625
626 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
627
628 var keycode;
629 var shift_key = false;
630
631 var cmdline = $('cmdline');
632
633 try {
634 shift_key = e.shiftKey;
635 } catch (e) {
636
637 }
638
639 if (window.event) {
640 keycode = window.event.keyCode;
641 } else if (e) {
642 keycode = e.which;
643 }
644
645 var keychar = String.fromCharCode(keycode);
646
647 if (keycode == 27) { // escape
648 if (Element.visible("hotkey_help_overlay")) {
649 Element.hide("hotkey_help_overlay");
650 }
651 hotkey_prefix = false;
652 }
653
654 if (keycode == 16) return; // ignore lone shift
655 if (keycode == 17) return; // ignore lone ctrl
656
657 if ((keycode == 70 || keycode == 67 || keycode == 71 || keycode == 65)
658 && !hotkey_prefix) {
659
660 var date = new Date();
661 var ts = Math.round(date.getTime() / 1000);
662
663 hotkey_prefix = keycode;
664 hotkey_prefix_pressed = ts;
665
666 cmdline.innerHTML = keychar;
667 Element.show(cmdline);
668
669 console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
670 return true;
671 }
672
673 if (Element.visible("hotkey_help_overlay")) {
674 Element.hide("hotkey_help_overlay");
675 }
676
677 /* Global hotkeys */
678
679 Element.hide(cmdline);
680
681 if (!hotkey_prefix) {
682
683 if (keycode == 69) { // e
684 var id = getActiveArticleId();
685 emailArticle(id);
686 }
687
688 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
689 if (!Element.visible("hotkey_help_overlay")) {
690 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
691 } else {
692 Element.hide("hotkey_help_overlay");
693 }
694 return false;
695 }
696
697 if (keycode == 191 || keychar == '/') { // /
698 search();
699 return false;
700 }
701
702 if (keycode == 74) { // j
703 var rv = dijit.byId("feedTree").getPreviousFeed(
704 getActiveFeedId(), activeFeedIsCat());
705
706 if (rv) viewfeed(rv[0], '', rv[1]);
707
708 return;
709 }
710
711 if (keycode == 75) { // k
712 var rv = dijit.byId("feedTree").getNextFeed(
713 getActiveFeedId(), activeFeedIsCat());
714
715 if (rv) viewfeed(rv[0], '', rv[1]);
716
717 return;
718 }
719
720 if (shift_key && keycode == 40) { // shift-down
721 catchupRelativeToArticle(1);
722 return;
723 }
724
725 if (shift_key && keycode == 38) { // shift-up
726 catchupRelativeToArticle(0);
727 return;
728 }
729
730 if (shift_key && keycode == 78) { // N
731 scrollArticle(50);
732 return;
733 }
734
735 if (shift_key && keycode == 80) { // P
736 scrollArticle(-50);
737 return;
738 }
739
740 if (keycode == 68 && shift_key) { // shift-D
741 dismissSelectedArticles();
742 return;
743 }
744
745 if (keycode == 88 && shift_key) { // shift-X
746 dismissReadArticles();
747 return;
748 }
749
750 if (keycode == 78 || keycode == 40) { // n, down
751 if (typeof moveToPost != 'undefined') {
752 moveToPost('next');
753 return false;
754 }
755 }
756
757 if (keycode == 80 || keycode == 38) { // p, up
758 if (typeof moveToPost != 'undefined') {
759 moveToPost('prev');
760 return false;
761 }
762 }
763
764 if (keycode == 83 && shift_key) { // S
765 selectionTogglePublished(undefined, false, true);
766 return;
767 }
768
769 if (keycode == 83) { // s
770 selectionToggleMarked(undefined, false, true);
771 return;
772 }
773
774 if (keycode == 85) { // u
775 selectionToggleUnread(undefined, false, true)
776 return;
777 }
778
779 if (keycode == 84 && shift_key) { // T
780 var id = getActiveArticleId();
781 if (id) {
782 editArticleTags(id, getActiveFeedId(), isCdmMode());
783 return;
784 }
785 }
786
787 if (keycode == 9) { // tab
788 var id = getArticleUnderPointer();
789 if (id) {
790 var cb = $("RCHK-" + id);
791
792 if (cb) {
793 cb.checked = !cb.checked;
794 toggleSelectRowById(cb, "RROW-" + id);
795 return false;
796 }
797 }
798 }
799
800 if (keycode == 79) { // o
801 if (getActiveArticleId()) {
802 openArticleInNewWindow(getActiveArticleId());
803 return;
804 }
805 }
806
807 if (keycode == 81 && shift_key) { // Q
808 if (typeof catchupAllFeeds != 'undefined') {
809 catchupAllFeeds();
810 return;
811 }
812 }
813
814 if (keycode == 88 && !shift_key) { // x
815 if (activeFeedIsCat()) {
816 dijit.byId("feedTree").collapseCat(getActiveFeedId());
817 return;
818 }
819 }
820 }
821
822 /* Prefix a */
823
824 if (hotkey_prefix == 65) { // a
825 hotkey_prefix = false;
826
827 if (keycode == 65) { // a
828 selectArticles('all');
829 return;
830 }
831
832 if (keycode == 85) { // u
833 selectArticles('unread');
834 return;
835 }
836
837 if (keycode == 73) { // i
838 selectArticles('invert');
839 return;
840 }
841
842 if (keycode == 78) { // n
843 selectArticles('none');
844 return;
845 }
846
847 }
848
849 /* Prefix f */
850
851 if (hotkey_prefix == 70) { // f
852
853 hotkey_prefix = false;
854
855 if (keycode == 81) { // q
856 if (getActiveFeedId()) {
857 catchupCurrentFeed();
858 return;
859 }
860 }
861
862 if (keycode == 82) { // r
863 if (getActiveFeedId()) {
864 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
865 return;
866 }
867 }
868
869 if (keycode == 65) { // a
870 toggleDispRead();
871 return false;
872 }
873
874 if (keycode == 85) { // u
875 if (getActiveFeedId()) {
876 viewfeed(getActiveFeedId(), '');
877 return false;
878 }
879 }
880
881 if (keycode == 69) { // e
882
883 if (activeFeedIsCat())
884 alert(__("You can't edit this kind of feed."));
885 else
886 editFeed(getActiveFeedId());
887 return;
888
889 return false;
890 }
891
892 if (keycode == 83) { // s
893 quickAddFeed();
894 return false;
895 }
896
897 if (keycode == 67 && shift_key) { // C
898 if (typeof catchupAllFeeds != 'undefined') {
899 catchupAllFeeds();
900 return false;
901 }
902 }
903
904 if (keycode == 67) { // c
905 if (getActiveFeedId()) {
906 catchupCurrentFeed();
907 return false;
908 }
909 }
910
911 if (keycode == 87) { // w
912 feeds_sort_by_unread = !feeds_sort_by_unread;
913 return resort_feedlist();
914 }
915
916 if (keycode == 88) { // x
917 reverseHeadlineOrder();
918 return;
919 }
920 }
921
922 /* Prefix c */
923
924 if (hotkey_prefix == 67) { // c
925 hotkey_prefix = false;
926
927 if (keycode == 70) { // f
928 quickAddFilter();
929 return false;
930 }
931
932 if (keycode == 76) { // l
933 addLabel();
934 return false;
935 }
936
937 if (keycode == 83) { // s
938 if (typeof collapse_feedlist != 'undefined') {
939 collapse_feedlist();
940 return false;
941 }
942 }
943
944 if (keycode == 77) { // m
945 // TODO: sortable feedlist
946 return;
947 }
948
949 if (keycode == 78) { // n
950 catchupRelativeToArticle(1);
951 return;
952 }
953
954 if (keycode == 80) { // p
955 catchupRelativeToArticle(0);
956 return;
957 }
958
959
960 }
961
962 /* Prefix g */
963
964 if (hotkey_prefix == 71) { // g
965
966 hotkey_prefix = false;
967
968
969 if (keycode == 65) { // a
970 viewfeed(-4);
971 return false;
972 }
973
974 if (keycode == 83) { // s
975 viewfeed(-1);
976 return false;
977 }
978
979 if (keycode == 80 && shift_key) { // P
980 gotoPreferences();
981 return false;
982 }
983
984 if (keycode == 80) { // p
985 viewfeed(-2);
986 return false;
987 }
988
989 if (keycode == 70) { // f
990 viewfeed(-3);
991 return false;
992 }
993
994 if (keycode == 84) { // t
995 displayDlg("printTagCloud");
996 return false;
997 }
998 }
999
1000 /* Cmd */
1001
1002 if (hotkey_prefix == 224 || hotkey_prefix == 91) { // f
1003 hotkey_prefix = false;
1004 return;
1005 }
1006
1007 if (hotkey_prefix) {
1008 console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1009 } else {
1010 console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
1011 }
1012
1013
1014 } catch (e) {
1015 exception_error("hotkey_handler", e);
1016 }
1017 }
1018
1019 function inPreferences() {
1020 return false;
1021 }
1022
1023 function reverseHeadlineOrder() {
1024 try {
1025
1026 var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1027
1028 new Ajax.Request("backend.php", {
1029 parameters: query_str,
1030 onComplete: function(transport) {
1031 viewCurrentFeed();
1032 } });
1033
1034 } catch (e) {
1035 exception_error("reverseHeadlineOrder", e);
1036 }
1037 }
1038
1039 function scheduleFeedUpdate(id, is_cat) {
1040 try {
1041 if (!id) {
1042 id = getActiveFeedId();
1043 is_cat = activeFeedIsCat();
1044 }
1045
1046 if (!id) {
1047 alert(__("Please select some feed first."));
1048 return;
1049 }
1050
1051 var query = "?op=rpc&subop=scheduleFeedUpdate&id=" +
1052 param_escape(id) +
1053 "&is_cat=" + param_escape(is_cat);
1054
1055 console.log(query);
1056
1057 new Ajax.Request("backend.php", {
1058 parameters: query,
1059 onComplete: function(transport) {
1060 handle_rpc_json(transport);
1061
1062 var reply = JSON.parse(transport.responseText);
1063 var message = reply['message'];
1064
1065 if (message) {
1066 notify_info(message);
1067 return;
1068 }
1069
1070 } });
1071
1072
1073 } catch (e) {
1074 exception_error("scheduleFeedUpdate", e);
1075 }
1076 }
1077
1078 function newVersionDlg() {
1079 try {
1080 var query = "backend.php?op=dlg&id=newVersion";
1081
1082 if (dijit.byId("newVersionDlg"))
1083 dijit.byId("newVersionDlg").destroyRecursive();
1084
1085 dialog = new dijit.Dialog({
1086 id: "newVersionDlg",
1087 title: __("New version available!"),
1088 style: "width: 600px",
1089 href: query,
1090 });
1091
1092 dialog.show();
1093
1094 } catch (e) {
1095 exception_error("newVersionDlg", e);
1096 }
1097 }
1098
1099 function handle_rpc_json(transport, scheduled_call) {
1100 try {
1101 var reply = JSON.parse(transport.responseText);
1102
1103 if (reply) {
1104
1105 var error = reply['error'];
1106
1107 if (error) {
1108 var code = error['code'];
1109 var msg = error['msg'];
1110
1111 console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg);
1112
1113 if (code != 0) {
1114 fatalError(code, msg);
1115 return false;
1116 }
1117 }
1118
1119 var seq = reply['seq'];
1120
1121 if (seq) {
1122 if (get_seq() != seq) {
1123 console.log("[handle_rpc_json] sequence mismatch: " + seq +
1124 " (want: " + get_seq() + ")");
1125 return true;
1126 }
1127 }
1128
1129 var message = reply['message'];
1130
1131 if (message) {
1132 if (message == "UPDATE_COUNTERS") {
1133 console.log("need to refresh counters...");
1134 setInitParam("last_article_id", -1);
1135 _force_scheduled_update = true;
1136 }
1137 }
1138
1139 var counters = reply['counters'];
1140
1141 if (counters)
1142 parse_counters(counters, scheduled_call);
1143
1144 var runtime_info = reply['runtime-info'];;
1145
1146 if (runtime_info)
1147 parse_runtime_info(runtime_info);
1148
1149 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1150
1151 } else {
1152 notify_error("Error communicating with server.");
1153 }
1154
1155 } catch (e) {
1156 notify_error("Error communicating with server.");
1157 console.log(e);
1158 //exception_error("handle_rpc_json", e, transport);
1159 }
1160
1161 return true;
1162 }
1163