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