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