]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
f408197d2a478e827db5b1261e4712cdb32fc8ce
[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 number_of_feeds = 0;
7 var hotkey_prefix = false;
8 var hotkey_prefix_pressed = false;
9 var init_params = {};
10 var _force_scheduled_update = false;
11 var last_scheduled_update = false;
12 var treeModel;
13
14 var _rpc_seq = 0;
15
16 function next_seq() {
17 _rpc_seq += 1;
18 return _rpc_seq;
19 }
20
21 function get_seq() {
22 return _rpc_seq;
23 }
24
25 function activeFeedIsCat() {
26 return _active_feed_is_cat;
27 }
28
29 function getActiveFeedId() {
30 try {
31 //console.log("gAFID: " + _active_feed_id);
32 return _active_feed_id;
33 } catch (e) {
34 exception_error("getActiveFeedId", e);
35 }
36 }
37
38 function setActiveFeedId(id, is_cat) {
39 try {
40 _active_feed_id = id;
41
42 if (is_cat != undefined) {
43 _active_feed_is_cat = is_cat;
44 }
45
46 selectFeed(id, is_cat);
47
48 } catch (e) {
49 exception_error("setActiveFeedId", e);
50 }
51 }
52
53
54 function dlg_frefresh_callback(transport, deleted_feed) {
55 if (getActiveFeedId() == deleted_feed) {
56 setTimeout("viewfeed(-5)", 100);
57 }
58
59 setTimeout('updateFeedList()', 50);
60 closeInfoBox();
61 }
62
63 function updateFeedList() {
64 try {
65
66 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
67 // __("Loading, please wait...") + "</div>";
68
69 Element.show("feedlistLoading");
70
71 if (dijit.byId("feedTree")) {
72 dijit.byId("feedTree").destroyRecursive();
73 }
74
75 var store = new dojo.data.ItemFileWriteStore({
76 url: "backend.php?op=feeds"});
77
78 treeModel = new dijit.tree.ForestStoreModel({
79 store: store,
80 query: {
81 "type": "feed"
82 },
83 rootId: "root",
84 rootLabel: "Feeds",
85 childrenAttrs: ["items"]
86 });
87
88 var tree = new dijit.Tree({
89 model: treeModel,
90 _createTreeNode: function(args) {
91 var tnode = new dijit._TreeNode(args);
92
93 if (args.item.icon)
94 tnode.iconNode.src = args.item.icon[0];
95
96 //tnode.labelNode.innerHTML = args.label;
97 return tnode;
98 },
99 getIconClass: function (item, opened) {
100 return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon";
101 },
102 getLabelClass: function (item, opened) {
103 return (item.unread == 0) ? "dijitTreeLabel" : "dijitTreeLabel Unread";
104 },
105 getRowClass: function (item, opened) {
106 return (!item.error || item.error == '') ? "dijitTreeRow" :
107 "dijitTreeRow Error";
108 },
109 getLabel: function(item) {
110 if (item.unread > 0) {
111 return item.name + " (" + item.unread + ")";
112 } else {
113 return item.name;
114 }
115 },
116 onOpen: function (item, node) {
117 var id = String(item.id);
118 var cat_id = id.substr(id.indexOf(":")+1);
119
120 new Ajax.Request("backend.php",
121 { parameters: "backend.php?op=feeds&subop=collapse&cid=" +
122 param_escape(cat_id) + "&mode=1" } );
123 },
124 onClose: function (item, node) {
125 var id = String(item.id);
126 var cat_id = id.substr(id.indexOf(":")+1);
127
128 new Ajax.Request("backend.php",
129 { parameters: "backend.php?op=feeds&subop=collapse&cid=" +
130 param_escape(cat_id) + "&mode=0" } );
131
132 },
133 onClick: function (item, node) {
134 var id = String(item.id);
135 var is_cat = id.match("^CAT:");
136 var feed = id.substr(id.indexOf(":")+1);
137 viewfeed(feed, '', is_cat);
138 return false;
139 },
140 openOnClick: false,
141 showRoot: false,
142 id: "feedTree",
143 }, "feedTree");
144
145 $("feeds-holder").appendChild(tree.domNode);
146
147 var tmph = dojo.connect(tree, 'onLoad', function() {
148 dojo.disconnect(tmph);
149 Element.hide("feedlistLoading");
150 });
151
152 tree.startup();
153
154 } catch (e) {
155 exception_error("updateFeedList", e);
156 }
157 }
158
159 function catchupAllFeeds() {
160
161 var str = __("Mark all articles as read?");
162
163 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
164
165 var query_str = "backend.php?op=feeds&subop=catchupAll";
166
167 notify_progress("Marking all feeds as read...");
168
169 //console.log("catchupAllFeeds Q=" + query_str);
170
171 new Ajax.Request("backend.php", {
172 parameters: query_str,
173 onComplete: function(transport) {
174 feedlist_callback2(transport);
175 } });
176
177 global_unread = 0;
178 updateTitle("");
179 }
180 }
181
182 function viewCurrentFeed(subop) {
183
184 if (getActiveFeedId() != undefined) {
185 viewfeed(getActiveFeedId(), subop, activeFeedIsCat());
186 }
187 return false; // block unneeded form submits
188 }
189
190 function timeout() {
191 if (getInitParam("bw_limit") == "1") return;
192
193 try {
194 var date = new Date();
195 var ts = Math.round(date.getTime() / 1000);
196
197 if (ts - last_scheduled_update > 10 || _force_scheduled_update) {
198
199 //console.log("timeout()");
200
201 window.clearTimeout(counter_timeout_id);
202
203 var query_str = "?op=rpc&subop=getAllCounters&seq=" + next_seq();
204
205 var omode;
206
207 if (firsttime_update && !navigator.userAgent.match("Opera")) {
208 firsttime_update = false;
209 omode = "T";
210 } else {
211 omode = "flc";
212 }
213
214 query_str = query_str + "&omode=" + omode;
215
216 if (!_force_scheduled_update)
217 query_str = query_str + "&last_article_id=" + getInitParam("last_article_id");
218
219 //console.log("[timeout]" + query_str);
220
221 new Ajax.Request("backend.php", {
222 parameters: query_str,
223 onComplete: function(transport) {
224 handle_rpc_reply(transport, !_force_scheduled_update);
225 _force_scheduled_update = false;
226 } });
227
228 last_scheduled_update = ts;
229 }
230
231 } catch (e) {
232 exception_error("timeout", e);
233 }
234
235 setTimeout("timeout()", 3000);
236 }
237
238 function search() {
239 closeInfoBox();
240 viewCurrentFeed();
241 }
242
243 function updateTitle() {
244 var tmp = "Tiny Tiny RSS";
245
246 if (global_unread > 0) {
247 tmp = tmp + " (" + global_unread + ")";
248 }
249
250 if (window.fluid) {
251 if (global_unread > 0) {
252 window.fluid.dockBadge = global_unread;
253 } else {
254 window.fluid.dockBadge = "";
255 }
256 }
257
258 document.title = tmp;
259 }
260
261 function genericSanityCheck() {
262 setCookie("ttrss_test", "TEST");
263
264 if (getCookie("ttrss_test") != "TEST") {
265 fatalError(2);
266 }
267
268 return true;
269 }
270
271 function init() {
272 try {
273 Form.disable("main_toolbar_form");
274
275 dojo.require("dijit.layout.BorderContainer");
276 dojo.require("dijit.layout.TabContainer");
277 dojo.require("dijit.layout.ContentPane");
278 dojo.require("dijit.Dialog");
279 dojo.require("dijit.form.Button");
280 dojo.require("dojo.data.ItemFileWriteStore");
281 dojo.require("dijit.Tree");
282 dojo.require("dijit.form.Select");
283 dojo.require("dojo.parser");
284
285 if (typeof themeBeforeLayout == 'function') {
286 themeBeforeLayout();
287 }
288
289 dojo.addOnLoad(function() {
290 updateFeedList();
291 closeArticlePanel();
292
293 if (typeof themeAfterLayout == 'function') {
294 themeAfterLayout();
295 }
296
297 });
298
299 if (!genericSanityCheck())
300 return;
301
302 var params = "&ua=" + param_escape(navigator.userAgent);
303
304 loading_set_progress(30);
305
306 new Ajax.Request("backend.php", {
307 parameters: "backend.php?op=rpc&subop=sanityCheck" + params,
308 onComplete: function(transport) {
309 backend_sanity_check_callback(transport);
310 } });
311
312 } catch (e) {
313 exception_error("init", e);
314 }
315 }
316
317 function init_second_stage() {
318
319 try {
320
321 delCookie("ttrss_test");
322
323 var toolbar = document.forms["main_toolbar_form"];
324
325 dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode"));
326 dropboxSelect(toolbar.order_by, getInitParam("default_view_order_by"));
327
328 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
329
330 loading_set_progress(60);
331
332 if (has_local_storage())
333 localStorage.clear();
334
335 feedlist_init();
336 setTimeout("timeout()", 3000);
337
338 console.log("second stage ok");
339
340 } catch (e) {
341 exception_error("init_second_stage", e);
342 }
343 }
344
345 function quickMenuChange() {
346 var chooser = $("quickMenuChooser");
347 var opid = chooser[chooser.selectedIndex].value;
348
349 chooser.selectedIndex = 0;
350 quickMenuGo(opid);
351 }
352
353 function quickMenuGo(opid) {
354 try {
355
356 if (opid == "qmcPrefs") {
357 gotoPreferences();
358 }
359
360 if (opid == "qmcTagCloud") {
361 displayDlg("printTagCloud");
362 }
363
364 if (opid == "qmcSearch") {
365 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(),
366 function() {
367 document.forms['search_form'].query.focus();
368 });
369 return;
370 }
371
372 if (opid == "qmcAddFeed") {
373 quickAddFeed();
374 return;
375 }
376
377 if (opid == "qmcEditFeed") {
378 editFeedDlg(getActiveFeedId());
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 displayDlg('quickAddFilter', '',
417 function () {document.forms['filter_add_form'].reg_exp.focus();});
418 }
419
420 if (opid == "qmcAddLabel") {
421 addLabel();
422 }
423
424 if (opid == "qmcRescoreFeed") {
425 rescoreCurrentFeed();
426 }
427
428 if (opid == "qmcHKhelp") {
429 //Element.show("hotkey_help_overlay");
430 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
431 }
432
433 } catch (e) {
434 exception_error("quickMenuGo", e);
435 }
436 }
437
438 function toggleDispRead() {
439 try {
440
441 var hide = !(getInitParam("hide_read_feeds") == "1");
442
443 hideOrShowFeeds(hide);
444
445 var query = "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
446 param_escape(hide);
447
448 new Ajax.Request("backend.php", {
449 parameters: query,
450 onComplete: function(transport) {
451 setInitParam("hide_read_feeds", hide);
452 } });
453
454 } catch (e) {
455 exception_error("toggleDispRead", e);
456 }
457 }
458
459 function parse_runtime_info(elem) {
460
461 if (!elem || !elem.firstChild) {
462 console.warn("parse_runtime_info: invalid node passed");
463 return;
464 }
465
466 var data = JSON.parse(elem.firstChild.nodeValue);
467
468 //console.log("parsing runtime info...");
469
470 for (k in data) {
471 var v = data[k];
472
473 // console.log("RI: " + k + " => " + v);
474
475 if (k == "new_version_available") {
476 var icon = $("newVersionIcon");
477 if (icon) {
478 if (v == "1") {
479 icon.style.display = "inline";
480 } else {
481 icon.style.display = "none";
482 }
483 }
484 return;
485 }
486
487 var error_flag;
488
489 if (k == "daemon_is_running" && v != 1) {
490 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
491 return;
492 }
493
494 if (k == "daemon_stamp_ok" && v != 1) {
495 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
496 return;
497 }
498
499 init_params[k] = v;
500 notify('');
501 }
502 }
503
504 function catchupCurrentFeed() {
505
506 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
507
508 var str = __("Mark all articles in %s as read?").replace("%s", fn);
509
510 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
511 return viewCurrentFeed('MarkAllRead')
512 }
513 }
514
515 function catchupFeedInGroup(id) {
516
517 try {
518
519 var title = getFeedName(id);
520
521 var str = __("Mark all articles in %s as read?").replace("%s", title);
522
523 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
524 return viewCurrentFeed('MarkAllReadGR:' + id)
525 }
526
527 } catch (e) {
528 exception_error("catchupFeedInGroup", e);
529 }
530 }
531
532 function editFeedDlg(feed) {
533 try {
534
535 if (!feed) {
536 alert(__("Please select some feed first."));
537 return;
538 }
539
540 if ((feed <= 0) || activeFeedIsCat()) {
541 alert(__("You can't edit this kind of feed."));
542 return;
543 }
544
545 var query = "";
546
547 if (feed > 0) {
548 query = "?op=pref-feeds&subop=editfeed&id=" + param_escape(feed);
549 } else {
550 query = "?op=pref-labels&subop=edit&id=" + param_escape(-feed-11);
551 }
552
553 disableHotkeys();
554
555 notify_progress("Loading, please wait...", true);
556
557 new Ajax.Request("backend.php", {
558 parameters: query,
559 onComplete: function(transport) {
560 infobox_callback2(transport);
561 document.forms["edit_feed_form"].title.focus();
562 } });
563
564 } catch (e) {
565 exception_error("editFeedDlg", e);
566 }
567 }
568
569 /* this functions duplicate those of prefs.js feed editor, with
570 some differences because there is no feedlist */
571
572 function feedEditCancel() {
573 closeInfoBox();
574 return false;
575 }
576
577 function feedEditSave() {
578
579 try {
580
581 // FIXME: add parameter validation
582
583 var query = Form.serialize("edit_feed_form");
584
585 notify_progress("Saving feed...");
586
587 new Ajax.Request("backend.php", {
588 parameters: query,
589 onComplete: function(transport) {
590 dlg_frefresh_callback(transport);
591 } });
592
593 cache_flush();
594 closeInfoBox();
595
596 return false;
597
598 } catch (e) {
599 exception_error("feedEditSave (main)", e);
600 }
601 }
602
603 function collapse_feedlist() {
604 try {
605
606 if (!Element.visible('feeds-holder')) {
607 Element.show('feeds-holder');
608 $("collapse_feeds_btn").innerHTML = "&lt;&lt;";
609 } else {
610 Element.hide('feeds-holder');
611 $("collapse_feeds_btn").innerHTML = "&gt;&gt;";
612 }
613
614 dijit.byId("main").resize();
615
616 query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
617 new Ajax.Request("backend.php", { parameters: query });
618
619 } catch (e) {
620 exception_error("collapse_feedlist", e);
621 }
622 }
623
624 function viewModeChanged() {
625 cache_flush();
626 return viewCurrentFeed('')
627 }
628
629 function viewLimitChanged() {
630 cache_flush();
631 return viewCurrentFeed('')
632 }
633
634 /* function adjustArticleScore(id, score) {
635 try {
636
637 var pr = prompt(__("Assign score to article:"), score);
638
639 if (pr != undefined) {
640 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
641
642 new Ajax.Request("backend.php", {
643 parameters: query,
644 onComplete: function(transport) {
645 viewCurrentFeed();
646 } });
647
648 }
649 } catch (e) {
650 exception_error("adjustArticleScore", e);
651 }
652 } */
653
654 function rescoreCurrentFeed() {
655
656 var actid = getActiveFeedId();
657
658 if (activeFeedIsCat() || actid < 0) {
659 alert(__("You can't rescore this kind of feed."));
660 return;
661 }
662
663 if (!actid) {
664 alert(__("Please select some feed first."));
665 return;
666 }
667
668 var fn = getFeedName(actid);
669 var pr = __("Rescore articles in %s?").replace("%s", fn);
670
671 if (confirm(pr)) {
672 notify_progress("Rescoring articles...");
673
674 var query = "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid;
675
676 new Ajax.Request("backend.php", {
677 parameters: query,
678 onComplete: function(transport) {
679 viewCurrentFeed();
680 } });
681 }
682 }
683
684 function hotkey_handler(e) {
685
686 try {
687
688 var keycode;
689 var shift_key = false;
690
691 var cmdline = $('cmdline');
692
693 try {
694 shift_key = e.shiftKey;
695 } catch (e) {
696
697 }
698
699 if (window.event) {
700 keycode = window.event.keyCode;
701 } else if (e) {
702 keycode = e.which;
703 }
704
705 var keychar = String.fromCharCode(keycode);
706
707 if (keycode == 27) { // escape
708 if (Element.visible("hotkey_help_overlay")) {
709 Element.hide("hotkey_help_overlay");
710 }
711 hotkey_prefix = false;
712 closeInfoBox();
713 }
714
715 var dialog = dijit.byId("infoBox");
716 var dialog_visible = false;
717
718 if (dialog)
719 dialog_visible = Element.visible(dialog.domNode);
720
721 if (dialog_visible || !hotkeys_enabled) {
722 console.log("hotkeys disabled");
723 return;
724 }
725
726 if (keycode == 16) return; // ignore lone shift
727 if (keycode == 17) return; // ignore lone ctrl
728
729 if ((keycode == 70 || keycode == 67 || keycode == 71)
730 && !hotkey_prefix) {
731
732 var date = new Date();
733 var ts = Math.round(date.getTime() / 1000);
734
735 hotkey_prefix = keycode;
736 hotkey_prefix_pressed = ts;
737
738 cmdline.innerHTML = keychar;
739 Element.show(cmdline);
740
741 console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
742 return true;
743 }
744
745 if (Element.visible("hotkey_help_overlay")) {
746 Element.hide("hotkey_help_overlay");
747 }
748
749 /* Global hotkeys */
750
751 Element.hide(cmdline);
752
753 if (!hotkey_prefix) {
754
755 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
756 if (!Element.visible("hotkey_help_overlay")) {
757 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
758 } else {
759 Element.hide("hotkey_help_overlay");
760 }
761 return false;
762 }
763
764 if (keycode == 191 || keychar == '/') { // /
765 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat(),
766 function() {
767 document.forms['search_form'].query.focus();
768 });
769 return false;
770 }
771
772 if (keycode == 74) { // j
773 // TODO: move to previous feed
774 return;
775 }
776
777 if (keycode == 75) { // k
778 // TODO: move to next feed
779 return;
780 }
781
782 if (shift_key && keycode == 40) { // shift-down
783 catchupRelativeToArticle(1);
784 return;
785 }
786
787 if (shift_key && keycode == 38) { // shift-up
788 catchupRelativeToArticle(0);
789 return;
790 }
791
792 if (shift_key && keycode == 78) { // N
793 scrollArticle(50);
794 return;
795 }
796
797 if (shift_key && keycode == 80) { // P
798 scrollArticle(-50);
799 return;
800 }
801
802 if (keycode == 68 && shift_key) { // shift-D
803 dismissSelectedArticles();
804 }
805
806 if (keycode == 88 && shift_key) { // shift-X
807 dismissReadArticles();
808 }
809
810 if (keycode == 78 || keycode == 40) { // n, down
811 if (typeof moveToPost != 'undefined') {
812 moveToPost('next');
813 return false;
814 }
815 }
816
817 if (keycode == 80 || keycode == 38) { // p, up
818 if (typeof moveToPost != 'undefined') {
819 moveToPost('prev');
820 return false;
821 }
822 }
823
824 if (keycode == 83 && shift_key) { // S
825 selectionTogglePublished(undefined, false, true);
826 return;
827 }
828
829 if (keycode == 83) { // s
830 selectionToggleMarked(undefined, false, true);
831 return;
832 }
833
834
835 if (keycode == 85) { // u
836 selectionToggleUnread(undefined, false, true)
837 return;
838 }
839
840 if (keycode == 84 && shift_key) { // T
841 var id = getActiveArticleId();
842 if (id) {
843 editArticleTags(id, getActiveFeedId(), isCdmMode());
844 return;
845 }
846 }
847
848 if (keycode == 9) { // tab
849 var id = getArticleUnderPointer();
850 if (id) {
851 var cb = $("RCHK-" + id);
852
853 if (cb) {
854 cb.checked = !cb.checked;
855 toggleSelectRowById(cb, "RROW-" + id);
856 return false;
857 }
858 }
859 }
860
861 if (keycode == 79) { // o
862 if (getActiveArticleId()) {
863 openArticleInNewWindow(getActiveArticleId());
864 return;
865 }
866 }
867
868 if (keycode == 81 && shift_key) { // Q
869 if (typeof catchupAllFeeds != 'undefined') {
870 catchupAllFeeds();
871 return;
872 }
873 }
874
875 if (keycode == 88) { // x
876 if (activeFeedIsCat()) {
877 toggleCollapseCat(getActiveFeedId());
878 }
879 }
880 }
881
882 /* Prefix f */
883
884 if (hotkey_prefix == 70) { // f
885
886 hotkey_prefix = false;
887
888 if (keycode == 81) { // q
889 if (getActiveFeedId()) {
890 catchupCurrentFeed();
891 return;
892 }
893 }
894
895 if (keycode == 82) { // r
896 if (getActiveFeedId()) {
897 viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat());
898 return;
899 }
900 }
901
902 if (keycode == 65) { // a
903 toggleDispRead();
904 return false;
905 }
906
907 if (keycode == 85) { // u
908 if (getActiveFeedId()) {
909 viewfeed(getActiveFeedId(), "ForceUpdate");
910 return false;
911 }
912 }
913
914 if (keycode == 69) { // e
915 editFeedDlg(getActiveFeedId());
916 return false;
917 }
918
919 if (keycode == 83) { // s
920 quickAddFeed();
921 return false;
922 }
923
924 if (keycode == 67 && shift_key) { // C
925 if (typeof catchupAllFeeds != 'undefined') {
926 catchupAllFeeds();
927 return false;
928 }
929 }
930
931 if (keycode == 67) { // c
932 if (getActiveFeedId()) {
933 catchupCurrentFeed();
934 return false;
935 }
936 }
937
938 if (keycode == 87) { // w
939 feeds_sort_by_unread = !feeds_sort_by_unread;
940 return resort_feedlist();
941 }
942
943 if (keycode == 88) { // x
944 reverseHeadlineOrder();
945 return;
946 }
947 }
948
949 /* Prefix c */
950
951 if (hotkey_prefix == 67) { // c
952 hotkey_prefix = false;
953
954 if (keycode == 70) { // f
955 displayDlg('quickAddFilter', '',
956 function () {document.forms['filter_add_form'].reg_exp.focus();});
957 return false;
958 }
959
960 if (keycode == 76) { // l
961 addLabel();
962 return false;
963 }
964
965 if (keycode == 83) { // s
966 if (typeof collapse_feedlist != 'undefined') {
967 collapse_feedlist();
968 return false;
969 }
970 }
971
972 if (keycode == 77) { // m
973 // TODO: sortable feedlist
974 return;
975 }
976
977 if (keycode == 78) { // n
978 catchupRelativeToArticle(1);
979 return;
980 }
981
982 if (keycode == 80) { // p
983 catchupRelativeToArticle(0);
984 return;
985 }
986
987
988 }
989
990 /* Prefix g */
991
992 if (hotkey_prefix == 71) { // g
993
994 hotkey_prefix = false;
995
996
997 if (keycode == 65) { // a
998 viewfeed(-4);
999 return false;
1000 }
1001
1002 if (keycode == 83) { // s
1003 viewfeed(-1);
1004 return false;
1005 }
1006
1007 if (keycode == 80 && shift_key) { // P
1008 gotoPreferences();
1009 return false;
1010 }
1011
1012 if (keycode == 80) { // p
1013 viewfeed(-2);
1014 return false;
1015 }
1016
1017 if (keycode == 70) { // f
1018 viewfeed(-3);
1019 return false;
1020 }
1021
1022 if (keycode == 84 && shift_key) { // T
1023 toggleTags();
1024 return false;
1025 }
1026 }
1027
1028 /* Cmd */
1029
1030 if (hotkey_prefix == 224 || hotkey_prefix == 91) { // f
1031 hotkey_prefix = false;
1032 return;
1033 }
1034
1035 if (hotkey_prefix) {
1036 console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
1037 } else {
1038 console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
1039 }
1040
1041
1042 } catch (e) {
1043 exception_error("hotkey_handler", e);
1044 }
1045 }
1046
1047 function inPreferences() {
1048 return false;
1049 }
1050
1051 function reverseHeadlineOrder() {
1052 try {
1053
1054 var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1055
1056 new Ajax.Request("backend.php", {
1057 parameters: query_str,
1058 onComplete: function(transport) {
1059 viewCurrentFeed();
1060 } });
1061
1062 } catch (e) {
1063 exception_error("reverseHeadlineOrder", e);
1064 }
1065 }
1066
1067 function showFeedsWithErrors() {
1068 displayDlg('feedUpdateErrors');
1069 }
1070
1071 function handle_rpc_reply(transport, scheduled_call) {
1072 try {
1073 if (transport.responseXML) {
1074
1075 if (!transport_error_check(transport)) return false;
1076
1077 var seq = transport.responseXML.getElementsByTagName("seq")[0];
1078
1079 if (seq) {
1080 seq = seq.firstChild.nodeValue;
1081
1082 if (get_seq() != seq) {
1083 //console.log("[handle_rpc_reply] sequence mismatch: " + seq);
1084 return true;
1085 }
1086 }
1087
1088 var message = transport.responseXML.getElementsByTagName("message")[0];
1089
1090 if (message) {
1091 message = message.firstChild.nodeValue;
1092
1093 if (message == "UPDATE_COUNTERS") {
1094 console.log("need to refresh counters...");
1095 setInitParam("last_article_id", -1);
1096 _force_scheduled_update = true;
1097 }
1098 }
1099
1100 var counters = transport.responseXML.getElementsByTagName("counters")[0];
1101
1102 if (counters)
1103 parse_counters(counters, scheduled_call);
1104
1105 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
1106
1107 if (runtime_info)
1108 parse_runtime_info(runtime_info);
1109
1110 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1111
1112 } else {
1113 notify_error("Error communicating with server.");
1114 }
1115
1116 } catch (e) {
1117 exception_error("handle_rpc_reply", e, transport);
1118 }
1119
1120 return true;
1121 }
1122
1123 function scheduleFeedUpdate() {
1124 try {
1125
1126 if (!getActiveFeedId()) {
1127 alert(__("Please select some feed first."));
1128 return;
1129 }
1130
1131 var query = "?op=rpc&subop=scheduleFeedUpdate&id=" +
1132 param_escape(getActiveFeedId()) +
1133 "&is_cat=" + param_escape(activeFeedIsCat());
1134
1135 console.log(query);
1136
1137 new Ajax.Request("backend.php", {
1138 parameters: query,
1139 onComplete: function(transport) {
1140
1141 if (transport.responseXML) {
1142 var message = transport.responseXML.getElementsByTagName("message")[0];
1143
1144 if (message) {
1145 notify_info(message.firstChild.nodeValue);
1146 return;
1147 }
1148 }
1149
1150 notify_error("Error communicating with server.");
1151
1152 } });
1153
1154
1155 } catch (e) {
1156 exception_error("scheduleFeedUpdate", e);
1157 }
1158 }