]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
viewfeed: fix typo
[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 // can't use cache_clear() here because viewfeed might not have initialized yet
334 if ('sessionStorage' in window && window['sessionStorage'] !== null)
335 sessionStorage.clear();
336
337 console.log("second stage ok");
338
339 } catch (e) {
340 exception_error("init_second_stage", e);
341 }
342 }
343
344 function quickMenuGo(opid) {
345 try {
346 if (opid == "qmcPrefs") {
347 gotoPreferences();
348 }
349
350 if (opid == "qmcTagCloud") {
351 displayDlg("printTagCloud");
352 }
353
354 if (opid == "qmcTagSelect") {
355 displayDlg("printTagSelect");
356 }
357
358 if (opid == "qmcSearch") {
359 search();
360 return;
361 }
362
363 if (opid == "qmcAddFeed") {
364 quickAddFeed();
365 return;
366 }
367
368 if (opid == "qmcDigest") {
369 window.location.href = "digest.php";
370 return;
371 }
372
373 if (opid == "qmcEditFeed") {
374 if (activeFeedIsCat())
375 alert(__("You can't edit this kind of feed."));
376 else
377 editFeed(getActiveFeedId());
378 return;
379 }
380
381 if (opid == "qmcRemoveFeed") {
382 var actid = getActiveFeedId();
383
384 if (activeFeedIsCat()) {
385 alert(__("You can't unsubscribe from the category."));
386 return;
387 }
388
389 if (!actid) {
390 alert(__("Please select some feed first."));
391 return;
392 }
393
394 var fn = getFeedName(actid);
395
396 var pr = __("Unsubscribe from %s?").replace("%s", fn);
397
398 if (confirm(pr)) {
399 unsubscribeFeed(actid);
400 }
401
402 return;
403 }
404
405 if (opid == "qmcCatchupAll") {
406 catchupAllFeeds();
407 return;
408 }
409
410 if (opid == "qmcShowOnlyUnread") {
411 toggleDispRead();
412 return;
413 }
414
415 if (opid == "qmcAddFilter") {
416 quickAddFilter();
417 return;
418 }
419
420 if (opid == "qmcAddLabel") {
421 addLabel();
422 return;
423 }
424
425 if (opid == "qmcRescoreFeed") {
426 rescoreCurrentFeed();
427 return;
428 }
429
430 if (opid == "qmcHKhelp") {
431 //Element.show("hotkey_help_overlay");
432 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
433 }
434
435 if (opid == "qmcAbout") {
436 dialog = new dijit.Dialog({
437 title: __("About..."),
438 style: "width: 400px",
439 href: "backend.php?op=dlg&id=about",
440 });
441
442 dialog.show();
443 }
444
445 } catch (e) {
446 exception_error("quickMenuGo", e);
447 }
448 }
449
450 function toggleDispRead() {
451 try {
452
453 var hide = !(getInitParam("hide_read_feeds") == "1");
454
455 hideOrShowFeeds(hide);
456
457 var query = "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
458 param_escape(hide);
459
460 setInitParam("hide_read_feeds", hide);
461
462 new Ajax.Request("backend.php", {
463 parameters: query,
464 onComplete: function(transport) {
465 } });
466
467 } catch (e) {
468 exception_error("toggleDispRead", e);
469 }
470 }
471
472 function parse_runtime_info(data) {
473
474 //console.log("parsing runtime info...");
475
476 for (k in data) {
477 var v = data[k];
478
479 // console.log("RI: " + k + " => " + v);
480
481 if (k == "new_version_available") {
482 var icon = $("newVersionIcon");
483 if (icon) {
484 if (v == "1") {
485 icon.style.display = "inline";
486 } else {
487 icon.style.display = "none";
488 }
489 }
490 return;
491 }
492
493 var error_flag;
494
495 if (k == "daemon_is_running" && v != 1) {
496 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
497 return;
498 }
499
500 if (k == "daemon_stamp_ok" && v != 1) {
501 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
502 return;
503 }
504
505 if (k == "max_feed_id" || k == "num_feeds") {
506 if (init_params[k] != v) {
507 console.log("feed count changed, need to reload feedlist.");
508 updateFeedList();
509 }
510 }
511
512 init_params[k] = v;
513 notify('');
514 }
515 }
516
517 function catchupCurrentFeed() {
518
519 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
520
521 var str = __("Mark all articles in %s as read?").replace("%s", fn);
522
523 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
524 return viewCurrentFeed('MarkAllRead')
525 }
526 }
527
528 function catchupFeedInGroup(id) {
529
530 try {
531
532 var title = getFeedName(id);
533
534 var str = __("Mark all articles in %s as read?").replace("%s", title);
535
536 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
537 return viewCurrentFeed('MarkAllReadGR:' + id)
538 }
539
540 } catch (e) {
541 exception_error("catchupFeedInGroup", e);
542 }
543 }
544
545 function collapse_feedlist() {
546 try {
547
548 if (!Element.visible('feeds-holder')) {
549 Element.show('feeds-holder');
550 Element.show('feeds-holder_splitter');
551 $("collapse_feeds_btn").innerHTML = "&lt;&lt;";
552 } else {
553 Element.hide('feeds-holder');
554 Element.hide('feeds-holder_splitter');
555 $("collapse_feeds_btn").innerHTML = "&gt;&gt;";
556 }
557
558 dijit.byId("main").resize();
559
560 query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
561 new Ajax.Request("backend.php", { parameters: query });
562
563 } catch (e) {
564 exception_error("collapse_feedlist", e);
565 }
566 }
567
568 function viewModeChanged() {
569 return viewCurrentFeed('')
570 }
571
572 function viewLimitChanged() {
573 return viewCurrentFeed('')
574 }
575
576 /* function adjustArticleScore(id, score) {
577 try {
578
579 var pr = prompt(__("Assign score to article:"), score);
580
581 if (pr != undefined) {
582 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
583
584 new Ajax.Request("backend.php", {
585 parameters: query,
586 onComplete: function(transport) {
587 viewCurrentFeed();
588 } });
589
590 }
591 } catch (e) {
592 exception_error("adjustArticleScore", e);
593 }
594 } */
595
596 function rescoreCurrentFeed() {
597
598 var actid = getActiveFeedId();
599
600 if (activeFeedIsCat() || actid < 0) {
601 alert(__("You can't rescore this kind of feed."));
602 return;
603 }
604
605 if (!actid) {
606 alert(__("Please select some feed first."));
607 return;
608 }
609
610 var fn = getFeedName(actid);
611 var pr = __("Rescore articles in %s?").replace("%s", fn);
612
613 if (confirm(pr)) {
614 notify_progress("Rescoring articles...");
615
616 var query = "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid;
617
618 new Ajax.Request("backend.php", {
619 parameters: query,
620 onComplete: function(transport) {
621 viewCurrentFeed();
622 } });
623 }
624 }
625
626 function hotkey_handler(e) {
627 try {
628
629 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
630
631 var keycode;
632 var shift_key = false;
633
634 var cmdline = $('cmdline');
635
636 try {
637 shift_key = e.shiftKey;
638 } catch (e) {
639
640 }
641
642 if (window.event) {
643 keycode = window.event.keyCode;
644 } else if (e) {
645 keycode = e.which;
646 }
647
648 var keychar = String.fromCharCode(keycode);
649
650 if (keycode == 27) { // escape
651 if (Element.visible("hotkey_help_overlay")) {
652 Element.hide("hotkey_help_overlay");
653 }
654 hotkey_prefix = false;
655 }
656
657 if (keycode == 16) return; // ignore lone shift
658 if (keycode == 17) return; // ignore lone ctrl
659
660 if ((keycode == 70 || keycode == 67 || keycode == 71 || keycode == 65)
661 && !hotkey_prefix) {
662
663 var date = new Date();
664 var ts = Math.round(date.getTime() / 1000);
665
666 hotkey_prefix = keycode;
667 hotkey_prefix_pressed = ts;
668
669 cmdline.innerHTML = keychar;
670 Element.show(cmdline);
671
672 console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
673 return true;
674 }
675
676 if (Element.visible("hotkey_help_overlay")) {
677 Element.hide("hotkey_help_overlay");
678 }
679
680 /* Global hotkeys */
681
682 Element.hide(cmdline);
683
684 if (!hotkey_prefix) {
685
686 if (keycode == 69) { // e
687 var id = getActiveArticleId();
688 emailArticle(id);
689 }
690
691 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
692 if (!Element.visible("hotkey_help_overlay")) {
693 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
694 } else {
695 Element.hide("hotkey_help_overlay");
696 }
697 return false;
698 }
699
700 if (keycode == 191 || keychar == '/') { // /
701 search();
702 return false;
703 }
704
705 if (keycode == 74) { // j
706 var rv = dijit.byId("feedTree").getPreviousFeed(
707 getActiveFeedId(), activeFeedIsCat());
708
709 if (rv) viewfeed(rv[0], '', rv[1]);
710
711 return;
712 }
713
714 if (keycode == 75) { // k
715 var rv = dijit.byId("feedTree").getNextFeed(
716 getActiveFeedId(), activeFeedIsCat());
717
718 if (rv) viewfeed(rv[0], '', rv[1]);
719
720 return;
721 }
722
723 if (shift_key && keycode == 40) { // shift-down
724 catchupRelativeToArticle(1);
725 return;
726 }
727
728 if (shift_key && keycode == 38) { // shift-up
729 catchupRelativeToArticle(0);
730 return;
731 }
732
733 if (shift_key && keycode == 78) { // N
734 scrollArticle(50);
735 return;
736 }
737
738 if (shift_key && keycode == 80) { // P
739 scrollArticle(-50);
740 return;
741 }
742
743 if (keycode == 68 && shift_key) { // shift-D
744 dismissSelectedArticles();
745 return;
746 }
747
748 if (keycode == 88 && shift_key) { // shift-X
749 dismissReadArticles();
750 return;
751 }
752
753 if (keycode == 78 || keycode == 40) { // n, down
754 if (typeof moveToPost != 'undefined') {
755 moveToPost('next');
756 return false;
757 }
758 }
759
760 if (keycode == 80 || keycode == 38) { // p, up
761 if (typeof moveToPost != 'undefined') {
762 moveToPost('prev');
763 return false;
764 }
765 }
766
767 if (keycode == 83 && shift_key) { // S
768 selectionTogglePublished(undefined, false, true);
769 return;
770 }
771
772 if (keycode == 83) { // s
773 selectionToggleMarked(undefined, false, true);
774 return;
775 }
776
777 if (keycode == 85) { // u
778 selectionToggleUnread(undefined, false, true)
779 return;
780 }
781
782 if (keycode == 84 && shift_key) { // T
783 var id = getActiveArticleId();
784 if (id) {
785 editArticleTags(id, getActiveFeedId(), isCdmMode());
786 return;
787 }
788 }
789
790 if (keycode == 9) { // tab
791 var id = getArticleUnderPointer();
792 if (id) {
793 var cb = $("RCHK-" + id);
794
795 if (cb) {
796 cb.checked = !cb.checked;
797 toggleSelectRowById(cb, "RROW-" + id);
798 return false;
799 }
800 }
801 }
802
803 if (keycode == 79) { // o
804 if (getActiveArticleId()) {
805 openArticleInNewWindow(getActiveArticleId());
806 return;
807 }
808 }
809
810 if (keycode == 81 && shift_key) { // Q
811 if (typeof catchupAllFeeds != 'undefined') {
812 catchupAllFeeds();
813 return;
814 }
815 }
816
817 if (keycode == 88 && !shift_key) { // x
818 if (activeFeedIsCat()) {
819 dijit.byId("feedTree").collapseCat(getActiveFeedId());
820 return;
821 }
822 }
823 }
824
825 /* Prefix a */
826
827 if (hotkey_prefix == 65) { // a
828 hotkey_prefix = false;
829
830 if (keycode == 65) { // a
831 selectArticles('all');
832 return;
833 }
834
835 if (keycode == 85) { // u
836 selectArticles('unread');
837 return;
838 }
839
840 if (keycode == 73) { // i
841 selectArticles('invert');
842 return;
843 }
844
845 if (keycode == 78) { // n
846 selectArticles('none');
847 return;
848 }
849
850 }
851
852 /* Prefix f */
853
854 if (hotkey_prefix == 70) { // f
855
856 hotkey_prefix = false;
857
858 if (keycode == 81) { // q
859 if (getActiveFeedId()) {
860 catchupCurrentFeed();
861 return;
862 }
863 }
864
865 if (keycode == 82) { // r
866 if (getActiveFeedId()) {
867 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
868 return;
869 }
870 }
871
872 if (keycode == 65) { // a
873 toggleDispRead();
874 return false;
875 }
876
877 if (keycode == 85) { // u
878 if (getActiveFeedId()) {
879 viewfeed(getActiveFeedId(), '');
880 return false;
881 }
882 }
883
884 if (keycode == 69) { // e
885
886 if (activeFeedIsCat())
887 alert(__("You can't edit this kind of feed."));
888 else
889 editFeed(getActiveFeedId());
890 return;
891
892 return false;
893 }
894
895 if (keycode == 83) { // s
896 quickAddFeed();
897 return false;
898 }
899
900 if (keycode == 67 && shift_key) { // C
901 if (typeof catchupAllFeeds != 'undefined') {
902 catchupAllFeeds();
903 return false;
904 }
905 }
906
907 if (keycode == 67) { // c
908 if (getActiveFeedId()) {
909 catchupCurrentFeed();
910 return false;
911 }
912 }
913
914 if (keycode == 87) { // w
915 feeds_sort_by_unread = !feeds_sort_by_unread;
916 return resort_feedlist();
917 }
918
919 if (keycode == 88) { // x
920 reverseHeadlineOrder();
921 return;
922 }
923 }
924
925 /* Prefix c */
926
927 if (hotkey_prefix == 67) { // c
928 hotkey_prefix = false;
929
930 if (keycode == 70) { // f
931 quickAddFilter();
932 return false;
933 }
934
935 if (keycode == 76) { // l
936 addLabel();
937 return false;
938 }
939
940 if (keycode == 83) { // s
941 if (typeof collapse_feedlist != 'undefined') {
942 collapse_feedlist();
943 return false;
944 }
945 }
946
947 if (keycode == 77) { // m
948 // TODO: sortable feedlist
949 return;
950 }
951
952 if (keycode == 78) { // n
953 catchupRelativeToArticle(1);
954 return;
955 }
956
957 if (keycode == 80) { // p
958 catchupRelativeToArticle(0);
959 return;
960 }
961
962
963 }
964
965 /* Prefix g */
966
967 if (hotkey_prefix == 71) { // g
968
969 hotkey_prefix = false;
970
971
972 if (keycode == 65) { // a
973 viewfeed(-4);
974 return false;
975 }
976
977 if (keycode == 83) { // s
978 viewfeed(-1);
979 return false;
980 }
981
982 if (keycode == 80 && shift_key) { // P
983 gotoPreferences();
984 return false;
985 }
986
987 if (keycode == 80) { // p
988 viewfeed(-2);
989 return false;
990 }
991
992 if (keycode == 70) { // f
993 viewfeed(-3);
994 return false;
995 }
996
997 if (keycode == 84) { // t
998 displayDlg("printTagCloud");
999 return false;
1000 }
1001 }
1002
1003 /* Cmd */
1004
1005 if (hotkey_prefix == 224 || hotkey_prefix == 91) { // f
1006 hotkey_prefix = false;
1007 return;
1008 }
1009
1010 if (hotkey_prefix) {
1011 console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1012 } else {
1013 console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
1014 }
1015
1016
1017 } catch (e) {
1018 exception_error("hotkey_handler", e);
1019 }
1020 }
1021
1022 function inPreferences() {
1023 return false;
1024 }
1025
1026 function reverseHeadlineOrder() {
1027 try {
1028
1029 var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1030
1031 new Ajax.Request("backend.php", {
1032 parameters: query_str,
1033 onComplete: function(transport) {
1034 viewCurrentFeed();
1035 } });
1036
1037 } catch (e) {
1038 exception_error("reverseHeadlineOrder", e);
1039 }
1040 }
1041
1042 function scheduleFeedUpdate(id, is_cat) {
1043 try {
1044 if (!id) {
1045 id = getActiveFeedId();
1046 is_cat = activeFeedIsCat();
1047 }
1048
1049 if (!id) {
1050 alert(__("Please select some feed first."));
1051 return;
1052 }
1053
1054 var query = "?op=rpc&subop=scheduleFeedUpdate&id=" +
1055 param_escape(id) +
1056 "&is_cat=" + param_escape(is_cat);
1057
1058 console.log(query);
1059
1060 new Ajax.Request("backend.php", {
1061 parameters: query,
1062 onComplete: function(transport) {
1063 handle_rpc_json(transport);
1064
1065 var reply = JSON.parse(transport.responseText);
1066 var message = reply['message'];
1067
1068 if (message) {
1069 notify_info(message);
1070 return;
1071 }
1072
1073 } });
1074
1075
1076 } catch (e) {
1077 exception_error("scheduleFeedUpdate", e);
1078 }
1079 }
1080
1081 function newVersionDlg() {
1082 try {
1083 var query = "backend.php?op=dlg&id=newVersion";
1084
1085 if (dijit.byId("newVersionDlg"))
1086 dijit.byId("newVersionDlg").destroyRecursive();
1087
1088 dialog = new dijit.Dialog({
1089 id: "newVersionDlg",
1090 title: __("New version available!"),
1091 style: "width: 600px",
1092 href: query,
1093 });
1094
1095 dialog.show();
1096
1097 } catch (e) {
1098 exception_error("newVersionDlg", e);
1099 }
1100 }
1101
1102 function handle_rpc_json(transport, scheduled_call) {
1103 try {
1104 var reply = JSON.parse(transport.responseText);
1105
1106 if (reply) {
1107
1108 var error = reply['error'];
1109
1110 if (error) {
1111 var code = error['code'];
1112 var msg = error['msg'];
1113
1114 console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg);
1115
1116 if (code != 0) {
1117 fatalError(code, msg);
1118 return false;
1119 }
1120 }
1121
1122 var seq = reply['seq'];
1123
1124 if (seq) {
1125 if (get_seq() != seq) {
1126 console.log("[handle_rpc_json] sequence mismatch: " + seq +
1127 " (want: " + get_seq() + ")");
1128 return true;
1129 }
1130 }
1131
1132 var message = reply['message'];
1133
1134 if (message) {
1135 if (message == "UPDATE_COUNTERS") {
1136 console.log("need to refresh counters...");
1137 setInitParam("last_article_id", -1);
1138 _force_scheduled_update = true;
1139 }
1140 }
1141
1142 var counters = reply['counters'];
1143
1144 if (counters)
1145 parse_counters(counters, scheduled_call);
1146
1147 var runtime_info = reply['runtime-info'];;
1148
1149 if (runtime_info)
1150 parse_runtime_info(runtime_info);
1151
1152 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1153
1154 } else {
1155 notify_error("Error communicating with server.");
1156 }
1157
1158 } catch (e) {
1159 notify_error("Error communicating with server.");
1160 console.log(e);
1161 //exception_error("handle_rpc_json", e, transport);
1162 }
1163
1164 return true;
1165 }
1166