]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
rework search dialog
[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
640 try {
641
642 var widget = dijit.getEnclosingWidget(e.target);
643 if (widget && Element.visible(widget.domNode)) return;
644
645 var keycode;
646 var shift_key = false;
647
648 var cmdline = $('cmdline');
649
650 try {
651 shift_key = e.shiftKey;
652 } catch (e) {
653
654 }
655
656 if (window.event) {
657 keycode = window.event.keyCode;
658 } else if (e) {
659 keycode = e.which;
660 }
661
662 var keychar = String.fromCharCode(keycode);
663
664 if (keycode == 27) { // escape
665 if (Element.visible("hotkey_help_overlay")) {
666 Element.hide("hotkey_help_overlay");
667 }
668 hotkey_prefix = false;
669 closeInfoBox();
670 }
671
672 var dialog = dijit.byId("infoBox");
673 var dialog_visible = false;
674
675 if (dialog)
676 dialog_visible = Element.visible(dialog.domNode);
677
678 if (dialog_visible || !hotkeys_enabled) {
679 console.log("hotkeys disabled");
680 return;
681 }
682
683 if (keycode == 16) return; // ignore lone shift
684 if (keycode == 17) return; // ignore lone ctrl
685
686 if ((keycode == 70 || keycode == 67 || keycode == 71)
687 && !hotkey_prefix) {
688
689 var date = new Date();
690 var ts = Math.round(date.getTime() / 1000);
691
692 hotkey_prefix = keycode;
693 hotkey_prefix_pressed = ts;
694
695 cmdline.innerHTML = keychar;
696 Element.show(cmdline);
697
698 console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
699 return true;
700 }
701
702 if (Element.visible("hotkey_help_overlay")) {
703 Element.hide("hotkey_help_overlay");
704 }
705
706 /* Global hotkeys */
707
708 Element.hide(cmdline);
709
710 if (!hotkey_prefix) {
711
712 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
713 if (!Element.visible("hotkey_help_overlay")) {
714 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
715 } else {
716 Element.hide("hotkey_help_overlay");
717 }
718 return false;
719 }
720
721 if (keycode == 191 || keychar == '/') { // /
722 search();
723 return false;
724 }
725
726 if (keycode == 74) { // j
727 // TODO: move to previous feed
728 return;
729 }
730
731 if (keycode == 75) { // k
732 // TODO: move to next feed
733 return;
734 }
735
736 if (shift_key && keycode == 40) { // shift-down
737 catchupRelativeToArticle(1);
738 return;
739 }
740
741 if (shift_key && keycode == 38) { // shift-up
742 catchupRelativeToArticle(0);
743 return;
744 }
745
746 if (shift_key && keycode == 78) { // N
747 scrollArticle(50);
748 return;
749 }
750
751 if (shift_key && keycode == 80) { // P
752 scrollArticle(-50);
753 return;
754 }
755
756 if (keycode == 68 && shift_key) { // shift-D
757 dismissSelectedArticles();
758 }
759
760 if (keycode == 88 && shift_key) { // shift-X
761 dismissReadArticles();
762 }
763
764 if (keycode == 78 || keycode == 40) { // n, down
765 if (typeof moveToPost != 'undefined') {
766 moveToPost('next');
767 return false;
768 }
769 }
770
771 if (keycode == 80 || keycode == 38) { // p, up
772 if (typeof moveToPost != 'undefined') {
773 moveToPost('prev');
774 return false;
775 }
776 }
777
778 if (keycode == 83 && shift_key) { // S
779 selectionTogglePublished(undefined, false, true);
780 return;
781 }
782
783 if (keycode == 83) { // s
784 selectionToggleMarked(undefined, false, true);
785 return;
786 }
787
788
789 if (keycode == 85) { // u
790 selectionToggleUnread(undefined, false, true)
791 return;
792 }
793
794 if (keycode == 84 && shift_key) { // T
795 var id = getActiveArticleId();
796 if (id) {
797 editArticleTags(id, getActiveFeedId(), isCdmMode());
798 return;
799 }
800 }
801
802 if (keycode == 9) { // tab
803 var id = getArticleUnderPointer();
804 if (id) {
805 var cb = $("RCHK-" + id);
806
807 if (cb) {
808 cb.checked = !cb.checked;
809 toggleSelectRowById(cb, "RROW-" + id);
810 return false;
811 }
812 }
813 }
814
815 if (keycode == 79) { // o
816 if (getActiveArticleId()) {
817 openArticleInNewWindow(getActiveArticleId());
818 return;
819 }
820 }
821
822 if (keycode == 81 && shift_key) { // Q
823 if (typeof catchupAllFeeds != 'undefined') {
824 catchupAllFeeds();
825 return;
826 }
827 }
828
829 if (keycode == 88) { // x
830 if (activeFeedIsCat()) {
831 toggleCollapseCat(getActiveFeedId());
832 }
833 }
834 }
835
836 /* Prefix f */
837
838 if (hotkey_prefix == 70) { // f
839
840 hotkey_prefix = false;
841
842 if (keycode == 81) { // q
843 if (getActiveFeedId()) {
844 catchupCurrentFeed();
845 return;
846 }
847 }
848
849 if (keycode == 82) { // r
850 if (getActiveFeedId()) {
851 viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat());
852 return;
853 }
854 }
855
856 if (keycode == 65) { // a
857 toggleDispRead();
858 return false;
859 }
860
861 if (keycode == 85) { // u
862 if (getActiveFeedId()) {
863 viewfeed(getActiveFeedId(), "ForceUpdate");
864 return false;
865 }
866 }
867
868 if (keycode == 69) { // e
869
870 if (activeFeedIsCat())
871 alert(__("You can't edit this kind of feed."));
872 else
873 editFeed(getActiveFeedId());
874 return;
875
876 return false;
877 }
878
879 if (keycode == 83) { // s
880 quickAddFeed();
881 return false;
882 }
883
884 if (keycode == 67 && shift_key) { // C
885 if (typeof catchupAllFeeds != 'undefined') {
886 catchupAllFeeds();
887 return false;
888 }
889 }
890
891 if (keycode == 67) { // c
892 if (getActiveFeedId()) {
893 catchupCurrentFeed();
894 return false;
895 }
896 }
897
898 if (keycode == 87) { // w
899 feeds_sort_by_unread = !feeds_sort_by_unread;
900 return resort_feedlist();
901 }
902
903 if (keycode == 88) { // x
904 reverseHeadlineOrder();
905 return;
906 }
907 }
908
909 /* Prefix c */
910
911 if (hotkey_prefix == 67) { // c
912 hotkey_prefix = false;
913
914 if (keycode == 70) { // f
915 quickAddFilter();
916 return false;
917 }
918
919 if (keycode == 76) { // l
920 addLabel();
921 return false;
922 }
923
924 if (keycode == 83) { // s
925 if (typeof collapse_feedlist != 'undefined') {
926 collapse_feedlist();
927 return false;
928 }
929 }
930
931 if (keycode == 77) { // m
932 // TODO: sortable feedlist
933 return;
934 }
935
936 if (keycode == 78) { // n
937 catchupRelativeToArticle(1);
938 return;
939 }
940
941 if (keycode == 80) { // p
942 catchupRelativeToArticle(0);
943 return;
944 }
945
946
947 }
948
949 /* Prefix g */
950
951 if (hotkey_prefix == 71) { // g
952
953 hotkey_prefix = false;
954
955
956 if (keycode == 65) { // a
957 viewfeed(-4);
958 return false;
959 }
960
961 if (keycode == 83) { // s
962 viewfeed(-1);
963 return false;
964 }
965
966 if (keycode == 80 && shift_key) { // P
967 gotoPreferences();
968 return false;
969 }
970
971 if (keycode == 80) { // p
972 viewfeed(-2);
973 return false;
974 }
975
976 if (keycode == 70) { // f
977 viewfeed(-3);
978 return false;
979 }
980
981 if (keycode == 84 && shift_key) { // T
982 toggleTags();
983 return false;
984 }
985 }
986
987 /* Cmd */
988
989 if (hotkey_prefix == 224 || hotkey_prefix == 91) { // f
990 hotkey_prefix = false;
991 return;
992 }
993
994 if (hotkey_prefix) {
995 console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar);
996 } else {
997 console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
998 }
999
1000
1001 } catch (e) {
1002 exception_error("hotkey_handler", e);
1003 }
1004 }
1005
1006 function inPreferences() {
1007 return false;
1008 }
1009
1010 function reverseHeadlineOrder() {
1011 try {
1012
1013 var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES";
1014
1015 new Ajax.Request("backend.php", {
1016 parameters: query_str,
1017 onComplete: function(transport) {
1018 viewCurrentFeed();
1019 } });
1020
1021 } catch (e) {
1022 exception_error("reverseHeadlineOrder", e);
1023 }
1024 }
1025
1026 function showFeedsWithErrors() {
1027 displayDlg('feedUpdateErrors');
1028 }
1029
1030 function handle_rpc_reply(transport, scheduled_call) {
1031 try {
1032 if (transport.responseXML) {
1033
1034 if (!transport_error_check(transport)) return false;
1035
1036 var seq = transport.responseXML.getElementsByTagName("seq")[0];
1037
1038 if (seq) {
1039 seq = seq.firstChild.nodeValue;
1040
1041 if (get_seq() != seq) {
1042 //console.log("[handle_rpc_reply] sequence mismatch: " + seq);
1043 return true;
1044 }
1045 }
1046
1047 var message = transport.responseXML.getElementsByTagName("message")[0];
1048
1049 if (message) {
1050 message = message.firstChild.nodeValue;
1051
1052 if (message == "UPDATE_COUNTERS") {
1053 console.log("need to refresh counters...");
1054 setInitParam("last_article_id", -1);
1055 _force_scheduled_update = true;
1056 }
1057 }
1058
1059 var counters = transport.responseXML.getElementsByTagName("counters")[0];
1060
1061 if (counters)
1062 parse_counters(counters, scheduled_call);
1063
1064 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
1065
1066 if (runtime_info)
1067 parse_runtime_info(runtime_info);
1068
1069 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1070
1071 } else {
1072 notify_error("Error communicating with server.");
1073 }
1074
1075 } catch (e) {
1076 exception_error("handle_rpc_reply", e, transport);
1077 }
1078
1079 return true;
1080 }
1081
1082 function scheduleFeedUpdate(id, is_cat) {
1083 try {
1084 if (!id) {
1085 id = getActiveFeedId();
1086 is_cat = activeFeedIsCat();
1087 }
1088
1089 if (!id) {
1090 alert(__("Please select some feed first."));
1091 return;
1092 }
1093
1094 var query = "?op=rpc&subop=scheduleFeedUpdate&id=" +
1095 param_escape(id) +
1096 "&is_cat=" + param_escape(is_cat);
1097
1098 console.log(query);
1099
1100 new Ajax.Request("backend.php", {
1101 parameters: query,
1102 onComplete: function(transport) {
1103
1104 if (transport.responseXML) {
1105 var message = transport.responseXML.getElementsByTagName("message")[0];
1106
1107 if (message) {
1108 notify_info(message.firstChild.nodeValue);
1109 return;
1110 }
1111 }
1112
1113 notify_error("Error communicating with server.");
1114
1115 } });
1116
1117
1118 } catch (e) {
1119 exception_error("scheduleFeedUpdate", e);
1120 }
1121 }