]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
re-add ForceUpdate to viewfeed for update debugging, add some filter debugging
[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 hotkey_prefix = false;
7 var hotkey_prefix_pressed = false;
8 var init_params = {};
9 var _force_scheduled_update = false;
10 var last_scheduled_update = false;
11
12 var _rpc_seq = 0;
13
14 function next_seq() {
15 _rpc_seq += 1;
16 return _rpc_seq;
17 }
18
19 function get_seq() {
20 return _rpc_seq;
21 }
22
23 function activeFeedIsCat() {
24 return _active_feed_is_cat;
25 }
26
27 function getActiveFeedId() {
28 try {
29 //console.log("gAFID: " + _active_feed_id);
30 return _active_feed_id;
31 } catch (e) {
32 exception_error("getActiveFeedId", e);
33 }
34 }
35
36 function setActiveFeedId(id, is_cat) {
37 try {
38 _active_feed_id = id;
39
40 if (is_cat != undefined) {
41 _active_feed_is_cat = is_cat;
42 }
43
44 selectFeed(id, is_cat);
45
46 } catch (e) {
47 exception_error("setActiveFeedId", e);
48 }
49 }
50
51
52 function updateFeedList() {
53 try {
54
55 // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
56 // __("Loading, please wait...") + "</div>";
57
58 Element.show("feedlistLoading");
59
60 if (dijit.byId("feedTree")) {
61 dijit.byId("feedTree").destroyRecursive();
62 }
63
64 var store = new dojo.data.ItemFileWriteStore({
65 url: "backend.php?op=feeds"});
66
67 var treeModel = new fox.FeedStoreModel({
68 store: store,
69 query: {
70 "type": "feed"
71 },
72 rootId: "root",
73 rootLabel: "Feeds",
74 childrenAttrs: ["items"]
75 });
76
77 var tree = new fox.FeedTree({
78 persist: false,
79 model: treeModel,
80 onOpen: function (item, node) {
81 var id = String(item.id);
82 var cat_id = id.substr(id.indexOf(":")+1);
83
84 new Ajax.Request("backend.php",
85 { parameters: "backend.php?op=feeds&subop=collapse&cid=" +
86 param_escape(cat_id) + "&mode=0" } );
87 },
88 onClose: function (item, node) {
89 var id = String(item.id);
90 var cat_id = id.substr(id.indexOf(":")+1);
91
92 new Ajax.Request("backend.php",
93 { parameters: "backend.php?op=feeds&subop=collapse&cid=" +
94 param_escape(cat_id) + "&mode=1" } );
95
96 },
97 onClick: function (item, node) {
98 var id = String(item.id);
99 var is_cat = id.match("^CAT:");
100 var feed = id.substr(id.indexOf(":")+1);
101 viewfeed(feed, '', is_cat);
102 return false;
103 },
104 openOnClick: false,
105 showRoot: false,
106 id: "feedTree",
107 }, "feedTree");
108
109 /* var menu = new dijit.Menu({id: 'feedMenu'});
110
111 menu.addChild(new dijit.MenuItem({
112 label: "Simple menu item"
113 }));
114
115 // menu.bindDomNode(tree.domNode); */
116
117 var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) {
118 console.log(dijit.getEnclosingWidget(event.target));
119 dojo.disconnect(tmph);
120 });
121
122 $("feeds-holder").appendChild(tree.domNode);
123
124 var tmph = dojo.connect(tree, 'onLoad', function() {
125 dojo.disconnect(tmph);
126 Element.hide("feedlistLoading");
127
128 tree.collapseHiddenCats();
129
130 feedlist_init();
131
132 // var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
133 // menu.bindDomNode(node);
134
135 loading_set_progress(25);
136 });
137
138 tree.startup();
139
140 } catch (e) {
141 exception_error("updateFeedList", e);
142 }
143 }
144
145 function catchupAllFeeds() {
146
147 var str = __("Mark all articles as read?");
148
149 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
150
151 var query_str = "backend.php?op=feeds&subop=catchupAll";
152
153 notify_progress("Marking all feeds as read...");
154
155 //console.log("catchupAllFeeds Q=" + query_str);
156
157 new Ajax.Request("backend.php", {
158 parameters: query_str,
159 onComplete: function(transport) {
160 feedlist_callback2(transport);
161 } });
162
163 global_unread = 0;
164 updateTitle("");
165 }
166 }
167
168 function viewCurrentFeed(subop) {
169
170 if (getActiveFeedId() != undefined) {
171 viewfeed(getActiveFeedId(), subop, activeFeedIsCat());
172 }
173 return false; // block unneeded form submits
174 }
175
176 function timeout() {
177 if (getInitParam("bw_limit") == "1") return;
178
179 try {
180 var date = new Date();
181 var ts = Math.round(date.getTime() / 1000);
182
183 if (ts - last_scheduled_update > 10 || _force_scheduled_update) {
184
185 //console.log("timeout()");
186
187 window.clearTimeout(counter_timeout_id);
188
189 var query_str = "?op=rpc&subop=getAllCounters&seq=" + next_seq();
190
191 var omode;
192
193 if (firsttime_update && !navigator.userAgent.match("Opera")) {
194 firsttime_update = false;
195 omode = "T";
196 } else {
197 omode = "flc";
198 }
199
200 query_str = query_str + "&omode=" + omode;
201
202 if (!_force_scheduled_update)
203 query_str = query_str + "&last_article_id=" + getInitParam("last_article_id");
204
205 //console.log("[timeout]" + query_str);
206
207 new Ajax.Request("backend.php", {
208 parameters: query_str,
209 onComplete: function(transport) {
210 handle_rpc_json(transport, !_force_scheduled_update);
211 _force_scheduled_update = false;
212 } });
213
214 last_scheduled_update = ts;
215 }
216
217 } catch (e) {
218 exception_error("timeout", e);
219 }
220
221 setTimeout("timeout()", 3000);
222 }
223
224 function search() {
225 var query = "backend.php?op=dlg&id=search&param=" +
226 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
227
228 if (dijit.byId("searchDlg"))
229 dijit.byId("searchDlg").destroyRecursive();
230
231 dialog = new dijit.Dialog({
232 id: "searchDlg",
233 title: __("Search"),
234 style: "width: 600px",
235 execute: function() {
236 if (this.validate()) {
237 _search_query = dojo.objectToQuery(this.attr('value'));
238 this.hide();
239 viewCurrentFeed();
240 }
241 },
242 href: query});
243
244 dialog.show();
245 }
246
247 function updateTitle() {
248 var tmp = "Tiny Tiny RSS";
249
250 if (global_unread > 0) {
251 tmp = tmp + " (" + global_unread + ")";
252 }
253
254 if (window.fluid) {
255 if (global_unread > 0) {
256 window.fluid.dockBadge = global_unread;
257 } else {
258 window.fluid.dockBadge = "";
259 }
260 }
261
262 document.title = tmp;
263 }
264
265 function genericSanityCheck() {
266 setCookie("ttrss_test", "TEST");
267
268 if (getCookie("ttrss_test") != "TEST") {
269 fatalError(2);
270 }
271
272 return true;
273 }
274
275 function init() {
276 try {
277 //Form.disable("main_toolbar_form");
278
279 dojo.require("dijit.layout.BorderContainer");
280 dojo.require("dijit.layout.TabContainer");
281 dojo.require("dijit.layout.ContentPane");
282 dojo.require("dijit.Dialog");
283 dojo.require("dijit.form.Button");
284 dojo.require("dijit.Menu");
285 dojo.require("dojo.data.ItemFileWriteStore");
286 dojo.require("dijit.Tree");
287 dojo.require("dijit.form.Select");
288 dojo.require("dijit.form.TextBox");
289 dojo.require("dijit.form.ValidationTextBox");
290 dojo.require("dijit.form.FilteringSelect");
291 dojo.require("dijit.form.CheckBox");
292 dojo.require("dijit.form.SimpleTextarea");
293 dojo.require("dijit.Toolbar");
294 dojo.require("dijit.ProgressBar");
295 dojo.require("dijit.Menu");
296 dojo.require("dojo.parser");
297
298 dojo.registerModulePath("fox", "../..");
299
300 dojo.require("fox.FeedTree");
301
302 if (typeof themeBeforeLayout == 'function') {
303 themeBeforeLayout();
304 }
305
306 dojo.addOnLoad(function() {
307 updateFeedList();
308 closeArticlePanel();
309
310 if (typeof themeAfterLayout == 'function') {
311 themeAfterLayout();
312 }
313
314 });
315
316 if (!genericSanityCheck())
317 return;
318
319 loading_set_progress(20);
320
321 var hasAudio = !!((myAudioTag = document.createElement('audio')).canPlayType);
322
323 new Ajax.Request("backend.php", {
324 parameters: {op: "rpc", subop: "sanityCheck", hasAudio: hasAudio},
325 onComplete: function(transport) {
326 backend_sanity_check_callback(transport);
327 } });
328
329 } catch (e) {
330 exception_error("init", e);
331 }
332 }
333
334 function init_second_stage() {
335
336 try {
337
338 delCookie("ttrss_test");
339
340 var toolbar = document.forms["main_toolbar_form"];
341
342 dijit.getEnclosingWidget(toolbar.view_mode).attr('value',
343 getInitParam("default_view_mode"));
344
345 dijit.getEnclosingWidget(toolbar.order_by).attr('value',
346 getInitParam("default_view_order_by"));
347
348 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
349
350 loading_set_progress(30);
351
352 if (has_local_storage())
353 sessionStorage.clear();
354
355 console.log("second stage ok");
356
357 } catch (e) {
358 exception_error("init_second_stage", e);
359 }
360 }
361
362 function quickMenuGo(opid) {
363 try {
364 if (opid == "qmcPrefs") {
365 gotoPreferences();
366 }
367
368 if (opid == "qmcTagCloud") {
369 displayDlg("printTagCloud");
370 }
371
372 if (opid == "qmcSearch") {
373 search();
374 return;
375 }
376
377 if (opid == "qmcAddFeed") {
378 quickAddFeed();
379 return;
380 }
381
382 if (opid == "qmcDigest") {
383 window.location.href = "digest.php";
384 return;
385 }
386
387 if (opid == "qmcEditFeed") {
388 if (activeFeedIsCat())
389 alert(__("You can't edit this kind of feed."));
390 else
391 editFeed(getActiveFeedId());
392 return;
393 }
394
395 if (opid == "qmcRemoveFeed") {
396 var actid = getActiveFeedId();
397
398 if (activeFeedIsCat()) {
399 alert(__("You can't unsubscribe from the category."));
400 return;
401 }
402
403 if (!actid) {
404 alert(__("Please select some feed first."));
405 return;
406 }
407
408 var fn = getFeedName(actid);
409
410 var pr = __("Unsubscribe from %s?").replace("%s", fn);
411
412 if (confirm(pr)) {
413 unsubscribeFeed(actid);
414 }
415
416 return;
417 }
418
419 if (opid == "qmcCatchupAll") {
420 catchupAllFeeds();
421 return;
422 }
423
424 if (opid == "qmcShowOnlyUnread") {
425 toggleDispRead();
426 return;
427 }
428
429 if (opid == "qmcAddFilter") {
430 quickAddFilter();
431 return;
432 }
433
434 if (opid == "qmcAddLabel") {
435 addLabel();
436 return;
437 }
438
439 if (opid == "qmcRescoreFeed") {
440 rescoreCurrentFeed();
441 return;
442 }
443
444 if (opid == "qmcHKhelp") {
445 //Element.show("hotkey_help_overlay");
446 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
447 }
448
449 } catch (e) {
450 exception_error("quickMenuGo", e);
451 }
452 }
453
454 function toggleDispRead() {
455 try {
456
457 var hide = !(getInitParam("hide_read_feeds") == "1");
458
459 hideOrShowFeeds(hide);
460
461 var query = "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" +
462 param_escape(hide);
463
464 setInitParam("hide_read_feeds", hide);
465
466 new Ajax.Request("backend.php", {
467 parameters: query,
468 onComplete: function(transport) {
469 } });
470
471 } catch (e) {
472 exception_error("toggleDispRead", e);
473 }
474 }
475
476 function parse_runtime_info(data) {
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 if (k == "max_feed_id" || k == "num_feeds") {
510 if (init_params[k] != v) {
511 console.log("feed count changed, need to reload feedlist.");
512 updateFeedList();
513 }
514 }
515
516 init_params[k] = v;
517 notify('');
518 }
519 }
520
521 function catchupCurrentFeed() {
522
523 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
524
525 var str = __("Mark all articles in %s as read?").replace("%s", fn);
526
527 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
528 return viewCurrentFeed('MarkAllRead')
529 }
530 }
531
532 function catchupFeedInGroup(id) {
533
534 try {
535
536 var title = getFeedName(id);
537
538 var str = __("Mark all articles in %s as read?").replace("%s", title);
539
540 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
541 return viewCurrentFeed('MarkAllReadGR:' + id)
542 }
543
544 } catch (e) {
545 exception_error("catchupFeedInGroup", e);
546 }
547 }
548
549 function collapse_feedlist() {
550 try {
551
552 if (!Element.visible('feeds-holder')) {
553 Element.show('feeds-holder');
554 Element.show('feeds-holder_splitter');
555 $("collapse_feeds_btn").innerHTML = "&lt;&lt;";
556 } else {
557 Element.hide('feeds-holder');
558 Element.hide('feeds-holder_splitter');
559 $("collapse_feeds_btn").innerHTML = "&gt;&gt;";
560 }
561
562 dijit.byId("main").resize();
563
564 query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true";
565 new Ajax.Request("backend.php", { parameters: query });
566
567 } catch (e) {
568 exception_error("collapse_feedlist", e);
569 }
570 }
571
572 function viewModeChanged() {
573 cache_flush();
574 return viewCurrentFeed('')
575 }
576
577 function viewLimitChanged() {
578 cache_flush();
579 return viewCurrentFeed('')
580 }
581
582 /* function adjustArticleScore(id, score) {
583 try {
584
585 var pr = prompt(__("Assign score to article:"), score);
586
587 if (pr != undefined) {
588 var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr;
589
590 new Ajax.Request("backend.php", {
591 parameters: query,
592 onComplete: function(transport) {
593 viewCurrentFeed();
594 } });
595
596 }
597 } catch (e) {
598 exception_error("adjustArticleScore", e);
599 }
600 } */
601
602 function rescoreCurrentFeed() {
603
604 var actid = getActiveFeedId();
605
606 if (activeFeedIsCat() || actid < 0) {
607 alert(__("You can't rescore this kind of feed."));
608 return;
609 }
610
611 if (!actid) {
612 alert(__("Please select some feed first."));
613 return;
614 }
615
616 var fn = getFeedName(actid);
617 var pr = __("Rescore articles in %s?").replace("%s", fn);
618
619 if (confirm(pr)) {
620 notify_progress("Rescoring articles...");
621
622 var query = "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid;
623
624 new Ajax.Request("backend.php", {
625 parameters: query,
626 onComplete: function(transport) {
627 viewCurrentFeed();
628 } });
629 }
630 }
631
632 function hotkey_handler(e) {
633 try {
634
635 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
636
637 var keycode;
638 var shift_key = false;
639
640 var cmdline = $('cmdline');
641
642 try {
643 shift_key = e.shiftKey;
644 } catch (e) {
645
646 }
647
648 if (window.event) {
649 keycode = window.event.keyCode;
650 } else if (e) {
651 keycode = e.which;
652 }
653
654 var keychar = String.fromCharCode(keycode);
655
656 if (keycode == 27) { // escape
657 if (Element.visible("hotkey_help_overlay")) {
658 Element.hide("hotkey_help_overlay");
659 }
660 hotkey_prefix = false;
661 }
662
663 if (keycode == 16) return; // ignore lone shift
664 if (keycode == 17) return; // ignore lone ctrl
665
666 if ((keycode == 70 || keycode == 67 || keycode == 71)
667 && !hotkey_prefix) {
668
669 var date = new Date();
670 var ts = Math.round(date.getTime() / 1000);
671
672 hotkey_prefix = keycode;
673 hotkey_prefix_pressed = ts;
674
675 cmdline.innerHTML = keychar;
676 Element.show(cmdline);
677
678 console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts);
679 return true;
680 }
681
682 if (Element.visible("hotkey_help_overlay")) {
683 Element.hide("hotkey_help_overlay");
684 }
685
686 /* Global hotkeys */
687
688 Element.hide(cmdline);
689
690 if (!hotkey_prefix) {
691
692 if ((keycode == 191 || keychar == '?') && shift_key) { // ?
693 if (!Element.visible("hotkey_help_overlay")) {
694 Effect.Appear("hotkey_help_overlay", {duration : 0.3});
695 } else {
696 Element.hide("hotkey_help_overlay");
697 }
698 return false;
699 }
700
701 if (keycode == 191 || keychar == '/') { // /
702 search();
703 return false;
704 }
705
706 if (keycode == 74) { // j
707 var rv = dijit.byId("feedTree").model.getPreviousFeed(
708 getActiveFeedId(), activeFeedIsCat());
709
710 if (rv) viewfeed(rv[0], '', rv[1]);
711
712 return;
713 }
714
715 if (keycode == 75) { // k
716 var rv = dijit.byId("feedTree").model.getNextFeed(
717 getActiveFeedId(), activeFeedIsCat());
718
719 if (rv) viewfeed(rv[0], '', rv[1]);
720
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 dijit.byId("feedTree").collapseCat(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(), '', 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(), '');
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(JSON.parse(counters.firstChild.nodeValue), scheduled_call);
1051
1052 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info")[0];
1053
1054 if (runtime_info)
1055 parse_runtime_info(JSON.parse(runtime_info.firstChild.nodeValue));
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 handle_rpc_json(transport);
1092
1093 var reply = JSON.parse(transport.responseText);
1094 var message = reply['message'];
1095
1096 if (message) {
1097 notify_info(message);
1098 return;
1099 }
1100
1101 } });
1102
1103
1104 } catch (e) {
1105 exception_error("scheduleFeedUpdate", e);
1106 }
1107 }
1108
1109 function newVersionDlg() {
1110 try {
1111 var query = "backend.php?op=dlg&id=newVersion";
1112
1113 if (dijit.byId("newVersionDlg"))
1114 dijit.byId("newVersionDlg").destroyRecursive();
1115
1116 dialog = new dijit.Dialog({
1117 id: "newVersionDlg",
1118 title: __("New version available!"),
1119 style: "width: 600px",
1120 href: query,
1121 });
1122
1123 dialog.show();
1124
1125 } catch (e) {
1126 exception_error("newVersionDlg", e);
1127 }
1128 }
1129
1130 function handle_rpc_json(transport, scheduled_call) {
1131 try {
1132 var reply = JSON.parse(transport.responseText);
1133
1134 if (reply) {
1135
1136 var error = reply['error'];
1137
1138 if (error) {
1139 var code = error['code'];
1140 var msg = error['msg'];
1141 if (code != 0) {
1142 fatalError(code, msg);
1143 return false;
1144 }
1145 }
1146
1147 var seq = reply['seq'];
1148
1149 if (seq) {
1150 if (get_seq() != seq) {
1151 console.log("[handle_rpc_json] sequence mismatch: " + seq +
1152 " (want: " + get_seq() + ")");
1153 return true;
1154 }
1155 }
1156
1157 var message = reply['message'];
1158
1159 if (message) {
1160 if (message == "UPDATE_COUNTERS") {
1161 console.log("need to refresh counters...");
1162 setInitParam("last_article_id", -1);
1163 _force_scheduled_update = true;
1164 }
1165 }
1166
1167 var counters = reply['counters'];
1168
1169 if (counters)
1170 parse_counters(counters, scheduled_call);
1171
1172 var runtime_info = reply['runtime-info'];;
1173
1174 if (runtime_info)
1175 parse_runtime_info(runtime_info);
1176
1177 hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
1178
1179 } else {
1180 notify_error("Error communicating with server.");
1181 }
1182
1183 } catch (e) {
1184 notify_error("Error communicating with server.");
1185 console.log(e);
1186 //exception_error("handle_rpc_json", e, transport);
1187 }
1188
1189 return true;
1190 }
1191