]>
Commit | Line | Data |
---|---|---|
1 | /* global dijit, __ */ | |
2 | ||
3 | let global_unread = -1; | |
4 | let _widescreen_mode = false; | |
5 | let _rpc_seq = 0; | |
6 | let _active_feed_id = 0; | |
7 | let _active_feed_is_cat = false; | |
8 | let hotkey_actions = {}; | |
9 | ||
10 | function next_seq() { | |
11 | _rpc_seq += 1; | |
12 | return _rpc_seq; | |
13 | } | |
14 | ||
15 | function get_seq() { | |
16 | return _rpc_seq; | |
17 | } | |
18 | ||
19 | function activeFeedIsCat() { | |
20 | return !!_active_feed_is_cat; | |
21 | } | |
22 | ||
23 | function getActiveFeedId() { | |
24 | return _active_feed_id; | |
25 | } | |
26 | ||
27 | function setActiveFeedId(id, is_cat) { | |
28 | hash_set('f', id); | |
29 | hash_set('c', is_cat ? 1 : 0); | |
30 | ||
31 | _active_feed_id = id; | |
32 | _active_feed_is_cat = is_cat; | |
33 | ||
34 | $("headlines-frame").setAttribute("feed-id", id); | |
35 | $("headlines-frame").setAttribute("is-cat", is_cat ? 1 : 0); | |
36 | ||
37 | selectFeed(id, is_cat); | |
38 | ||
39 | PluginHost.run(PluginHost.HOOK_FEED_SET_ACTIVE, _active_article_id); | |
40 | } | |
41 | ||
42 | ||
43 | function updateFeedList() { | |
44 | try { | |
45 | Element.show("feedlistLoading"); | |
46 | ||
47 | resetCounterCache(); | |
48 | ||
49 | if (dijit.byId("feedTree")) { | |
50 | dijit.byId("feedTree").destroyRecursive(); | |
51 | } | |
52 | ||
53 | const store = new dojo.data.ItemFileWriteStore({ | |
54 | url: "backend.php?op=pref_feeds&method=getfeedtree&mode=2" | |
55 | }); | |
56 | ||
57 | const treeModel = new fox.FeedStoreModel({ | |
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 | ||
67 | const tree = new fox.FeedTree({ | |
68 | model: treeModel, | |
69 | onClick: function (item, node) { | |
70 | const id = String(item.id); | |
71 | const is_cat = id.match("^CAT:"); | |
72 | const feed = id.substr(id.indexOf(":") + 1); | |
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 | ||
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 | } | |
106 | } | |
107 | ||
108 | function catchupAllFeeds() { | |
109 | ||
110 | const str = __("Mark all articles as read?"); | |
111 | ||
112 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { | |
113 | ||
114 | notify_progress("Marking all feeds as read..."); | |
115 | ||
116 | xhrPost("backend.php", {op: "feeds", method: "catchupAll"}, () => { | |
117 | request_counters(true); | |
118 | viewCurrentFeed(); | |
119 | }); | |
120 | ||
121 | global_unread = 0; | |
122 | updateTitle(""); | |
123 | } | |
124 | } | |
125 | ||
126 | function viewCurrentFeed(method) { | |
127 | console.log("viewCurrentFeed: " + method); | |
128 | ||
129 | if (getActiveFeedId() != undefined) { | |
130 | viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), method: method}); | |
131 | } | |
132 | return false; // block unneeded form submits | |
133 | } | |
134 | ||
135 | function timeout() { | |
136 | if (getInitParam("bw_limit") != "1") { | |
137 | request_counters(true); | |
138 | setTimeout(timeout, 60*1000); | |
139 | } | |
140 | } | |
141 | ||
142 | function search() { | |
143 | const query = "backend.php?op=feeds&method=search¶m=" + | |
144 | param_escape(getActiveFeedId() + ":" + activeFeedIsCat()); | |
145 | ||
146 | if (dijit.byId("searchDlg")) | |
147 | dijit.byId("searchDlg").destroyRecursive(); | |
148 | ||
149 | const dialog = new dijit.Dialog({ | |
150 | id: "searchDlg", | |
151 | title: __("Search"), | |
152 | style: "width: 600px", | |
153 | execute: function() { | |
154 | if (this.validate()) { | |
155 | _search_query = this.attr('value'); | |
156 | this.hide(); | |
157 | viewCurrentFeed(); | |
158 | } | |
159 | }, | |
160 | href: query}); | |
161 | ||
162 | dialog.show(); | |
163 | } | |
164 | ||
165 | function updateTitle() { | |
166 | let tmp = "Tiny Tiny RSS"; | |
167 | ||
168 | if (global_unread > 0) { | |
169 | tmp = "(" + global_unread + ") " + tmp; | |
170 | } | |
171 | ||
172 | document.title = tmp; | |
173 | } | |
174 | ||
175 | function genericSanityCheck() { | |
176 | setCookie("ttrss_test", "TEST"); | |
177 | ||
178 | if (getCookie("ttrss_test") != "TEST") { | |
179 | return fatalError(2); | |
180 | } | |
181 | ||
182 | return true; | |
183 | } | |
184 | ||
185 | ||
186 | function init() { | |
187 | ||
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", | |
209 | "dijit/form/MultiSelect", | |
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", | |
226 | "fox/FeedStoreModel", | |
227 | "fox/FeedTree" ], function (dojo, ready, parser) { | |
228 | ||
229 | ready(function() { | |
230 | ||
231 | try { | |
232 | parser.parse(); | |
233 | ||
234 | if (!genericSanityCheck()) | |
235 | return false; | |
236 | ||
237 | loading_set_progress(30); | |
238 | ||
239 | const a = document.createElement('audio'); | |
240 | ||
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 | init_hotkey_actions(); | |
247 | ||
248 | const params = { | |
249 | op: "rpc", method: "sanityCheck", hasAudio: hasAudio, | |
250 | hasMp3: hasMp3, | |
251 | clientTzOffset: clientTzOffset, | |
252 | hasSandbox: hasSandbox | |
253 | }; | |
254 | ||
255 | xhrPost("backend.php", params, (transport) => { | |
256 | try { | |
257 | backend_sanity_check_callback(transport); | |
258 | } catch (e) { | |
259 | console.error(e); | |
260 | } | |
261 | }); | |
262 | ||
263 | } catch (e) { | |
264 | exception_error(e); | |
265 | } | |
266 | ||
267 | }); | |
268 | ||
269 | ||
270 | }); | |
271 | } | |
272 | ||
273 | function init_hotkey_actions() { | |
274 | hotkey_actions["next_feed"] = function() { | |
275 | const rv = dijit.byId("feedTree").getNextFeed( | |
276 | getActiveFeedId(), activeFeedIsCat()); | |
277 | ||
278 | if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) | |
279 | }; | |
280 | hotkey_actions["prev_feed"] = function() { | |
281 | const rv = dijit.byId("feedTree").getPreviousFeed( | |
282 | getActiveFeedId(), activeFeedIsCat()); | |
283 | ||
284 | if (rv) viewfeed({feed: rv[0], is_cat: rv[1], can_wait: true}) | |
285 | }; | |
286 | hotkey_actions["next_article"] = function() { | |
287 | moveToPost('next'); | |
288 | }; | |
289 | hotkey_actions["prev_article"] = function() { | |
290 | moveToPost('prev'); | |
291 | }; | |
292 | hotkey_actions["next_article_noscroll"] = function() { | |
293 | moveToPost('next', true); | |
294 | }; | |
295 | hotkey_actions["prev_article_noscroll"] = function() { | |
296 | moveToPost('prev', true); | |
297 | }; | |
298 | hotkey_actions["next_article_noexpand"] = function() { | |
299 | moveToPost('next', true, true); | |
300 | }; | |
301 | hotkey_actions["prev_article_noexpand"] = function() { | |
302 | moveToPost('prev', true, true); | |
303 | }; | |
304 | hotkey_actions["collapse_article"] = function() { | |
305 | const id = getActiveArticleId(); | |
306 | const elem = $("CICD-"+id); | |
307 | ||
308 | if (elem) { | |
309 | if (elem.visible()) { | |
310 | cdmCollapseArticle(null, id); | |
311 | } | |
312 | else { | |
313 | cdmExpandArticle(id); | |
314 | } | |
315 | } | |
316 | }; | |
317 | hotkey_actions["toggle_expand"] = function() { | |
318 | const id = getActiveArticleId(); | |
319 | const elem = $("CICD-"+id); | |
320 | ||
321 | if (elem) { | |
322 | if (elem.visible()) { | |
323 | cdmCollapseArticle(null, id, false); | |
324 | } | |
325 | else { | |
326 | cdmExpandArticle(id); | |
327 | } | |
328 | } | |
329 | }; | |
330 | hotkey_actions["search_dialog"] = function() { | |
331 | search(); | |
332 | }; | |
333 | hotkey_actions["toggle_mark"] = function() { | |
334 | selectionToggleMarked(undefined, false, true); | |
335 | }; | |
336 | hotkey_actions["toggle_publ"] = function() { | |
337 | selectionTogglePublished(undefined, false, true); | |
338 | }; | |
339 | hotkey_actions["toggle_unread"] = function() { | |
340 | selectionToggleUnread(undefined, false, true); | |
341 | }; | |
342 | hotkey_actions["edit_tags"] = function() { | |
343 | const id = getActiveArticleId(); | |
344 | if (id) { | |
345 | editArticleTags(id); | |
346 | } | |
347 | } | |
348 | hotkey_actions["open_in_new_window"] = function() { | |
349 | if (getActiveArticleId()) { | |
350 | openArticleInNewWindow(getActiveArticleId()); | |
351 | } | |
352 | }; | |
353 | hotkey_actions["catchup_below"] = function() { | |
354 | catchupRelativeToArticle(1); | |
355 | }; | |
356 | hotkey_actions["catchup_above"] = function() { | |
357 | catchupRelativeToArticle(0); | |
358 | }; | |
359 | hotkey_actions["article_scroll_down"] = function() { | |
360 | scrollArticle(40); | |
361 | }; | |
362 | hotkey_actions["article_scroll_up"] = function() { | |
363 | scrollArticle(-40); | |
364 | }; | |
365 | hotkey_actions["close_article"] = function() { | |
366 | if (isCdmMode()) { | |
367 | if (!getInitParam("cdm_expanded")) { | |
368 | cdmCollapseArticle(false, getActiveArticleId()); | |
369 | } | |
370 | } else { | |
371 | closeArticlePanel(); | |
372 | } | |
373 | }; | |
374 | hotkey_actions["email_article"] = function() { | |
375 | if (typeof emailArticle != "undefined") { | |
376 | emailArticle(); | |
377 | } else if (typeof mailtoArticle != "undefined") { | |
378 | mailtoArticle(); | |
379 | } else { | |
380 | alert(__("Please enable mail plugin first.")); | |
381 | } | |
382 | }; | |
383 | hotkey_actions["select_all"] = function() { | |
384 | selectArticles('all'); | |
385 | }; | |
386 | hotkey_actions["select_unread"] = function() { | |
387 | selectArticles('unread'); | |
388 | }; | |
389 | hotkey_actions["select_marked"] = function() { | |
390 | selectArticles('marked'); | |
391 | }; | |
392 | hotkey_actions["select_published"] = function() { | |
393 | selectArticles('published'); | |
394 | }; | |
395 | hotkey_actions["select_invert"] = function() { | |
396 | selectArticles('invert'); | |
397 | }; | |
398 | hotkey_actions["select_none"] = function() { | |
399 | selectArticles('none'); | |
400 | }; | |
401 | hotkey_actions["feed_refresh"] = function() { | |
402 | if (getActiveFeedId() != undefined) { | |
403 | viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat()}); | |
404 | return; | |
405 | } | |
406 | }; | |
407 | hotkey_actions["feed_unhide_read"] = function() { | |
408 | toggleDispRead(); | |
409 | }; | |
410 | hotkey_actions["feed_subscribe"] = function() { | |
411 | quickAddFeed(); | |
412 | }; | |
413 | hotkey_actions["feed_debug_update"] = function() { | |
414 | if (!activeFeedIsCat() && parseInt(getActiveFeedId()) > 0) { | |
415 | window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + getActiveFeedId() + | |
416 | "&csrf_token=" + getInitParam("csrf_token")); | |
417 | } else { | |
418 | alert("You can't debug this kind of feed."); | |
419 | } | |
420 | }; | |
421 | ||
422 | hotkey_actions["feed_debug_viewfeed"] = function() { | |
423 | viewfeed({feed: getActiveFeedId(), is_cat: activeFeedIsCat(), viewfeed_debug: true}); | |
424 | }; | |
425 | ||
426 | hotkey_actions["feed_edit"] = function() { | |
427 | if (activeFeedIsCat()) | |
428 | alert(__("You can't edit this kind of feed.")); | |
429 | else | |
430 | editFeed(getActiveFeedId()); | |
431 | }; | |
432 | hotkey_actions["feed_catchup"] = function() { | |
433 | if (getActiveFeedId() != undefined) { | |
434 | catchupCurrentFeed(); | |
435 | return; | |
436 | } | |
437 | }; | |
438 | hotkey_actions["feed_reverse"] = function() { | |
439 | reverseHeadlineOrder(); | |
440 | }; | |
441 | hotkey_actions["feed_toggle_vgroup"] = function() { | |
442 | xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => { | |
443 | viewCurrentFeed(); | |
444 | }) | |
445 | }; | |
446 | hotkey_actions["catchup_all"] = function() { | |
447 | catchupAllFeeds(); | |
448 | }; | |
449 | hotkey_actions["cat_toggle_collapse"] = function() { | |
450 | if (activeFeedIsCat()) { | |
451 | dijit.byId("feedTree").collapseCat(getActiveFeedId()); | |
452 | return; | |
453 | } | |
454 | }; | |
455 | hotkey_actions["goto_all"] = function() { | |
456 | viewfeed({feed: -4}); | |
457 | }; | |
458 | hotkey_actions["goto_fresh"] = function() { | |
459 | viewfeed({feed: -3}); | |
460 | }; | |
461 | hotkey_actions["goto_marked"] = function() { | |
462 | viewfeed({feed: -1}); | |
463 | }; | |
464 | hotkey_actions["goto_published"] = function() { | |
465 | viewfeed({feed: -2}); | |
466 | }; | |
467 | hotkey_actions["goto_tagcloud"] = function() { | |
468 | displayDlg(__("Tag cloud"), "printTagCloud"); | |
469 | }; | |
470 | hotkey_actions["goto_prefs"] = function() { | |
471 | gotoPreferences(); | |
472 | }; | |
473 | hotkey_actions["select_article_cursor"] = function() { | |
474 | const id = getArticleUnderPointer(); | |
475 | if (id) { | |
476 | const row = $("RROW-" + id); | |
477 | ||
478 | if (row) { | |
479 | const cb = dijit.getEnclosingWidget( | |
480 | row.getElementsByClassName("rchk")[0]); | |
481 | ||
482 | if (cb) { | |
483 | cb.attr("checked", !cb.attr("checked")); | |
484 | toggleSelectRowById(cb, "RROW-" + id); | |
485 | return false; | |
486 | } | |
487 | } | |
488 | } | |
489 | }; | |
490 | hotkey_actions["create_label"] = function() { | |
491 | addLabel(); | |
492 | }; | |
493 | hotkey_actions["create_filter"] = function() { | |
494 | quickAddFilter(); | |
495 | }; | |
496 | hotkey_actions["collapse_sidebar"] = function() { | |
497 | collapse_feedlist(); | |
498 | }; | |
499 | hotkey_actions["toggle_embed_original"] = function() { | |
500 | if (typeof embedOriginalArticle != "undefined") { | |
501 | if (getActiveArticleId()) | |
502 | embedOriginalArticle(getActiveArticleId()); | |
503 | } else { | |
504 | alert(__("Please enable embed_original plugin first.")); | |
505 | } | |
506 | }; | |
507 | hotkey_actions["toggle_widescreen"] = function() { | |
508 | if (!isCdmMode()) { | |
509 | _widescreen_mode = !_widescreen_mode; | |
510 | ||
511 | // reset stored sizes because geometry changed | |
512 | setCookie("ttrss_ci_width", 0); | |
513 | setCookie("ttrss_ci_height", 0); | |
514 | ||
515 | switchPanelMode(_widescreen_mode); | |
516 | } else { | |
517 | alert(__("Widescreen is not available in combined mode.")); | |
518 | } | |
519 | }; | |
520 | hotkey_actions["help_dialog"] = function() { | |
521 | helpDialog("main"); | |
522 | }; | |
523 | hotkey_actions["toggle_combined_mode"] = function() { | |
524 | notify_progress("Loading, please wait..."); | |
525 | ||
526 | const value = isCdmMode() ? "false" : "true"; | |
527 | ||
528 | xhrPost("backend.php", {op: "rpc", method: "setpref", key: "COMBINED_DISPLAY_MODE", value: value}, () => { | |
529 | setInitParam("combined_display_mode", | |
530 | !getInitParam("combined_display_mode")); | |
531 | ||
532 | closeArticlePanel(); | |
533 | viewCurrentFeed(); | |
534 | }) | |
535 | }; | |
536 | hotkey_actions["toggle_cdm_expanded"] = function() { | |
537 | notify_progress("Loading, please wait..."); | |
538 | ||
539 | const value = getInitParam("cdm_expanded") ? "false" : "true"; | |
540 | ||
541 | xhrPost("backend.php", {op: "rpc", method: "setpref", key: "CDM_EXPANDED", value: value}, () => { | |
542 | setInitParam("cdm_expanded", !getInitParam("cdm_expanded")); | |
543 | viewCurrentFeed(); | |
544 | }); | |
545 | }; | |
546 | } | |
547 | ||
548 | function init_second_stage() { | |
549 | updateFeedList(); | |
550 | closeArticlePanel(); | |
551 | ||
552 | if (parseInt(getCookie("ttrss_fh_width")) > 0) { | |
553 | dijit.byId("feeds-holder").domNode.setStyle( | |
554 | {width: getCookie("ttrss_fh_width") + "px" }); | |
555 | } | |
556 | ||
557 | dijit.byId("main").resize(); | |
558 | ||
559 | var tmph = dojo.connect(dijit.byId('feeds-holder'), 'resize', | |
560 | function (args) { | |
561 | if (args && args.w >= 0) { | |
562 | setCookie("ttrss_fh_width", args.w, getInitParam("cookie_lifetime")); | |
563 | } | |
564 | }); | |
565 | ||
566 | var tmph = dojo.connect(dijit.byId('content-insert'), 'resize', | |
567 | function (args) { | |
568 | if (args && args.w >= 0 && args.h >= 0) { | |
569 | setCookie("ttrss_ci_width", args.w, getInitParam("cookie_lifetime")); | |
570 | setCookie("ttrss_ci_height", args.h, getInitParam("cookie_lifetime")); | |
571 | } | |
572 | }); | |
573 | ||
574 | delCookie("ttrss_test"); | |
575 | ||
576 | const toolbar = document.forms["main_toolbar_form"]; | |
577 | ||
578 | dijit.getEnclosingWidget(toolbar.view_mode).attr('value', | |
579 | getInitParam("default_view_mode")); | |
580 | ||
581 | dijit.getEnclosingWidget(toolbar.order_by).attr('value', | |
582 | getInitParam("default_view_order_by")); | |
583 | ||
584 | const hash_feed_id = hash_get('f'); | |
585 | const hash_feed_is_cat = hash_get('c') == "1"; | |
586 | ||
587 | if (hash_feed_id != undefined) { | |
588 | setActiveFeedId(hash_feed_id, hash_feed_is_cat); | |
589 | } | |
590 | ||
591 | loading_set_progress(50); | |
592 | ||
593 | // can't use cache_clear() here because viewfeed might not have initialized yet | |
594 | if ('sessionStorage' in window && window['sessionStorage'] !== null) | |
595 | sessionStorage.clear(); | |
596 | ||
597 | /*const hotkeys = getInitParam("hotkeys"); | |
598 | const tmp = []; | |
599 | ||
600 | for (const sequence in hotkeys[1]) { | |
601 | const filtered = sequence.replace(/\|.*$/, ""); | |
602 | tmp[filtered] = hotkeys[1][sequence]; | |
603 | } | |
604 | ||
605 | hotkeys[1] = tmp; | |
606 | setInitParam("hotkeys", hotkeys);*/ | |
607 | ||
608 | _widescreen_mode = getInitParam("widescreen"); | |
609 | switchPanelMode(_widescreen_mode); | |
610 | ||
611 | console.log("second stage ok"); | |
612 | ||
613 | if (getInitParam("simple_update")) { | |
614 | console.log("scheduling simple feed updater..."); | |
615 | window.setTimeout(update_random_feed, 30*1000); | |
616 | } | |
617 | } | |
618 | ||
619 | function quickMenuGo(opid) { | |
620 | switch (opid) { | |
621 | case "qmcPrefs": | |
622 | gotoPreferences(); | |
623 | break; | |
624 | case "qmcLogout": | |
625 | gotoLogout(); | |
626 | break; | |
627 | case "qmcTagCloud": | |
628 | displayDlg(__("Tag cloud"), "printTagCloud"); | |
629 | break; | |
630 | case "qmcSearch": | |
631 | search(); | |
632 | break; | |
633 | case "qmcAddFeed": | |
634 | quickAddFeed(); | |
635 | break; | |
636 | case "qmcDigest": | |
637 | window.location.href = "backend.php?op=digest"; | |
638 | break; | |
639 | case "qmcEditFeed": | |
640 | if (activeFeedIsCat()) | |
641 | alert(__("You can't edit this kind of feed.")); | |
642 | else | |
643 | editFeed(getActiveFeedId()); | |
644 | break; | |
645 | case "qmcRemoveFeed": | |
646 | var actid = getActiveFeedId(); | |
647 | ||
648 | if (activeFeedIsCat()) { | |
649 | alert(__("You can't unsubscribe from the category.")); | |
650 | return; | |
651 | } | |
652 | ||
653 | if (!actid) { | |
654 | alert(__("Please select some feed first.")); | |
655 | return; | |
656 | } | |
657 | ||
658 | var fn = getFeedName(actid); | |
659 | ||
660 | var pr = __("Unsubscribe from %s?").replace("%s", fn); | |
661 | ||
662 | if (confirm(pr)) { | |
663 | unsubscribeFeed(actid); | |
664 | } | |
665 | break; | |
666 | case "qmcCatchupAll": | |
667 | catchupAllFeeds(); | |
668 | break; | |
669 | case "qmcShowOnlyUnread": | |
670 | toggleDispRead(); | |
671 | break; | |
672 | case "qmcToggleWidescreen": | |
673 | if (!isCdmMode()) { | |
674 | _widescreen_mode = !_widescreen_mode; | |
675 | ||
676 | // reset stored sizes because geometry changed | |
677 | setCookie("ttrss_ci_width", 0); | |
678 | setCookie("ttrss_ci_height", 0); | |
679 | ||
680 | switchPanelMode(_widescreen_mode); | |
681 | } else { | |
682 | alert(__("Widescreen is not available in combined mode.")); | |
683 | } | |
684 | break; | |
685 | case "qmcHKhelp": | |
686 | helpDialog("main"); | |
687 | break; | |
688 | default: | |
689 | console.log("quickMenuGo: unknown action: " + opid); | |
690 | } | |
691 | } | |
692 | ||
693 | function toggleDispRead() { | |
694 | ||
695 | const hide = !(getInitParam("hide_read_feeds") == "1"); | |
696 | ||
697 | xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => { | |
698 | hideOrShowFeeds(hide); | |
699 | setInitParam("hide_read_feeds", hide); | |
700 | }); | |
701 | } | |
702 | ||
703 | function parse_runtime_info(data) { | |
704 | ||
705 | //console.log("parsing runtime info..."); | |
706 | ||
707 | for (const k in data) { | |
708 | const v = data[k]; | |
709 | ||
710 | // console.log("RI: " + k + " => " + v); | |
711 | ||
712 | if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) { | |
713 | if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) { | |
714 | window.location.reload(); | |
715 | } | |
716 | } | |
717 | ||
718 | if (k == "daemon_is_running" && v != 1) { | |
719 | notify_error("<span onclick=\"explainError(1)\">Update daemon is not running.</span>", true); | |
720 | return; | |
721 | } | |
722 | ||
723 | if (k == "update_result") { | |
724 | const updatesIcon = dijit.byId("updatesIcon").domNode; | |
725 | ||
726 | if (v) { | |
727 | Element.show(updatesIcon); | |
728 | } else { | |
729 | Element.hide(updatesIcon); | |
730 | } | |
731 | } | |
732 | ||
733 | if (k == "daemon_stamp_ok" && v != 1) { | |
734 | notify_error("<span onclick=\"explainError(3)\">Update daemon is not updating feeds.</span>", true); | |
735 | return; | |
736 | } | |
737 | ||
738 | if (k == "max_feed_id" || k == "num_feeds") { | |
739 | if (init_params[k] != v) { | |
740 | console.log("feed count changed, need to reload feedlist."); | |
741 | updateFeedList(); | |
742 | } | |
743 | } | |
744 | ||
745 | init_params[k] = v; | |
746 | notify(''); | |
747 | } | |
748 | ||
749 | PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data); | |
750 | } | |
751 | ||
752 | function collapse_feedlist() { | |
753 | Element.toggle("feeds-holder"); | |
754 | ||
755 | const splitter = $("feeds-holder_splitter"); | |
756 | ||
757 | Element.visible("feeds-holder") ? splitter.show() : splitter.hide(); | |
758 | ||
759 | dijit.byId("main").resize(); | |
760 | } | |
761 | ||
762 | function viewModeChanged() { | |
763 | cache_clear(); | |
764 | return viewCurrentFeed(''); | |
765 | } | |
766 | ||
767 | function hotkey_handler(e) { | |
768 | if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return; | |
769 | ||
770 | const action_name = keyevent_to_action(e); | |
771 | ||
772 | if (action_name) { | |
773 | const action_func = hotkey_actions[action_name]; | |
774 | ||
775 | if (action_func != null) { | |
776 | action_func(); | |
777 | e.stopPropagation(); | |
778 | return false; | |
779 | } | |
780 | } | |
781 | } | |
782 | ||
783 | function inPreferences() { | |
784 | return false; | |
785 | } | |
786 | ||
787 | function reverseHeadlineOrder() { | |
788 | ||
789 | const toolbar = document.forms["main_toolbar_form"]; | |
790 | const order_by = dijit.getEnclosingWidget(toolbar.order_by); | |
791 | ||
792 | let value = order_by.attr('value'); | |
793 | ||
794 | if (value == "date_reverse") | |
795 | value = "default"; | |
796 | else | |
797 | value = "date_reverse"; | |
798 | ||
799 | order_by.attr('value', value); | |
800 | ||
801 | viewCurrentFeed(); | |
802 | ||
803 | } | |
804 | ||
805 | function handle_rpc_json(transport, scheduled_call) { | |
806 | ||
807 | const netalert_dijit = dijit.byId("net-alert"); | |
808 | let netalert = false; | |
809 | ||
810 | if (netalert_dijit) netalert = netalert_dijit.domNode; | |
811 | ||
812 | try { | |
813 | const reply = JSON.parse(transport.responseText); | |
814 | ||
815 | if (reply) { | |
816 | ||
817 | const error = reply['error']; | |
818 | ||
819 | if (error) { | |
820 | const code = error['code']; | |
821 | const msg = error['msg']; | |
822 | ||
823 | console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg); | |
824 | ||
825 | if (code != 0) { | |
826 | fatalError(code, msg); | |
827 | return false; | |
828 | } | |
829 | } | |
830 | ||
831 | const seq = reply['seq']; | |
832 | ||
833 | if (seq && get_seq() != seq) { | |
834 | console.log("[handle_rpc_json] sequence mismatch: " + seq + | |
835 | " (want: " + get_seq() + ")"); | |
836 | return true; | |
837 | } | |
838 | ||
839 | const message = reply['message']; | |
840 | ||
841 | if (message == "UPDATE_COUNTERS") { | |
842 | console.log("need to refresh counters..."); | |
843 | setInitParam("last_article_id", -1); | |
844 | request_counters(true); | |
845 | } | |
846 | ||
847 | const counters = reply['counters']; | |
848 | ||
849 | if (counters) | |
850 | parse_counters(counters, scheduled_call); | |
851 | ||
852 | const runtime_info = reply['runtime-info']; | |
853 | ||
854 | if (runtime_info) | |
855 | parse_runtime_info(runtime_info); | |
856 | ||
857 | if (netalert) netalert.hide(); | |
858 | ||
859 | return reply; | |
860 | ||
861 | } else { | |
862 | if (netalert) | |
863 | netalert.show(); | |
864 | else | |
865 | notify_error("Communication problem with server."); | |
866 | } | |
867 | ||
868 | } catch (e) { | |
869 | if (netalert) | |
870 | netalert.show(); | |
871 | else | |
872 | notify_error("Communication problem with server."); | |
873 | ||
874 | console.error(e); | |
875 | } | |
876 | ||
877 | return false; | |
878 | } | |
879 | ||
880 | function switchPanelMode(wide) { | |
881 | if (isCdmMode()) return; | |
882 | ||
883 | const article_id = getActiveArticleId(); | |
884 | ||
885 | if (wide) { | |
886 | dijit.byId("headlines-wrap-inner").attr("design", 'sidebar'); | |
887 | dijit.byId("content-insert").attr("region", "trailing"); | |
888 | ||
889 | dijit.byId("content-insert").domNode.setStyle({width: '50%', | |
890 | height: 'auto', | |
891 | borderTopWidth: '0px' }); | |
892 | ||
893 | if (parseInt(getCookie("ttrss_ci_width")) > 0) { | |
894 | dijit.byId("content-insert").domNode.setStyle( | |
895 | {width: getCookie("ttrss_ci_width") + "px" }); | |
896 | } | |
897 | ||
898 | $("headlines-frame").setStyle({ borderBottomWidth: '0px' }); | |
899 | $("headlines-frame").addClassName("wide"); | |
900 | ||
901 | } else { | |
902 | ||
903 | dijit.byId("content-insert").attr("region", "bottom"); | |
904 | ||
905 | dijit.byId("content-insert").domNode.setStyle({width: 'auto', | |
906 | height: '50%', | |
907 | borderTopWidth: '0px'}); | |
908 | ||
909 | if (parseInt(getCookie("ttrss_ci_height")) > 0) { | |
910 | dijit.byId("content-insert").domNode.setStyle( | |
911 | {height: getCookie("ttrss_ci_height") + "px" }); | |
912 | } | |
913 | ||
914 | $("headlines-frame").setStyle({ borderBottomWidth: '1px' }); | |
915 | $("headlines-frame").removeClassName("wide"); | |
916 | ||
917 | } | |
918 | ||
919 | closeArticlePanel(); | |
920 | ||
921 | if (article_id) view(article_id); | |
922 | ||
923 | xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0}); | |
924 | } | |
925 | ||
926 | function update_random_feed() { | |
927 | console.log("in update_random_feed"); | |
928 | ||
929 | xhrPost("backend.php", { op: "rpc", method: "updateRandomFeed" }, (transport) => { | |
930 | handle_rpc_json(transport, true); | |
931 | window.setTimeout(update_random_feed, 30*1000); | |
932 | }); | |
933 | } | |
934 | ||
935 | function hash_get(key) { | |
936 | const kv = window.location.hash.substring(1).toQueryParams(); | |
937 | return kv[key]; | |
938 | } | |
939 | function hash_set(key, value) { | |
940 | const kv = window.location.hash.substring(1).toQueryParams(); | |
941 | kv[key] = value; | |
942 | window.location.hash = $H(kv).toQueryString(); | |
943 | } |