]> git.wh0rd.org - tt-rss.git/blame - js/tt-rss.js
remove expandable CDM headlines
[tt-rss.git] / js / tt-rss.js
CommitLineData
4508e310
AD
1/* global dijit, __ */
2
8572e010 3let global_unread = -1;
8572e010
AD
4let _widescreen_mode = false;
5let _rpc_seq = 0;
6let _active_feed_id = 0;
7let _active_feed_is_cat = false;
7e8be97b 8let hotkey_actions = {};
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() {
0d272273 20 return !!_active_feed_is_cat;
3d72bbdb
AD
21}
22
23function getActiveFeedId() {
1bfe1d7b 24 return _active_feed_id;
3d72bbdb
AD
25}
26
27function setActiveFeedId(id, is_cat) {
1bfe1d7b
AD
28 hash_set('f', id);
29 hash_set('c', is_cat ? 1 : 0);
3d72bbdb 30
1bfe1d7b
AD
31 _active_feed_id = id;
32 _active_feed_is_cat = is_cat;
535a4c7d 33
1bfe1d7b
AD
34 $("headlines-frame").setAttribute("feed-id", id);
35 $("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0);
67b9d740 36
1bfe1d7b 37 selectFeed(id, is_cat);
8d388f32 38
1bfe1d7b 39 PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, _active_article_id);
3d72bbdb
AD
40}
41
42
50eefedb 43function updateFeedList() {
e0a957b3
AD
44 try {
45 Element.show("feedlistLoading");
102cfe73 46
e0a957b3 47 resetCounterCache();
9c99281f 48
e0a957b3
AD
49 if (dijit.byId("feedTree")) {
50 dijit.byId("feedTree").destroyRecursive();
1bfe1d7b 51 }
c73b739b 52
424e28db 53 const store = new dojo.data.ItemFileWriteStore({
e0a957b3
AD
54 url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2"
55 });
56
424e28db 57 const treeModel = new fox.FeedStoreModel({
e0a957b3
AD
58 store: store,
59 query: {
60 "type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
61 },
62 rootId: "root",
63 rootLabel: "Feeds",
64 childrenAttrs: ["items"]
65 });
66
424e28db 67 const tree = new fox.FeedTree({
e0a957b3
AD
68 model: treeModel,
69 onClick: function (item, node) {
424e28db
AD
70 const id = String(item.id);
71 const is_cat = id.match("^CAT:");
72 const feed = id.substr(id.indexOf(":") + 1);
e0a957b3
AD
73 viewfeed({feed: feed, is_cat: is_cat});
74 return false;
75 },
76 openOnClick: false,
77 showRoot: false,
78 persist: true,
79 id: "feedTree",
80 }, "feedTree");
81
e0a957b3
AD
82 var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) {
83 console.log(dijit.getEnclosingWidget(event.target));
84 dojo.disconnect(tmph);
85 });
86
87 $("feeds-holder").appendChild(tree.domNode);
88
89 var tmph = dojo.connect(tree, 'onLoad', function () {
90 dojo.disconnect(tmph);
91 Element.hide("feedlistLoading");
92
93 try {
94 feedlist_init();
95
96 loading_set_progress(25);
97 } catch (e) {
98 exception_error(e);
99 }
100 });
101
102 tree.startup();
103 } catch (e) {
104 exception_error(e);
105 }
1a66d16e 106}
175847de 107
476cac42 108function catchupAllFeeds() {
076682aa 109
424e28db 110 const str = __("Mark all articles as read?");
476cac42 111
f8232151 112 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
476cac42 113
f8232151 114 notify_progress("Marking all feeds as read...");
476cac42 115
0d272273
AD
116 xhrPost("backend.php", {op: "feeds", method: "catchupAll"}, () => {
117 request_counters(true);
118 viewCurrentFeed();
119 });
f8232151
AD
120
121 global_unread = 0;
122 updateTitle("");
123 }
476cac42 124}
1cd17194 125
791877c3
AD
126function viewCurrentFeed(method) {
127 console.log("viewCurrentFeed: " + method);
1a66d16e 128
ec6e2fd3 129 if (getActiveFeedId() != undefined) {
791877c3 130 viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), method: method});
f0601b87 131 }
164f4738 132 return false; // block unneeded form submits
f0601b87
AD
133}
134
40d13c28 135function timeout() {
5b55e9e2 136 if (getInitParam("bw_limit") != "1") {
22adcd74 137 request_counters(true);
88946d33 138 setTimeout(timeout, 60*1000);
f8fb4498 139 }
ac53063a
AD
140}
141
f0601b87 142function search() {
424e28db 143 const query = "backend.php?op=feeds&method=search&param=" +
973fe3c6
AD
144 param_escape(getActiveFeedId() + ":" + activeFeedIsCat());
145
146 if (dijit.byId("searchDlg"))
147 dijit.byId("searchDlg").destroyRecursive();
148
424e28db 149 const dialog = new dijit.Dialog({
973fe3c6
AD
150 id: "searchDlg",
151 title: __("Search"),
152 style: "width: 600px",
153 execute: function() {
154 if (this.validate()) {
560b9fdd 155 _search_query = this.attr('value');
973fe3c6
AD
156 this.hide();
157 viewCurrentFeed();
158 }
159 },
160 href: query});
161
162 dialog.show();
76798ff3 163}
1cd17194 164
f8fb4498 165function updateTitle() {
424e28db 166 let tmp = "Tiny Tiny RSS";
21703604 167
fc69e641 168 if (global_unread > 0) {
3a693fa7 169 tmp = "(" + global_unread + ") " + tmp;
fc69e641
AD
170 }
171
fc69e641
AD
172 document.title = tmp;
173}
174
22a93ad8 175function genericSanityCheck() {
57937c42 176 setCookie("ttrss_test", "TEST");
009646d2 177
57937c42 178 if (getCookie("ttrss_test") != "TEST") {
68535211 179 return fatalError(2);
295f9b42
AD
180 }
181
22a93ad8
AD
182 return true;
183}
184
9fabf9fc 185
22a93ad8 186function init() {
0dbc20a8 187
1bfe1d7b
AD
188 window.onerror = function(message, filename, lineno, colno, error) {
189 report_error(message, filename, lineno, colno, error);
190 };
191
192 require(["dojo/_base/kernel",
193 "dojo/ready",
194 "dojo/parser",
195 "dojo/_base/loader",
196 "dojo/_base/html",
197 "dojo/query",
198 "dijit/ProgressBar",
199 "dijit/ColorPalette",
200 "dijit/Dialog",
201 "dijit/form/Button",
202 "dijit/form/ComboButton",
203 "dijit/form/CheckBox",
204 "dijit/form/DropDownButton",
205 "dijit/form/FilteringSelect",
206 "dijit/form/Form",
207 "dijit/form/RadioButton",
208 "dijit/form/Select",
267bcee3 209 "dijit/form/MultiSelect",
1bfe1d7b
AD
210 "dijit/form/SimpleTextarea",
211 "dijit/form/TextBox",
212 "dijit/form/ComboBox",
213 "dijit/form/ValidationTextBox",
214 "dijit/InlineEditBox",
215 "dijit/layout/AccordionContainer",
216 "dijit/layout/BorderContainer",
217 "dijit/layout/ContentPane",
218 "dijit/layout/TabContainer",
219 "dijit/PopupMenuItem",
220 "dijit/Menu",
221 "dijit/Toolbar",
222 "dijit/Tree",
223 "dijit/tree/dndSource",
224 "dijit/tree/ForestStoreModel",
225 "dojo/data/ItemFileWriteStore",
a3e2f1a9 226 "fox/FeedStoreModel",
1bfe1d7b
AD
227 "fox/FeedTree" ], function (dojo, ready, parser) {
228
229 ready(function() {
230
231 try {
546b419f 232 parser.parse();
0dbc20a8
AD
233
234 if (!genericSanityCheck())
235 return false;
236
237 loading_set_progress(30);
0dbc20a8
AD
238 init_hotkey_actions();
239
fd752a79
AD
240 const a = document.createElement('audio');
241 const hasAudio = !!a.canPlayType;
242 const hasSandbox = "sandbox" in document.createElement("iframe");
243 const hasMp3 = !!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''));
244 const clientTzOffset = new Date().getTimezoneOffset() * 60;
245
246 const params = {
0d272273
AD
247 op: "rpc", method: "sanityCheck", hasAudio: hasAudio,
248 hasMp3: hasMp3,
249 clientTzOffset: clientTzOffset,
250 hasSandbox: hasSandbox
251 };
252
253 xhrPost("backend.php", params, (transport) => {
254 try {
255 backend_sanity_check_callback(transport);
256 } catch (e) {
257 console.error(e);
258 }
1bfe1d7b 259 });
0d272273 260
1bfe1d7b
AD
261 } catch (e) {
262 exception_error(e);
263 }
0dbc20a8 264
1bfe1d7b 265 });
9fabf9fc 266
47179952 267
1bfe1d7b 268 });
7719618b 269}
86741347 270
0dbc20a8
AD
271function init_hotkey_actions() {
272 hotkey_actions["next_feed"] = function() {
424e28db 273 const rv = dijit.byId("feedTree").getNextFeed(
0dbc20a8
AD
274 getActiveFeedId(), activeFeedIsCat());
275
276 if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true})
277 };
278 hotkey_actions["prev_feed"] = function() {
424e28db 279 const rv = dijit.byId("feedTree").getPreviousFeed(
0dbc20a8
AD
280 getActiveFeedId(), activeFeedIsCat());
281
282 if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true})
283 };
284 hotkey_actions["next_article"] = function() {
285 moveToPost('next');
286 };
287 hotkey_actions["prev_article"] = function() {
288 moveToPost('prev');
289 };
290 hotkey_actions["next_article_noscroll"] = function() {
291 moveToPost('next', true);
292 };
293 hotkey_actions["prev_article_noscroll"] = function() {
294 moveToPost('prev', true);
295 };
296 hotkey_actions["next_article_noexpand"] = function() {
297 moveToPost('next', true, true);
298 };
299 hotkey_actions["prev_article_noexpand"] = function() {
300 moveToPost('prev', true, true);
301 };
0dbc20a8
AD
302 hotkey_actions["search_dialog"] = function() {
303 search();
304 };
305 hotkey_actions["toggle_mark"] = function() {
306 selectionToggleMarked(undefined, false, true);
307 };
308 hotkey_actions["toggle_publ"] = function() {
309 selectionTogglePublished(undefined, false, true);
310 };
311 hotkey_actions["toggle_unread"] = function() {
312 selectionToggleUnread(undefined, false, true);
313 };
314 hotkey_actions["edit_tags"] = function() {
424e28db 315 const id = getActiveArticleId();
0dbc20a8
AD
316 if (id) {
317 editArticleTags(id);
424e28db 318 }
0dbc20a8
AD
319 }
320 hotkey_actions["open_in_new_window"] = function() {
321 if (getActiveArticleId()) {
322 openArticleInNewWindow(getActiveArticleId());
0dbc20a8
AD
323 }
324 };
325 hotkey_actions["catchup_below"] = function() {
326 catchupRelativeToArticle(1);
327 };
328 hotkey_actions["catchup_above"] = function() {
329 catchupRelativeToArticle(0);
330 };
331 hotkey_actions["article_scroll_down"] = function() {
0dbc20a8
AD
332 scrollArticle(40);
333 };
334 hotkey_actions["article_scroll_up"] = function() {
0dbc20a8
AD
335 scrollArticle(-40);
336 };
337 hotkey_actions["close_article"] = function() {
9563e3bc 338 closeArticlePanel();
0dbc20a8
AD
339 };
340 hotkey_actions["email_article"] = function() {
341 if (typeof emailArticle != "undefined") {
342 emailArticle();
343 } else if (typeof mailtoArticle != "undefined") {
344 mailtoArticle();
345 } else {
346 alert(__("Please enable mail plugin first."));
347 }
348 };
349 hotkey_actions["select_all"] = function() {
350 selectArticles('all');
351 };
352 hotkey_actions["select_unread"] = function() {
353 selectArticles('unread');
354 };
355 hotkey_actions["select_marked"] = function() {
356 selectArticles('marked');
357 };
358 hotkey_actions["select_published"] = function() {
359 selectArticles('published');
360 };
361 hotkey_actions["select_invert"] = function() {
362 selectArticles('invert');
363 };
364 hotkey_actions["select_none"] = function() {
365 selectArticles('none');
366 };
367 hotkey_actions["feed_refresh"] = function() {
368 if (getActiveFeedId() != undefined) {
369 viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat()});
370 return;
371 }
372 };
373 hotkey_actions["feed_unhide_read"] = function() {
374 toggleDispRead();
375 };
376 hotkey_actions["feed_subscribe"] = function() {
377 quickAddFeed();
378 };
379 hotkey_actions["feed_debug_update"] = function() {
380 if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) {
381 window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() +
382 "&csrf_token=" + getInitParam("csrf_token"));
383 } else {
384 alert("You can't debug this kind of feed.");
385 }
386 };
387
388 hotkey_actions["feed_debug_viewfeed"] = function() {
389 viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), viewfeed_debug: true});
390 };
391
392 hotkey_actions["feed_edit"] = function() {
393 if (activeFeedIsCat())
394 alert(__("You can't edit this kind of feed."));
395 else
396 editFeed(getActiveFeedId());
397 };
398 hotkey_actions["feed_catchup"] = function() {
399 if (getActiveFeedId() != undefined) {
400 catchupCurrentFeed();
401 return;
402 }
403 };
404 hotkey_actions["feed_reverse"] = function() {
405 reverseHeadlineOrder();
406 };
407 hotkey_actions["feed_toggle_vgroup"] = function() {
0d272273
AD
408 xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => {
409 viewCurrentFeed();
410 })
0dbc20a8
AD
411 };
412 hotkey_actions["catchup_all"] = function() {
413 catchupAllFeeds();
414 };
415 hotkey_actions["cat_toggle_collapse"] = function() {
416 if (activeFeedIsCat()) {
417 dijit.byId("feedTree").collapseCat(getActiveFeedId());
418 return;
419 }
420 };
421 hotkey_actions["goto_all"] = function() {
422 viewfeed({feed: -4});
423 };
424 hotkey_actions["goto_fresh"] = function() {
425 viewfeed({feed: -3});
426 };
427 hotkey_actions["goto_marked"] = function() {
428 viewfeed({feed: -1});
429 };
430 hotkey_actions["goto_published"] = function() {
431 viewfeed({feed: -2});
432 };
433 hotkey_actions["goto_tagcloud"] = function() {
434 displayDlg(__("Tag cloud"), "printTagCloud");
435 };
436 hotkey_actions["goto_prefs"] = function() {
437 gotoPreferences();
438 };
439 hotkey_actions["select_article_cursor"] = function() {
424e28db 440 const id = getArticleUnderPointer();
0dbc20a8 441 if (id) {
424e28db 442 const row = $("RROW-" + id);
0dbc20a8
AD
443
444 if (row) {
424e28db 445 const cb = dijit.getEnclosingWidget(
0dbc20a8
AD
446 row.getElementsByClassName("rchk")[0]);
447
448 if (cb) {
449 cb.attr("checked", !cb.attr("checked"));
450 toggleSelectRowById(cb, "RROW-" + id);
451 return false;
452 }
c73b739b 453 }
0dbc20a8
AD
454 }
455 };
456 hotkey_actions["create_label"] = function() {
457 addLabel();
458 };
459 hotkey_actions["create_filter"] = function() {
460 quickAddFilter();
461 };
462 hotkey_actions["collapse_sidebar"] = function() {
463 collapse_feedlist();
464 };
465 hotkey_actions["toggle_embed_original"] = function() {
466 if (typeof embedOriginalArticle != "undefined") {
467 if (getActiveArticleId())
468 embedOriginalArticle(getActiveArticleId());
469 } else {
470 alert(__("Please enable embed_original plugin first."));
471 }
472 };
473 hotkey_actions["toggle_widescreen"] = function() {
474 if (!isCdmMode()) {
475 _widescreen_mode = !_widescreen_mode;
c73b739b 476
0dbc20a8
AD
477 // reset stored sizes because geometry changed
478 setCookie("ttrss_ci_width", 0);
479 setCookie("ttrss_ci_height", 0);
c73b739b 480
0dbc20a8
AD
481 switchPanelMode(_widescreen_mode);
482 } else {
483 alert(__("Widescreen is not available in combined mode."));
484 }
485 };
486 hotkey_actions["help_dialog"] = function() {
487 helpDialog("main");
488 };
489 hotkey_actions["toggle_combined_mode"] = function() {
490 notify_progress("Loading, please wait...");
491
424e28db 492 const value = isCdmMode() ? "false" : "true";
0dbc20a8 493
0d272273
AD
494 xhrPost("backend.php", {op: "rpc", method: "setpref", key: "COMBINED_DISPLAY_MODE", value: value}, () => {
495 setInitParam("combined_display_mode",
496 !getInitParam("combined_display_mode"));
0dbc20a8 497
0d272273
AD
498 closeArticlePanel();
499 viewCurrentFeed();
500 })
0dbc20a8 501 };
0dbc20a8
AD
502}
503
504function init_second_stage() {
1bfe1d7b
AD
505 updateFeedList();
506 closeArticlePanel();
0dbc20a8 507
1bfe1d7b
AD
508 if (parseInt(getCookie("ttrss_fh_width")) > 0) {
509 dijit.byId("feeds-holder").domNode.setStyle(
510 {width: getCookie("ttrss_fh_width") + "px" });
511 }
0dbc20a8 512
1bfe1d7b 513 dijit.byId("main").resize();
0dbc20a8 514
1bfe1d7b
AD
515 var tmph = dojo.connect(dijit.byId('feeds-holder'), 'resize',
516 function (args) {
517 if (args && args.w >= 0) {
518 setCookie("ttrss_fh_width", args.w, getInitParam("cookie_lifetime"));
519 }
520 });
2f587484 521
1bfe1d7b
AD
522 var tmph = dojo.connect(dijit.byId('content-insert'), 'resize',
523 function (args) {
524 if (args && args.w >= 0 && args.h >= 0) {
525 setCookie("ttrss_ci_width", args.w, getInitParam("cookie_lifetime"));
526 setCookie("ttrss_ci_height", args.h, getInitParam("cookie_lifetime"));
527 }
528 });
770bbb02 529
1bfe1d7b 530 delCookie("ttrss_test");
f31673f7 531
424e28db 532 const toolbar = document.forms["main_toolbar_form"];
37f1a234 533
1bfe1d7b
AD
534 dijit.getEnclosingWidget(toolbar.view_mode).attr('value',
535 getInitParam("default_view_mode"));
c6784aea 536
1bfe1d7b
AD
537 dijit.getEnclosingWidget(toolbar.order_by).attr('value',
538 getInitParam("default_view_order_by"));
5f136c9a 539
424e28db
AD
540 const hash_feed_id = hash_get('f');
541 const hash_feed_is_cat = hash_get('c') == "1";
4480b26e 542
1bfe1d7b
AD
543 if (hash_feed_id != undefined) {
544 setActiveFeedId(hash_feed_id, hash_feed_is_cat);
545 }
730dbf19 546
1bfe1d7b 547 loading_set_progress(50);
ff0010c1 548
1bfe1d7b
AD
549 // can't use cache_clear() here because viewfeed might not have initialized yet
550 if ('sessionStorage' in window && window['sessionStorage'] !== null)
551 sessionStorage.clear();
e5e2cf3b 552
7e8be97b 553 /*const hotkeys = getInitParam("hotkeys");
424e28db 554 const tmp = [];
e5e2cf3b 555
424e28db
AD
556 for (const sequence in hotkeys[1]) {
557 const filtered = sequence.replace(/\|.*$/, "");
1bfe1d7b
AD
558 tmp[filtered] = hotkeys[1][sequence];
559 }
e5e2cf3b 560
1bfe1d7b 561 hotkeys[1] = tmp;
7e8be97b 562 setInitParam("hotkeys", hotkeys);*/
d44f3da4 563
1bfe1d7b
AD
564 _widescreen_mode = getInitParam("widescreen");
565 switchPanelMode(_widescreen_mode);
fcf70c51 566
1bfe1d7b 567 console.log("second stage ok");
8b83bf5f 568
1bfe1d7b
AD
569 if (getInitParam("simple_update")) {
570 console.log("scheduling simple feed updater...");
571 window.setTimeout(update_random_feed, 30*1000);
2f587484 572 }
1cd17194 573}
ac43eba1 574
c09ec856 575function quickMenuGo(opid) {
1bfe1d7b
AD
576 switch (opid) {
577 case "qmcPrefs":
578 gotoPreferences();
579 break;
580 case "qmcLogout":
581 gotoLogout();
582 break;
583 case "qmcTagCloud":
584 displayDlg(__("Tag cloud"), "printTagCloud");
585 break;
586 case "qmcSearch":
587 search();
588 break;
589 case "qmcAddFeed":
590 quickAddFeed();
591 break;
592 case "qmcDigest":
593 window.location.href = "backend.php?op=digest";
594 break;
595 case "qmcEditFeed":
596 if (activeFeedIsCat())
597 alert(__("You can't edit this kind of feed."));
598 else
599 editFeed(getActiveFeedId());
600 break;
601 case "qmcRemoveFeed":
602 var actid = getActiveFeedId();
442d77f1 603
1bfe1d7b
AD
604 if (activeFeedIsCat()) {
605 alert(__("You can't unsubscribe from the category."));
606 return;
607 }
442d77f1 608
1bfe1d7b
AD
609 if (!actid) {
610 alert(__("Please select some feed first."));
611 return;
612 }
64a2875d 613
1bfe1d7b 614 var fn = getFeedName(actid);
89cb787e 615
1bfe1d7b 616 var pr = __("Unsubscribe from %s?").replace("%s", fn);
89cb787e 617
1bfe1d7b
AD
618 if (confirm(pr)) {
619 unsubscribeFeed(actid);
620 }
621 break;
622 case "qmcCatchupAll":
623 catchupAllFeeds();
624 break;
625 case "qmcShowOnlyUnread":
626 toggleDispRead();
627 break;
1bfe1d7b
AD
628 case "qmcToggleWidescreen":
629 if (!isCdmMode()) {
630 _widescreen_mode = !_widescreen_mode;
1bcf8f45 631
1bfe1d7b
AD
632 // reset stored sizes because geometry changed
633 setCookie("ttrss_ci_width", 0);
634 setCookie("ttrss_ci_height", 0);
89018afa 635
1bfe1d7b
AD
636 switchPanelMode(_widescreen_mode);
637 } else {
638 alert(__("Widescreen is not available in combined mode."));
238eff01 639 }
1bfe1d7b
AD
640 break;
641 case "qmcHKhelp":
642 helpDialog("main");
643 break;
644 default:
645 console.log("quickMenuGo: unknown action: " + opid);
a24f525c 646 }
e2f8f7b4
AD
647}
648
3745788e 649function toggleDispRead() {
3745788e 650
424e28db 651 const hide = !(getInitParam("hide_read_feeds") == "1");
3745788e 652
0d272273
AD
653 xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => {
654 hideOrShowFeeds(hide);
655 setInitParam("hide_read_feeds", hide);
656 });
3745788e 657}
295f9b42 658
563b9c78 659function parse_runtime_info(data) {
71ad883b 660
f8fb4498 661 //console.log("parsing runtime info...");
1cb7492d 662
424e28db
AD
663 for (const k in data) {
664 const v = data[k];
3ac2b520 665
563b9c78 666// console.log("RI: " + k + " => " + v);
1cb7492d 667
16314dda 668 if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) {
4cdb8173 669 if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) {
16314dda
AD
670 window.location.reload();
671 }
672 }
673
ef16ae37 674 if (k == "daemon_is_running" && v != 1) {
415a3b50 675 notify_error("<span onclick=\"explainError(1)\">Update daemon is not running.</span>", true);
5ae8f858 676 return;
8e00ae9b
AD
677 }
678
efcc5d36 679 if (k == "update_result") {
424e28db 680 const updatesIcon = dijit.byId("updatesIcon").domNode;
efcc5d36 681
119ba03b 682 if (v) {
efcc5d36
AD
683 Element.show(updatesIcon);
684 } else {
685 Element.hide(updatesIcon);
686 }
687 }
688
8e00ae9b 689 if (k == "daemon_stamp_ok" && v != 1) {
415a3b50 690 notify_error("<span onclick=\"explainError(3)\">Update daemon is not updating feeds.</span>", true);
5ae8f858 691 return;
8e00ae9b
AD
692 }
693
8cd576a1
AD
694 if (k == "max_feed_id" || k == "num_feeds") {
695 if (init_params[k] != v) {
696 console.log("feed count changed, need to reload feedlist.");
697 updateFeedList();
698 }
699 }
700
009646d2 701 init_params[k] = v;
5ae8f858 702 notify('');
71ad883b 703 }
8ceea119 704
705 PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data);
71ad883b 706}
fce24838 707
8389b150 708function collapse_feedlist() {
1bfe1d7b 709 Element.toggle("feeds-holder");
0ce61157 710
424e28db 711 const splitter = $("feeds-holder_splitter");
b1a80693 712
1bfe1d7b 713 Element.visible("feeds-holder") ? splitter.show() : splitter.hide();
b1a80693 714
1bfe1d7b 715 dijit.byId("main").resize();
3c2d7945 716}
8389b150 717
3c2d7945 718function viewModeChanged() {
4f79e9aa 719 cache_clear();
e331188f 720 return viewCurrentFeed('');
3c2d7945 721}
8389b150 722
93f66472 723function hotkey_handler(e) {
1bfe1d7b 724 if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
18606807 725
7e8be97b 726 const action_name = keyevent_to_action(e);
a83b58f1 727
7e8be97b
AD
728 if (action_name) {
729 const action_func = hotkey_actions[action_name];
a83b58f1 730
7e8be97b
AD
731 if (action_func != null) {
732 action_func();
733 e.stopPropagation();
734 return false;
735 }
93f66472
AD
736 }
737}
61a20560 738
a5819bb3
AD
739function inPreferences() {
740 return false;
741}
8a3e0b1a
AD
742
743function reverseHeadlineOrder() {
b9a06a0e 744
424e28db
AD
745 const toolbar = document.forms["main_toolbar_form"];
746 const order_by = dijit.getEnclosingWidget(toolbar.order_by);
b9a06a0e 747
424e28db 748 let value = order_by.attr('value');
b9a06a0e 749
1bfe1d7b
AD
750 if (value == "date_reverse")
751 value = "default";
752 else
753 value = "date_reverse";
b9a06a0e 754
1bfe1d7b 755 order_by.attr('value', value);
b9a06a0e 756
1bfe1d7b 757 viewCurrentFeed();
8a3e0b1a 758
8a3e0b1a 759}
fe1087fb 760
563b9c78 761function handle_rpc_json(transport, scheduled_call) {
563b9c78 762
424e28db
AD
763 const netalert_dijit = dijit.byId("net-alert");
764 let netalert = false;
3188e863
AD
765
766 if (netalert_dijit) netalert = netalert_dijit.domNode;
df63125d 767
3188e863 768 try {
424e28db 769 const reply = JSON.parse(transport.responseText);
df63125d 770
563b9c78
AD
771 if (reply) {
772
424e28db 773 const error = reply['error'];
563b9c78
AD
774
775 if (error) {
424e28db
AD
776 const code = error['code'];
777 const msg = error['msg'];
009646d2
AD
778
779 console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg);
780
563b9c78
AD
781 if (code != 0) {
782 fatalError(code, msg);
783 return false;
784 }
785 }
786
424e28db 787 const seq = reply['seq'];
563b9c78 788
1b91bb45 789 if (seq && get_seq() != seq) {
4508e310
AD
790 console.log("[handle_rpc_json] sequence mismatch: " + seq +
791 " (want: " + get_seq() + ")");
792 return true;
563b9c78
AD
793 }
794
424e28db 795 const message = reply['message'];
563b9c78 796
4508e310
AD
797 if (message == "UPDATE_COUNTERS") {
798 console.log("need to refresh counters...");
799 setInitParam("last_article_id", -1);
800 request_counters(true);
563b9c78
AD
801 }
802
424e28db 803 const counters = reply['counters'];
009646d2 804
563b9c78
AD
805 if (counters)
806 parse_counters(counters, scheduled_call);
807
424e28db 808 const runtime_info = reply['runtime-info'];
563b9c78
AD
809
810 if (runtime_info)
811 parse_runtime_info(runtime_info);
812
3188e863 813 if (netalert) netalert.hide();
6effae6d 814
0d272273
AD
815 return reply;
816
817 } else {
818 if (netalert)
819 netalert.show();
820 else
821 notify_error("Communication problem with server.");
822 }
563b9c78
AD
823
824 } catch (e) {
df63125d 825 if (netalert)
3188e863 826 netalert.show();
df63125d
AD
827 else
828 notify_error("Communication problem with server.");
829
1bfe1d7b 830 console.error(e);
563b9c78
AD
831 }
832
0d272273 833 return false;
563b9c78
AD
834}
835
1bcf8f45 836function switchPanelMode(wide) {
1bfe1d7b 837 if (isCdmMode()) return;
1bcf8f45 838
424e28db 839 const article_id = getActiveArticleId();
1bcf8f45 840
1bfe1d7b
AD
841 if (wide) {
842 dijit.byId("headlines-wrap-inner").attr("design", 'sidebar');
843 dijit.byId("content-insert").attr("region", "trailing");
89018afa 844
1bfe1d7b
AD
845 dijit.byId("content-insert").domNode.setStyle({width: '50%',
846 height: 'auto',
847 borderTopWidth: '0px' });
1bcf8f45 848
1bfe1d7b
AD
849 if (parseInt(getCookie("ttrss_ci_width")) > 0) {
850 dijit.byId("content-insert").domNode.setStyle(
851 {width: getCookie("ttrss_ci_width") + "px" });
852 }
1bcf8f45 853
1bfe1d7b
AD
854 $("headlines-frame").setStyle({ borderBottomWidth: '0px' });
855 $("headlines-frame").addClassName("wide");
1bcf8f45 856
1bfe1d7b 857 } else {
1bcf8f45 858
1bfe1d7b 859 dijit.byId("content-insert").attr("region", "bottom");
89018afa 860
1bfe1d7b
AD
861 dijit.byId("content-insert").domNode.setStyle({width: 'auto',
862 height: '50%',
863 borderTopWidth: '0px'});
15a82901 864
1bfe1d7b
AD
865 if (parseInt(getCookie("ttrss_ci_height")) > 0) {
866 dijit.byId("content-insert").domNode.setStyle(
867 {height: getCookie("ttrss_ci_height") + "px" });
1bcf8f45
AD
868 }
869
1bfe1d7b
AD
870 $("headlines-frame").setStyle({ borderBottomWidth: '1px' });
871 $("headlines-frame").removeClassName("wide");
1bcf8f45 872
1bfe1d7b 873 }
1bcf8f45 874
1bfe1d7b 875 closeArticlePanel();
7d8f5657 876
1bfe1d7b 877 if (article_id) view(article_id);
7d8f5657 878
0d272273 879 xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0});
1bcf8f45 880}
8b83bf5f
AD
881
882function update_random_feed() {
1bfe1d7b 883 console.log("in update_random_feed");
8b83bf5f 884
0d272273
AD
885 xhrPost("backend.php", { op: "rpc", method: "updateRandomFeed" }, (transport) => {
886 handle_rpc_json(transport, true);
887 window.setTimeout(update_random_feed, 30*1000);
888 });
8b83bf5f 889}
1b04a298
AD
890
891function hash_get(key) {
424e28db 892 const kv = window.location.hash.substring(1).toQueryParams();
1bfe1d7b 893 return kv[key];
1b04a298
AD
894}
895function hash_set(key, value) {
424e28db 896 const kv = window.location.hash.substring(1).toQueryParams();
1bfe1d7b
AD
897 kv[key] = value;
898 window.location.hash = $H(kv).toQueryString();
1b04a298 899}