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