]> git.wh0rd.org - tt-rss.git/blame - js/tt-rss.js
get_article_filter: fix missing argument
[tt-rss.git] / js / tt-rss.js
CommitLineData
806a3d14 1var global_unread = -1;
93f66472 2var hotkey_prefix = false;
164469f9 3var hotkey_prefix_pressed = false;
d725f0ce 4var hotkey_actions = {};
1bcf8f45 5var _widescreen_mode = false;
6237ea05 6var _rpc_seq = 0;
535a4c7d
AD
7var _active_feed_id = 0;
8var _active_feed_is_cat = false;
6237ea05
AD
9
10function next_seq() {
11 _rpc_seq += 1;
12 return _rpc_seq;
13}
14
15function get_seq() {
16 return _rpc_seq;
17}
18
3d72bbdb 19function activeFeedIsCat() {
535a4c7d 20 return _active_feed_is_cat;
3d72bbdb
AD
21}
22
23function getActiveFeedId() {
3d72bbdb 24 try {
535a4c7d 25 return _active_feed_id;
3d72bbdb
AD
26 } catch (e) {
27 exception_error("getActiveFeedId", e);
28 }
29}
30
31function setActiveFeedId(id, is_cat) {
3d72bbdb 32 try {
1b04a298
AD
33 hash_set('f', id);
34 hash_set('c', is_cat ? 1 : 0);
3d72bbdb 35
535a4c7d
AD
36 _active_feed_id = id;
37 _active_feed_is_cat = is_cat;
38
67b9d740
AD
39 $("headlines-frame").setAttribute("feed-id", id);
40 $("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0);
41
fcf70c51 42 selectFeed(id, is_cat);
3d72bbdb
AD
43 } catch (e) {
44 exception_error("setActiveFeedId", e);
45 }
46}
47
48
50eefedb
AD
49function updateFeedList() {
50 try {
102cfe73 51
009646d2 52// $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" +
9c99281f
AD
53// __("Loading, please wait...") + "</div>";
54
55 Element.show("feedlistLoading");
56
102cfe73
AD
57 if (dijit.byId("feedTree")) {
58 dijit.byId("feedTree").destroyRecursive();
50eefedb 59 }
102cfe73
AD
60
61 var store = new dojo.data.ItemFileWriteStore({
2ecd2df5 62 url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"});
102cfe73 63
e032e2e7 64 var treeModel = new fox.FeedStoreModel({
102cfe73
AD
65 store: store,
66 query: {
854a2ace 67 "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
102cfe73
AD
68 },
69 rootId: "root",
70 rootLabel: "Feeds",
71 childrenAttrs: ["items"]
72 });
73
05f224a3 74 var tree = new fox.FeedTree({
102cfe73 75 model: treeModel,
102cfe73
AD
76 onClick: function (item, node) {
77 var id = String(item.id);
78 var is_cat = id.match("^CAT:");
79 var feed = id.substr(id.indexOf(":")+1);
80 viewfeed(feed, '', is_cat);
81 return false;
82 },
83 openOnClick: false,
84 showRoot: false,
85 id: "feedTree",
86 }, "feedTree");
87
997429c2 88/* var menu = new dijit.Menu({id: 'feedMenu'});
009646d2 89
997429c2
AD
90 menu.addChild(new dijit.MenuItem({
91 label: "Simple menu item"
92 }));
93
94// menu.bindDomNode(tree.domNode); */
009646d2
AD
95
96 var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) {
997429c2
AD
97 console.log(dijit.getEnclosingWidget(event.target));
98 dojo.disconnect(tmph);
99 });
100
102cfe73
AD
101 $("feeds-holder").appendChild(tree.domNode);
102
9c99281f
AD
103 var tmph = dojo.connect(tree, 'onLoad', function() {
104 dojo.disconnect(tmph);
105 Element.hide("feedlistLoading");
1a709d21 106
1beea800 107 feedlist_init();
997429c2
AD
108
109// var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode
110// menu.bindDomNode(node);
111
fcc36744 112 loading_set_progress(25);
9c99281f
AD
113 });
114
102cfe73 115 tree.startup();
e1123aee 116
50eefedb
AD
117 } catch (e) {
118 exception_error("updateFeedList", e);
119 }
1a66d16e 120}
175847de 121
476cac42 122function catchupAllFeeds() {
076682aa 123
f8232151 124 var str = __("Mark all articles as read?");
476cac42 125
f8232151 126 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
476cac42 127
f30ef1fa 128 var query_str = "backend.php?op=feeds&method=catchupAll";
1a66d16e 129
f8232151 130 notify_progress("Marking all feeds as read...");
476cac42 131
f8fb4498 132 //console.log("catchupAllFeeds Q=" + query_str);
fc69e641 133
b4e75b2a
AD
134 new Ajax.Request("backend.php", {
135 parameters: query_str,
009646d2
AD
136 onComplete: function(transport) {
137 feedlist_callback2(transport);
f8232151
AD
138 } });
139
140 global_unread = 0;
141 updateTitle("");
142 }
476cac42 143}
1cd17194 144
f30ef1fa 145function viewCurrentFeed(method) {
973c4a64 146 console.log("viewCurrentFeed");
1a66d16e 147
ec6e2fd3 148 if (getActiveFeedId() != undefined) {
f30ef1fa 149 viewfeed(getActiveFeedId(), method, activeFeedIsCat());
f0601b87 150 }
164f4738 151 return false; // block unneeded form submits
f0601b87
AD
152}
153
40d13c28 154function timeout() {
5b55e9e2
AD
155 if (getInitParam("bw_limit") != "1") {
156 request_counters();
157 setTimeout("timeout()", 60*1000);
f8fb4498 158 }
ac53063a
AD
159}
160
f0601b87 161function search() {
1c9bda91 162 var query = "backend.php?op=feeds&method=search&param=" +
973fe3c6
AD
163 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
164
165 if (dijit.byId("searchDlg"))
166 dijit.byId("searchDlg").destroyRecursive();
167
168 dialog = new dijit.Dialog({
169 id: "searchDlg",
170 title: __("Search"),
171 style: "width: 600px",
172 execute: function() {
173 if (this.validate()) {
174 _search_query = dojo.objectToQuery(this.attr('value'));
175 this.hide();
176 viewCurrentFeed();
177 }
178 },
179 href: query});
180
181 dialog.show();
76798ff3 182}
1cd17194 183
f8fb4498 184function updateTitle() {
99534a3d 185 var tmp = "Tiny Tiny RSS";
21703604 186
fc69e641 187 if (global_unread > 0) {
3a693fa7 188 tmp = "(" + global_unread + ") " + tmp;
fc69e641
AD
189 }
190
fdf47b9d
AD
191 if (window.fluid) {
192 if (global_unread > 0) {
193 window.fluid.dockBadge = global_unread;
194 } else {
195 window.fluid.dockBadge = "";
196 }
197 }
198
fc69e641
AD
199 document.title = tmp;
200}
201
22a93ad8 202function genericSanityCheck() {
57937c42 203 setCookie("ttrss_test", "TEST");
009646d2 204
57937c42 205 if (getCookie("ttrss_test") != "TEST") {
68535211 206 return fatalError(2);
295f9b42
AD
207 }
208
22a93ad8
AD
209 return true;
210}
211
9fabf9fc 212
22a93ad8 213function init() {
7719618b 214 try {
04150375 215 //dojo.registerModulePath("fox", "../../js/");
05f224a3
AD
216
217 dojo.require("fox.FeedTree");
218
1354d172
AD
219 dojo.require("dijit.ColorPalette");
220 dojo.require("dijit.Dialog");
221 dojo.require("dijit.form.Button");
222 dojo.require("dijit.form.CheckBox");
223 dojo.require("dijit.form.DropDownButton");
224 dojo.require("dijit.form.FilteringSelect");
225 dojo.require("dijit.form.Form");
226 dojo.require("dijit.form.RadioButton");
227 dojo.require("dijit.form.Select");
228 dojo.require("dijit.form.SimpleTextarea");
229 dojo.require("dijit.form.TextBox");
230 dojo.require("dijit.form.ValidationTextBox");
231 dojo.require("dijit.InlineEditBox");
232 dojo.require("dijit.layout.AccordionContainer");
233 dojo.require("dijit.layout.BorderContainer");
234 dojo.require("dijit.layout.ContentPane");
235 dojo.require("dijit.layout.TabContainer");
236 dojo.require("dijit.Menu");
237 dojo.require("dijit.ProgressBar");
238 dojo.require("dijit.ProgressBar");
239 dojo.require("dijit.Toolbar");
240 dojo.require("dijit.Tree");
241 dojo.require("dijit.tree.dndSource");
242 dojo.require("dojo.data.ItemFileWriteStore");
243
d80b3f3d
AD
244 dojo.parser.parse();
245
009646d2 246 if (!genericSanityCheck())
68535211 247 return false;
ac43eba1 248
fcc36744 249 loading_set_progress(20);
fca95d5f 250
40fe2d73
AD
251 var a = document.createElement('audio');
252
253 var hasAudio = !!a.canPlayType;
4f7d69e1 254 var hasSandbox = "sandbox" in document.createElement("iframe");
40fe2d73 255 var hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));
c3edc667 256
b4e75b2a 257 new Ajax.Request("backend.php", {
4f7d69e1 258 parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio,
40fe2d73 259 hasMp3: hasMp3,
4f7d69e1 260 hasSandbox: hasSandbox},
9ca945a6
AD
261 onComplete: function(transport) {
262 backend_sanity_check_callback(transport);
263 } });
b6c2c963 264
9fabf9fc
PM
265 hotkey_actions["next_feed"] = function() {
266 var rv = dijit.byId("feedTree").getNextFeed(
267 getActiveFeedId(), activeFeedIsCat());
268
269 if (rv) viewfeed(rv[0], '', rv[1]);
270 };
271 hotkey_actions["prev_feed"] = function() {
272 var rv = dijit.byId("feedTree").getPreviousFeed(
273 getActiveFeedId(), activeFeedIsCat());
274
275 if (rv) viewfeed(rv[0], '', rv[1]);
276 };
277 hotkey_actions["next_article"] = function() {
278 moveToPost('next');
279 };
280 hotkey_actions["prev_article"] = function() {
281 moveToPost('prev');
282 };
283 hotkey_actions["next_article_noscroll"] = function() {
284 moveToPost('next', true);
285 };
286 hotkey_actions["prev_article_noscroll"] = function() {
287 moveToPost('prev', true);
288 };
8b35d171
SC
289 hotkey_actions["next_article_noexpand"] = function() {
290 moveToPost('next', true, true);
291 };
292 hotkey_actions["prev_article_noexpand"] = function() {
293 moveToPost('prev', true, true);
294 };
9fabf9fc
PM
295 hotkey_actions["collapse_article"] = function() {
296 var id = getActiveArticleId();
297 var elem = $("CICD-"+id);
298 if(elem.visible()) {
299 cdmCollapseArticle(null, id);
300 }
301 else {
302 cdmExpandArticle(id);
303 }
304 };
8b35d171
SC
305 hotkey_actions["toggle_expand"] = function() {
306 var id = getActiveArticleId();
307 var elem = $("CICD-"+id);
308 if(elem.visible()) {
309 cdmUnexpandArticle(null, id);
310 }
311 else {
312 cdmExpandArticle(id);
313 }
314 };
9fabf9fc
PM
315 hotkey_actions["search_dialog"] = function() {
316 search();
317 };
318 hotkey_actions["toggle_mark"] = function() {
319 selectionToggleMarked(undefined, false, true);
320 };
321 hotkey_actions["toggle_publ"] = function() {
322 selectionTogglePublished(undefined, false, true);
323 };
324 hotkey_actions["toggle_unread"] = function() {
325 selectionToggleUnread(undefined, false, true);
326 };
327 hotkey_actions["edit_tags"] = function() {
328 var id = getActiveArticleId();
329 if (id) {
330 editArticleTags(id, getActiveFeedId(), isCdmMode());
331 };
332 }
333 hotkey_actions["dismiss_selected"] = function() {
334 dismissSelectedArticles();
335 };
336 hotkey_actions["open_in_new_window"] = function() {
337 if (getActiveArticleId()) {
338 openArticleInNewWindow(getActiveArticleId());
339 return;
340 }
341 };
342 hotkey_actions["catchup_below"] = function() {
343 catchupRelativeToArticle(1);
344 };
345 hotkey_actions["catchup_above"] = function() {
346 catchupRelativeToArticle(0);
347 };
348 hotkey_actions["article_scroll_down"] = function() {
349 var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
350
cee09850 351 scrollArticle(40);
9fabf9fc
PM
352 };
353 hotkey_actions["article_scroll_up"] = function() {
354 var ctr = $("content_insert") ? $("content_insert") : $("headlines-frame");
355
cee09850 356 scrollArticle(-40);
9fabf9fc
PM
357 };
358 hotkey_actions["close_article"] = function() {
359 if (isCdmMode()) {
360 if (!getInitParam("cdm_expanded")) {
361 cdmCollapseArticle(false, getActiveArticleId());
362 } else {
363 dismissArticle(getActiveArticleId());
364 }
365 } else {
366 closeArticlePanel();
367 }
368 };
369 hotkey_actions["email_article"] = function() {
370 if (typeof emailArticle != "undefined") {
371 emailArticle();
372 } else if (typeof mailtoArticle != "undefined") {
373 mailtoArticle();
374 } else {
375 alert(__("Please enable mail plugin first."));
376 }
377 };
378 hotkey_actions["select_all"] = function() {
379 selectArticles('all');
380 };
381 hotkey_actions["select_unread"] = function() {
382 selectArticles('unread');
383 };
384 hotkey_actions["select_marked"] = function() {
385 selectArticles('marked');
386 };
387 hotkey_actions["select_published"] = function() {
388 selectArticles('published');
389 };
390 hotkey_actions["select_invert"] = function() {
391 selectArticles('invert');
392 };
393 hotkey_actions["select_none"] = function() {
394 selectArticles('none');
395 };
396 hotkey_actions["feed_refresh"] = function() {
397 if (getActiveFeedId() != undefined) {
398 viewfeed(getActiveFeedId(), '', activeFeedIsCat());
399 return;
400 }
401 };
402 hotkey_actions["feed_unhide_read"] = function() {
403 toggleDispRead();
404 };
405 hotkey_actions["feed_subscribe"] = function() {
406 quickAddFeed();
407 };
408 hotkey_actions["feed_debug_update"] = function() {
409 window.open("backend.php?op=feeds&method=view&feed=" + getActiveFeedId() +
410 "&view_mode=adaptive&order_by=default&update=&m=ForceUpdate&cat=" +
411 activeFeedIsCat() + "&DevForceUpdate=1&debug=1&xdebug=1&csrf_token=" +
412 getInitParam("csrf_token"));
413 };
414 hotkey_actions["feed_edit"] = function() {
415 if (activeFeedIsCat())
416 alert(__("You can't edit this kind of feed."));
417 else
418 editFeed(getActiveFeedId());
419 };
420 hotkey_actions["feed_catchup"] = function() {
421 if (getActiveFeedId() != undefined) {
422 catchupCurrentFeed();
423 return;
424 }
425 };
426 hotkey_actions["feed_reverse"] = function() {
427 reverseHeadlineOrder();
428 };
429 hotkey_actions["catchup_all"] = function() {
430 catchupAllFeeds();
431 };
432 hotkey_actions["cat_toggle_collapse"] = function() {
433 if (activeFeedIsCat()) {
434 dijit.byId("feedTree").collapseCat(getActiveFeedId());
435 return;
436 }
437 };
438 hotkey_actions["goto_all"] = function() {
439 viewfeed(-4);
440 };
441 hotkey_actions["goto_fresh"] = function() {
442 viewfeed(-3);
443 };
444 hotkey_actions["goto_marked"] = function() {
445 viewfeed(-1);
446 };
447 hotkey_actions["goto_published"] = function() {
448 viewfeed(-2);
449 };
450 hotkey_actions["goto_tagcloud"] = function() {
fb54e3b1 451 displayDlg(__("Tag cloud"), "printTagCloud");
9fabf9fc
PM
452 };
453 hotkey_actions["goto_prefs"] = function() {
454 gotoPreferences();
455 };
456 hotkey_actions["select_article_cursor"] = function() {
457 var id = getArticleUnderPointer();
458 if (id) {
7e27c914
AD
459 var row = $("RROW-" + id);
460
461 if (row) {
462 var cb = dijit.getEnclosingWidget(
463 row.getElementsByClassName("rchk")[0]);
464
465 if (cb) {
466 cb.attr("checked", !cb.attr("checked"));
467 toggleSelectRowById(cb, "RROW-" + id);
468 return false;
469 }
9fabf9fc
PM
470 }
471 }
472 };
473 hotkey_actions["create_label"] = function() {
474 addLabel();
475 };
476 hotkey_actions["create_filter"] = function() {
477 quickAddFilter();
478 };
479 hotkey_actions["collapse_sidebar"] = function() {
480 collapse_feedlist();
481 };
482 hotkey_actions["toggle_embed_original"] = function() {
483 if (typeof embedOriginalArticle != "undefined") {
484 if (getActiveArticleId())
485 embedOriginalArticle(getActiveArticleId());
486 } else {
487 alert(__("Please enable embed_original plugin first."));
488 }
489 };
490 hotkey_actions["toggle_widescreen"] = function() {
491 if (!isCdmMode()) {
492 _widescreen_mode = !_widescreen_mode;
493
494 switchPanelMode(_widescreen_mode);
495 }
496 };
497 hotkey_actions["help_dialog"] = function() {
498 helpDialog("main");
499 };
500 hotkey_actions["toggle_combined_mode"] = function() {
501 notify_progress("Loading, please wait...");
502
503 var value = isCdmMode() ? "false" : "true";
504 var query = "?op=rpc&method=setpref&key=COMBINED_DISPLAY_MODE&value=" + value;
505
506 new Ajax.Request("backend.php", {
507 parameters: query,
508 onComplete: function(transport) {
22af1232
AD
509 setInitParam("combined_display_mode",
510 !getInitParam("combined_display_mode"));
511
512 closeArticlePanel();
513 viewCurrentFeed();
514
515 } });
9fabf9fc 516 };
60b88b25
AD
517 hotkey_actions["toggle_cdm_expanded"] = function() {
518 notify_progress("Loading, please wait...");
519
520 var value = getInitParam("cdm_expanded") ? "false" : "true";
521 var query = "?op=rpc&method=setpref&key=CDM_EXPANDED&value=" + value;
522
523 new Ajax.Request("backend.php", {
524 parameters: query,
525 onComplete: function(transport) {
526 setInitParam("cdm_expanded", !getInitParam("cdm_expanded"));
527 viewCurrentFeed();
528 } });
529 };
9fabf9fc 530
47179952 531
7719618b
AD
532 } catch (e) {
533 exception_error("init", e);
a8d28f48 534 }
7719618b 535}
86741347 536
7719618b 537function init_second_stage() {
295f9b42 538
7719618b 539 try {
118f4180
AD
540 dojo.addOnLoad(function() {
541 updateFeedList();
542 closeArticlePanel();
543
7d8f5657
AD
544 _widescreen_mode = getInitParam("widescreen");
545
546 if (_widescreen_mode) {
547 switchPanelMode(_widescreen_mode);
548 }
549
118f4180 550 });
2f587484 551
57937c42 552 delCookie("ttrss_test");
770bbb02 553
40496720 554 var toolbar = document.forms["main_toolbar_form"];
f31673f7 555
009646d2 556 dijit.getEnclosingWidget(toolbar.view_mode).attr('value',
37f1a234
AD
557 getInitParam("default_view_mode"));
558
009646d2 559 dijit.getEnclosingWidget(toolbar.order_by).attr('value',
37f1a234 560 getInitParam("default_view_order_by"));
c6784aea 561
61a20560 562 feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1;
5f136c9a 563
4480b26e
AD
564 var hash_feed_id = hash_get('f');
565 var hash_feed_is_cat = hash_get('c') == "1";
566
567 if (hash_feed_id != undefined) {
568 setActiveFeedId(hash_feed_id, hash_feed_is_cat);
569 }
570
fcc36744 571 loading_set_progress(30);
730dbf19 572
37c03d3a
AD
573 // can't use cache_clear() here because viewfeed might not have initialized yet
574 if ('sessionStorage' in window && window['sessionStorage'] !== null)
575 sessionStorage.clear();
ff0010c1 576
e5e2cf3b
AD
577 var hotkeys = getInitParam("hotkeys");
578 var tmp = [];
579
580 for (sequence in hotkeys[1]) {
581 filtered = sequence.replace(/\|.*$/, "");
582 tmp[filtered] = hotkeys[1][sequence];
583 }
584
585 hotkeys[1] = tmp;
586 setInitParam("hotkeys", hotkeys);
587
4a28ab44 588 console.log("second stage ok");
fcf70c51 589
8b83bf5f
AD
590 if (getInitParam("simple_update")) {
591 console.log("scheduling simple feed updater...");
592 window.setTimeout("update_random_feed()", 30*1000);
593 }
594
7719618b
AD
595 } catch (e) {
596 exception_error("init_second_stage", e);
2f587484 597 }
1cd17194 598}
ac43eba1 599
c09ec856 600function quickMenuGo(opid) {
bb3423cf 601 try {
2d1282d4
AD
602 switch (opid) {
603 case "qmcPrefs":
bb3423cf 604 gotoPreferences();
2d1282d4
AD
605 break;
606 case "qmcLogout":
607 gotoLogout();
608 break;
609 case "qmcTagCloud":
fb54e3b1 610 displayDlg(__("Tag cloud"), "printTagCloud");
2d1282d4
AD
611 break;
612 case "qmcTagSelect":
fb54e3b1 613 displayDlg(__("Select item(s) by tags"), "printTagSelect");
2d1282d4
AD
614 break;
615 case "qmcSearch":
973fe3c6 616 search();
2d1282d4
AD
617 break;
618 case "qmcAddFeed":
3393238d 619 quickAddFeed();
2d1282d4
AD
620 break;
621 case "qmcDigest":
ac220751 622 window.location.href = "backend.php?op=digest";
2d1282d4
AD
623 break;
624 case "qmcEditFeed":
33f31dfd
AD
625 if (activeFeedIsCat())
626 alert(__("You can't edit this kind of feed."));
627 else
628 editFeed(getActiveFeedId());
2d1282d4
AD
629 break;
630 case "qmcRemoveFeed":
bb3423cf 631 var actid = getActiveFeedId();
442d77f1
AD
632
633 if (activeFeedIsCat()) {
89cb787e 634 alert(__("You can't unsubscribe from the category."));
442d77f1 635 return;
009646d2 636 }
442d77f1
AD
637
638 if (!actid) {
89cb787e 639 alert(__("Please select some feed first."));
bb3423cf
AD
640 return;
641 }
64a2875d
AD
642
643 var fn = getFeedName(actid);
89cb787e
AD
644
645 var pr = __("Unsubscribe from %s?").replace("%s", fn);
646
647 if (confirm(pr)) {
e978f78d 648 unsubscribeFeed(actid);
bb3423cf 649 }
2d1282d4
AD
650 break;
651 case "qmcCatchupAll":
bb3423cf 652 catchupAllFeeds();
2d1282d4
AD
653 break;
654 case "qmcShowOnlyUnread":
bb3423cf 655 toggleDispRead();
2d1282d4
AD
656 break;
657 case "qmcAddFilter":
db4e4539 658 quickAddFilter();
2d1282d4
AD
659 break;
660 case "qmcAddLabel":
1380f8ee 661 addLabel();
2d1282d4
AD
662 break;
663 case "qmcRescoreFeed":
9a85081a 664 rescoreCurrentFeed();
2d1282d4
AD
665 break;
666 case "qmcToggleWidescreen":
1bcf8f45
AD
667 if (!isCdmMode()) {
668 _widescreen_mode = !_widescreen_mode;
669
670 switchPanelMode(_widescreen_mode);
671 }
2d1282d4
AD
672 break;
673 case "qmcHKhelp":
b8cb4d08 674 helpDialog("main");
2d1282d4
AD
675 break;
676 default:
677 console.log("quickMenuGo: unknown action: " + opid);
238eff01
AD
678 }
679
bb3423cf
AD
680 } catch (e) {
681 exception_error("quickMenuGo", e);
a24f525c 682 }
e2f8f7b4
AD
683}
684
3745788e 685function toggleDispRead() {
7f123cda 686 try {
3745788e 687
dbfc9522 688 var hide = !(getInitParam("hide_read_feeds") == "1");
3745788e 689
dbfc9522 690 hideOrShowFeeds(hide);
e8bd0da9 691
f30ef1fa 692 var query = "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" +
dbfc9522 693 param_escape(hide);
e8bd0da9 694
05f224a3
AD
695 setInitParam("hide_read_feeds", hide);
696
dbfc9522
AD
697 new Ajax.Request("backend.php", {
698 parameters: query,
009646d2 699 onComplete: function(transport) {
dbfc9522 700 } });
009646d2 701
7f123cda
AD
702 } catch (e) {
703 exception_error("toggleDispRead", e);
3745788e 704 }
3745788e 705}
295f9b42 706
563b9c78 707function parse_runtime_info(data) {
71ad883b 708
f8fb4498 709 //console.log("parsing runtime info...");
1cb7492d 710
c4f7ba80
AD
711 for (k in data) {
712 var v = data[k];
3ac2b520 713
563b9c78 714// console.log("RI: " + k + " => " + v);
1cb7492d 715
d9fa39f1 716 if (k == "new_version_available") {
2d1282d4
AD
717 if (v == "1") {
718 Element.show(dijit.byId("newVersionIcon").domNode);
719 } else {
720 Element.hide(dijit.byId("newVersionIcon").domNode);
d9fa39f1 721 }
5ae8f858 722 return;
d9fa39f1
AD
723 }
724
16314dda 725 if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
4cdb8173 726 if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) {
16314dda
AD
727 window.location.reload();
728 }
729 }
730
ef16ae37 731 if (k == "daemon_is_running" && v != 1) {
8e00ae9b 732 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true);
5ae8f858 733 return;
8e00ae9b
AD
734 }
735
736 if (k == "daemon_stamp_ok" && v != 1) {
737 notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true);
5ae8f858 738 return;
8e00ae9b
AD
739 }
740
8cd576a1
AD
741 if (k == "max_feed_id" || k == "num_feeds") {
742 if (init_params[k] != v) {
743 console.log("feed count changed, need to reload feedlist.");
744 updateFeedList();
745 }
746 }
747
009646d2 748 init_params[k] = v;
5ae8f858 749 notify('');
71ad883b
AD
750 }
751}
fce24838 752
8389b150
AD
753function collapse_feedlist() {
754 try {
0ce61157
AD
755
756 if (!Element.visible('feeds-holder')) {
757 Element.show('feeds-holder');
ab7b5042 758 Element.show('feeds-holder_splitter');
0ce61157
AD
759 $("collapse_feeds_btn").innerHTML = "&lt;&lt;";
760 } else {
761 Element.hide('feeds-holder');
ab7b5042 762 Element.hide('feeds-holder_splitter');
0ce61157
AD
763 $("collapse_feeds_btn").innerHTML = "&gt;&gt;";
764 }
765
766 dijit.byId("main").resize();
6e4f4ce1 767
f30ef1fa 768 query = "?op=rpc&method=setpref&key=_COLLAPSED_FEEDLIST&value=true";
fcf70c51 769 new Ajax.Request("backend.php", { parameters: query });
6e4f4ce1 770
8389b150 771 } catch (e) {
f88c7814 772 exception_error("collapse_feedlist", e);
8389b150 773 }
3c2d7945 774}
8389b150 775
3c2d7945 776function viewModeChanged() {
4f79e9aa 777 cache_clear();
e331188f 778 return viewCurrentFeed('');
3c2d7945 779}
8389b150 780
9a85081a
AD
781function rescoreCurrentFeed() {
782
783 var actid = getActiveFeedId();
784
9c99281f 785 if (activeFeedIsCat() || actid < 0) {
9a85081a
AD
786 alert(__("You can't rescore this kind of feed."));
787 return;
009646d2 788 }
9a85081a
AD
789
790 if (!actid) {
791 alert(__("Please select some feed first."));
792 return;
793 }
794
795 var fn = getFeedName(actid);
69811a7d 796 var pr = __("Rescore articles in %s?").replace("%s", fn);
9a85081a
AD
797
798 if (confirm(pr)) {
799 notify_progress("Rescoring articles...");
800
f30ef1fa 801 var query = "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid;
9a85081a 802
b4e75b2a
AD
803 new Ajax.Request("backend.php", {
804 parameters: query,
805 onComplete: function(transport) {
806 viewCurrentFeed();
807 } });
9a85081a
AD
808 }
809}
810
93f66472 811function hotkey_handler(e) {
93f66472
AD
812 try {
813
8386f861 814 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
18606807 815
e331188f 816 var keycode = false;
93f66472
AD
817 var shift_key = false;
818
78935092 819 var cmdline = $('cmdline');
93f66472 820
3fb40112
AD
821 shift_key = e.shiftKey;
822 ctrl_key = e.ctrlKey;
009646d2 823
93f66472
AD
824 if (window.event) {
825 keycode = window.event.keyCode;
826 } else if (e) {
827 keycode = e.which;
828 }
829
eec498c3 830 var keychar = String.fromCharCode(keycode);
c177f2e6 831
93f66472 832 if (keycode == 27) { // escape
93f66472 833 hotkey_prefix = false;
009646d2 834 }
93f66472 835
93f66472 836 if (keycode == 16) return; // ignore lone shift
ac743c83 837 if (keycode == 17) return; // ignore lone ctrl
93f66472 838
5b18c936 839 keychar = keychar.toLowerCase();
a83b58f1 840
e218c5f5
AD
841 var hotkeys = getInitParam("hotkeys");
842
843 if (!hotkey_prefix && hotkeys[0].indexOf(keychar) != -1) {
a83b58f1
AD
844
845 var date = new Date();
846 var ts = Math.round(date.getTime() / 1000);
847
848 hotkey_prefix = keychar;
849 hotkey_prefix_pressed = ts;
850
851 cmdline.innerHTML = keychar;
852 Element.show(cmdline);
853
854 return true;
855 }
856
857 Element.hide(cmdline);
858
859 var hotkey = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
5b18c936
AD
860
861 // ensure ^*char notation
862 if (shift_key) hotkey = "*" + hotkey;
3fb40112 863 if (ctrl_key) hotkey = "^" + hotkey;
5b18c936 864
a83b58f1
AD
865 hotkey = hotkey_prefix ? hotkey_prefix + " " + hotkey : hotkey;
866 hotkey_prefix = false;
867
868 var hotkey_action = false;
869 var hotkeys = getInitParam("hotkeys");
870
e218c5f5
AD
871 for (sequence in hotkeys[1]) {
872 if (sequence == hotkey) {
873 hotkey_action = hotkeys[1][sequence];
874 break;
a83b58f1
AD
875 }
876 }
877
9fabf9fc 878 var action = hotkey_actions[hotkey_action];
b6c2c963
AD
879
880 if (action != null) {
881 action();
882 return false;
883 }
a83b58f1 884
93f66472
AD
885 } catch (e) {
886 exception_error("hotkey_handler", e);
887 }
888}
61a20560 889
a5819bb3
AD
890function inPreferences() {
891 return false;
892}
8a3e0b1a
AD
893
894function reverseHeadlineOrder() {
895 try {
896
b9a06a0e 897 /* var query_str = "?op=rpc&method=togglepref&key=REVERSE_HEADLINES";
8a3e0b1a
AD
898
899 new Ajax.Request("backend.php", {
900 parameters: query_str,
009646d2 901 onComplete: function(transport) {
8a3e0b1a 902 viewCurrentFeed();
b9a06a0e
AD
903 } }); */
904
905 var toolbar = document.forms["main_toolbar_form"];
906 var order_by = dijit.getEnclosingWidget(toolbar.order_by);
907
908 var value = order_by.attr('value');
909
910 if (value == "date_reverse")
911 value = "default";
912 else
913 value = "date_reverse";
914
915 order_by.attr('value', value);
916
917 viewCurrentFeed();
8a3e0b1a
AD
918
919 } catch (e) {
920 exception_error("reverseHeadlineOrder", e);
921 }
922}
fe1087fb 923
63855db1
AD
924function newVersionDlg() {
925 try {
3f363052 926 var query = "backend.php?op=dlg&method=newVersion";
63855db1
AD
927
928 if (dijit.byId("newVersionDlg"))
929 dijit.byId("newVersionDlg").destroyRecursive();
930
931 dialog = new dijit.Dialog({
932 id: "newVersionDlg",
933 title: __("New version available!"),
934 style: "width: 600px",
935 href: query,
936 });
937
938 dialog.show();
939
940 } catch (e) {
941 exception_error("newVersionDlg", e);
942 }
943}
563b9c78
AD
944
945function handle_rpc_json(transport, scheduled_call) {
946 try {
947 var reply = JSON.parse(transport.responseText);
948
949 if (reply) {
950
951 var error = reply['error'];
952
953 if (error) {
954 var code = error['code'];
955 var msg = error['msg'];
009646d2
AD
956
957 console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg);
958
563b9c78
AD
959 if (code != 0) {
960 fatalError(code, msg);
961 return false;
962 }
963 }
964
965 var seq = reply['seq'];
966
967 if (seq) {
968 if (get_seq() != seq) {
009646d2 969 console.log("[handle_rpc_json] sequence mismatch: " + seq +
563b9c78
AD
970 " (want: " + get_seq() + ")");
971 return true;
972 }
973 }
974
975 var message = reply['message'];
976
977 if (message) {
978 if (message == "UPDATE_COUNTERS") {
979 console.log("need to refresh counters...");
980 setInitParam("last_article_id", -1);
5b55e9e2 981 request_counters(true);
563b9c78
AD
982 }
983 }
984
985 var counters = reply['counters'];
009646d2 986
563b9c78
AD
987 if (counters)
988 parse_counters(counters, scheduled_call);
989
990 var runtime_info = reply['runtime-info'];;
991
992 if (runtime_info)
993 parse_runtime_info(runtime_info);
994
2d1282d4 995 Element.hide(dijit.byId("net-alert").domNode);
6effae6d 996
563b9c78 997 } else {
6effae6d 998 //notify_error("Error communicating with server.");
2d1282d4 999 Element.show(dijit.byId("net-alert").domNode);
563b9c78
AD
1000 }
1001
1002 } catch (e) {
2d1282d4 1003 Element.show(dijit.byId("net-alert").domNode);
6effae6d 1004 //notify_error("Error communicating with server.");
beb119a2
AD
1005 console.log(e);
1006 //exception_error("handle_rpc_json", e, transport);
563b9c78
AD
1007 }
1008
1009 return true;
1010}
1011
1bcf8f45
AD
1012function switchPanelMode(wide) {
1013 try {
c186beae
AD
1014 if (isCdmMode()) return;
1015
1bcf8f45
AD
1016 article_id = getActiveArticleId();
1017
1018 if (wide) {
1019 dijit.byId("headlines-wrap-inner").attr("design", 'sidebar');
1020 dijit.byId("content-insert").attr("region", "trailing");
1021
1022 dijit.byId("content-insert").domNode.setStyle({width: '50%',
1023 height: 'auto',
533bd7b7
AD
1024 borderLeftWidth: '1px',
1025 borderLeftColor: '#c0c0c0',
fd535b31 1026 borderTopWidth: '0px' });
1bcf8f45 1027
fd535b31 1028 $("headlines-toolbar").setStyle({ borderBottomWidth: '0px' });
1bcf8f45
AD
1029
1030 } else {
1031
1032 dijit.byId("content-insert").attr("region", "bottom");
1033
1034 dijit.byId("content-insert").domNode.setStyle({width: 'auto',
1035 height: '50%',
533bd7b7 1036 borderLeftWidth: '0px',
8853f0ed 1037 borderTopWidth: '1px'});
1bcf8f45 1038
fd535b31 1039 $("headlines-toolbar").setStyle({ borderBottomWidth: '1px' });
1bcf8f45
AD
1040 }
1041
1042 closeArticlePanel();
1043
1044 if (article_id) view(article_id);
1045
7d8f5657
AD
1046 new Ajax.Request("backend.php", {
1047 parameters: "op=rpc&method=setpanelmode&wide=" + (wide ? 1 : 0),
1048 onComplete: function(transport) {
1049 console.log(transport.responseText);
1050 } });
1051
1052
1bcf8f45
AD
1053 } catch (e) {
1054 exception_error("switchPanelMode", e);
1055 }
1056}
8b83bf5f
AD
1057
1058function update_random_feed() {
1059 try {
1060 console.log("in update_random_feed");
1061
1062 new Ajax.Request("backend.php", {
1063 parameters: "op=rpc&method=updateRandomFeed",
1064 onComplete: function(transport) {
1065 handle_rpc_json(transport, true);
1066 window.setTimeout("update_random_feed()", 30*1000);
1067 } });
1068
1069 } catch (e) {
1070 exception_error("update_random_feed", e);
1071 }
1072}
1b04a298
AD
1073
1074function hash_get(key) {
1075 try {
1076 kv = window.location.hash.substring(1).toQueryParams();
1077 return kv[key];
1078 } catch (e) {
3cc5a3cd 1079 exception_error("hash_get", e);
1b04a298
AD
1080 }
1081}
1082function hash_set(key, value) {
1083 try {
1084 kv = window.location.hash.substring(1).toQueryParams();
1085 kv[key] = value;
1086 window.location.hash = $H(kv).toQueryString();
1087 } catch (e) {
1088 exception_error("hash_set", e);
1089 }
1090}