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