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