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