]>
Commit | Line | Data |
---|---|---|
1 | var total_unread = 0; | |
2 | var global_unread = -1; | |
3 | var firsttime_update = true; | |
4 | var _active_feed_id = 0; | |
5 | var _active_feed_is_cat = false; | |
6 | var hotkey_prefix = false; | |
7 | var hotkey_prefix_pressed = false; | |
8 | var _force_scheduled_update = false; | |
9 | var last_scheduled_update = false; | |
10 | ||
11 | var _rpc_seq = 0; | |
12 | ||
13 | function next_seq() { | |
14 | _rpc_seq += 1; | |
15 | return _rpc_seq; | |
16 | } | |
17 | ||
18 | function get_seq() { | |
19 | return _rpc_seq; | |
20 | } | |
21 | ||
22 | function activeFeedIsCat() { | |
23 | return _active_feed_is_cat; | |
24 | } | |
25 | ||
26 | function getActiveFeedId() { | |
27 | try { | |
28 | //console.log("gAFID: " + _active_feed_id); | |
29 | return _active_feed_id; | |
30 | } catch (e) { | |
31 | exception_error("getActiveFeedId", e); | |
32 | } | |
33 | } | |
34 | ||
35 | function setActiveFeedId(id, is_cat) { | |
36 | try { | |
37 | _active_feed_id = id; | |
38 | ||
39 | if (is_cat != undefined) { | |
40 | _active_feed_is_cat = is_cat; | |
41 | } | |
42 | ||
43 | selectFeed(id, is_cat); | |
44 | ||
45 | } catch (e) { | |
46 | exception_error("setActiveFeedId", e); | |
47 | } | |
48 | } | |
49 | ||
50 | ||
51 | function updateFeedList() { | |
52 | try { | |
53 | ||
54 | // $("feeds-holder").innerHTML = "<div id=\"feedlistLoading\">" + | |
55 | // __("Loading, please wait...") + "</div>"; | |
56 | ||
57 | Element.show("feedlistLoading"); | |
58 | ||
59 | if (dijit.byId("feedTree")) { | |
60 | dijit.byId("feedTree").destroyRecursive(); | |
61 | } | |
62 | ||
63 | var store = new dojo.data.ItemFileWriteStore({ | |
64 | url: "backend.php?op=feeds"}); | |
65 | ||
66 | var treeModel = new fox.FeedStoreModel({ | |
67 | store: store, | |
68 | query: { | |
69 | "type": "feed" | |
70 | }, | |
71 | rootId: "root", | |
72 | rootLabel: "Feeds", | |
73 | childrenAttrs: ["items"] | |
74 | }); | |
75 | ||
76 | var tree = new fox.FeedTree({ | |
77 | persist: false, | |
78 | model: treeModel, | |
79 | onOpen: function (item, node) { | |
80 | var id = String(item.id); | |
81 | var cat_id = id.substr(id.indexOf(":")+1); | |
82 | ||
83 | new Ajax.Request("backend.php", | |
84 | { parameters: "backend.php?op=feeds&method=collapse&cid=" + | |
85 | param_escape(cat_id) + "&mode=0" } ); | |
86 | }, | |
87 | onClose: function (item, node) { | |
88 | var id = String(item.id); | |
89 | var cat_id = id.substr(id.indexOf(":")+1); | |
90 | ||
91 | new Ajax.Request("backend.php", | |
92 | { parameters: "backend.php?op=feeds&method=collapse&cid=" + | |
93 | param_escape(cat_id) + "&mode=1" } ); | |
94 | ||
95 | }, | |
96 | onClick: function (item, node) { | |
97 | var id = String(item.id); | |
98 | var is_cat = id.match("^CAT:"); | |
99 | var feed = id.substr(id.indexOf(":")+1); | |
100 | viewfeed(feed, '', is_cat); | |
101 | return false; | |
102 | }, | |
103 | openOnClick: false, | |
104 | showRoot: false, | |
105 | id: "feedTree", | |
106 | }, "feedTree"); | |
107 | ||
108 | /* var menu = new dijit.Menu({id: 'feedMenu'}); | |
109 | ||
110 | menu.addChild(new dijit.MenuItem({ | |
111 | label: "Simple menu item" | |
112 | })); | |
113 | ||
114 | // menu.bindDomNode(tree.domNode); */ | |
115 | ||
116 | var tmph = dojo.connect(dijit.byId('feedMenu'), '_openMyself', function (event) { | |
117 | console.log(dijit.getEnclosingWidget(event.target)); | |
118 | dojo.disconnect(tmph); | |
119 | }); | |
120 | ||
121 | $("feeds-holder").appendChild(tree.domNode); | |
122 | ||
123 | var tmph = dojo.connect(tree, 'onLoad', function() { | |
124 | dojo.disconnect(tmph); | |
125 | Element.hide("feedlistLoading"); | |
126 | ||
127 | tree.collapseHiddenCats(); | |
128 | ||
129 | feedlist_init(); | |
130 | ||
131 | // var node = dijit.byId("feedTree")._itemNodesMap['FEED:-2'][0].domNode | |
132 | // menu.bindDomNode(node); | |
133 | ||
134 | loading_set_progress(25); | |
135 | }); | |
136 | ||
137 | tree.startup(); | |
138 | ||
139 | } catch (e) { | |
140 | exception_error("updateFeedList", e); | |
141 | } | |
142 | } | |
143 | ||
144 | function catchupAllFeeds() { | |
145 | ||
146 | var str = __("Mark all articles as read?"); | |
147 | ||
148 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { | |
149 | ||
150 | var query_str = "backend.php?op=feeds&method=catchupAll"; | |
151 | ||
152 | notify_progress("Marking all feeds as read..."); | |
153 | ||
154 | //console.log("catchupAllFeeds Q=" + query_str); | |
155 | ||
156 | new Ajax.Request("backend.php", { | |
157 | parameters: query_str, | |
158 | onComplete: function(transport) { | |
159 | feedlist_callback2(transport); | |
160 | } }); | |
161 | ||
162 | global_unread = 0; | |
163 | updateTitle(""); | |
164 | } | |
165 | } | |
166 | ||
167 | function viewCurrentFeed(method) { | |
168 | ||
169 | if (getActiveFeedId() != undefined) { | |
170 | viewfeed(getActiveFeedId(), method, activeFeedIsCat()); | |
171 | } | |
172 | return false; // block unneeded form submits | |
173 | } | |
174 | ||
175 | function timeout() { | |
176 | if (getInitParam("bw_limit") == "1") return; | |
177 | ||
178 | try { | |
179 | var date = new Date(); | |
180 | var ts = Math.round(date.getTime() / 1000); | |
181 | ||
182 | if (ts - last_scheduled_update > 10 || _force_scheduled_update) { | |
183 | ||
184 | //console.log("timeout()"); | |
185 | ||
186 | window.clearTimeout(counter_timeout_id); | |
187 | ||
188 | var query_str = "?op=rpc&method=getAllCounters&seq=" + next_seq(); | |
189 | ||
190 | var omode; | |
191 | ||
192 | if (firsttime_update && !navigator.userAgent.match("Opera")) { | |
193 | firsttime_update = false; | |
194 | omode = "T"; | |
195 | } else { | |
196 | omode = "flc"; | |
197 | } | |
198 | ||
199 | query_str = query_str + "&omode=" + omode; | |
200 | ||
201 | if (!_force_scheduled_update) | |
202 | query_str = query_str + "&last_article_id=" + getInitParam("last_article_id"); | |
203 | ||
204 | //console.log("[timeout]" + query_str); | |
205 | ||
206 | new Ajax.Request("backend.php", { | |
207 | parameters: query_str, | |
208 | onComplete: function(transport) { | |
209 | handle_rpc_json(transport, !_force_scheduled_update); | |
210 | _force_scheduled_update = false; | |
211 | } }); | |
212 | ||
213 | last_scheduled_update = ts; | |
214 | } | |
215 | ||
216 | } catch (e) { | |
217 | exception_error("timeout", e); | |
218 | } | |
219 | ||
220 | setTimeout("timeout()", 3000); | |
221 | } | |
222 | ||
223 | function search() { | |
224 | var query = "backend.php?op=dlg&method=search¶m=" + | |
225 | param_escape(getActiveFeedId() + ":" + activeFeedIsCat()); | |
226 | ||
227 | if (dijit.byId("searchDlg")) | |
228 | dijit.byId("searchDlg").destroyRecursive(); | |
229 | ||
230 | dialog = new dijit.Dialog({ | |
231 | id: "searchDlg", | |
232 | title: __("Search"), | |
233 | style: "width: 600px", | |
234 | execute: function() { | |
235 | if (this.validate()) { | |
236 | _search_query = dojo.objectToQuery(this.attr('value')); | |
237 | this.hide(); | |
238 | viewCurrentFeed(); | |
239 | } | |
240 | }, | |
241 | href: query}); | |
242 | ||
243 | dialog.show(); | |
244 | } | |
245 | ||
246 | function updateTitle() { | |
247 | var tmp = "Tiny Tiny RSS"; | |
248 | ||
249 | if (global_unread > 0) { | |
250 | tmp = tmp + " (" + global_unread + ")"; | |
251 | } | |
252 | ||
253 | if (window.fluid) { | |
254 | if (global_unread > 0) { | |
255 | window.fluid.dockBadge = global_unread; | |
256 | } else { | |
257 | window.fluid.dockBadge = ""; | |
258 | } | |
259 | } | |
260 | ||
261 | document.title = tmp; | |
262 | } | |
263 | ||
264 | function genericSanityCheck() { | |
265 | setCookie("ttrss_test", "TEST"); | |
266 | ||
267 | if (getCookie("ttrss_test") != "TEST") { | |
268 | return fatalError(2); | |
269 | } | |
270 | ||
271 | return true; | |
272 | } | |
273 | ||
274 | function init() { | |
275 | try { | |
276 | //dojo.registerModulePath("fox", "../../js/"); | |
277 | ||
278 | dojo.require("fox.FeedTree"); | |
279 | ||
280 | if (typeof themeBeforeLayout == 'function') { | |
281 | themeBeforeLayout(); | |
282 | } | |
283 | ||
284 | dojo.parser.parse(); | |
285 | ||
286 | dojo.addOnLoad(function() { | |
287 | updateFeedList(); | |
288 | closeArticlePanel(); | |
289 | ||
290 | if (typeof themeAfterLayout == 'function') { | |
291 | themeAfterLayout(); | |
292 | } | |
293 | ||
294 | }); | |
295 | ||
296 | if (!genericSanityCheck()) | |
297 | return false; | |
298 | ||
299 | loading_set_progress(20); | |
300 | ||
301 | var hasAudio = !!((myAudioTag = document.createElement('audio')).canPlayType); | |
302 | ||
303 | new Ajax.Request("backend.php", { | |
304 | parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio}, | |
305 | onComplete: function(transport) { | |
306 | backend_sanity_check_callback(transport); | |
307 | } }); | |
308 | ||
309 | } catch (e) { | |
310 | exception_error("init", e); | |
311 | } | |
312 | } | |
313 | ||
314 | function init_second_stage() { | |
315 | ||
316 | try { | |
317 | ||
318 | delCookie("ttrss_test"); | |
319 | ||
320 | var toolbar = document.forms["main_toolbar_form"]; | |
321 | ||
322 | dijit.getEnclosingWidget(toolbar.view_mode).attr('value', | |
323 | getInitParam("default_view_mode")); | |
324 | ||
325 | dijit.getEnclosingWidget(toolbar.order_by).attr('value', | |
326 | getInitParam("default_view_order_by")); | |
327 | ||
328 | feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1; | |
329 | ||
330 | loading_set_progress(30); | |
331 | ||
332 | // can't use cache_clear() here because viewfeed might not have initialized yet | |
333 | if ('sessionStorage' in window && window['sessionStorage'] !== null) | |
334 | sessionStorage.clear(); | |
335 | ||
336 | console.log("second stage ok"); | |
337 | ||
338 | } catch (e) { | |
339 | exception_error("init_second_stage", e); | |
340 | } | |
341 | } | |
342 | ||
343 | function quickMenuGo(opid) { | |
344 | try { | |
345 | if (opid == "qmcPrefs") { | |
346 | gotoPreferences(); | |
347 | } | |
348 | ||
349 | if (opid == "qmcTagCloud") { | |
350 | displayDlg("printTagCloud"); | |
351 | } | |
352 | ||
353 | if (opid == "qmcTagSelect") { | |
354 | displayDlg("printTagSelect"); | |
355 | } | |
356 | ||
357 | if (opid == "qmcSearch") { | |
358 | search(); | |
359 | return; | |
360 | } | |
361 | ||
362 | if (opid == "qmcAddFeed") { | |
363 | quickAddFeed(); | |
364 | return; | |
365 | } | |
366 | ||
367 | if (opid == "qmcDigest") { | |
368 | window.location.href = "digest.php"; | |
369 | return; | |
370 | } | |
371 | ||
372 | if (opid == "qmcEditFeed") { | |
373 | if (activeFeedIsCat()) | |
374 | alert(__("You can't edit this kind of feed.")); | |
375 | else | |
376 | editFeed(getActiveFeedId()); | |
377 | return; | |
378 | } | |
379 | ||
380 | if (opid == "qmcRemoveFeed") { | |
381 | var actid = getActiveFeedId(); | |
382 | ||
383 | if (activeFeedIsCat()) { | |
384 | alert(__("You can't unsubscribe from the category.")); | |
385 | return; | |
386 | } | |
387 | ||
388 | if (!actid) { | |
389 | alert(__("Please select some feed first.")); | |
390 | return; | |
391 | } | |
392 | ||
393 | var fn = getFeedName(actid); | |
394 | ||
395 | var pr = __("Unsubscribe from %s?").replace("%s", fn); | |
396 | ||
397 | if (confirm(pr)) { | |
398 | unsubscribeFeed(actid); | |
399 | } | |
400 | ||
401 | return; | |
402 | } | |
403 | ||
404 | if (opid == "qmcCatchupAll") { | |
405 | catchupAllFeeds(); | |
406 | return; | |
407 | } | |
408 | ||
409 | if (opid == "qmcShowOnlyUnread") { | |
410 | toggleDispRead(); | |
411 | return; | |
412 | } | |
413 | ||
414 | if (opid == "qmcAddFilter") { | |
415 | quickAddFilter(); | |
416 | return; | |
417 | } | |
418 | ||
419 | if (opid == "qmcAddLabel") { | |
420 | addLabel(); | |
421 | return; | |
422 | } | |
423 | ||
424 | if (opid == "qmcRescoreFeed") { | |
425 | rescoreCurrentFeed(); | |
426 | return; | |
427 | } | |
428 | ||
429 | if (opid == "qmcHKhelp") { | |
430 | new Ajax.Request("backend.php", { | |
431 | parameters: "?op=backend&method=help&topic=main", | |
432 | onComplete: function(transport) { | |
433 | $("hotkey_help_overlay").innerHTML = transport.responseText; | |
434 | Effect.Appear("hotkey_help_overlay", {duration : 0.3}); | |
435 | } }); | |
436 | } | |
437 | ||
438 | } catch (e) { | |
439 | exception_error("quickMenuGo", e); | |
440 | } | |
441 | } | |
442 | ||
443 | function toggleDispRead() { | |
444 | try { | |
445 | ||
446 | var hide = !(getInitParam("hide_read_feeds") == "1"); | |
447 | ||
448 | hideOrShowFeeds(hide); | |
449 | ||
450 | var query = "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" + | |
451 | param_escape(hide); | |
452 | ||
453 | setInitParam("hide_read_feeds", hide); | |
454 | ||
455 | new Ajax.Request("backend.php", { | |
456 | parameters: query, | |
457 | onComplete: function(transport) { | |
458 | } }); | |
459 | ||
460 | } catch (e) { | |
461 | exception_error("toggleDispRead", e); | |
462 | } | |
463 | } | |
464 | ||
465 | function parse_runtime_info(data) { | |
466 | ||
467 | //console.log("parsing runtime info..."); | |
468 | ||
469 | for (k in data) { | |
470 | var v = data[k]; | |
471 | ||
472 | // console.log("RI: " + k + " => " + v); | |
473 | ||
474 | if (k == "new_version_available") { | |
475 | var icon = $("newVersionIcon"); | |
476 | if (icon) { | |
477 | if (v == "1") { | |
478 | icon.style.display = "inline"; | |
479 | } else { | |
480 | icon.style.display = "none"; | |
481 | } | |
482 | } | |
483 | return; | |
484 | } | |
485 | ||
486 | if (k == "daemon_is_running" && v != 1) { | |
487 | notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not running.</span>", true); | |
488 | return; | |
489 | } | |
490 | ||
491 | if (k == "daemon_stamp_ok" && v != 1) { | |
492 | notify_error("<span onclick=\"javascript:explainError(3)\">Update daemon is not updating feeds.</span>", true); | |
493 | return; | |
494 | } | |
495 | ||
496 | if (k == "max_feed_id" || k == "num_feeds") { | |
497 | if (init_params[k] != v) { | |
498 | console.log("feed count changed, need to reload feedlist."); | |
499 | updateFeedList(); | |
500 | } | |
501 | } | |
502 | ||
503 | init_params[k] = v; | |
504 | notify(''); | |
505 | } | |
506 | } | |
507 | ||
508 | function catchupCurrentFeed() { | |
509 | ||
510 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
511 | ||
512 | var str = __("Mark all articles in %s as read?").replace("%s", fn); | |
513 | ||
514 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { | |
515 | return viewCurrentFeed('MarkAllRead'); | |
516 | } | |
517 | } | |
518 | ||
519 | function catchupFeedInGroup(id) { | |
520 | ||
521 | try { | |
522 | ||
523 | var title = getFeedName(id); | |
524 | ||
525 | var str = __("Mark all articles in %s as read?").replace("%s", title); | |
526 | ||
527 | if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { | |
528 | return viewCurrentFeed('MarkAllReadGR:' + id); | |
529 | } | |
530 | ||
531 | } catch (e) { | |
532 | exception_error("catchupFeedInGroup", e); | |
533 | } | |
534 | } | |
535 | ||
536 | function collapse_feedlist() { | |
537 | try { | |
538 | ||
539 | if (!Element.visible('feeds-holder')) { | |
540 | Element.show('feeds-holder'); | |
541 | Element.show('feeds-holder_splitter'); | |
542 | $("collapse_feeds_btn").innerHTML = "<<"; | |
543 | } else { | |
544 | Element.hide('feeds-holder'); | |
545 | Element.hide('feeds-holder_splitter'); | |
546 | $("collapse_feeds_btn").innerHTML = ">>"; | |
547 | } | |
548 | ||
549 | dijit.byId("main").resize(); | |
550 | ||
551 | query = "?op=rpc&method=setpref&key=_COLLAPSED_FEEDLIST&value=true"; | |
552 | new Ajax.Request("backend.php", { parameters: query }); | |
553 | ||
554 | } catch (e) { | |
555 | exception_error("collapse_feedlist", e); | |
556 | } | |
557 | } | |
558 | ||
559 | function viewModeChanged() { | |
560 | return viewCurrentFeed(''); | |
561 | } | |
562 | ||
563 | function viewLimitChanged() { | |
564 | return viewCurrentFeed(''); | |
565 | } | |
566 | ||
567 | /* function adjustArticleScore(id, score) { | |
568 | try { | |
569 | ||
570 | var pr = prompt(__("Assign score to article:"), score); | |
571 | ||
572 | if (pr != undefined) { | |
573 | var query = "?op=rpc&method=setScore&id=" + id + "&score=" + pr; | |
574 | ||
575 | new Ajax.Request("backend.php", { | |
576 | parameters: query, | |
577 | onComplete: function(transport) { | |
578 | viewCurrentFeed(); | |
579 | } }); | |
580 | ||
581 | } | |
582 | } catch (e) { | |
583 | exception_error("adjustArticleScore", e); | |
584 | } | |
585 | } */ | |
586 | ||
587 | function rescoreCurrentFeed() { | |
588 | ||
589 | var actid = getActiveFeedId(); | |
590 | ||
591 | if (activeFeedIsCat() || actid < 0) { | |
592 | alert(__("You can't rescore this kind of feed.")); | |
593 | return; | |
594 | } | |
595 | ||
596 | if (!actid) { | |
597 | alert(__("Please select some feed first.")); | |
598 | return; | |
599 | } | |
600 | ||
601 | var fn = getFeedName(actid); | |
602 | var pr = __("Rescore articles in %s?").replace("%s", fn); | |
603 | ||
604 | if (confirm(pr)) { | |
605 | notify_progress("Rescoring articles..."); | |
606 | ||
607 | var query = "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid; | |
608 | ||
609 | new Ajax.Request("backend.php", { | |
610 | parameters: query, | |
611 | onComplete: function(transport) { | |
612 | viewCurrentFeed(); | |
613 | } }); | |
614 | } | |
615 | } | |
616 | ||
617 | function hotkey_handler(e) { | |
618 | try { | |
619 | ||
620 | if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return; | |
621 | ||
622 | var keycode = false; | |
623 | var shift_key = false; | |
624 | ||
625 | var cmdline = $('cmdline'); | |
626 | ||
627 | try { | |
628 | shift_key = e.shiftKey; | |
629 | } catch (e) { | |
630 | ||
631 | } | |
632 | ||
633 | if (window.event) { | |
634 | keycode = window.event.keyCode; | |
635 | } else if (e) { | |
636 | keycode = e.which; | |
637 | } | |
638 | ||
639 | var keychar = String.fromCharCode(keycode); | |
640 | ||
641 | if (keycode == 27) { // escape | |
642 | if (Element.visible("hotkey_help_overlay")) { | |
643 | Element.hide("hotkey_help_overlay"); | |
644 | } | |
645 | hotkey_prefix = false; | |
646 | } | |
647 | ||
648 | if (keycode == 16) return; // ignore lone shift | |
649 | if (keycode == 17) return; // ignore lone ctrl | |
650 | ||
651 | if ((keycode == 70 || keycode == 67 || keycode == 71 || keycode == 65) | |
652 | && !hotkey_prefix) { | |
653 | ||
654 | var date = new Date(); | |
655 | var ts = Math.round(date.getTime() / 1000); | |
656 | ||
657 | hotkey_prefix = keycode; | |
658 | hotkey_prefix_pressed = ts; | |
659 | ||
660 | cmdline.innerHTML = keychar; | |
661 | Element.show(cmdline); | |
662 | ||
663 | console.log("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts); | |
664 | return true; | |
665 | } | |
666 | ||
667 | if (Element.visible("hotkey_help_overlay")) { | |
668 | Element.hide("hotkey_help_overlay"); | |
669 | } | |
670 | ||
671 | /* Global hotkeys */ | |
672 | ||
673 | Element.hide(cmdline); | |
674 | ||
675 | if (!hotkey_prefix) { | |
676 | ||
677 | if (keycode == 27) { // escape | |
678 | closeArticlePanel(); | |
679 | return; | |
680 | } | |
681 | ||
682 | if (keycode == 69) { // e | |
683 | var id = getActiveArticleId(); | |
684 | emailArticle(id); | |
685 | } | |
686 | ||
687 | if ((keycode == 191 || keychar == '?') && shift_key) { // ? | |
688 | ||
689 | new Ajax.Request("backend.php", { | |
690 | parameters: "?op=backend&method=help&topic=main", | |
691 | onComplete: function(transport) { | |
692 | $("hotkey_help_overlay").innerHTML = transport.responseText; | |
693 | Effect.Appear("hotkey_help_overlay", {duration : 0.3}); | |
694 | } }); | |
695 | return false; | |
696 | } | |
697 | ||
698 | if (keycode == 191 || keychar == '/') { // / | |
699 | search(); | |
700 | return false; | |
701 | } | |
702 | ||
703 | if (keycode == 74 && !shift_key) { // j | |
704 | var rv = dijit.byId("feedTree").getPreviousFeed( | |
705 | getActiveFeedId(), activeFeedIsCat()); | |
706 | ||
707 | if (rv) viewfeed(rv[0], '', rv[1]); | |
708 | ||
709 | return; | |
710 | } | |
711 | ||
712 | if (keycode == 75) { // k | |
713 | var rv = dijit.byId("feedTree").getNextFeed( | |
714 | getActiveFeedId(), activeFeedIsCat()); | |
715 | ||
716 | if (rv) viewfeed(rv[0], '', rv[1]); | |
717 | ||
718 | return; | |
719 | } | |
720 | ||
721 | if (shift_key && keycode == 40) { // shift-down | |
722 | catchupRelativeToArticle(1); | |
723 | return; | |
724 | } | |
725 | ||
726 | if (shift_key && keycode == 38) { // shift-up | |
727 | catchupRelativeToArticle(0); | |
728 | return; | |
729 | } | |
730 | ||
731 | if (shift_key && keycode == 78) { // N | |
732 | scrollArticle(50); | |
733 | return; | |
734 | } | |
735 | ||
736 | if (shift_key && keycode == 80) { // P | |
737 | scrollArticle(-50); | |
738 | return; | |
739 | } | |
740 | ||
741 | if (keycode == 68 && shift_key) { // shift-D | |
742 | dismissSelectedArticles(); | |
743 | return; | |
744 | } | |
745 | ||
746 | if (keycode == 88 && shift_key) { // shift-X | |
747 | dismissReadArticles(); | |
748 | return; | |
749 | } | |
750 | ||
751 | if (keycode == 78 || keycode == 40) { // n, down | |
752 | if (typeof moveToPost != 'undefined') { | |
753 | moveToPost('next'); | |
754 | return false; | |
755 | } | |
756 | } | |
757 | ||
758 | if (keycode == 80 || keycode == 38) { // p, up | |
759 | if (typeof moveToPost != 'undefined') { | |
760 | moveToPost('prev'); | |
761 | return false; | |
762 | } | |
763 | } | |
764 | ||
765 | if (keycode == 83 && shift_key) { // S | |
766 | selectionTogglePublished(undefined, false, true); | |
767 | return; | |
768 | } | |
769 | ||
770 | if (keycode == 83) { // s | |
771 | selectionToggleMarked(undefined, false, true); | |
772 | return; | |
773 | } | |
774 | ||
775 | if (keycode == 85) { // u | |
776 | selectionToggleUnread(undefined, false, true); | |
777 | return; | |
778 | } | |
779 | ||
780 | if (keycode == 84 && shift_key) { // T | |
781 | var id = getActiveArticleId(); | |
782 | if (id) { | |
783 | editArticleTags(id, getActiveFeedId(), isCdmMode()); | |
784 | return; | |
785 | } | |
786 | } | |
787 | ||
788 | if (keycode == 9) { // tab | |
789 | var id = getArticleUnderPointer(); | |
790 | if (id) { | |
791 | var cb = $("RCHK-" + id); | |
792 | ||
793 | if (cb) { | |
794 | cb.checked = !cb.checked; | |
795 | toggleSelectRowById(cb, "RROW-" + id); | |
796 | return false; | |
797 | } | |
798 | } | |
799 | } | |
800 | ||
801 | if (keycode == 79) { // o | |
802 | if (getActiveArticleId()) { | |
803 | openArticleInNewWindow(getActiveArticleId()); | |
804 | return; | |
805 | } | |
806 | } | |
807 | ||
808 | if (keycode == 81 && shift_key) { // Q | |
809 | if (typeof catchupAllFeeds != 'undefined') { | |
810 | catchupAllFeeds(); | |
811 | return; | |
812 | } | |
813 | } | |
814 | ||
815 | if (keycode == 88 && !shift_key) { // x | |
816 | if (activeFeedIsCat()) { | |
817 | dijit.byId("feedTree").collapseCat(getActiveFeedId()); | |
818 | return; | |
819 | } | |
820 | } | |
821 | } | |
822 | ||
823 | /* Prefix a */ | |
824 | ||
825 | if (hotkey_prefix == 65) { // a | |
826 | hotkey_prefix = false; | |
827 | ||
828 | if (keycode == 65) { // a | |
829 | selectArticles('all'); | |
830 | return; | |
831 | } | |
832 | ||
833 | if (keycode == 85) { // u | |
834 | selectArticles('unread'); | |
835 | return; | |
836 | } | |
837 | ||
838 | if (keycode == 73) { // i | |
839 | selectArticles('invert'); | |
840 | return; | |
841 | } | |
842 | ||
843 | if (keycode == 78) { // n | |
844 | selectArticles('none'); | |
845 | return; | |
846 | } | |
847 | ||
848 | } | |
849 | ||
850 | /* Prefix f */ | |
851 | ||
852 | if (hotkey_prefix == 70) { // f | |
853 | ||
854 | hotkey_prefix = false; | |
855 | ||
856 | if (keycode == 81) { // q | |
857 | if (getActiveFeedId()) { | |
858 | catchupCurrentFeed(); | |
859 | return; | |
860 | } | |
861 | } | |
862 | ||
863 | if (keycode == 82) { // r | |
864 | if (getActiveFeedId()) { | |
865 | viewfeed(getActiveFeedId(), '', activeFeedIsCat()); | |
866 | return; | |
867 | } | |
868 | } | |
869 | ||
870 | if (keycode == 65) { // a | |
871 | toggleDispRead(); | |
872 | return false; | |
873 | } | |
874 | ||
875 | if (keycode == 85) { // u | |
876 | if (getActiveFeedId()) { | |
877 | viewfeed(getActiveFeedId(), ''); | |
878 | return false; | |
879 | } | |
880 | } | |
881 | ||
882 | if (keycode == 69) { // e | |
883 | ||
884 | if (activeFeedIsCat()) | |
885 | alert(__("You can't edit this kind of feed.")); | |
886 | else | |
887 | editFeed(getActiveFeedId()); | |
888 | return; | |
889 | ||
890 | return false; | |
891 | } | |
892 | ||
893 | if (keycode == 83) { // s | |
894 | quickAddFeed(); | |
895 | return false; | |
896 | } | |
897 | ||
898 | if (keycode == 67 && shift_key) { // C | |
899 | if (typeof catchupAllFeeds != 'undefined') { | |
900 | catchupAllFeeds(); | |
901 | return false; | |
902 | } | |
903 | } | |
904 | ||
905 | if (keycode == 67) { // c | |
906 | if (getActiveFeedId()) { | |
907 | catchupCurrentFeed(); | |
908 | return false; | |
909 | } | |
910 | } | |
911 | ||
912 | if (keycode == 88) { // x | |
913 | reverseHeadlineOrder(); | |
914 | return; | |
915 | } | |
916 | } | |
917 | ||
918 | /* Prefix c */ | |
919 | ||
920 | if (hotkey_prefix == 67) { // c | |
921 | hotkey_prefix = false; | |
922 | ||
923 | if (keycode == 70) { // f | |
924 | quickAddFilter(); | |
925 | return false; | |
926 | } | |
927 | ||
928 | if (keycode == 76) { // l | |
929 | addLabel(); | |
930 | return false; | |
931 | } | |
932 | ||
933 | if (keycode == 83) { // s | |
934 | if (typeof collapse_feedlist != 'undefined') { | |
935 | collapse_feedlist(); | |
936 | return false; | |
937 | } | |
938 | } | |
939 | ||
940 | if (keycode == 77) { // m | |
941 | // TODO: sortable feedlist | |
942 | return; | |
943 | } | |
944 | ||
945 | if (keycode == 78) { // n | |
946 | catchupRelativeToArticle(1); | |
947 | return; | |
948 | } | |
949 | ||
950 | if (keycode == 80) { // p | |
951 | catchupRelativeToArticle(0); | |
952 | return; | |
953 | } | |
954 | ||
955 | ||
956 | } | |
957 | ||
958 | /* Prefix g */ | |
959 | ||
960 | if (hotkey_prefix == 71) { // g | |
961 | ||
962 | hotkey_prefix = false; | |
963 | ||
964 | ||
965 | if (keycode == 65) { // a | |
966 | viewfeed(-4); | |
967 | return false; | |
968 | } | |
969 | ||
970 | if (keycode == 83) { // s | |
971 | viewfeed(-1); | |
972 | return false; | |
973 | } | |
974 | ||
975 | if (keycode == 80 && shift_key) { // P | |
976 | gotoPreferences(); | |
977 | return false; | |
978 | } | |
979 | ||
980 | if (keycode == 80) { // p | |
981 | viewfeed(-2); | |
982 | return false; | |
983 | } | |
984 | ||
985 | if (keycode == 70) { // f | |
986 | viewfeed(-3); | |
987 | return false; | |
988 | } | |
989 | ||
990 | if (keycode == 84) { // t | |
991 | displayDlg("printTagCloud"); | |
992 | return false; | |
993 | } | |
994 | } | |
995 | ||
996 | /* Cmd */ | |
997 | ||
998 | if (hotkey_prefix == 224 || hotkey_prefix == 91) { // f | |
999 | hotkey_prefix = false; | |
1000 | return; | |
1001 | } | |
1002 | ||
1003 | if (hotkey_prefix) { | |
1004 | console.log("KP: PREFIX=" + hotkey_prefix + " CODE=" + keycode + " CHAR=" + keychar); | |
1005 | } else { | |
1006 | console.log("KP: CODE=" + keycode + " CHAR=" + keychar); | |
1007 | } | |
1008 | ||
1009 | ||
1010 | } catch (e) { | |
1011 | exception_error("hotkey_handler", e); | |
1012 | } | |
1013 | } | |
1014 | ||
1015 | function inPreferences() { | |
1016 | return false; | |
1017 | } | |
1018 | ||
1019 | function reverseHeadlineOrder() { | |
1020 | try { | |
1021 | ||
1022 | var query_str = "?op=rpc&method=togglepref&key=REVERSE_HEADLINES"; | |
1023 | ||
1024 | new Ajax.Request("backend.php", { | |
1025 | parameters: query_str, | |
1026 | onComplete: function(transport) { | |
1027 | viewCurrentFeed(); | |
1028 | } }); | |
1029 | ||
1030 | } catch (e) { | |
1031 | exception_error("reverseHeadlineOrder", e); | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | function scheduleFeedUpdate(id, is_cat) { | |
1036 | try { | |
1037 | if (!id) { | |
1038 | id = getActiveFeedId(); | |
1039 | is_cat = activeFeedIsCat(); | |
1040 | } | |
1041 | ||
1042 | if (!id) { | |
1043 | alert(__("Please select some feed first.")); | |
1044 | return; | |
1045 | } | |
1046 | ||
1047 | var query = "?op=rpc&method=scheduleFeedUpdate&id=" + | |
1048 | param_escape(id) + | |
1049 | "&is_cat=" + param_escape(is_cat); | |
1050 | ||
1051 | console.log(query); | |
1052 | ||
1053 | new Ajax.Request("backend.php", { | |
1054 | parameters: query, | |
1055 | onComplete: function(transport) { | |
1056 | handle_rpc_json(transport); | |
1057 | ||
1058 | var reply = JSON.parse(transport.responseText); | |
1059 | var message = reply['message']; | |
1060 | ||
1061 | if (message) { | |
1062 | notify_info(message); | |
1063 | return; | |
1064 | } | |
1065 | ||
1066 | } }); | |
1067 | ||
1068 | ||
1069 | } catch (e) { | |
1070 | exception_error("scheduleFeedUpdate", e); | |
1071 | } | |
1072 | } | |
1073 | ||
1074 | function newVersionDlg() { | |
1075 | try { | |
1076 | var query = "backend.php?op=dlg&method=newVersion"; | |
1077 | ||
1078 | if (dijit.byId("newVersionDlg")) | |
1079 | dijit.byId("newVersionDlg").destroyRecursive(); | |
1080 | ||
1081 | dialog = new dijit.Dialog({ | |
1082 | id: "newVersionDlg", | |
1083 | title: __("New version available!"), | |
1084 | style: "width: 600px", | |
1085 | href: query, | |
1086 | }); | |
1087 | ||
1088 | dialog.show(); | |
1089 | ||
1090 | } catch (e) { | |
1091 | exception_error("newVersionDlg", e); | |
1092 | } | |
1093 | } | |
1094 | ||
1095 | function handle_rpc_json(transport, scheduled_call) { | |
1096 | try { | |
1097 | var reply = JSON.parse(transport.responseText); | |
1098 | ||
1099 | if (reply) { | |
1100 | ||
1101 | var error = reply['error']; | |
1102 | ||
1103 | if (error) { | |
1104 | var code = error['code']; | |
1105 | var msg = error['msg']; | |
1106 | ||
1107 | console.warn("[handle_rpc_json] received fatal error " + code + "/" + msg); | |
1108 | ||
1109 | if (code != 0) { | |
1110 | fatalError(code, msg); | |
1111 | return false; | |
1112 | } | |
1113 | } | |
1114 | ||
1115 | var seq = reply['seq']; | |
1116 | ||
1117 | if (seq) { | |
1118 | if (get_seq() != seq) { | |
1119 | console.log("[handle_rpc_json] sequence mismatch: " + seq + | |
1120 | " (want: " + get_seq() + ")"); | |
1121 | return true; | |
1122 | } | |
1123 | } | |
1124 | ||
1125 | var message = reply['message']; | |
1126 | ||
1127 | if (message) { | |
1128 | if (message == "UPDATE_COUNTERS") { | |
1129 | console.log("need to refresh counters..."); | |
1130 | setInitParam("last_article_id", -1); | |
1131 | _force_scheduled_update = true; | |
1132 | } | |
1133 | } | |
1134 | ||
1135 | var counters = reply['counters']; | |
1136 | ||
1137 | if (counters) | |
1138 | parse_counters(counters, scheduled_call); | |
1139 | ||
1140 | var runtime_info = reply['runtime-info'];; | |
1141 | ||
1142 | if (runtime_info) | |
1143 | parse_runtime_info(runtime_info); | |
1144 | ||
1145 | hideOrShowFeeds(getInitParam("hide_read_feeds") == 1); | |
1146 | ||
1147 | } else { | |
1148 | notify_error("Error communicating with server."); | |
1149 | } | |
1150 | ||
1151 | } catch (e) { | |
1152 | notify_error("Error communicating with server."); | |
1153 | console.log(e); | |
1154 | //exception_error("handle_rpc_json", e, transport); | |
1155 | } | |
1156 | ||
1157 | return true; | |
1158 | } | |
1159 |