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