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