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