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