]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
a64bed37412a9cb6c10722a065caad9805eb855f
[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 == 27) { // escape
687 closeArticlePanel();
688 return;
689 }
690
691 if (keycode == 69) { // e
692 var id = getActiveArticleId();
693 emailArticle(id);
694 }
695
696 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
697 if (!Element.visible("hotkey_help_overlay")) {
698 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
699 } else {
700 Element.hide("hotkey_help_overlay");
701 }
702 return false;
703 }
704
705 if (keycode == 191 || keychar == '/') { // /
706 search();
707 return false;
708 }
709
710 if (keycode == 74 && !shift_key) { // j
711 var rv = dijit.byId("feedTree").getPreviousFeed(
712 getActiveFeedId(), activeFeedIsCat());
713
714 if (rv) viewfeed(rv[0], '', rv[1]);
715
716 return;
717 }
718
719 if (keycode == 75) { // k
720 var rv = dijit.byId("feedTree").getNextFeed(
721 getActiveFeedId(), activeFeedIsCat());
722
723 if (rv) viewfeed(rv[0], '', rv[1]);
724
725 return;
726 }
727
728 if (shift_key && keycode == 40) { // shift-down
729 catchupRelativeToArticle(1);
730 return;
731 }
732
733 if (shift_key && keycode == 38) { // shift-up
734 catchupRelativeToArticle(0);
735 return;
736 }
737
738 if (shift_key && keycode == 78) { // N
739 scrollArticle(50);
740 return;
741 }
742
743 if (shift_key && keycode == 80) { // P
744 scrollArticle(-50);
745 return;
746 }
747
748 if (keycode == 68 && shift_key) { // shift-D
749 dismissSelectedArticles();
750 return;
751 }
752
753 if (keycode == 88 && shift_key) { // shift-X
754 dismissReadArticles();
755 return;
756 }
757
758 if (keycode == 78 || keycode == 40) { // n, down
759 if (typeof moveToPost != 'undefined') {
760 moveToPost('next');
761 return false;
762 }
763 }
764
765 if (keycode == 80 || keycode == 38) { // p, up
766 if (typeof moveToPost != 'undefined') {
767 moveToPost('prev');
768 return false;
769 }
770 }
771
772 if (keycode == 83 && shift_key) { // S
773 selectionTogglePublished(undefined, false, true);
774 return;
775 }
776
777 if (keycode == 83) { // s
778 selectionToggleMarked(undefined, false, true);
779 return;
780 }
781
782 if (keycode == 85) { // u
783 selectionToggleUnread(undefined, false, true)
784 return;
785 }
786
787 if (keycode == 84 && shift_key) { // T
788 var id = getActiveArticleId();
789 if (id) {
790 editArticleTags(id, getActiveFeedId(), isCdmMode());
791 return;
792 }
793 }
794
795 if (keycode == 9) { // tab
796 var id = getArticleUnderPointer();
797 if (id) {
798 var cb = $("RCHK-" + id);
799
800 if (cb) {
801 cb.checked = !cb.checked;
802 toggleSelectRowById(cb, "RROW-" + id);
803 return false;
804 }
805 }
806 }
807
808 if (keycode == 79) { // o
809 if (getActiveArticleId()) {
810 openArticleInNewWindow(getActiveArticleId());
811 return;
812 }
813 }
814
815 if (keycode == 81 && shift_key) { // Q
816 if (typeof catchupAllFeeds != 'undefined') {
817 catchupAllFeeds();
818 return;
819 }
820 }
821
822 if (keycode == 88 && !shift_key) { // x
823 if (activeFeedIsCat()) {
824 dijit.byId("feedTree").collapseCat(getActiveFeedId());
825 return;
826 }
827 }
828 }
829
830 /* Prefix a */
831
832 if (hotkey_prefix == 65) { // a
833 hotkey_prefix = false;
834
835 if (keycode == 65) { // a
836 selectArticles('all');
837 return;
838 }
839
840 if (keycode == 85) { // u
841 selectArticles('unread');
842 return;
843 }
844
845 if (keycode == 73) { // i
846 selectArticles('invert');
847 return;
848 }
849
850 if (keycode == 78) { // n
851 selectArticles('none');
852 return;
853 }
854
855 }
856
857 /* Prefix f */
858
859 if (hotkey_prefix == 70) { // f
860
861 hotkey_prefix = false;
862
863 if (keycode == 81) { // q
864 if (getActiveFeedId()) {
865 catchupCurrentFeed();
866 return;
867 }
868 }
869
870 if (keycode == 82) { // r
871 if (getActiveFeedId()) {
872 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
873 return;
874 }
875 }
876
877 if (keycode == 65) { // a
878 toggleDispRead();
879 return false;
880 }
881
882 if (keycode == 85) { // u
883 if (getActiveFeedId()) {
884 viewfeed(getActiveFeedId(), '');
885 return false;
886 }
887 }
888
889 if (keycode == 69) { // e
890
891 if (activeFeedIsCat())
892 alert(__("You can't edit this kind of feed."));
893 else
894 editFeed(getActiveFeedId());
895 return;
896
897 return false;
898 }
899
900 if (keycode == 83) { // s
901 quickAddFeed();
902 return false;
903 }
904
905 if (keycode == 67 && shift_key) { // C
906 if (typeof catchupAllFeeds != 'undefined') {
907 catchupAllFeeds();
908 return false;
909 }
910 }
911
912 if (keycode == 67) { // c
913 if (getActiveFeedId()) {
914 catchupCurrentFeed();
915 return false;
916 }
917 }
918
919 if (keycode == 87) { // w
920 feeds_sort_by_unread = !feeds_sort_by_unread;
921 return resort_feedlist();
922 }
923
924 if (keycode == 88) { // x
925 reverseHeadlineOrder();
926 return;
927 }
928 }
929
930 /* Prefix c */
931
932 if (hotkey_prefix == 67) { // c
933 hotkey_prefix = false;
934
935 if (keycode == 70) { // f
936 quickAddFilter();
937 return false;
938 }
939
940 if (keycode == 76) { // l
941 addLabel();
942 return false;
943 }
944
945 if (keycode == 83) { // s
946 if (typeof collapse_feedlist != 'undefined') {
947 collapse_feedlist();
948 return false;
949 }
950 }
951
952 if (keycode == 77) { // m
953 // TODO: sortable feedlist
954 return;
955 }
956
957 if (keycode == 78) { // n
958 catchupRelativeToArticle(1);
959 return;
960 }
961
962 if (keycode == 80) { // p
963 catchupRelativeToArticle(0);
964 return;
965 }
966
967
968 }
969
970 /* Prefix g */
971
972 if (hotkey_prefix == 71) { // g
973
974 hotkey_prefix = false;
975
976
977 if (keycode == 65) { // a
978 viewfeed(-4);
979 return false;
980 }
981
982 if (keycode == 83) { // s
983 viewfeed(-1);
984 return false;
985 }
986
987 if (keycode == 80 && shift_key) { // P
988 gotoPreferences();
989 return false;
990 }
991
992 if (keycode == 80) { // p
993 viewfeed(-2);
994 return false;
995 }
996
997 if (keycode == 70) { // f
998 viewfeed(-3);
999 return false;
1000 }
1001
1002 if (keycode == 84) { // t
1003 displayDlg("printTagCloud");
1004 return false;
1005 }
1006 }
1007
1008 /* Cmd */
1009
1010 if (hotkey_prefix == 224 || hotkey_prefix == 91) { // f
1011 hotkey_prefix = false;
1012 return;
1013 }
1014
1015 if (hotkey_prefix) {
1016 console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1017 } else {
1018 console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
1019 }
1020
1021
1022 } catch (e) {
1023 exception_error("hotkey_handler", e);
1024 }
1025 }
1026
1027 function inPreferences() {
1028 return false;
1029 }
1030
1031 function reverseHeadlineOrder() {
1032 try {
1033
1034 var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1035
1036 new Ajax.Request("backend.php", {
1037 parameters: query_str,
1038 onComplete: function(transport) {
1039 viewCurrentFeed();
1040 } });
1041
1042 } catch (e) {
1043 exception_error("reverseHeadlineOrder", e);
1044 }
1045 }
1046
1047 function scheduleFeedUpdate(id, is_cat) {
1048 try {
1049 if (!id) {
1050 id = getActiveFeedId();
1051 is_cat = activeFeedIsCat();
1052 }
1053
1054 if (!id) {
1055 alert(__("Please select some feed first."));
1056 return;
1057 }
1058
1059 var query = "?op=rpc&subop=scheduleFeedUpdate&id=" +
1060 param_escape(id) +
1061 "&is_cat=" + param_escape(is_cat);
1062
1063 console.log(query);
1064
1065 new Ajax.Request("backend.php", {
1066 parameters: query,
1067 onComplete: function(transport) {
1068 handle_rpc_json(transport);
1069
1070 var reply = JSON.parse(transport.responseText);
1071 var message = reply['message'];
1072
1073 if (message) {
1074 notify_info(message);
1075 return;
1076 }
1077
1078 } });
1079
1080
1081 } catch (e) {
1082 exception_error("scheduleFeedUpdate", e);
1083 }
1084 }
1085
1086 function newVersionDlg() {
1087 try {
1088 var query = "backend.php?op=dlg&id=newVersion";
1089
1090 if (dijit.byId("newVersionDlg"))
1091 dijit.byId("newVersionDlg").destroyRecursive();
1092
1093 dialog = new dijit.Dialog({
1094 id: "newVersionDlg",
1095 title: __("New version available!"),
1096 style: "width: 600px",
1097 href: query,
1098 });
1099
1100 dialog.show();
1101
1102 } catch (e) {
1103 exception_error("newVersionDlg", e);
1104 }
1105 }
1106
1107 function handle_rpc_json(transport, scheduled_call) {
1108 try {
1109 var reply = JSON.parse(transport.responseText);
1110
1111 if (reply) {
1112
1113 var error = reply['error'];
1114
1115 if (error) {
1116 var code = error['code'];
1117 var msg = error['msg'];
1118
1119 console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg);
1120
1121 if (code != 0) {
1122 fatalError(code, msg);
1123 return false;
1124 }
1125 }
1126
1127 var seq = reply['seq'];
1128
1129 if (seq) {
1130 if (get_seq() != seq) {
1131 console.log("[handle_rpc_json] sequence mismatch: " + seq +
1132 " (want: " + get_seq() + ")");
1133 return true;
1134 }
1135 }
1136
1137 var message = reply['message'];
1138
1139 if (message) {
1140 if (message == "UPDATE_COUNTERS") {
1141 console.log("need to refresh counters...");
1142 setInitParam("last_article_id", -1);
1143 _force_scheduled_update = true;
1144 }
1145 }
1146
1147 var counters = reply['counters'];
1148
1149 if (counters)
1150 parse_counters(counters, scheduled_call);
1151
1152 var runtime_info = reply['runtime-info'];;
1153
1154 if (runtime_info)
1155 parse_runtime_info(runtime_info);
1156
1157 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1158
1159 } else {
1160 notify_error("Error communicating with server.");
1161 }
1162
1163 } catch (e) {
1164 notify_error("Error communicating with server.");
1165 console.log(e);
1166 //exception_error("handle_rpc_json", e, transport);
1167 }
1168
1169 return true;
1170 }
1171