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