tt-rss.js 22 KB

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