From 049a37aa0e7d37cafd979e7d470c7649700b5010 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:05:28 +0300 Subject: WIP reshuffling of JS global context into separate logical objects --- js/functions.js | 178 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 95 insertions(+), 83 deletions(-) (limited to 'js/functions.js') diff --git a/js/functions.js b/js/functions.js index 4a9785fac..d9778ad22 100755 --- a/js/functions.js +++ b/js/functions.js @@ -50,13 +50,85 @@ function xhrJson(url, params, complete) { } /* add method to remove element from array */ - Array.prototype.remove = function(s) { for (let i=0; i < this.length; i++) { if (s == this[i]) this.splice(i, 1); } }; +const Utils = { + cleanupMemory: function(root) { + const dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode); + + dijits.each(function (d) { + dojo.destroy(d.domNode); + }); + + $$("#" + root + " *").each(function (i) { + i.parentNode ? i.parentNode.removeChild(i) : true; + }); + }, + helpDialog: function(topic) { + const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); + + if (dijit.byId("helpDlg")) + dijit.byId("helpDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "helpDlg", + title: __("Help"), + style: "width: 600px", + href: query, + }); + + dialog.show(); + }, + displayDlg: function(title, id, param, callback) { + notify_progress("Loading, please wait...", true); + + const query = {op: "dlg", method: id, param: param}; + + xhrPost("backend.php", query, (transport) => { + try { + const content = transport.responseText; + + let dialog = dijit.byId("infoBox"); + + if (!dialog) { + dialog = new dijit.Dialog({ + title: title, + id: 'infoBox', + style: "width: 600px", + onCancel: function () { + return true; + }, + onExecute: function () { + return true; + }, + onClose: function () { + return true; + }, + content: content + }); + } else { + dialog.attr('title', title); + dialog.attr('content', content); + } + + dialog.show(); + + notify(""); + + if (callback) callback(transport); + } catch (e) { + exception_error(e); + } + }); + + return false; + }, +}; + function report_error(message, filename, lineno, colno, error) { exception_error(error, null, filename, lineno); } @@ -324,51 +396,6 @@ function closeInfoBox() { return false; } -function displayDlg(title, id, param, callback) { - notify_progress("Loading, please wait...", true); - - const query = { op: "dlg", method: id, param: param }; - - xhrPost("backend.php", query, (transport) => { - try { - const content = transport.responseText; - - let dialog = dijit.byId("infoBox"); - - if (!dialog) { - dialog = new dijit.Dialog({ - title: title, - id: 'infoBox', - style: "width: 600px", - onCancel: function () { - return true; - }, - onExecute: function () { - return true; - }, - onClose: function () { - return true; - }, - content: content - }); - } else { - dialog.attr('title', title); - dialog.attr('content', content); - } - - dialog.show(); - - notify(""); - - if (callback) callback(transport); - } catch (e) { - exception_error(e); - } - }); - - return false; -} - function getInitParam(key) { return init_params[key]; } @@ -453,7 +480,7 @@ function filterDlgCheckAction(sender) { function explainError(code) { - return displayDlg(__("Error explained"), "explainError", code); + return Utils.displayDlg(__("Error explained"), "explainError", code); } function setLoadingProgress(p) { @@ -489,9 +516,9 @@ function uploadIconHandler(rc) { case 0: notify_info("Upload complete."); if (inPreferences()) { - updateFeedList(); + Feeds.reload(); } else { - setTimeout('updateFeedList(false, false)', 50); + setTimeout('Feeds.reload(false, false)', 50); } break; case 1: @@ -514,9 +541,9 @@ function removeFeedIcon(id) { xhrPost("backend.php", query, (transport) => { notify_info("Feed icon removed."); if (inPreferences()) { - updateFeedList(); + Feeds.reload(); } else { - setTimeout('updateFeedList(false, false)', 50); + setTimeout('Feeds.reload(false, false)', 50); } }); } @@ -556,7 +583,7 @@ function addLabel(select, callback) { } else if (inPreferences()) { updateLabelList(); } else { - updateFeedList(); + Feeds.reload(); } }); } @@ -616,7 +643,7 @@ function quickAddFeed() { dialog.hide(); notify_info(__("Subscribed to %s").replace("%s", feed_url)); - updateFeedList(); + Feeds.reload(); break; case 2: dialog.show_error(__("Specified URL seems to be invalid.")); @@ -889,7 +916,7 @@ function quickAddFilter() { if (!inPreferences()) { query = { op: "pref-filters", method: "newfilter", - feed: getActiveFeedId(), is_cat: activeFeedIsCat() }; + feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat() }; } else { query = { op: "pref-filters", method: "newfilter" }; } @@ -973,8 +1000,8 @@ function quickAddFilter() { if (selectedText != "") { - const feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) : - getActiveFeedId(); + const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) : + Feeds.getActiveFeedId(); const rule = { reg_exp: selectedText, feed_id: [feed_id], filter_type: 1 }; @@ -991,12 +1018,12 @@ function quickAddFilter() { if (reply && reply.title) title = reply.title; - if (title || getActiveFeedId() || activeFeedIsCat()) { + if (title || Feeds.getActiveFeedId() || Feeds.activeFeedIsCat()) { - console.log(title + " " + getActiveFeedId()); + console.log(title + " " + Feeds.getActiveFeedId()); - const feed_id = activeFeedIsCat() ? 'CAT:' + parseInt(getActiveFeedId()) : - getActiveFeedId(); + const feed_id = Feeds.activeFeedIsCat() ? 'CAT:' + parseInt(Feeds.getActiveFeedId()) : + Feeds.getActiveFeedId(); const rule = { reg_exp: title, feed_id: [feed_id], filter_type: 1 }; @@ -1024,12 +1051,13 @@ function unsubscribeFeed(feed_id, title) { if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide(); if (inPreferences()) { - updateFeedList(); + Feeds.reload(); } else { - if (feed_id == getActiveFeedId()) - setTimeout(function() { viewfeed({feed:-5}) }, 100); + if (feed_id == Feeds.getActiveFeedId()) + setTimeout(() => { Feeds.viewfeed({feed:-5}) }, + 100); - if (feed_id < 0) updateFeedList(); + if (feed_id < 0) Feeds.reload(); } }); } @@ -1219,7 +1247,7 @@ function editFeed(feed) { xhrPost("backend.php", dialog.attr('value'), () => { dialog.hide(); notify(''); - updateFeedList(); + Feeds.reload(); }); } }, @@ -1290,7 +1318,7 @@ function feedBrowser() { xhrPost("backend.php", query, () => { notify(''); - updateFeedList(); + Feeds.reload(); }); } else { @@ -1375,7 +1403,7 @@ function showFeedsWithErrors() { xhrPost("backend.php", query, () => { notify(''); dialog.hide(); - updateFeedList(); + Feeds.reload(); }); } @@ -1399,22 +1427,6 @@ function get_timestamp() { return Math.round(date.getTime() / 1000); } -function helpDialog(topic) { - const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); - - if (dijit.byId("helpDlg")) - dijit.byId("helpDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "helpDlg", - title: __("Help"), - style: "width: 600px", - href: query, - }); - - dialog.show(); -} - // noinspection JSUnusedGlobalSymbols function label_to_feed_id(label) { return _label_base_index - 1 - Math.abs(label); -- cgit v1.2.3-54-g00ecf From d86ddbc635376231ba2e0a70c04f526cb9fedd58 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:21:26 +0300 Subject: further objectification of JS code --- classes/feeds.php | 4 +- index.php | 8 +- js/FeedTree.js | 4 +- js/feedlist.js | 330 ++++++++++++++++++++++++++---------------------------- js/functions.js | 128 +++++++++++++++++++++ js/tt-rss.js | 134 +--------------------- js/viewfeed.js | 38 +++---- 7 files changed, 316 insertions(+), 330 deletions(-) (limited to 'js/functions.js') diff --git a/classes/feeds.php b/classes/feeds.php index 93e44e3bb..63366fd0d 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -388,7 +388,7 @@ class Feeds extends Handler_Protected { $vgroup_last_feed = $feed_id; - $vf_catchup_link = "".__('mark feed as read').""; + $vf_catchup_link = "".__('mark feed as read').""; $reply['content'] .= "
". "
$feed_icon_img
". @@ -481,7 +481,7 @@ class Feeds extends Handler_Protected { $vgroup_last_feed = $feed_id; - $vf_catchup_link = "".__('mark feed as read').""; + $vf_catchup_link = "".__('mark feed as read').""; $feed_icon_src = Feeds::getFeedIcon($feed_id); $feed_icon_img = ""; diff --git a/index.php b/index.php index 48bd559f8..820db9073 100644 --- a/index.php +++ b/index.php @@ -207,16 +207,16 @@ -
+
-
+
-
+
-
+
diff --git a/js/FeedTree.js b/js/FeedTree.js index 21a19bf85..55eb3dc30 100755 --- a/js/FeedTree.js +++ b/js/FeedTree.js @@ -41,7 +41,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"], menu.addChild(new dijit.MenuItem({ label: __("Mark as read"), onClick: function() { - catchupFeed(this.getParent().row_id); + Feeds.catchupFeed(this.getParent().row_id); }})); if (bare_id > 0) { @@ -69,7 +69,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"], menu.addChild(new dijit.MenuItem({ label: __("Mark as read"), onClick: function() { - catchupFeed(this.getParent().row_id, true); + Feeds.catchupFeed(this.getParent().row_id, true); }})); menu.addChild(new dijit.MenuItem({ diff --git a/js/feedlist.js b/js/feedlist.js index b808451b4..c2a0e816d 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -69,23 +69,23 @@ const Feeds = { continue; } - /*if (getFeedUnread(id, (kind == "cat")) != ctr || + /*if (Feeds.getFeedUnread(id, (kind == "cat")) != ctr || (kind == "cat")) { }*/ - setFeedUnread(id, (kind == "cat"), ctr); - setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr); + Feeds.setFeedUnread(id, (kind == "cat"), ctr); + Feeds.setFeedValue(id, (kind == "cat"), 'auxcounter', auxctr); if (kind != "cat") { - setFeedValue(id, false, 'error', error); - setFeedValue(id, false, 'updated', updated); + Feeds.setFeedValue(id, false, 'error', error); + Feeds.setFeedValue(id, false, 'updated', updated); if (id > 0) { if (has_img) { - setFeedIcon(id, false, + Feeds.setFeedIcon(id, false, getInitParam("icons_url") + "/" + id + ".ico?" + has_img); } else { - setFeedIcon(id, false, 'images/blank_icon.gif'); + Feeds.setFeedIcon(id, false, 'images/blank_icon.gif'); } } } @@ -104,7 +104,7 @@ const Feeds = { }, openNextUnreadFeed: function() { const is_cat = Feeds.activeFeedIsCat(); - const nuf = getNextUnreadFeed(Feeds.getActiveFeedId(), is_cat); + const nuf = Feeds.getNextUnreadFeed(Feeds.getActiveFeedId(), is_cat); if (nuf) this.viewfeed({feed: nuf, is_cat: is_cat}); }, collapseFeedlist: function() { @@ -129,13 +129,13 @@ const Feeds = { counters_last_request = timestamp; - let query = {op: "rpc", method: "getAllCounters", seq: App.next_seq()}; + let query = {op: "rpc", method: "getAllCounters", seq: Utils.next_seq()}; if (!force) query.last_article_id = getInitParam("last_article_id"); xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); }); } else { @@ -357,7 +357,7 @@ const Feeds = { Form.enable("main_toolbar_form"); if (!delayed) - if (!setFeedExpandoIcon(feed, is_cat, + if (!Feeds.setFeedExpandoIcon(feed, is_cat, (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) notify_progress("Loading, please wait...", true); @@ -377,7 +377,7 @@ const Feeds = { catchupBatchedArticles(() => { xhrPost("backend.php", query, (transport) => { try { - setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); + Feeds.setFeedExpandoIcon(feed, is_cat, 'images/blank_icon.gif'); Headlines.onLoaded(transport, offset); PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); } catch (e) { @@ -404,221 +404,207 @@ const Feeds = { } }, decrementFeedCounter: function(feed, is_cat) { - let ctr = getFeedUnread(feed, is_cat); + let ctr = Feeds.getFeedUnread(feed, is_cat); if (ctr > 0) { - setFeedUnread(feed, is_cat, ctr - 1); + Feeds.setFeedUnread(feed, is_cat, ctr - 1); App.global_unread -= 1; App.updateTitle(); if (!is_cat) { - const cat = parseInt(getFeedCategory(feed)); + const cat = parseInt(Feeds.getFeedCategory(feed)); if (!isNaN(cat)) { - ctr = getFeedUnread(cat, true); + ctr = Feeds.getFeedUnread(cat, true); if (ctr > 0) { - setFeedUnread(cat, true, ctr - 1); + Feeds.setFeedUnread(cat, true, ctr - 1); } } } } - } -}; - -function getFeedUnread(feed, is_cat) { - try { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.getFeedUnread(feed, is_cat); - - } catch (e) { - // - } - - return -1; -} - -function getFeedCategory(feed) { - try { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.getFeedCategory(feed); - - } catch (e) { - // - } - - return false; -} - -function getFeedName(feed, is_cat) { - - if (isNaN(feed)) return feed; // it's a tag - - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.getFeedValue(feed, is_cat, 'name'); -} - -/* function getFeedValue(feed, is_cat, key) { - try { - const tree = dijit.byId("feedTree"); - - if (tree && tree.model) - return tree.model.getFeedValue(feed, is_cat, key); + }, + catchupFeed: function(feed, is_cat, mode) { + if (is_cat == undefined) is_cat = false; + + let str = false; + + switch (mode) { + case "1day": + str = __("Mark %w in %s older than 1 day as read?"); + break; + case "1week": + str = __("Mark %w in %s older than 1 week as read?"); + break; + case "2week": + str = __("Mark %w in %s older than 2 weeks as read?"); + break; + default: + str = __("Mark %w in %s as read?"); + } - } catch (e) { - // - } - return ''; -} */ + const mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); + const fn = Feeds.getFeedName(feed, is_cat); -function setFeedUnread(feed, is_cat, unread) { - const tree = dijit.byId("feedTree"); + str = str.replace("%s", fn) + .replace("%w", mark_what); - if (tree && tree.model) - return tree.model.setFeedUnread(feed, is_cat, unread); -} + if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { + return; + } -function setFeedValue(feed, is_cat, key, value) { - try { - const tree = dijit.byId("feedTree"); + const catchup_query = { + op: 'rpc', method: 'catchupFeed', feed_id: feed, + is_cat: is_cat, mode: mode, search_query: last_search_query[0], + search_lang: last_search_query[1] + }; - if (tree && tree.model) - return tree.model.setFeedValue(feed, is_cat, key, value); + notify_progress("Loading, please wait...", true); - } catch (e) { - // - } -} + xhrPost("backend.php", catchup_query, (transport) => { + Utils.handleRpcJson(transport); -function setFeedIcon(feed, is_cat, src) { - const tree = dijit.byId("feedTree"); + const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; - if (tree) return tree.setFeedIcon(feed, is_cat, src); -} + if (show_next_feed) { + const nuf = Feeds.getNextUnreadFeed(feed, is_cat); -function setFeedExpandoIcon(feed, is_cat, src) { - const tree = dijit.byId("feedTree"); + if (nuf) { + this.viewfeed({feed: nuf, is_cat: is_cat}); + } + } else if (feed == Feeds.getActiveFeedId() && is_cat == Feeds.activeFeedIsCat()) { + this.viewCurrentFeed(); + } - if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); + notify(""); + }); + }, + catchupCurrentFeed: function(mode) { + Feeds.catchupFeed(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat(), mode); + }, + catchupFeedInGroup: function(id) { + const title = Feeds.getFeedName(id); - return false; -} + const str = __("Mark all articles in %s as read?").replace("%s", title); -function getNextUnreadFeed(feed, is_cat) { - const tree = dijit.byId("feedTree"); - const nuf = tree.model.getNextUnreadFeed(feed, is_cat); + if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { - if (nuf) - return tree.model.store.getValue(nuf, 'bare_id'); -} + const rows = $$("#headlines-frame > div[id*=RROW][data-orig-feed-id='" + id + "']"); -function catchupCurrentFeed(mode) { - catchupFeed(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat(), mode); -} + if (rows.length > 0) { -function catchupFeedInGroup(id) { - const title = getFeedName(id); + rows.each(function (row) { + row.removeClassName("Unread"); - const str = __("Mark all articles in %s as read?").replace("%s", title); + if (row.getAttribute("data-article-id") != getActiveArticleId()) { + new Effect.Fade(row, {duration: 0.5}); + } - if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { + }); - const rows = $$("#headlines-frame > div[id*=RROW][data-orig-feed-id='"+id+"']"); + const feedTitles = $$("#headlines-frame > div[class='feed-title']"); - if (rows.length > 0) { + for (let i = 0; i < feedTitles.length; i++) { + if (feedTitles[i].getAttribute("data-feed-id") == id) { - rows.each(function (row) { - row.removeClassName("Unread"); + if (i < feedTitles.length - 1) { + new Effect.Fade(feedTitles[i], {duration: 0.5}); + } - if (row.getAttribute("data-article-id") != getActiveArticleId()) { - new Effect.Fade(row, {duration: 0.5}); + break; + } } - }); - - const feedTitles = $$("#headlines-frame > div[class='feed-title']"); + Headlines.updateFloatingTitle(true); + } - for (let i = 0; i < feedTitles.length; i++) { - if (feedTitles[i].getAttribute("data-feed-id") == id) { + notify_progress("Loading, please wait...", true); - if (i < feedTitles.length - 1) { - new Effect.Fade(feedTitles[i], {duration: 0.5}); - } + xhrPost("backend.php", {op: "rpc", method: "catchupFeed", feed_id: id, is_cat: false}, (transport) => { + Utils.handleRpcJson(transport); + }); + } + }, + getFeedUnread: function(feed, is_cat) { + try { + const tree = dijit.byId("feedTree"); - break; - } - } + if (tree && tree.model) + return tree.model.getFeedUnread(feed, is_cat); - Headlines.updateFloatingTitle(true); + } catch (e) { + // } - notify_progress("Loading, please wait...", true); + return -1; + }, + getFeedCategory: function(feed) { + try { + const tree = dijit.byId("feedTree"); - xhrPost("backend.php", { op: "rpc", method: "catchupFeed", feed_id: id, is_cat: false}, (transport) => { - App.handleRpcJson(transport); - }); - } -} - -function catchupFeed(feed, is_cat, mode) { - if (is_cat == undefined) is_cat = false; - - let str = false; - - switch (mode) { - case "1day": - str = __("Mark %w in %s older than 1 day as read?"); - break; - case "1week": - str = __("Mark %w in %s older than 1 week as read?"); - break; - case "2week": - str = __("Mark %w in %s older than 2 weeks as read?"); - break; - default: - str = __("Mark %w in %s as read?"); - } + if (tree && tree.model) + return tree.getFeedCategory(feed); - const mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); - const fn = getFeedName(feed, is_cat); + } catch (e) { + // + } - str = str.replace("%s", fn) - .replace("%w", mark_what); + return false; + }, + getFeedName: function(feed, is_cat) { + if (isNaN(feed)) return feed; // it's a tag - if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { - return; - } + const tree = dijit.byId("feedTree"); - const catchup_query = {op: 'rpc', method: 'catchupFeed', feed_id: feed, - is_cat: is_cat, mode: mode, search_query: last_search_query[0], - search_lang: last_search_query[1]}; + if (tree && tree.model) + return tree.model.getFeedValue(feed, is_cat, 'name'); + }, + setFeedUnread: function(feed, is_cat, unread) { + const tree = dijit.byId("feedTree"); - notify_progress("Loading, please wait...", true); + if (tree && tree.model) + return tree.model.setFeedUnread(feed, is_cat, unread); + }, + setFeedValue: function(feed, is_cat, key, value) { + try { + const tree = dijit.byId("feedTree"); - xhrPost("backend.php", catchup_query, (transport) => { - App.handleRpcJson(transport); + if (tree && tree.model) + return tree.model.setFeedValue(feed, is_cat, key, value); - const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; + } catch (e) { + // + } + }, + getFeedValue: function(feed, is_cat, key) { + try { + const tree = dijit.byId("feedTree"); - if (show_next_feed) { - const nuf = getNextUnreadFeed(feed, is_cat); + if (tree && tree.model) + return tree.model.getFeedValue(feed, is_cat, key); - if (nuf) { - Feeds.viewfeed({feed: nuf, is_cat: is_cat}); - } - } else if (feed == Feeds.getActiveFeedId() && is_cat == Feeds.activeFeedIsCat()) { - Feeds.viewCurrentFeed(); + } catch (e) { + // } + return ''; + }, + setFeedIcon: function(feed, is_cat, src) { + const tree = dijit.byId("feedTree"); - notify(""); - }); -} + if (tree) return tree.setFeedIcon(feed, is_cat, src); + }, + setFeedExpandoIcon: function(feed, is_cat, src) { + const tree = dijit.byId("feedTree"); + if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); + return false; + }, + getNextUnreadFeed: function(feed, is_cat) { + const tree = dijit.byId("feedTree"); + const nuf = tree.model.getNextUnreadFeed(feed, is_cat); + if (nuf) + return tree.model.store.getValue(nuf, 'bare_id'); + } +}; diff --git a/js/functions.js b/js/functions.js index d9778ad22..174dbebfe 100755 --- a/js/functions.js +++ b/js/functions.js @@ -57,6 +57,14 @@ Array.prototype.remove = function(s) { }; const Utils = { + _rpc_seq: 0, + next_seq: function() { + this._rpc_seq += 1; + return this._rpc_seq; + }, + get_seq: function() { + return this._rpc_seq; + }, cleanupMemory: function(root) { const dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode); @@ -127,6 +135,126 @@ const Utils = { return false; }, + handleRpcJson: function(transport) { + + const netalert_dijit = dijit.byId("net-alert"); + let netalert = false; + + if (netalert_dijit) netalert = netalert_dijit.domNode; + + try { + const reply = JSON.parse(transport.responseText); + + if (reply) { + + const error = reply['error']; + + if (error) { + const code = error['code']; + const msg = error['msg']; + + console.warn("[handleRpcJson] received fatal error " + code + "/" + msg); + + if (code != 0) { + fatalError(code, msg); + return false; + } + } + + const seq = reply['seq']; + + if (seq && this.get_seq() != seq) { + console.log("[handleRpcJson] sequence mismatch: " + seq + + " (want: " + this.get_seq() + ")"); + return true; + } + + const message = reply['message']; + + if (message == "UPDATE_COUNTERS") { + console.log("need to refresh counters..."); + setInitParam("last_article_id", -1); + Feeds.requestCounters(true); + } + + const counters = reply['counters']; + + if (counters) + Feeds.parseCounters(counters); + + const runtime_info = reply['runtime-info']; + + if (runtime_info) + Utils.parseRuntimeInfo(runtime_info); + + if (netalert) netalert.hide(); + + return reply; + + } else { + if (netalert) + netalert.show(); + else + notify_error("Communication problem with server."); + } + + } catch (e) { + if (netalert) + netalert.show(); + else + notify_error("Communication problem with server."); + + console.error(e); + } + + return false; + }, + parseRuntimeInfo: function(data) { + + //console.log("parsing runtime info..."); + + for (const k in data) { + const v = data[k]; + + if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) { + if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) { + window.location.reload(); + } + } + + if (k == "daemon_is_running" && v != 1) { + notify_error("Update daemon is not running.", true); + return; + } + + if (k == "update_result") { + const updatesIcon = dijit.byId("updatesIcon").domNode; + + if (v) { + Element.show(updatesIcon); + } else { + Element.hide(updatesIcon); + } + } + + if (k == "daemon_stamp_ok" && v != 1) { + notify_error("Update daemon is not updating feeds.", true); + return; + } + + if (k == "max_feed_id" || k == "num_feeds") { + if (init_params[k] != v) { + console.log("feed count changed, need to reload feedlist."); + Feeds.reload(); + } + } + + init_params[k] = v; + notify(''); + } + + PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data); + }, }; function report_error(message, filename, lineno, colno, error) { diff --git a/js/tt-rss.js b/js/tt-rss.js index b5b785321..078ac7c63 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -4,15 +4,7 @@ let _widescreen_mode = false; let hotkey_actions = {}; const App = { - _rpc_seq: 0, global_unread: -1, - next_seq: function() { - this._rpc_seq += 1; - return this._rpc_seq; - }, - get_seq: function() { - return this._rpc_seq; - }, updateTitle: function() { let tmp = "Tiny Tiny RSS"; @@ -85,126 +77,6 @@ const App = { xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0}); }, - parseRuntimeInfo: function(data) { - - //console.log("parsing runtime info..."); - - for (const k in data) { - const v = data[k]; - - if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) { - if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) { - window.location.reload(); - } - } - - if (k == "daemon_is_running" && v != 1) { - notify_error("Update daemon is not running.", true); - return; - } - - if (k == "update_result") { - const updatesIcon = dijit.byId("updatesIcon").domNode; - - if (v) { - Element.show(updatesIcon); - } else { - Element.hide(updatesIcon); - } - } - - if (k == "daemon_stamp_ok" && v != 1) { - notify_error("Update daemon is not updating feeds.", true); - return; - } - - if (k == "max_feed_id" || k == "num_feeds") { - if (init_params[k] != v) { - console.log("feed count changed, need to reload feedlist."); - Feeds.reload(); - } - } - - init_params[k] = v; - notify(''); - } - - PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data); - }, - handleRpcJson: function(transport) { - - const netalert_dijit = dijit.byId("net-alert"); - let netalert = false; - - if (netalert_dijit) netalert = netalert_dijit.domNode; - - try { - const reply = JSON.parse(transport.responseText); - - if (reply) { - - const error = reply['error']; - - if (error) { - const code = error['code']; - const msg = error['msg']; - - console.warn("[handleRpcJson] received fatal error " + code + "/" + msg); - - if (code != 0) { - fatalError(code, msg); - return false; - } - } - - const seq = reply['seq']; - - if (seq && this.get_seq() != seq) { - console.log("[handleRpcJson] sequence mismatch: " + seq + - " (want: " + this.get_seq() + ")"); - return true; - } - - const message = reply['message']; - - if (message == "UPDATE_COUNTERS") { - console.log("need to refresh counters..."); - setInitParam("last_article_id", -1); - Feeds.requestCounters(true); - } - - const counters = reply['counters']; - - if (counters) - Feeds.parseCounters(counters); - - const runtime_info = reply['runtime-info']; - - if (runtime_info) - this.parseRuntimeInfo(runtime_info); - - if (netalert) netalert.hide(); - - return reply; - - } else { - if (netalert) - netalert.show(); - else - notify_error("Communication problem with server."); - } - - } catch (e) { - if (netalert) - netalert.show(); - else - notify_error("Communication problem with server."); - - console.error(e); - } - - return false; - }, }; function search() { @@ -459,7 +331,7 @@ function init_hotkey_actions() { }; hotkey_actions["feed_catchup"] = function() { if (Feeds.getActiveFeedId() != undefined) { - catchupCurrentFeed(); + Feeds.catchupCurrentFeed(); return; } }; @@ -677,7 +549,7 @@ function quickMenuGo(opid) { return; } - var fn = getFeedName(actid); + var fn = Feeds.getFeedName(actid); var pr = __("Unsubscribe from %s?").replace("%s", fn); @@ -743,7 +615,7 @@ function update_random_feed() { console.log("in update_random_feed"); xhrPost("backend.php", { op: "rpc", method: "updateRandomFeed" }, (transport) => { - App.handleRpcJson(transport, true); + Utils.handleRpcJson(transport, true); window.setTimeout(update_random_feed, 30*1000); }); } diff --git a/js/viewfeed.js b/js/viewfeed.js index 637aa0473..bb3f5ef98 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -75,7 +75,7 @@ const Headlines = { const view_mode = document.forms["main_toolbar_form"].view_mode.value; const unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length; const num_all = $$("#headlines-frame > div[id*=RROW]").length; - const num_unread = getFeedUnread(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); + const num_unread = Feeds.getFeedUnread(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); // TODO implement marked & published @@ -248,7 +248,7 @@ const Headlines = { } }, onLoaded: function(transport, offset) { - const reply = App.handleRpcJson(transport); + const reply = Utils.handleRpcJson(transport); console.log("Headlines.onLoaded: offset=", offset); @@ -436,7 +436,7 @@ function view(id, noexpand) { xhrPost("backend.php", {op: "article", method: "view", id: id, cids: cids.toString()}, (transport) => { try { - const reply = App.handleRpcJson(transport); + const reply = Utils.handleRpcJson(transport); if (reply) { @@ -491,7 +491,7 @@ function toggleMark(id, client_only) { if (!client_only) xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); }); } } @@ -518,7 +518,7 @@ function togglePub(id, client_only) { if (!client_only) xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); }); } @@ -642,7 +642,7 @@ function toggleUnread(id, cmode) { if (row.className != origClassName) xhrPost("backend.php", {op: "rpc", method: "catchupSelected", cmode: cmode, ids: id},(transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); }); } } @@ -659,7 +659,7 @@ function selectionRemoveLabel(id, ids) { ids: ids.toString(), lid: id }; xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); updateHeadlineLabels(transport); }); } @@ -676,7 +676,7 @@ function selectionAssignLabel(id, ids) { ids: ids.toString(), lid: id }; xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); updateHeadlineLabels(transport); }); } @@ -719,7 +719,7 @@ function selectionToggleUnread(params) { notify_progress("Loading, please wait..."); xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); if (callback) callback(transport); }); } @@ -740,7 +740,7 @@ function selectionToggleMarked(ids) { ids: rows.toString(), cmode: 2 }; xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); }); } @@ -762,7 +762,7 @@ function selectionTogglePublished(ids) { ids: rows.toString(), cmode: 2 }; xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); }); } } @@ -862,7 +862,7 @@ function deleteSelection() { return; } - const fn = getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); + const fn = Feeds.getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); let str; if (Feeds.getActiveFeedId() != 0) { @@ -881,7 +881,7 @@ function deleteSelection() { const query = { op: "rpc", method: "delete", ids: rows.toString() }; xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); Feeds.viewCurrentFeed(); }); } @@ -896,7 +896,7 @@ function archiveSelection() { return; } - const fn = getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); + const fn = Feeds.getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); let str; let op; @@ -924,7 +924,7 @@ function archiveSelection() { const query = {op: "rpc", method: op, ids: rows.toString()}; xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); Feeds.viewCurrentFeed(); }); } @@ -938,7 +938,7 @@ function catchupSelection() { return; } - const fn = getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); + const fn = Feeds.getFeedName(Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); let str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length); @@ -1091,7 +1091,7 @@ function catchupBatchedArticles(callback) { cmode: 0, ids: batch.toString() }; xhrPost("backend.php", query, (transport) => { - const reply = App.handleRpcJson(transport); + const reply = Utils.handleRpcJson(transport); if (reply) { const batch = reply.ids; @@ -1167,7 +1167,7 @@ function catchupRelativeToArticle(below, id) { cmode: 0, ids: ids_to_mark.toString() }; xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + Utils.handleRpcJson(transport); }); } } @@ -1489,7 +1489,7 @@ function initHeadlinesMenu() { menu.addChild(new dijit.MenuItem({ label: __("Mark feed as read"), onClick: function () { - catchupFeedInGroup(this.getParent().currentTarget.getAttribute("data-feed-id")); + Feeds.catchupFeedInGroup(this.getParent().currentTarget.getAttribute("data-feed-id")); } })); -- cgit v1.2.3-54-g00ecf From 1d82bd4f19de40f0cf966545c372595caa2c8afe Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:42:21 +0300 Subject: further objectification --- index.php | 6 +- js/functions.js | 110 +++++++------ js/tt-rss.js | 449 ++++++++++++++++++++++++--------------------------- js/viewfeed.js | 181 +++++++++++---------- plugins/note/note.js | 2 +- 5 files changed, 364 insertions(+), 384 deletions(-) (limited to 'js/functions.js') diff --git a/index.php b/index.php index 820db9073..8b4b954ef 100644 --- a/index.php +++ b/index.php @@ -139,7 +139,7 @@ @@ -187,7 +187,7 @@
"; + onchange=\"Headlines.onActionChanged(this)\">"; $reply .= ""; @@ -299,7 +299,7 @@ class Feeds extends Handler_Protected { $label_cache = $line["label_cache"]; $labels = false; - $mouseover_attrs = "onmouseover='postMouseIn(event, $id)' onmouseout='postMouseOut($id)'"; + $mouseover_attrs = "onmouseover='Article.mouseIn($id)' onmouseout='Article.mouseOut($id)'"; if ($label_cache) { $label_cache = json_decode($label_cache, true); diff --git a/index.php b/index.php index 8b4b954ef..c8ff3f7c9 100644 --- a/index.php +++ b/index.php @@ -240,18 +240,18 @@
-
-
+
+
-
-
-
+
+
+
-
-
+
+
-
-
+
+
get_hooks(PluginHost::HOOK_ACTION_ITEM) as $p) { @@ -260,7 +260,7 @@ ?> -
+
diff --git a/js/feedlist.js b/js/feedlist.js index ad863f94c..c295bf22b 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -6,6 +6,7 @@ const Feeds = { infscroll_disabled: 0, _infscroll_timeout: false, _search_query: false, + last_search_query: [], _viewfeed_wait_timeout: false, _counters_prev: [], // NOTE: this implementation is incomplete @@ -206,7 +207,7 @@ const Feeds = { Utils.setLoadingProgress(50); - document.onkeydown = App.hotkeyHandler; + document.onkeydown = () => { App.hotkeyHandler(event) }; window.setInterval(() => { hotkeyPrefixTimeout() }, 3 * 1000); window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000); @@ -436,7 +437,7 @@ const Feeds = { str = __("Mark %w in %s as read?"); } - const mark_what = last_search_query && last_search_query[0] ? __("search results") : __("all articles"); + const mark_what = this.last_search_query && this.last_search_query[0] ? __("search results") : __("all articles"); const fn = this.getFeedName(feed, is_cat); str = str.replace("%s", fn) @@ -448,8 +449,8 @@ const Feeds = { const catchup_query = { op: 'rpc', method: 'catchupFeed', feed_id: feed, - is_cat: is_cat, mode: mode, search_query: last_search_query[0], - search_lang: last_search_query[1] + is_cat: is_cat, mode: mode, search_query: this.last_search_query[0], + search_lang: this.last_search_query[1] }; notify_progress("Loading, please wait...", true); diff --git a/js/functions.js b/js/functions.js index 1a0fca484..b6d86b51c 100755 --- a/js/functions.js +++ b/js/functions.js @@ -1025,7 +1025,7 @@ function uploadIconHandler(rc) { switch (rc) { case 0: notify_info("Upload complete."); - if (inPreferences()) { + if (App.isPrefs()) { Feeds.reload(); } else { setTimeout('Feeds.reload(false, false)', 50); @@ -1050,7 +1050,7 @@ function removeFeedIcon(id) { xhrPost("backend.php", query, (transport) => { notify_info("Feed icon removed."); - if (inPreferences()) { + if (App.isPrefs()) { Feeds.reload(); } else { setTimeout('Feeds.reload(false, false)', 50); @@ -1090,7 +1090,7 @@ function addLabel(select, callback) { xhrPost("backend.php", query, (transport) => { if (callback) { callback(transport); - } else if (inPreferences()) { + } else if (App.isPrefs()) { updateLabelList(); } else { Feeds.reload(); @@ -1317,7 +1317,7 @@ function editFilterTest(query) { function quickAddFilter() { let query; - if (!inPreferences()) { + if (!App.isPrefs()) { query = { op: "pref-filters", method: "newfilter", feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat() }; } else { @@ -1385,7 +1385,7 @@ function quickAddFilter() { const query = dojo.formToQuery("filter_new_form"); xhrPost("backend.php", query, (transport) => { - if (inPreferences()) { + if (App.isPrefs()) { updateFilterList(); } @@ -1395,7 +1395,7 @@ function quickAddFilter() { }, href: "backend.php?" + dojo.objectToQuery(query)}); - if (!inPreferences()) { + if (!App.isPrefs()) { const selectedText = getSelectionText(); const lh = dojo.connect(dialog, "onLoad", function(){ @@ -1453,7 +1453,7 @@ function unsubscribeFeed(feed_id, title) { xhrPost("backend.php", query, (transport) => { if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide(); - if (inPreferences()) { + if (App.isPrefs()) { Feeds.reload(); } else { if (feed_id == Feeds.getActiveFeedId()) diff --git a/js/prefs.js b/js/prefs.js index a9417cf3c..8308a747f 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -65,7 +65,7 @@ const App = { }); }, initSecondStage: function() { - document.onkeydown = this.hotkeyHandler; + document.onkeydown = () => { App.hotkeyHandler(event) }; Utils.setLoadingProgress(50); notify(""); @@ -111,8 +111,11 @@ const App = { console.log("unhandled action: " + action_name + "; keycode: " + event.which); } } + }, + isPrefs: function() { + return true; } -} +}; function notify_callback2(transport, sticky) { notify_info(transport.responseText, sticky); @@ -909,10 +912,6 @@ function labelColorReset() { } } -function inPreferences() { - return true; -} - function editProfiles() { if (dijit.byId("profileEditDlg")) diff --git a/js/tt-rss.js b/js/tt-rss.js index 02cf1ddb6..46f100e27 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -1,10 +1,9 @@ /* global dijit, __ */ -let hotkey_actions = {}; - const App = { global_unread: -1, _widescreen_mode: false, + hotkey_actions: {}, init: function() { window.onerror = function (message, filename, lineno, colno, error) { @@ -57,7 +56,7 @@ const App = { return false; Utils.setLoadingProgress(30); - init_hotkey_actions(); + App.initHotkeyActions(); const a = document.createElement('audio'); const hasAudio = !!a.canPlayType; @@ -179,7 +178,7 @@ const App = { const action_name = Utils.keyeventToAction(event); if (action_name) { - const action_func = hotkey_actions[action_name]; + const action_func = this.hotkey_actions[action_name]; if (action_func != null) { action_func(); @@ -233,331 +232,328 @@ const App = { xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0}); }, -}; + initHotkeyActions: function() { + this.hotkey_actions["next_feed"] = function () { + const rv = dijit.byId("feedTree").getNextFeed( + Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); -function init_hotkey_actions() { - hotkey_actions["next_feed"] = function () { - const rv = dijit.byId("feedTree").getNextFeed( - Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); - - if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true}) - }; - hotkey_actions["prev_feed"] = function () { - const rv = dijit.byId("feedTree").getPreviousFeed( - Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); - - if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true}) - }; - hotkey_actions["next_article"] = function () { - Headlines.moveToPost('next'); - }; - hotkey_actions["prev_article"] = function () { - Headlines.moveToPost('prev'); - }; - hotkey_actions["next_article_noscroll"] = function () { - Headlines.moveToPost('next', true); - }; - hotkey_actions["prev_article_noscroll"] = function () { - Headlines.moveToPost('prev', true); - }; - hotkey_actions["next_article_noexpand"] = function () { - Headlines.moveToPost('next', true, true); - }; - hotkey_actions["prev_article_noexpand"] = function () { - Headlines.moveToPost('prev', true, true); - }; - hotkey_actions["search_dialog"] = function () { - Feeds.search(); - }; - hotkey_actions["toggle_mark"] = function () { - Headlines.selectionToggleMarked(); - }; - hotkey_actions["toggle_publ"] = function () { - Headlines.selectionTogglePublished(); - }; - hotkey_actions["toggle_unread"] = function () { - Headlines.selectionToggleUnread({no_error: 1}); - }; - hotkey_actions["edit_tags"] = function () { - const id = Article.getActiveArticleId(); - if (id) { - Article.editArticleTags(id); - } - } - hotkey_actions["open_in_new_window"] = function () { - if (Article.getActiveArticleId()) { - Article.openArticleInNewWindow(Article.getActiveArticleId()); - } - }; - hotkey_actions["catchup_below"] = function () { - catchupRelativeToArticle(1); - }; - hotkey_actions["catchup_above"] = function () { - catchupRelativeToArticle(0); - }; - hotkey_actions["article_scroll_down"] = function () { - scrollArticle(40); - }; - hotkey_actions["article_scroll_up"] = function () { - scrollArticle(-40); - }; - hotkey_actions["close_article"] = function () { - if (App.isCombinedMode()) { - Article.cdmCollapseActive(); - } else { - Article.closeArticlePanel(); - } - }; - hotkey_actions["email_article"] = function () { - if (typeof emailArticle != "undefined") { - emailArticle(); - } else if (typeof mailtoArticle != "undefined") { - mailtoArticle(); - } else { - alert(__("Please enable mail plugin first.")); - } - }; - hotkey_actions["select_all"] = function () { - Headlines.selectArticles('all'); - }; - hotkey_actions["select_unread"] = function () { - Headlines.selectArticles('unread'); - }; - hotkey_actions["select_marked"] = function () { - Headlines.selectArticles('marked'); - }; - hotkey_actions["select_published"] = function () { - Headlines.selectArticles('published'); - }; - hotkey_actions["select_invert"] = function () { - Headlines.selectArticles('invert'); - }; - hotkey_actions["select_none"] = function () { - Headlines.selectArticles('none'); - }; - hotkey_actions["feed_refresh"] = function () { - if (Feeds.getActiveFeedId() != undefined) { - Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat()}); - } - }; - hotkey_actions["feed_unhide_read"] = function () { - Feeds.toggleDispRead(); - }; - hotkey_actions["feed_subscribe"] = function () { - CommonDialogs.quickAddFeed(); - }; - hotkey_actions["feed_debug_update"] = function () { - if (!Feeds.activeFeedIsCat() && parseInt(Feeds.getActiveFeedId()) > 0) { - window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + Feeds.getActiveFeedId() + - "&csrf_token=" + getInitParam("csrf_token")); - } else { - alert("You can't debug this kind of feed."); - } - }; - - hotkey_actions["feed_debug_viewfeed"] = function () { - Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat(), viewfeed_debug: true}); - }; - - hotkey_actions["feed_edit"] = function () { - if (Feeds.activeFeedIsCat()) - alert(__("You can't edit this kind of feed.")); - else - editFeed(Feeds.getActiveFeedId()); - }; - hotkey_actions["feed_catchup"] = function () { - if (Feeds.getActiveFeedId() != undefined) { - Feeds.catchupCurrentFeed(); - } - }; - hotkey_actions["feed_reverse"] = function () { - Headlines.reverseHeadlineOrder(); - }; - hotkey_actions["feed_toggle_vgroup"] = function () { - xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => { - Feeds.viewCurrentFeed(); - }) - }; - hotkey_actions["catchup_all"] = function () { - Feeds.catchupAllFeeds(); - }; - hotkey_actions["cat_toggle_collapse"] = function () { - if (Feeds.activeFeedIsCat()) { - dijit.byId("feedTree").collapseCat(Feeds.getActiveFeedId()); - } - }; - hotkey_actions["goto_all"] = function () { - Feeds.viewfeed({feed: -4}); - }; - hotkey_actions["goto_fresh"] = function () { - Feeds.viewfeed({feed: -3}); - }; - hotkey_actions["goto_marked"] = function () { - Feeds.viewfeed({feed: -1}); - }; - hotkey_actions["goto_published"] = function () { - Feeds.viewfeed({feed: -2}); - }; - hotkey_actions["goto_tagcloud"] = function () { - Utils.displayDlg(__("Tag cloud"), "printTagCloud"); - }; - hotkey_actions["goto_prefs"] = function () { - gotoPreferences(); - }; - hotkey_actions["select_article_cursor"] = function () { - const id = getArticleUnderPointer(); - if (id) { - const row = $("RROW-" + id); - - if (row) { - const cb = dijit.getEnclosingWidget( - row.select(".rchk")[0]); - - if (cb) { - if (!row.hasClassName("active")) - cb.attr("checked", !cb.attr("checked")); - - toggleSelectRowById(cb, "RROW-" + id); - return false; - } + if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true}) + }; + this.hotkey_actions["prev_feed"] = function () { + const rv = dijit.byId("feedTree").getPreviousFeed( + Feeds.getActiveFeedId(), Feeds.activeFeedIsCat()); + + if (rv) Feeds.viewfeed({feed: rv[0], is_cat: rv[1], delayed: true}) + }; + this.hotkey_actions["next_article"] = function () { + Headlines.moveToPost('next'); + }; + this.hotkey_actions["prev_article"] = function () { + Headlines.moveToPost('prev'); + }; + this.hotkey_actions["next_article_noscroll"] = function () { + Headlines.moveToPost('next', true); + }; + this.hotkey_actions["prev_article_noscroll"] = function () { + Headlines.moveToPost('prev', true); + }; + this.hotkey_actions["next_article_noexpand"] = function () { + Headlines.moveToPost('next', true, true); + }; + this.hotkey_actions["prev_article_noexpand"] = function () { + Headlines.moveToPost('prev', true, true); + }; + this.hotkey_actions["search_dialog"] = function () { + Feeds.search(); + }; + this.hotkey_actions["toggle_mark"] = function () { + Headlines.selectionToggleMarked(); + }; + this.hotkey_actions["toggle_publ"] = function () { + Headlines.selectionTogglePublished(); + }; + this.hotkey_actions["toggle_unread"] = function () { + Headlines.selectionToggleUnread({no_error: 1}); + }; + this.hotkey_actions["edit_tags"] = function () { + const id = Article.getActiveArticleId(); + if (id) { + Article.editArticleTags(id); } } - }; - hotkey_actions["create_label"] = function () { - addLabel(); - }; - hotkey_actions["create_filter"] = function () { - quickAddFilter(); - }; - hotkey_actions["collapse_sidebar"] = function () { - Feeds.viewCurrentFeed(); - }; - hotkey_actions["toggle_embed_original"] = function () { - if (typeof embedOriginalArticle != "undefined") { - if (Article.getActiveArticleId()) - embedOriginalArticle(Article.getActiveArticleId()); - } else { - alert(__("Please enable embed_original plugin first.")); - } - }; - hotkey_actions["toggle_widescreen"] = function () { - if (!App.isCombinedMode()) { - App._widescreen_mode = !App._widescreen_mode; + this.hotkey_actions["open_in_new_window"] = function () { + if (Article.getActiveArticleId()) { + Article.openArticleInNewWindow(Article.getActiveArticleId()); + } + }; + this.hotkey_actions["catchup_below"] = function () { + Headlines.catchupRelativeToArticle(1); + }; + this.hotkey_actions["catchup_above"] = function () { + Headlines.catchupRelativeToArticle(0); + }; + this.hotkey_actions["article_scroll_down"] = function () { + Article.scrollArticle(40); + }; + this.hotkey_actions["article_scroll_up"] = function () { + Article.scrollArticle(-40); + }; + this.hotkey_actions["close_article"] = function () { + if (App.isCombinedMode()) { + Article.cdmCollapseActive(); + } else { + Article.closeArticlePanel(); + } + }; + this.hotkey_actions["email_article"] = function () { + if (typeof emailArticle != "undefined") { + emailArticle(); + } else if (typeof mailtoArticle != "undefined") { + mailtoArticle(); + } else { + alert(__("Please enable mail plugin first.")); + } + }; + this.hotkey_actions["select_all"] = function () { + Headlines.selectArticles('all'); + }; + this.hotkey_actions["select_unread"] = function () { + Headlines.selectArticles('unread'); + }; + this.hotkey_actions["select_marked"] = function () { + Headlines.selectArticles('marked'); + }; + this.hotkey_actions["select_published"] = function () { + Headlines.selectArticles('published'); + }; + this.hotkey_actions["select_invert"] = function () { + Headlines.selectArticles('invert'); + }; + this.hotkey_actions["select_none"] = function () { + Headlines.selectArticles('none'); + }; + this.hotkey_actions["feed_refresh"] = function () { + if (Feeds.getActiveFeedId() != undefined) { + Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat()}); + } + }; + this.hotkey_actions["feed_unhide_read"] = function () { + Feeds.toggleDispRead(); + }; + this.hotkey_actions["feed_subscribe"] = function () { + CommonDialogs.quickAddFeed(); + }; + this.hotkey_actions["feed_debug_update"] = function () { + if (!Feeds.activeFeedIsCat() && parseInt(Feeds.getActiveFeedId()) > 0) { + window.open("backend.php?op=feeds&method=update_debugger&feed_id=" + Feeds.getActiveFeedId() + + "&csrf_token=" + getInitParam("csrf_token")); + } else { + alert("You can't debug this kind of feed."); + } + }; - // reset stored sizes because geometry changed - setCookie("ttrss_ci_width", 0); - setCookie("ttrss_ci_height", 0); + this.hotkey_actions["feed_debug_viewfeed"] = function () { + Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat(), viewfeed_debug: true}); + }; - App.switchPanelMode(App._widescreen_mode); - } else { - alert(__("Widescreen is not available in combined mode.")); - } - }; - hotkey_actions["help_dialog"] = function () { - Utils.helpDialog("main"); - }; - hotkey_actions["toggle_combined_mode"] = function () { - notify_progress("Loading, please wait..."); + this.hotkey_actions["feed_edit"] = function () { + if (Feeds.activeFeedIsCat()) + alert(__("You can't edit this kind of feed.")); + else + editFeed(Feeds.getActiveFeedId()); + }; + this.hotkey_actions["feed_catchup"] = function () { + if (Feeds.getActiveFeedId() != undefined) { + Feeds.catchupCurrentFeed(); + } + }; + this.hotkey_actions["feed_reverse"] = function () { + Headlines.reverseHeadlineOrder(); + }; + this.hotkey_actions["feed_toggle_vgroup"] = function () { + xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => { + Feeds.viewCurrentFeed(); + }) + }; + this.hotkey_actions["catchup_all"] = function () { + Feeds.catchupAllFeeds(); + }; + this.hotkey_actions["cat_toggle_collapse"] = function () { + if (Feeds.activeFeedIsCat()) { + dijit.byId("feedTree").collapseCat(Feeds.getActiveFeedId()); + } + }; + this.hotkey_actions["goto_all"] = function () { + Feeds.viewfeed({feed: -4}); + }; + this.hotkey_actions["goto_fresh"] = function () { + Feeds.viewfeed({feed: -3}); + }; + this.hotkey_actions["goto_marked"] = function () { + Feeds.viewfeed({feed: -1}); + }; + this.hotkey_actions["goto_published"] = function () { + Feeds.viewfeed({feed: -2}); + }; + this.hotkey_actions["goto_tagcloud"] = function () { + Utils.displayDlg(__("Tag cloud"), "printTagCloud"); + }; + this.hotkey_actions["goto_prefs"] = function () { + document.location.href = "prefs.php"; + }; + this.hotkey_actions["select_article_cursor"] = function () { + const id = Article.getArticleUnderPointer(); + if (id) { + const row = $("RROW-" + id); - const value = App.isCombinedMode() ? "false" : "true"; + if (row) { + const cb = dijit.getEnclosingWidget( + row.select(".rchk")[0]); - xhrPost("backend.php", {op: "rpc", method: "setpref", key: "COMBINED_DISPLAY_MODE", value: value}, () => { - setInitParam("combined_display_mode", - !getInitParam("combined_display_mode")); + if (cb) { + if (!row.hasClassName("active")) + cb.attr("checked", !cb.attr("checked")); - Article.closeArticlePanel(); + toggleSelectRowById(cb, "RROW-" + id); + return false; + } + } + } + }; + this.hotkey_actions["create_label"] = function () { + addLabel(); + }; + this.hotkey_actions["create_filter"] = function () { + quickAddFilter(); + }; + this.hotkey_actions["collapse_sidebar"] = function () { Feeds.viewCurrentFeed(); - }) - }; - hotkey_actions["toggle_cdm_expanded"] = function () { - notify_progress("Loading, please wait..."); + }; + this.hotkey_actions["toggle_embed_original"] = function () { + if (typeof embedOriginalArticle != "undefined") { + if (Article.getActiveArticleId()) + embedOriginalArticle(Article.getActiveArticleId()); + } else { + alert(__("Please enable embed_original plugin first.")); + } + }; + this.hotkey_actions["toggle_widescreen"] = function () { + if (!App.isCombinedMode()) { + App._widescreen_mode = !App._widescreen_mode; - const value = getInitParam("cdm_expanded") ? "false" : "true"; + // reset stored sizes because geometry changed + setCookie("ttrss_ci_width", 0); + setCookie("ttrss_ci_height", 0); - xhrPost("backend.php", {op: "rpc", method: "setpref", key: "CDM_EXPANDED", value: value}, () => { - setInitParam("cdm_expanded", !getInitParam("cdm_expanded")); - Feeds.viewCurrentFeed(); - }); - }; -} + App.switchPanelMode(App._widescreen_mode); + } else { + alert(__("Widescreen is not available in combined mode.")); + } + }; + this.hotkey_actions["help_dialog"] = function () { + Utils.helpDialog("main"); + }; + this.hotkey_actions["toggle_combined_mode"] = function () { + notify_progress("Loading, please wait..."); -function quickMenuGo(opid) { - switch (opid) { - case "qmcPrefs": - gotoPreferences(); - break; - case "qmcLogout": - document.location.href = "backend.php?op=logout"; - break; - case "qmcTagCloud": - Utils.displayDlg(__("Tag cloud"), "printTagCloud"); - break; - case "qmcSearch": - Feeds.search(); - break; - case "qmcAddFeed": - CommonDialogs.quickAddFeed(); - break; - case "qmcDigest": - window.location.href = "backend.php?op=digest"; - break; - case "qmcEditFeed": - if (Feeds.activeFeedIsCat()) - alert(__("You can't edit this kind of feed.")); - else - editFeed(Feeds.getActiveFeedId()); - break; - case "qmcRemoveFeed": - var actid = Feeds.getActiveFeedId(); - - if (Feeds.activeFeedIsCat()) { - alert(__("You can't unsubscribe from the category.")); - return; - } + const value = App.isCombinedMode() ? "false" : "true"; - if (!actid) { - alert(__("Please select some feed first.")); - return; - } + xhrPost("backend.php", {op: "rpc", method: "setpref", key: "COMBINED_DISPLAY_MODE", value: value}, () => { + setInitParam("combined_display_mode", + !getInitParam("combined_display_mode")); + + Article.closeArticlePanel(); + Feeds.viewCurrentFeed(); + }) + }; + this.hotkey_actions["toggle_cdm_expanded"] = function () { + notify_progress("Loading, please wait..."); - var fn = Feeds.getFeedName(actid); + const value = getInitParam("cdm_expanded") ? "false" : "true"; - var pr = __("Unsubscribe from %s?").replace("%s", fn); + xhrPost("backend.php", {op: "rpc", method: "setpref", key: "CDM_EXPANDED", value: value}, () => { + setInitParam("cdm_expanded", !getInitParam("cdm_expanded")); + Feeds.viewCurrentFeed(); + }); + }; + }, + onActionSelected: function(opid) { + switch (opid) { + case "qmcPrefs": + gotoPreferences(); + break; + case "qmcLogout": + document.location.href = "backend.php?op=logout"; + break; + case "qmcTagCloud": + Utils.displayDlg(__("Tag cloud"), "printTagCloud"); + break; + case "qmcSearch": + Feeds.search(); + break; + case "qmcAddFeed": + CommonDialogs.quickAddFeed(); + break; + case "qmcDigest": + window.location.href = "backend.php?op=digest"; + break; + case "qmcEditFeed": + if (Feeds.activeFeedIsCat()) + alert(__("You can't edit this kind of feed.")); + else + editFeed(Feeds.getActiveFeedId()); + break; + case "qmcRemoveFeed": + var actid = Feeds.getActiveFeedId(); + + if (Feeds.activeFeedIsCat()) { + alert(__("You can't unsubscribe from the category.")); + return; + } - if (confirm(pr)) { - unsubscribeFeed(actid); - } - break; - case "qmcCatchupAll": - Feeds.catchupAllFeeds(); - break; - case "qmcShowOnlyUnread": - Feeds.toggleDispRead(); - break; - case "qmcToggleWidescreen": - if (!App.isCombinedMode()) { - App._widescreen_mode = !App._widescreen_mode; - - // reset stored sizes because geometry changed - setCookie("ttrss_ci_width", 0); - setCookie("ttrss_ci_height", 0); - - App.switchPanelMode(App._widescreen_mode); - } else { - alert(__("Widescreen is not available in combined mode.")); + if (!actid) { + alert(__("Please select some feed first.")); + return; + } + + var fn = Feeds.getFeedName(actid); + + var pr = __("Unsubscribe from %s?").replace("%s", fn); + + if (confirm(pr)) { + unsubscribeFeed(actid); + } + break; + case "qmcCatchupAll": + Feeds.catchupAllFeeds(); + break; + case "qmcShowOnlyUnread": + Feeds.toggleDispRead(); + break; + case "qmcToggleWidescreen": + if (!App.isCombinedMode()) { + App._widescreen_mode = !App._widescreen_mode; + + // reset stored sizes because geometry changed + setCookie("ttrss_ci_width", 0); + setCookie("ttrss_ci_height", 0); + + App.switchPanelMode(App._widescreen_mode); + } else { + alert(__("Widescreen is not available in combined mode.")); + } + break; + case "qmcHKhelp": + Utils.helpDialog("main"); + break; + default: + console.log("quickMenuGo: unknown action: " + opid); } - break; - case "qmcHKhelp": - Utils.helpDialog("main"); - break; - default: - console.log("quickMenuGo: unknown action: " + opid); + }, + isPrefs: function() { + return false; } -} - -function inPreferences() { - return false; -} +}; function hash_get(key) { const kv = window.location.hash.substring(1).toQueryParams(); @@ -569,7 +565,3 @@ function hash_set(key, value) { kv[key] = value; window.location.hash = $H(kv).toQueryString(); } - -function gotoPreferences() { - document.location.href = "prefs.php"; -} diff --git a/js/viewfeed.js b/js/viewfeed.js index cbbea8a05..e8995712a 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1,8 +1,5 @@ /* global dijit, __, ngettext */ -let post_under_pointer = false; -let last_search_query; - const ArticleCache = { has_storage: 'sessionStorage' in window && window['sessionStorage'] !== null, set: function(id, obj) { @@ -118,7 +115,7 @@ const Article = { c.attr('content', article); PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode); - correctHeadlinesOffset(Article.getActiveArticleId()); + Headlines.correctHeadlinesOffset(Article.getActiveArticleId()); try { c.focus(); @@ -126,7 +123,7 @@ const Article = { } }, view: function(id, noexpand) { - Article.setActiveArticleId(id); + this.setActiveArticleId(id); if (!noexpand) { console.log("loading article", id); @@ -135,7 +132,7 @@ const Article = { /* only request uncached articles */ - getRelativePostIds(id).each((n) => { + this.getRelativePostIds(id).each((n) => { if (!ArticleCache.get(n)) cids.push(n); }); @@ -313,6 +310,49 @@ const Article = { }, getActiveArticleId: function() { return this._active_article_id; + }, + scrollArticle: function(offset) { + if (!App.isCombinedMode()) { + const ci = $("content-insert"); + if (ci) { + ci.scrollTop += offset; + } + } else { + const hi = $("headlines-frame"); + if (hi) { + hi.scrollTop += offset; + } + + } + }, + getRelativePostIds: function(id, limit) { + + const tmp = []; + + if (!limit) limit = 6; //3 + + const ids = Headlines.getLoadedArticleIds(); + + for (let i = 0; i < ids.length; i++) { + if (ids[i] == id) { + for (let k = 1; k <= limit; k++) { + //if (i > k-1) tmp.push(ids[i-k]); + if (i < ids.length - k) tmp.push(ids[i + k]); + } + break; + } + } + + return tmp; + }, + mouseIn: function(id) { + this.post_under_pointer = id; + }, + mouseOut: function(id) { + this.post_under_pointer = false; + }, + getArticleUnderPointer: function() { + return this.post_under_pointer; } }; @@ -485,7 +525,7 @@ const Headlines = { ft.firstChild.innerHTML = "" + ft.firstChild.innerHTML; - initFloatingMenu(); + this.initFloatingMenu(); const cb = ft.select(".rchk")[0]; @@ -546,7 +586,7 @@ const Headlines = { is_cat = reply['headlines']['is_cat']; feed_id = reply['headlines']['id']; - last_search_query = reply['headlines']['search_query']; + Feeds.last_search_query = reply['headlines']['search_query']; if (feed_id != -7 && (feed_id != Feeds.getActiveFeedId() || is_cat != Feeds.activeFeedIsCat())) return; @@ -602,7 +642,7 @@ const Headlines = { if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); dijit.byId('headlines-frame').domNode.appendChild(hsp); - initHeadlinesMenu(); + this.initHeadlinesMenu(); if (Feeds.infscroll_disabled) hsp.innerHTML = "" + @@ -646,7 +686,7 @@ const Headlines = { markHeadline(ids[i]); } */ - initHeadlinesMenu(); + this.initHeadlinesMenu(); if (Feeds.infscroll_disabled) { hsp.innerHTML = "" + @@ -894,7 +934,7 @@ const Headlines = { if (!noscroll && article && article.offsetTop + article.offsetHeight > ctr.scrollTop + ctr.offsetHeight) { - scrollArticle(ctr.offsetHeight / 4); + Article.scrollArticle(ctr.offsetHeight / 4); } else if (next_id) { Article.setActiveArticleId(next_id); @@ -902,7 +942,7 @@ const Headlines = { } } else if (next_id) { - correctHeadlinesOffset(next_id); + Headlines.correctHeadlinesOffset(next_id); Article.view(next_id, noexpand); } } @@ -917,17 +957,17 @@ const Headlines = { const ctr = $("headlines-frame"); if (!noscroll && article && article.offsetTop < ctr.scrollTop) { - scrollArticle(-ctr.offsetHeight / 3); + Article.scrollArticle(-ctr.offsetHeight / 3); } else if (!noscroll && prev_article && prev_article.offsetTop < ctr.scrollTop) { - scrollArticle(-ctr.offsetHeight / 4); + Article.scrollArticle(-ctr.offsetHeight / 4); } else if (prev_id) { Article.setActiveArticleId(prev_id); Article.cdmScrollToArticleId(prev_id, noscroll); } } else if (prev_id) { - correctHeadlinesOffset(prev_id); + Headlines.correctHeadlinesOffset(prev_id); Article.view(prev_id, noexpand); } } @@ -986,7 +1026,7 @@ const Headlines = { xhrPost("backend.php", query, (transport) => { Utils.handleRpcJson(transport); - updateHeadlineLabels(transport); + this.onLabelsUpdated(transport); }); }, selectionAssignLabel: function(id, ids) { @@ -1004,7 +1044,7 @@ const Headlines = { xhrPost("backend.php", query, (transport) => { Utils.handleRpcJson(transport); - updateHeadlineLabels(transport); + this.onLabelsUpdated(transport); }); }, deleteSelection: function() { @@ -1212,362 +1252,306 @@ const Headlines = { } else { if (callback) callback(); } - } -}; - -function postMouseIn(e, id) { - post_under_pointer = id; -} - -function postMouseOut(id) { - post_under_pointer = false; -} - -function catchupRelativeToArticle(below, id) { + }, + catchupRelativeToArticle: function(below, id) { - if (!id) id = Article.getActiveArticleId(); + if (!id) id = Article.getActiveArticleId(); - if (!id) { - alert(__("No article is selected.")); - return; - } + if (!id) { + alert(__("No article is selected.")); + return; + } - const visible_ids = Headlines.getLoadedArticleIds(); + const visible_ids = this.getLoadedArticleIds(); - const ids_to_mark = []; + const ids_to_mark = []; - if (!below) { - for (let i = 0; i < visible_ids.length; i++) { - if (visible_ids[i] != id) { - const e = $("RROW-" + visible_ids[i]); + if (!below) { + for (let i = 0; i < visible_ids.length; i++) { + if (visible_ids[i] != id) { + const e = $("RROW-" + visible_ids[i]); - if (e && e.hasClassName("Unread")) { - ids_to_mark.push(visible_ids[i]); + if (e && e.hasClassName("Unread")) { + ids_to_mark.push(visible_ids[i]); + } + } else { + break; } - } else { - break; } - } - } else { - for (let i = visible_ids.length - 1; i >= 0; i--) { - if (visible_ids[i] != id) { - const e = $("RROW-" + visible_ids[i]); + } else { + for (let i = visible_ids.length - 1; i >= 0; i--) { + if (visible_ids[i] != id) { + const e = $("RROW-" + visible_ids[i]); - if (e && e.hasClassName("Unread")) { - ids_to_mark.push(visible_ids[i]); + if (e && e.hasClassName("Unread")) { + ids_to_mark.push(visible_ids[i]); + } + } else { + break; } - } else { - break; } } - } - if (ids_to_mark.length == 0) { - alert(__("No articles found to mark")); - } else { - const msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length); + if (ids_to_mark.length == 0) { + alert(__("No articles found to mark")); + } else { + const msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length); - if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) { + if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) { - for (var i = 0; i < ids_to_mark.length; i++) { - var e = $("RROW-" + ids_to_mark[i]); - e.removeClassName("Unread"); - } + for (var i = 0; i < ids_to_mark.length; i++) { + var e = $("RROW-" + ids_to_mark[i]); + e.removeClassName("Unread"); + } - const query = { op: "rpc", method: "catchupSelected", - cmode: 0, ids: ids_to_mark.toString() }; + const query = { + op: "rpc", method: "catchupSelected", + cmode: 0, ids: ids_to_mark.toString() + }; - xhrPost("backend.php", query, (transport) => { - Utils.handleRpcJson(transport); + xhrPost("backend.php", query, (transport) => { + Utils.handleRpcJson(transport); + }); + } + } + }, + onLabelsUpdated: function(transport) { + const data = JSON.parse(transport.responseText); + + if (data) { + data['info-for-headlines'].each(function (elem) { + $$(".HLLCTR-" + elem.id).each(function (ctr) { + ctr.innerHTML = elem.labels; + }); }); } - } -} + }, + onActionChanged: function(elem) { + eval(elem.value); + elem.attr('value', 'false'); + }, + correctHeadlinesOffset: function(id) { + const container = $("headlines-frame"); + const row = $("RROW-" + id); -function getArticleUnderPointer() { - return post_under_pointer; -} + if (!container || !row) return; -function scrollArticle(offset) { - if (!App.isCombinedMode()) { - const ci = $("content-insert"); - if (ci) { - ci.scrollTop += offset; - } - } else { - const hi = $("headlines-frame"); - if (hi) { - hi.scrollTop += offset; - } + const viewport = container.offsetHeight; - } -} + const rel_offset_top = row.offsetTop - container.scrollTop; + const rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; -function updateHeadlineLabels(transport) { - const data = JSON.parse(transport.responseText); + //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); + //console.log("Vport: " + viewport); - if (data) { - data['info-for-headlines'].each(function (elem) { - $$(".HLLCTR-" + elem.id).each(function (ctr) { - ctr.innerHTML = elem.labels; - }); - }); - } -} + if (rel_offset_top <= 0 || rel_offset_top > viewport) { + container.scrollTop = row.offsetTop; + } else if (rel_offset_bottom > viewport) { + container.scrollTop = row.offsetTop + row.offsetHeight - viewport; + } + }, + initFloatingMenu: function() { + if (!dijit.byId("floatingMenu")) { -function getRelativePostIds(id, limit) { + const menu = new dijit.Menu({ + id: "floatingMenu", + targetNodeIds: ["floatingTitle"] + }); - const tmp = []; + this.headlinesMenuCommon(menu); - if (!limit) limit = 6; //3 + menu.startup(); + } + }, + headlinesMenuCommon: function(menu) { - const ids = Headlines.getLoadedArticleIds(); + menu.addChild(new dijit.MenuItem({ + label: __("Open original article"), + onClick: function (event) { + Article.openArticleInNewWindow(this.getParent().currentTarget.getAttribute("data-article-id")); + } + })); - for (let i = 0; i < ids.length; i++) { - if (ids[i] == id) { - for (let k = 1; k <= limit; k++) { - //if (i > k-1) tmp.push(ids[i-k]); - if (i < ids.length - k) tmp.push(ids[i + k]); + menu.addChild(new dijit.MenuItem({ + label: __("Display article URL"), + onClick: function (event) { + Article.displayArticleUrl(this.getParent().currentTarget.getAttribute("data-article-id")); } - break; - } - } + })); - return tmp; -} + menu.addChild(new dijit.MenuSeparator()); -function correctHeadlinesOffset(id) { - const container = $("headlines-frame"); - const row = $("RROW-" + id); + menu.addChild(new dijit.MenuItem({ + label: __("Toggle unread"), + onClick: function () { - if (!container || !row) return; + let ids = Headlines.getSelectedArticleIds2(); + // cast to string + const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; + ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; - const viewport = container.offsetHeight; + Headlines.selectionToggleUnread({ids: ids, no_error: 1}); + } + })); - const rel_offset_top = row.offsetTop - container.scrollTop; - const rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; + menu.addChild(new dijit.MenuItem({ + label: __("Toggle starred"), + onClick: function () { + let ids = Headlines.getSelectedArticleIds2(); + // cast to string + const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; + ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; - //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); - //console.log("Vport: " + viewport); + Headlines.selectionToggleMarked(ids); + } + })); - if (rel_offset_top <= 0 || rel_offset_top > viewport) { - container.scrollTop = row.offsetTop; - } else if (rel_offset_bottom > viewport) { - container.scrollTop = row.offsetTop + row.offsetHeight - viewport; - } -} + menu.addChild(new dijit.MenuItem({ + label: __("Toggle published"), + onClick: function () { + let ids = Headlines.getSelectedArticleIds2(); + // cast to string + const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; + ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; -function headlineActionsChange(elem) { - eval(elem.value); - elem.attr('value', 'false'); -} + Headlines.selectionTogglePublished(ids); + } + })); -function initFloatingMenu() { - if (!dijit.byId("floatingMenu")) { + menu.addChild(new dijit.MenuSeparator()); - const menu = new dijit.Menu({ - id: "floatingMenu", - targetNodeIds: ["floatingTitle"] - }); + menu.addChild(new dijit.MenuItem({ + label: __("Mark above as read"), + onClick: function () { + Headlines.catchupRelativeToArticle(0, this.getParent().currentTarget.getAttribute("data-article-id")); + } + })); - headlinesMenuCommon(menu); + menu.addChild(new dijit.MenuItem({ + label: __("Mark below as read"), + onClick: function () { + Headlines.catchupRelativeToArticle(1, this.getParent().currentTarget.getAttribute("data-article-id")); + } + })); - menu.startup(); - } -} -function headlinesMenuCommon(menu) { + const labels = getInitParam("labels"); - menu.addChild(new dijit.MenuItem({ - label: __("Open original article"), - onClick: function (event) { - Article.openArticleInNewWindow(this.getParent().currentTarget.getAttribute("data-article-id")); - } - })); + if (labels && labels.length) { - menu.addChild(new dijit.MenuItem({ - label: __("Display article URL"), - onClick: function (event) { - Article.displayArticleUrl(this.getParent().currentTarget.getAttribute("data-article-id")); - } - })); + menu.addChild(new dijit.MenuSeparator()); - menu.addChild(new dijit.MenuSeparator()); + const labelAddMenu = new dijit.Menu({ownerMenu: menu}); + const labelDelMenu = new dijit.Menu({ownerMenu: menu}); - menu.addChild(new dijit.MenuItem({ - label: __("Toggle unread"), - onClick: function () { + labels.each(function (label) { + const bare_id = label.id; + const name = label.caption; - let ids = Headlines.getSelectedArticleIds2(); - // cast to string - const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; - ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; + labelAddMenu.addChild(new dijit.MenuItem({ + label: name, + labelId: bare_id, + onClick: function () { - Headlines.selectionToggleUnread({ids: ids, no_error: 1}); - } - })); + let ids = Headlines.getSelectedArticleIds2(); + // cast to string + const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; - menu.addChild(new dijit.MenuItem({ - label: __("Toggle starred"), - onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); - // cast to string - const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; - ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; + ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; - Headlines.selectionToggleMarked(ids); - } - })); + Headlines.selectionAssignLabel(this.labelId, ids); + } + })); - menu.addChild(new dijit.MenuItem({ - label: __("Toggle published"), - onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); - // cast to string - const id = (this.getParent().currentTarget.getAttribute("data-article-id")) + ""; - ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; + labelDelMenu.addChild(new dijit.MenuItem({ + label: name, + labelId: bare_id, + onClick: function () { + let ids = Headlines.getSelectedArticleIds2(); + // cast to string + const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; - Headlines.selectionTogglePublished(ids); - } - })); + ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; - menu.addChild(new dijit.MenuSeparator()); + Headlines.selectionRemoveLabel(this.labelId, ids); + } + })); - menu.addChild(new dijit.MenuItem({ - label: __("Mark above as read"), - onClick: function () { - catchupRelativeToArticle(0, this.getParent().currentTarget.getAttribute("data-article-id")); - } - })); + }); - menu.addChild(new dijit.MenuItem({ - label: __("Mark below as read"), - onClick: function () { - catchupRelativeToArticle(1, this.getParent().currentTarget.getAttribute("data-article-id")); - } - })); + menu.addChild(new dijit.PopupMenuItem({ + label: __("Assign label"), + popup: labelAddMenu + })); + menu.addChild(new dijit.PopupMenuItem({ + label: __("Remove label"), + popup: labelDelMenu + })); - const labels = getInitParam("labels"); + } + }, + initHeadlinesMenu: function() { + if (!dijit.byId("headlinesMenu")) { - if (labels && labels.length) { + const menu = new dijit.Menu({ + id: "headlinesMenu", + targetNodeIds: ["headlines-frame"], + selector: ".hlMenuAttach" + }); - menu.addChild(new dijit.MenuSeparator()); + this.headlinesMenuCommon(menu); - const labelAddMenu = new dijit.Menu({ownerMenu: menu}); - const labelDelMenu = new dijit.Menu({ownerMenu: menu}); + menu.startup(); + } - labels.each(function (label) { - const bare_id = label.id; - const name = label.caption; + /* vgroup feed title menu */ - labelAddMenu.addChild(new dijit.MenuItem({ - label: name, - labelId: bare_id, - onClick: function () { + if (!dijit.byId("headlinesFeedTitleMenu")) { - let ids = Headlines.getSelectedArticleIds2(); - // cast to string - const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; + const menu = new dijit.Menu({ + id: "headlinesFeedTitleMenu", + targetNodeIds: ["headlines-frame"], + selector: "div.cdmFeedTitle" + }); - ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; + menu.addChild(new dijit.MenuItem({ + label: __("Select articles in group"), + onClick: function (event) { + Headlines.selectArticles("all", + "#headlines-frame > div[id*=RROW]" + + "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']"); - Headlines.selectionAssignLabel(this.labelId, ids); } })); - labelDelMenu.addChild(new dijit.MenuItem({ - label: name, - labelId: bare_id, + menu.addChild(new dijit.MenuItem({ + label: __("Mark group as read"), onClick: function () { - let ids = Headlines.getSelectedArticleIds2(); - // cast to string - const id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + ""; - - ids = ids.length != 0 && ids.indexOf(id) != -1 ? ids : [id]; + Headlines.selectArticles("none"); + Headlines.selectArticles("all", + "#headlines-frame > div[id*=RROW]" + + "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']"); - Headlines.selectionRemoveLabel(this.labelId, ids); + Headlines.catchupSelection(); } })); - }); - - menu.addChild(new dijit.PopupMenuItem({ - label: __("Assign label"), - popup: labelAddMenu - })); - - menu.addChild(new dijit.PopupMenuItem({ - label: __("Remove label"), - popup: labelDelMenu - })); - - } -} - -function initHeadlinesMenu() { - if (!dijit.byId("headlinesMenu")) { - - const menu = new dijit.Menu({ - id: "headlinesMenu", - targetNodeIds: ["headlines-frame"], - selector: ".hlMenuAttach" - }); - - headlinesMenuCommon(menu); - - menu.startup(); - } - - /* vgroup feed title menu */ - - if (!dijit.byId("headlinesFeedTitleMenu")) { - - const menu = new dijit.Menu({ - id: "headlinesFeedTitleMenu", - targetNodeIds: ["headlines-frame"], - selector: "div.cdmFeedTitle" - }); - - menu.addChild(new dijit.MenuItem({ - label: __("Select articles in group"), - onClick: function (event) { - Headlines.selectArticles("all", - "#headlines-frame > div[id*=RROW]" + - "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']"); - - } - })); - - menu.addChild(new dijit.MenuItem({ - label: __("Mark group as read"), - onClick: function () { - Headlines.selectArticles("none"); - Headlines.selectArticles("all", - "#headlines-frame > div[id*=RROW]" + - "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']"); - - Headlines.catchupSelection(); - } - })); - - menu.addChild(new dijit.MenuItem({ - label: __("Mark feed as read"), - onClick: function () { - Feeds.catchupFeedInGroup(this.getParent().currentTarget.getAttribute("data-feed-id")); - } - })); + menu.addChild(new dijit.MenuItem({ + label: __("Mark feed as read"), + onClick: function () { + Feeds.catchupFeedInGroup(this.getParent().currentTarget.getAttribute("data-feed-id")); + } + })); - menu.addChild(new dijit.MenuItem({ - label: __("Edit feed"), - onClick: function () { - editFeed(this.getParent().currentTarget.getAttribute("data-feed-id")); - } - })); + menu.addChild(new dijit.MenuItem({ + label: __("Edit feed"), + onClick: function () { + editFeed(this.getParent().currentTarget.getAttribute("data-feed-id")); + } + })); - menu.startup(); + menu.startup(); + } } -} - - - +}; -- cgit v1.2.3-54-g00ecf From de9509cd31d63b036f63fc56697e018263e52eda Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 22:07:00 +0300 Subject: hotkeys: simplify prefix timeout handling --- js/feedlist.js | 3 ++- js/functions.js | 50 +++++++++++++++++++++----------------------------- js/prefs.js | 2 -- js/viewfeed.js | 2 +- 4 files changed, 24 insertions(+), 33 deletions(-) (limited to 'js/functions.js') diff --git a/js/feedlist.js b/js/feedlist.js index c295bf22b..bff62043f 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -1,3 +1,5 @@ +/* global notify,__,dijit */ + const Feeds = { counters_last_request: 0, _active_feed_id: 0, @@ -208,7 +210,6 @@ const Feeds = { Utils.setLoadingProgress(50); document.onkeydown = () => { App.hotkeyHandler(event) }; - window.setInterval(() => { hotkeyPrefixTimeout() }, 3 * 1000); window.setInterval(() => { Headlines.catchupBatchedArticles() }, 10 * 1000); if (!this.getActiveFeedId()) { diff --git a/js/functions.js b/js/functions.js index b6d86b51c..04a81d925 100755 --- a/js/functions.js +++ b/js/functions.js @@ -5,9 +5,6 @@ let _label_base_index = -1024; let loading_progress = 0; let notify_hide_timerid = false; -let hotkey_prefix = 0; -let hotkey_prefix_pressed = false; - Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( function (callOriginal, options) { @@ -58,6 +55,9 @@ Array.prototype.remove = function(s) { const Utils = { _rpc_seq: 0, + hotkey_prefix: 0, + hotkey_prefix_pressed: false, + hotkey_prefix_timeout: 0, next_seq: function() { this._rpc_seq += 1; return this._rpc_seq; @@ -75,30 +75,34 @@ const Utils = { Element.hide("overlay"); }, - keyeventToAction: function(e) { + keyeventToAction: function(event) { const hotkeys_map = getInitParam("hotkeys"); - const keycode = e.which; + const keycode = event.which; const keychar = String.fromCharCode(keycode).toLowerCase(); if (keycode == 27) { // escape and drop prefix - hotkey_prefix = false; + this.hotkey_prefix = false; } if (keycode == 16 || keycode == 17) return; // ignore lone shift / ctrl - if (!hotkey_prefix && hotkeys_map[0].indexOf(keychar) != -1) { + if (!this.hotkey_prefix && hotkeys_map[0].indexOf(keychar) != -1) { const date = new Date(); const ts = Math.round(date.getTime() / 1000); - hotkey_prefix = keychar; - hotkey_prefix_pressed = ts; - + this.hotkey_prefix = keychar; $("cmdline").innerHTML = keychar; Element.show("cmdline"); - e.stopPropagation(); + window.clearTimeout(this.hotkey_prefix_timeout); + this.hotkey_prefix_timeout = window.setTimeout(() => { + this.hotkey_prefix = false; + Element.hide("cmdline"); + }, 3 * 1000); + + event.stopPropagation(); return false; } @@ -108,13 +112,13 @@ const Utils = { let hotkey_name = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")"; // ensure ^*char notation - if (e.shiftKey) hotkey_name = "*" + hotkey_name; - if (e.ctrlKey) hotkey_name = "^" + hotkey_name; - if (e.altKey) hotkey_name = "+" + hotkey_name; - if (e.metaKey) hotkey_name = "%" + hotkey_name; + if (event.shiftKey) hotkey_name = "*" + hotkey_name; + if (event.ctrlKey) hotkey_name = "^" + hotkey_name; + if (event.altKey) hotkey_name = "+" + hotkey_name; + if (event.metaKey) hotkey_name = "%" + hotkey_name; - const hotkey_full = hotkey_prefix ? hotkey_prefix + " " + hotkey_name : hotkey_name; - hotkey_prefix = false; + const hotkey_full = this.hotkey_prefix ? this.hotkey_prefix + " " + hotkey_name : hotkey_name; + this.hotkey_prefix = false; let action_name = false; @@ -1008,18 +1012,6 @@ function strip_tags(s) { return s.replace(/<\/?[^>]+(>|$)/g, ""); } -function hotkeyPrefixTimeout() { - const date = new Date(); - const ts = Math.round(date.getTime() / 1000); - - if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) { - console.log("hotkey_prefix seems to be stuck, aborting"); - hotkey_prefix_pressed = false; - hotkey_prefix = false; - Element.hide('cmdline'); - } -} - // noinspection JSUnusedGlobalSymbols function uploadIconHandler(rc) { switch (rc) { diff --git a/js/prefs.js b/js/prefs.js index 8308a747f..1541d49d0 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -85,8 +85,6 @@ const App = { editFeed(param) }, 100); } - - setInterval(() => { hotkeyPrefixTimeout() }, 5 * 1000); }, hotkeyHandler: function (event) { if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; diff --git a/js/viewfeed.js b/js/viewfeed.js index b091e5ccb..01e5cb325 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1,4 +1,4 @@ -/* global dijit, __, ngettext */ +/* global dijit, __, ngettext, notify */ const ArticleCache = { has_storage: 'sessionStorage' in window && window['sessionStorage'] !== null, -- cgit v1.2.3-54-g00ecf From bc96eac2ac6579bfe7a4d99292c0ada3412dc54c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 22:19:20 +0300 Subject: addLabel -> CommonDialogs --- js/functions.js | 48 +++++++++++++++++++++++------------------------- js/prefs.js | 2 +- js/tt-rss.js | 4 ++-- 3 files changed, 26 insertions(+), 28 deletions(-) (limited to 'js/functions.js') diff --git a/js/functions.js b/js/functions.js index 04a81d925..f4e422aec 100755 --- a/js/functions.js +++ b/js/functions.js @@ -651,6 +651,29 @@ const CommonDialogs = { }); dialog.show(); + }, + addLabel: function(select, callback) { + const caption = prompt(__("Please enter label caption:"), ""); + + if (caption != undefined && caption.trim().length > 0) { + + const query = {op: "pref-labels", method: "add", caption: caption.trim()}; + + if (select) + Object.extend(query, {output: "select"}); + + notify_progress("Loading, please wait...", true); + + xhrPost("backend.php", query, (transport) => { + if (callback) { + callback(transport); + } else if (App.isPrefs()) { + updateLabelList(); + } else { + Feeds.reload(); + } + }); + } } }; @@ -1067,31 +1090,6 @@ function uploadFeedIcon() { return false; } -function addLabel(select, callback) { - const caption = prompt(__("Please enter label caption:"), ""); - - if (caption != undefined && caption.trim().length > 0) { - - const query = { op: "pref-labels", method: "add", caption: caption.trim() }; - - if (select) - Object.extend(query, {output: "select"}); - - notify_progress("Loading, please wait...", true); - - xhrPost("backend.php", query, (transport) => { - if (callback) { - callback(transport); - } else if (App.isPrefs()) { - updateLabelList(); - } else { - Feeds.reload(); - } - }); - } - -} - function createNewRuleElement(parentNode, replaceNode) { const form = document.forms["filter_new_rule_form"]; const query = { op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form) }; diff --git a/js/prefs.js b/js/prefs.js index 1541d49d0..67be0b474 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -97,7 +97,7 @@ const App = { CommonDialogs.quickAddFeed(); return false; case "create_label": - addLabel(); + CommonDialogs.addLabel(); return false; case "create_filter": quickAddFilter(); diff --git a/js/tt-rss.js b/js/tt-rss.js index 46f100e27..6dd4a91eb 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -421,7 +421,7 @@ const App = { } }; this.hotkey_actions["create_label"] = function () { - addLabel(); + CommonDialogs.addLabel(); }; this.hotkey_actions["create_filter"] = function () { quickAddFilter(); @@ -480,7 +480,7 @@ const App = { onActionSelected: function(opid) { switch (opid) { case "qmcPrefs": - gotoPreferences(); + document.location.href = "prefs.php"; break; case "qmcLogout": document.location.href = "backend.php?op=logout"; -- cgit v1.2.3-54-g00ecf From 1e2d4410d320fcee644add76293f229741a163cb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 22:39:29 +0300 Subject: move some more shared stuff to CommonDialogs, Filters, and Utils --- classes/dlg.php | 2 +- classes/pref/feeds.php | 8 +- classes/pref/filters.php | 4 +- js/FeedTree.js | 2 +- js/PrefFeedTree.js | 4 +- js/functions.js | 877 ++++++++++++++++++++-------------------- js/prefs.js | 6 +- js/tt-rss.js | 8 +- js/viewfeed.js | 2 +- plugins/af_psql_trgm/init.php | 2 +- plugins/af_readability/init.php | 2 +- tests/functional/BasicTest.php | 2 +- 12 files changed, 463 insertions(+), 456 deletions(-) (limited to 'js/functions.js') diff --git a/classes/dlg.php b/classes/dlg.php index 50cbd12dd..02249ea96 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -174,7 +174,7 @@ class Dlg extends Handler_Protected { print "
"; - print " "; print ""; print "
"; @@ -1247,7 +1247,7 @@ class Pref_Feeds extends Handler_Protected { var bare_id = id.substr(id.indexOf(':')+1); if (id.match('FEED:')) { - editFeed(bare_id); + CommonDialogs.editFeed(bare_id); } else if (id.match('CAT:')) { editCat(bare_id, item); } @@ -1441,7 +1441,7 @@ class Pref_Feeds extends Handler_Protected { print "
". + "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". htmlspecialchars($line["title"]).""; print ""; @@ -1506,7 +1506,7 @@ class Pref_Feeds extends Handler_Protected { print "". + "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". htmlspecialchars($line["title"]).": "; print ""; diff --git a/classes/pref/filters.php b/classes/pref/filters.php index e3503d545..e60628f8f 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -797,7 +797,7 @@ class Pref_Filters extends Handler_Protected { dojoType=\"dijit.MenuItem\">".__('None')."
"; print "
"; - print " "; print " "; print " -- cgit v1.2.3-54-g00ecf From 1930f0e4e088e4828b5b575a133c64bf46920e5d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 09:49:49 +0300 Subject: toggleSelect(etc): properly check for headlines object --- js/functions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/functions.js') diff --git a/js/functions.js b/js/functions.js index df7a33831..3a07b170f 100755 --- a/js/functions.js +++ b/js/functions.js @@ -1004,7 +1004,7 @@ function toggleSelectRow2(sender, row, is_cdm) { else row.removeClassName('Selected'); - if (typeof updateSelectedPrompt != undefined) + if (typeof Headlines != "undefined") Headlines.updateSelectedPrompt(); } @@ -1018,7 +1018,7 @@ function toggleSelectRow(sender, row) { else row.removeClassName('Selected'); - if (typeof updateSelectedPrompt != undefined) + if (typeof Headlines != "undefined") Headlines.updateSelectedPrompt(); } -- cgit v1.2.3-54-g00ecf From fb64726854479dc52993dd4a18ee2a54294d1ac4 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 10:01:03 +0300 Subject: filters: simplify list row selection for checkboxes --- js/functions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/functions.js') diff --git a/js/functions.js b/js/functions.js index 3a07b170f..b7d37044c 100755 --- a/js/functions.js +++ b/js/functions.js @@ -1137,7 +1137,7 @@ const Filters = { new dijit.form.CheckBox({ onChange: function () { - toggleSelectListRow2(this) + $$(".rchk")[0].up("li").toggleClassName("Selected"); }, }, cb); @@ -1186,7 +1186,7 @@ const Filters = { new dijit.form.CheckBox({ onChange: function () { - toggleSelectListRow2(this) + $$(".rchk")[0].up("li").toggleClassName("Selected"); }, }, cb); -- cgit v1.2.3-54-g00ecf From 8ea3a75df02fdf8ccfea6ca32965a1d407f089b6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 10:03:31 +0300 Subject: filters: simplify list row selection for checkboxes (properly) --- js/functions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/functions.js') diff --git a/js/functions.js b/js/functions.js index b7d37044c..59912905d 100755 --- a/js/functions.js +++ b/js/functions.js @@ -1137,7 +1137,7 @@ const Filters = { new dijit.form.CheckBox({ onChange: function () { - $$(".rchk")[0].up("li").toggleClassName("Selected"); + this.domNode.up("li").toggleClassName("Selected"); }, }, cb); @@ -1186,7 +1186,7 @@ const Filters = { new dijit.form.CheckBox({ onChange: function () { - $$(".rchk")[0].up("li").toggleClassName("Selected"); + this.domNode.up("li").toggleClassName("Selected"); }, }, cb); -- cgit v1.2.3-54-g00ecf From 2f85b50e3607b2b159989c493ac8f8c46a389559 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 10:16:25 +0300 Subject: remove toggleSelectListRow2() --- classes/pref/filters.php | 4 ++-- include/feedbrowser.php | 8 ++------ js/functions.js | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 16 deletions(-) (limited to 'js/functions.js') diff --git a/classes/pref/filters.php b/classes/pref/filters.php index e60628f8f..e48615395 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -429,7 +429,7 @@ class Pref_Filters extends Handler_Protected { $data = htmlspecialchars(json_encode($line)); - print "
  • ". + print "
  • ". "".$this->getRuleName($line)."". "
  • "; } @@ -473,7 +473,7 @@ class Pref_Filters extends Handler_Protected { $data = htmlspecialchars(json_encode($line)); - print "
  • ". + print "
  • ". "".$this->getActionName($line)."". "
  • "; } diff --git a/include/feedbrowser.php b/include/feedbrowser.php index 8ebeb20cc..a0b1b6e8f 100644 --- a/include/feedbrowser.php +++ b/include/feedbrowser.php @@ -53,12 +53,10 @@ $site_url = htmlspecialchars($line["site_url"]); $subscribers = $line["subscribers"]; - $check_box = ""; - $class = ($feedctr % 2) ? "even" : "odd"; - $site_url = " ". @@ -75,11 +73,9 @@ $feed_url = htmlspecialchars($line["feed_url"]); $site_url = htmlspecialchars($line["site_url"]); - $check_box = ""; - $class = ($feedctr % 2) ? "even" : "odd"; - if ($line['articles_archived'] > 0) { $archived = sprintf(_ngettext("%d archived article", "%d archived articles", (int) $line['articles_archived']), $line['articles_archived']); $archived = " ($archived)"; diff --git a/js/functions.js b/js/functions.js index 59912905d..ce6d7aca9 100755 --- a/js/functions.js +++ b/js/functions.js @@ -53,6 +53,15 @@ Array.prototype.remove = function(s) { } }; +const ListUtils = { + onChecked: function(elem) { + // account for dojo checkboxes + elem = elem.domNode || elem; + + elem.up("li").toggleClassName("Selected"); + } +}; + const Utils = { _rpc_seq: 0, hotkey_prefix: 0, @@ -984,12 +993,6 @@ function toggleSelectRowById(sender, id) { return toggleSelectRow(sender, row); } -/* this is for dijit Checkbox */ -function toggleSelectListRow2(sender) { - const row = sender.domNode.parentNode; - return toggleSelectRow(sender, row); -} - /* this is for dijit Checkbox */ function toggleSelectRow2(sender, row, is_cdm) { @@ -1137,7 +1140,7 @@ const Filters = { new dijit.form.CheckBox({ onChange: function () { - this.domNode.up("li").toggleClassName("Selected"); + ListUtils.onChecked(this); }, }, cb); @@ -1186,7 +1189,7 @@ const Filters = { new dijit.form.CheckBox({ onChange: function () { - this.domNode.up("li").toggleClassName("Selected"); + ListUtils.onChecked(this); }, }, cb); -- cgit v1.2.3-54-g00ecf From 874560db547f718b82d77657dc019d840c30e0ed Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 10:33:58 +0300 Subject: remove obsolete row selection functions move getUrlParam() to Utils --- classes/feeds.php | 4 ++-- classes/pref/feeds.php | 4 ++-- classes/pref/filters.php | 4 ++-- classes/pref/prefs.php | 6 ++--- classes/pref/users.php | 2 +- include/feedbrowser.php | 4 ++-- include/functions.php | 2 +- js/functions.js | 61 +++++++++++++----------------------------------- js/prefs.js | 6 ++--- js/tt-rss.js | 2 +- js/viewfeed.js | 8 +++++++ 11 files changed, 41 insertions(+), 62 deletions(-) (limited to 'js/functions.js') diff --git a/classes/feeds.php b/classes/feeds.php index c9e5ca496..b32521130 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -406,7 +406,7 @@ class Feeds extends Handler_Protected { $reply['content'] .= "
    "; $reply['content'] .= ""; $reply['content'] .= "$marked_pic"; @@ -505,7 +505,7 @@ class Feeds extends Handler_Protected { $tmp_content .= "
    "; $tmp_content .= ""; $tmp_content .= "$marked_pic"; diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index f47d24501..efc76701e 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1435,7 +1435,7 @@ class Pref_Feeds extends Handler_Protected { # id needed for selectTableRows() print ""; print ""; @@ -1500,7 +1500,7 @@ class Pref_Feeds extends Handler_Protected { # id needed for selectTableRows() print ""; print ""; diff --git a/classes/pref/filters.php b/classes/pref/filters.php index e48615395..f9b4bfb2a 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -429,7 +429,7 @@ class Pref_Filters extends Handler_Protected { $data = htmlspecialchars(json_encode($line)); - print "
  • ". + print "
  • ". "".$this->getRuleName($line)."". "
  • "; } @@ -473,7 +473,7 @@ class Pref_Filters extends Handler_Protected { $data = htmlspecialchars(json_encode($line)); - print "
  • ". + print "
  • ". "".$this->getActionName($line)."". "
  • "; } diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 82456f342..017f2e06c 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -799,7 +799,7 @@ class Pref_Prefs extends Handler_Protected { $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png"; - print ""; @@ -1023,7 +1023,7 @@ class Pref_Prefs extends Handler_Protected { print ""; @@ -1050,7 +1050,7 @@ class Pref_Prefs extends Handler_Protected { $edit_title = htmlspecialchars($line["title"]); print ""; diff --git a/classes/pref/users.php b/classes/pref/users.php index 1e6eae227..eda3e1a0e 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -419,7 +419,7 @@ class Pref_Users extends Handler_Protected { $line["created"] = make_local_datetime($line["created"], false); $line["last_login"] = make_local_datetime($line["last_login"], false); - print ""; diff --git a/include/feedbrowser.php b/include/feedbrowser.php index a0b1b6e8f..4f37241ea 100644 --- a/include/feedbrowser.php +++ b/include/feedbrowser.php @@ -53,7 +53,7 @@ $site_url = htmlspecialchars($line["site_url"]); $subscribers = $line["subscribers"]; - $check_box = ""; @@ -73,7 +73,7 @@ $feed_url = htmlspecialchars($line["feed_url"]); $site_url = htmlspecialchars($line["site_url"]); - $check_box = ""; if ($line['articles_archived'] > 0) { diff --git a/include/functions.php b/include/functions.php index f6d09fe67..2ec42c7ee 100755 --- a/include/functions.php +++ b/include/functions.php @@ -1244,7 +1244,7 @@ "g t" => "goto_tagcloud", "g *p" => "goto_prefs", // "other" => array( - "(9)|Tab" => "select_article_cursor", // tab + "r" => "select_article_cursor", "c l" => "create_label", "c f" => "create_filter", "c s" => "collapse_sidebar", diff --git a/js/functions.js b/js/functions.js index ce6d7aca9..033933794 100755 --- a/js/functions.js +++ b/js/functions.js @@ -53,8 +53,8 @@ Array.prototype.remove = function(s) { } }; -const ListUtils = { - onChecked: function(elem) { +const Lists = { + onRowChecked: function(elem) { // account for dojo checkboxes elem = elem.domNode || elem; @@ -62,11 +62,23 @@ const ListUtils = { } }; +const Tables = { + onRowChecked: function(elem) { + // account for dojo checkboxes + elem = elem.domNode || elem; + + elem.up("tr").toggleClassName("Selected"); + } +} + const Utils = { _rpc_seq: 0, hotkey_prefix: 0, hotkey_prefix_pressed: false, hotkey_prefix_timeout: 0, + urlParam: function(param) { + return String(window.location.href).parseQuery()[param]; + }, next_seq: function() { this._rpc_seq += 1; return this._rpc_seq; @@ -988,43 +1000,6 @@ function getCookie(name) { return unescape(dc.substring(begin + prefix.length, end)); } -function toggleSelectRowById(sender, id) { - const row = $(id); - return toggleSelectRow(sender, row); -} - -/* this is for dijit Checkbox */ -function toggleSelectRow2(sender, row, is_cdm) { - - if (!row) - if (!is_cdm) - row = sender.domNode.parentNode.parentNode; - else - row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs - - if (sender.checked && !row.hasClassName('Selected')) - row.addClassName('Selected'); - else - row.removeClassName('Selected'); - - if (typeof Headlines != "undefined") - Headlines.updateSelectedPrompt(); -} - - -function toggleSelectRow(sender, row) { - - if (!row) row = sender.parentNode.parentNode; - - if (sender.checked && !row.hasClassName('Selected')) - row.addClassName('Selected'); - else - row.removeClassName('Selected'); - - if (typeof Headlines != "undefined") - Headlines.updateSelectedPrompt(); -} - // noinspection JSUnusedGlobalSymbols function displayIfChecked(checkbox, elemId) { if (checkbox.checked) { @@ -1034,10 +1009,6 @@ function displayIfChecked(checkbox, elemId) { } } -function getURLParam(param){ - return String(window.location.href).parseQuery()[param]; -} - // noinspection JSUnusedGlobalSymbols function closeInfoBox() { const dialog = dijit.byId("infoBox"); @@ -1140,7 +1111,7 @@ const Filters = { new dijit.form.CheckBox({ onChange: function () { - ListUtils.onChecked(this); + Lists.onRowChecked(this); }, }, cb); @@ -1189,7 +1160,7 @@ const Filters = { new dijit.form.CheckBox({ onChange: function () { - ListUtils.onChecked(this); + Lists.onRowChecked(this); }, }, cb); diff --git a/js/prefs.js b/js/prefs.js index 40068b95c..f12c31441 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -69,17 +69,17 @@ const App = { Utils.setLoadingProgress(50); notify(""); - let tab = getURLParam('tab'); + let tab = Utils.urlParam('tab'); if (tab) { tab = dijit.byId(tab + "Tab"); if (tab) dijit.byId("pref-tabs").selectChild(tab); } - const method = getURLParam('method'); + const method = Utils.urlParam('method'); if (method == 'editFeed') { - const param = getURLParam('methodparam'); + const param = Utils.urlParam('methodparam'); window.setTimeout(function () { CommonDialogs.editFeed(param) diff --git a/js/tt-rss.js b/js/tt-rss.js index b337e0ae5..71bb2337a 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -414,7 +414,7 @@ const App = { if (!row.hasClassName("active")) cb.attr("checked", !cb.attr("checked")); - toggleSelectRowById(cb, "RROW-" + id); + Headlines.onRowChecked(cb); return false; } } diff --git a/js/viewfeed.js b/js/viewfeed.js index 93bc56c9d..e7703ed55 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1109,6 +1109,14 @@ const Headlines = { return rv; }, + onRowChecked: function(elem) { + // account for dojo checkboxes + elem = elem.domNode || elem; + + elem.up("div[id*=RROW]").toggleClassName("Selected"); + + this.updateSelectedPrompt(); + }, select: function(mode) { // mode = all,none,unread,invert,marked,published let query = "#headlines-frame > div[id*=RROW]"; -- cgit v1.2.3-54-g00ecf From aa2f119eb656cc2064da691328239010f51afb98 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 10:46:09 +0300 Subject: remove getSelectedTableRowIds (Tables.getSelected) --- js/functions.js | 35 ++++++++++++++++++----------------- js/prefs.js | 6 +++--- 2 files changed, 21 insertions(+), 20 deletions(-) (limited to 'js/functions.js') diff --git a/js/functions.js b/js/functions.js index 033933794..6e61f4c9f 100755 --- a/js/functions.js +++ b/js/functions.js @@ -62,14 +62,30 @@ const Lists = { } }; +// noinspection JSUnusedGlobalSymbols const Tables = { onRowChecked: function(elem) { // account for dojo checkboxes elem = elem.domNode || elem; elem.up("tr").toggleClassName("Selected"); + }, + getSelected: function(elemId) { + const rv = []; + + $(elemId).select("tr").each((row) => { + if (row.hasClassName("Selected")) { + // either older prefix-XXX notation or separate attribute + const rowId = row.getAttribute("data-row-id") || row.id.replace(/^[A-Z]*?-/, ""); + + if (!isNaN(rowId)) + rv.push(parseInt(rowId)); + } + }); + + return rv; } -} +}; const Utils = { _rpc_seq: 0, @@ -526,7 +542,7 @@ const CommonDialogs = { title: __("Feeds with update errors"), style: "width: 600px", getSelectedFeeds: function () { - return getSelectedTableRowIds("prefErrorFeedList"); + return Tables.getSelected("prefErrorFeedList"); }, removeSelected: function () { const sel_rows = this.getSelectedFeeds(); @@ -1570,21 +1586,6 @@ function selectTableRows(id, mode) { } } -function getSelectedTableRowIds(id) { - const rows = []; - - const elem_rows = $(id).rows; - - for (let i = 0; i < elem_rows.length; i++) { - if (elem_rows[i].hasClassName("Selected")) { - const bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, ""); - rows.push(bare_id); - } - } - - return rows; -} - // noinspection JSUnusedGlobalSymbols function label_to_feed_id(label) { return _label_base_index - 1 - Math.abs(label); diff --git a/js/prefs.js b/js/prefs.js index f12c31441..3b9e090cc 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -314,7 +314,7 @@ function getSelectedLabels() { } function getSelectedUsers() { - return getSelectedTableRowIds("prefUserList"); + return Tables.getSelected("prefUserList"); } function getSelectedFeeds() { @@ -832,7 +832,7 @@ function showInactiveFeeds() { title: __("Feeds without recent updates"), style: "width: 600px", getSelectedFeeds: function () { - return getSelectedTableRowIds("prefInactiveFeedList"); + return Tables.getSelected("prefInactiveFeedList"); }, removeSelected: function () { const sel_rows = this.getSelectedFeeds(); @@ -922,7 +922,7 @@ function editProfiles() { title: __("Settings Profiles"), style: "width: 600px", getSelectedProfiles: function () { - return getSelectedTableRowIds("prefFeedProfileList"); + return Tables.getSelected("prefFeedProfileList"); }, removeSelected: function () { const sel_rows = this.getSelectedProfiles(); -- cgit v1.2.3-54-g00ecf From e23b6e397dbbbba90f9a15a6fe2d45eb862efdc5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 11:25:32 +0300 Subject: prefs: store active tab for reload, remove most old table row functions --- classes/pref/feeds.php | 22 +++++-------- classes/pref/prefs.php | 11 +++---- classes/pref/users.php | 9 +++--- js/functions.js | 83 ++++++++++++++++---------------------------------- js/prefs.js | 39 ++++++++++++++++-------- 5 files changed, 70 insertions(+), 94 deletions(-) (limited to 'js/functions.js') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index efc76701e..0a7fed7b2 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1412,9 +1412,9 @@ class Pref_Feeds extends Handler_Protected { print "
    ". "" . __('Select').""; print "
    "; - print "
    ".__('All')."
    "; - print "
    ".__('None')."
    "; print "
    "; print "
    "; #toolbar @@ -1428,15 +1428,12 @@ class Pref_Feeds extends Handler_Protected { while ($line = $sth->fetch()) { $feed_id = $line["id"]; - $this_row_id = "id=\"FUPDD-$feed_id\""; - # class needed for selectTableRows() - print ""; + print ""; - # id needed for selectTableRows() print ""; + type=\"checkbox\">"; print ""; print "
    ". "" . __('Select').""; print "
    "; - print "
    ".__('All')."
    "; - print "
    ".__('None')."
    "; print "
    "; print "
    "; #toolbar @@ -1493,15 +1490,12 @@ class Pref_Feeds extends Handler_Protected { while ($line = $sth->fetch()) { $feed_id = $line["id"]; - $this_row_id = "id=\"FERDD-$feed_id\""; - # class needed for selectTableRows() - print ""; + print ""; - # id needed for selectTableRows() print ""; + type=\"checkbox\">"; print ""; print "". "" . __('Select').""; print "
    "; - print "
    ".__('All')."
    "; - print "
    ".__('None')."
    "; print "
    "; @@ -1019,10 +1019,9 @@ class Pref_Prefs extends Handler_Protected { print ""; - print ""; #odd + print ""; # data-row-id='0' <-- no point, shouldn't be removed print ""; @@ -1043,15 +1042,13 @@ class Pref_Prefs extends Handler_Protected { while ($line = $sth->fetch()) { $profile_id = $line["id"]; - $this_row_id = "id=\"FCATR-$profile_id\""; - print ""; + print ""; $edit_title = htmlspecialchars($line["title"]); print ""; diff --git a/classes/pref/users.php b/classes/pref/users.php index eda3e1a0e..fb7afcf04 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -354,9 +354,9 @@ class Pref_Users extends Handler_Protected { print "
    ". "" . __('Select').""; print "
    "; - print "
    ".__('All')."
    "; - print "
    ".__('None')."
    "; print "
    "; @@ -412,7 +412,7 @@ class Pref_Users extends Handler_Protected { $uid = $line["id"]; - print ""; + print ""; $line["login"] = htmlspecialchars($line["login"]); @@ -420,8 +420,7 @@ class Pref_Users extends Handler_Protected { $line["last_login"] = make_local_datetime($line["last_login"], false); print ""; + dojoType=\"dijit.form.CheckBox\" type=\"checkbox\">"; $onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'"; diff --git a/js/functions.js b/js/functions.js index 6e61f4c9f..673e0e8f1 100755 --- a/js/functions.js +++ b/js/functions.js @@ -55,10 +55,14 @@ Array.prototype.remove = function(s) { const Lists = { onRowChecked: function(elem) { + const checked = elem.domNode ? elem.attr("checked") : elem.checked; // account for dojo checkboxes elem = elem.domNode || elem; - elem.up("li").toggleClassName("Selected"); + const row = elem.up("li"); + + if (row) + checked ? row.addClassName("Selected") : row.removeClassName("Selected"); } }; @@ -66,9 +70,30 @@ const Lists = { const Tables = { onRowChecked: function(elem) { // account for dojo checkboxes + const checked = elem.domNode ? elem.attr("checked") : elem.checked; elem = elem.domNode || elem; - elem.up("tr").toggleClassName("Selected"); + const row = elem.up("tr"); + + if (row) + checked ? row.addClassName("Selected") : row.removeClassName("Selected"); + + }, + select: function(elemId, selected) { + $(elemId).select("tr").each((row) => { + const checkNode = row.select(".dijitCheckBox,input[type=checkbox]")[0]; + if (checkNode) { + const widget = dijit.getEnclosingWidget(checkNode); + + if (widget) { + widget.attr("checked", selected); + } else { + checkNode.checked = selected; + } + + this.onRowChecked(widget); + } + }); }, getSelected: function(elemId) { const rv = []; @@ -1532,60 +1557,6 @@ function uploadFeedIcon() { return false; } -// mode = all, none, invert -function selectTableRows(id, mode) { - const rows = $(id).rows; - - for (let i = 0; i < rows.length; i++) { - const row = rows[i]; - let cb = false; - let dcb = false; - - if (row.id && row.className) { - const bare_id = row.id.replace(/^[A-Z]*?-/, ""); - const inputs = rows[i].getElementsByTagName("input"); - - for (let j = 0; j < inputs.length; j++) { - const input = inputs[j]; - - if (input.getAttribute("type") == "checkbox" && - input.id.match(bare_id)) { - - cb = input; - dcb = dijit.getEnclosingWidget(cb); - break; - } - } - - if (cb || dcb) { - const issel = row.hasClassName("Selected"); - - if (mode == "all" && !issel) { - row.addClassName("Selected"); - cb.checked = true; - if (dcb) dcb.set("checked", true); - } else if (mode == "none" && issel) { - row.removeClassName("Selected"); - cb.checked = false; - if (dcb) dcb.set("checked", false); - - } else if (mode == "invert") { - - if (issel) { - row.removeClassName("Selected"); - cb.checked = false; - if (dcb) dcb.set("checked", false); - } else { - row.addClassName("Selected"); - cb.checked = true; - if (dcb) dcb.set("checked", true); - } - } - } - } - } -} - // noinspection JSUnusedGlobalSymbols function label_to_feed_id(label) { return _label_base_index - 1 - Math.abs(label); diff --git a/js/prefs.js b/js/prefs.js index 3b9e090cc..c2ff01d47 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -73,18 +73,34 @@ const App = { if (tab) { tab = dijit.byId(tab + "Tab"); - if (tab) dijit.byId("pref-tabs").selectChild(tab); - } + if (tab) { + dijit.byId("pref-tabs").selectChild(tab); + + switch (Utils.urlParam('method')) { + case "editfeed": + window.setTimeout(function () { + CommonDialogs.editFeed(Utils.urlParam('methodparam')) + }, 100); + break; + default: + console.warn("initSecondStage, unknown method:", Utils.urlParam("method")); + } + } + } else { + let tab = localStorage.getItem("ttrss:prefs-tab"); - const method = Utils.urlParam('method'); + if (tab) { + tab = dijit.byId(tab); + if (tab) { + dijit.byId("pref-tabs").selectChild(tab); + } + } + } - if (method == 'editFeed') { - const param = Utils.urlParam('methodparam'); + dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) { + localStorage.setItem("ttrss:prefs-tab", elem.id); + }); - window.setTimeout(function () { - CommonDialogs.editFeed(param) - }, 100); - } }, hotkeyHandler: function (event) { if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; @@ -725,8 +741,8 @@ function updateSystemList() { }); } -function selectTab(id, noupdate) { - if (!noupdate) { +function selectTab(id, selectOnly) { + if (!selectOnly) { notify_progress("Loading, please wait..."); switch (id) { @@ -754,7 +770,6 @@ function selectTab(id, noupdate) { const tab = dijit.byId(id + "Tab"); dijit.byId("pref-tabs").selectChild(tab); - } } -- cgit v1.2.3-54-g00ecf From 3a6dae92034791c199f9ddb4c60b8298b22c1d47 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 16:29:00 +0300 Subject: prefs: more of the same, really --- classes/pref/system.php | 2 +- js/PrefFilterTree.js | 20 +++++++++++++++----- js/PrefLabelTree.js | 14 ++++++++++---- js/functions.js | 4 ++-- js/prefs.js | 36 ++++++++++-------------------------- 5 files changed, 38 insertions(+), 38 deletions(-) (limited to 'js/functions.js') diff --git a/classes/pref/system.php b/classes/pref/system.php index f86fc7b0b..17dfb10ca 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -37,7 +37,7 @@ class Pref_System extends Handler_Protected { LIMIT 100"); print " "; + onclick=\"Prefs.updateEventLog()\">".__('Refresh')." "; print "  "; diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 9940372dd..37a99be89 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -86,11 +86,21 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio return rv; }, + reload: function() { + const user_search = $("filter_search"); + let search = ""; + if (user_search) { search = user_search.value; } + + xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => { + dijit.byId('filterConfigTab').attr('content', transport.responseText); + notify(""); + }); + }, resetFilterOrder: function() { notify_progress("Loading, please wait..."); xhrPost("backend.php", {op: "pref-filters", method: "filtersortreset"}, () => { - updateFilterList(); + this.reload(); }); }, joinSelectedFilters: function() { @@ -105,7 +115,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio notify_progress("Joining filters..."); xhrPost("backend.php", {op: "pref-filters", method: "join", ids: rows.toString()}, () => { - updateFilterList(); + this.reload(); }); } }, @@ -187,7 +197,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const query = {op: "pref-filters", method: "remove", ids: this.attr('value').id}; xhrPost("backend.php", query, () => { - updateFilterList(); + dijit.byId("filterTree").reload(); }); } }, @@ -214,7 +224,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => { dialog.hide(); - updateFilterList(); + dijit.byId("filterTree").reload(); }); } }, @@ -236,7 +246,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }; xhrPost("backend.php", query, () => { - updateFilterList(); + this.reload(); }); } } else { diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index ba052eb07..45edb34a1 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -48,6 +48,12 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f return rv; }, + reload: function() { + xhrPost("backend.php", { op: "pref-labels" }, (transport) => { + dijit.byId('labelConfigTab').attr('content', transport.responseText); + notify(""); + }); + }, editLabel: function(id) { const query = "backend.php?op=pref-labels&method=edit&id=" + param_escape(id); @@ -87,7 +93,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f }; xhrPost("backend.php", query, () => { - updateFilterList(); // maybe there's labels in there + dijit.byId("filterTree").reload(); // maybe there's labels in there }); }, @@ -102,7 +108,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f this.hide(); xhrPost("backend.php", this.attr('value'), () => { - updateFilterList(); // maybe there's labels in there + dijit.byId("filterTree").reload(); // maybe there's labels in there }); } }, @@ -123,7 +129,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f }; xhrPost("backend.php", query, () => { - updateLabelList(); + this.reload(); }); } @@ -144,7 +150,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f }; xhrPost("backend.php", query, () => { - updateLabelList(); + this.reload(); }); } } else { diff --git a/js/functions.js b/js/functions.js index 673e0e8f1..3a9a26f9b 100755 --- a/js/functions.js +++ b/js/functions.js @@ -739,7 +739,7 @@ const CommonDialogs = { if (callback) { callback(transport); } else if (App.isPrefs()) { - updateLabelList(); + dijit.byId("labelTree").reload(); } else { Feeds.reload(); } @@ -1442,7 +1442,7 @@ const Filters = { xhrPost("backend.php", query, () => { if (App.isPrefs()) { - updateFilterList(); + dijit.byId("filterTree").reload(); } dialog.hide(); diff --git a/js/prefs.js b/js/prefs.js index 2245f518f..771120048 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -131,6 +131,7 @@ const App = { } }; +// noinspection JSUnusedGlobalSymbols const Prefs = { clearFeedAccessKeys: function() { if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { @@ -143,13 +144,19 @@ const Prefs = { return false; }, + updateEventLog: function() { + xhrPost("backend.php", { op: "pref-system" }, (transport) => { + dijit.byId('systemConfigTab').attr('content', transport.responseText); + notify(""); + }); + }, clearEventLog: function() { if (confirm(__("Clear event log?"))) { notify_progress("Loading, please wait..."); xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => { - updateSystemList(); + this.updateEventLog(); }); } }, @@ -160,6 +167,7 @@ const Prefs = { const query = "backend.php?op=pref-prefs&method=editPrefProfiles"; + // noinspection JSUnusedGlobalSymbols const dialog = new dijit.Dialog({ id: "profileEditDlg", title: __("Settings Profiles"), @@ -275,6 +283,7 @@ const Prefs = { } }; +// noinspection JSUnusedGlobalSymbols const Users = { reload: function(sort) { const user_search = $("user_search"); @@ -434,31 +443,6 @@ function opmlImport() { } } -function updateFilterList() { - const user_search = $("filter_search"); - let search = ""; - if (user_search) { search = user_search.value; } - - xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => { - dijit.byId('filterConfigTab').attr('content', transport.responseText); - notify(""); - }); -} - -function updateLabelList() { - xhrPost("backend.php", { op: "pref-labels" }, (transport) => { - dijit.byId('labelConfigTab').attr('content', transport.responseText); - notify(""); - }); -} - -function updateSystemList() { - xhrPost("backend.php", { op: "pref-system" }, (transport) => { - dijit.byId('systemConfigTab').attr('content', transport.responseText); - notify(""); - }); -} - function opmlRegenKey() { if (confirm(__("Replace current OPML publishing address with a new one?"))) { notify_progress("Trying to change address...", true); -- cgit v1.2.3-54-g00ecf From 35ded4bc844d74f120196012c194be9ab5517688 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 16:30:32 +0300 Subject: edit phrasing of some alert()s --- js/PrefFeedTree.js | 10 +++++----- js/PrefFilterTree.js | 6 +++--- js/PrefLabelTree.js | 4 ++-- js/functions.js | 4 ++-- js/prefs.js | 8 ++++---- js/viewfeed.js | 18 +++++++++--------- plugins/mail/mail.js | 2 +- plugins/mailto/init.js | 2 +- 8 files changed, 27 insertions(+), 27 deletions(-) (limited to 'js/functions.js') diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index dbb188a34..7beeadd38 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -161,7 +161,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio } } else { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); } return false; @@ -202,7 +202,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }); } } else { - alert(__("No categories are selected.")); + alert(__("No categories selected.")); } return false; @@ -223,7 +223,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = this.getSelectedFeeds(); if (rows.length == 0) { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); return; } @@ -239,7 +239,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = this.getSelectedFeeds(); if (rows.length == 0) { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); return; } @@ -391,7 +391,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio } } else { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); } }, execute: function () { diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 37a99be89..9a2dd6c1c 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -107,7 +107,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = getSelectedFilters(); if (rows.length == 0) { - alert(__("No filters are selected.")); + alert(__("No filters selected.")); return; } @@ -123,7 +123,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = this.getSelectedFilters(); if (rows.length == 0) { - alert(__("No filters are selected.")); + alert(__("No filters selected.")); return; } @@ -250,7 +250,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }); } } else { - alert(__("No filters are selected.")); + alert(__("No filters selected.")); } return false; diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 45edb34a1..914df9a19 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -134,7 +134,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f } } else { - alert(__("No labels are selected.")); + alert(__("No labels selected.")); } }, removeSelected: function() { @@ -154,7 +154,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f }); } } else { - alert(__("No labels are selected.")); + alert(__("No labels selected.")); } return false; diff --git a/js/functions.js b/js/functions.js index 3a9a26f9b..3118da0f0 100755 --- a/js/functions.js +++ b/js/functions.js @@ -589,7 +589,7 @@ const CommonDialogs = { } } else { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); } }, execute: function () { @@ -670,7 +670,7 @@ const CommonDialogs = { }); } else { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); } }, diff --git a/js/prefs.js b/js/prefs.js index 771120048..3578a7007 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -194,7 +194,7 @@ const Prefs = { } } else { - alert(__("No profiles are selected.")); + alert(__("No profiles selected.")); } }, activateProfile: function () { @@ -337,7 +337,7 @@ const Users = { const rows = this.getSelection(); if (rows.length == 0) { - alert(__("No users are selected.")); + alert(__("No users selected.")); return; } @@ -376,14 +376,14 @@ const Users = { } } else { - alert(__("No users are selected.")); + alert(__("No users selected.")); } }, editSelected: function() { const rows = this.getSelection(); if (rows.length == 0) { - alert(__("No users are selected.")); + alert(__("No users selected.")); return; } diff --git a/js/viewfeed.js b/js/viewfeed.js index e7703ed55..0365feeeb 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -60,7 +60,7 @@ const Article = { } } else { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); } }, setScore: function(id, pic) { @@ -765,7 +765,7 @@ const Headlines = { if (ids.length == 0) { if (!no_error) - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -803,7 +803,7 @@ const Headlines = { const rows = ids || Headlines.getSelected(); if (rows.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -824,7 +824,7 @@ const Headlines = { const rows = ids || Headlines.getSelected(); if (rows.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -1019,7 +1019,7 @@ const Headlines = { if (!ids) ids = Headlines.getSelected(); if (ids.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -1037,7 +1037,7 @@ const Headlines = { if (!ids) ids = Headlines.getSelected(); if (ids.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -1055,7 +1055,7 @@ const Headlines = { const rows = Headlines.getSelected(); if (rows.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -1175,7 +1175,7 @@ const Headlines = { const rows = Headlines.getSelected(); if (rows.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } @@ -1215,7 +1215,7 @@ const Headlines = { const rows = Headlines.getSelected(); if (rows.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index 538970fc3..d6c28048b 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -4,7 +4,7 @@ function emailArticle(id) { var ids = Headlines.getSelected(); if (ids.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index 6b8520928..47321923a 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -4,7 +4,7 @@ function mailtoArticle(id) { const ids = Headlines.getSelected(); if (ids.length == 0) { - alert(__("No articles are selected.")); + alert(__("No articles selected.")); return; } -- cgit v1.2.3-54-g00ecf From fda3ad39c8d89b07d4ead691bacdca6865e46517 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 17:00:58 +0300 Subject: split several utility objects into separate dojo modules --- js/CommonDialogs.js | 392 ++++++++++++++++++ js/CommonFilters.js | 389 ++++++++++++++++++ js/PrefHelpers.js | 152 +++++++ js/PrefUsers.js | 119 ++++++ js/Utils.js | 338 ++++++++++++++++ js/functions.js | 1116 --------------------------------------------------- js/prefs.js | 287 +------------ js/tt-rss.js | 13 +- 8 files changed, 1420 insertions(+), 1386 deletions(-) create mode 100644 js/CommonDialogs.js create mode 100644 js/CommonFilters.js create mode 100644 js/PrefHelpers.js create mode 100644 js/PrefUsers.js create mode 100644 js/Utils.js (limited to 'js/functions.js') diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js new file mode 100644 index 000000000..757f84f81 --- /dev/null +++ b/js/CommonDialogs.js @@ -0,0 +1,392 @@ +define(["dojo/_base/declare"], function (declare) { + return declare("fox.CommonDialogs", null, { + quickAddFeed: function() { + const query = "backend.php?op=feeds&method=quickAddFeed"; + + // overlapping widgets + if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); + if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "feedAddDlg", + title: __("Subscribe to Feed"), + style: "width: 600px", + show_error: function (msg) { + const elem = $("fadd_error_message"); + + elem.innerHTML = msg; + + if (!Element.visible(elem)) + new Effect.Appear(elem); + + }, + execute: function () { + if (this.validate()) { + console.log(dojo.objectToQuery(this.attr('value'))); + + const feed_url = this.attr('value').feed; + + Element.show("feed_add_spinner"); + Element.hide("fadd_error_message"); + + xhrPost("backend.php", this.attr('value'), (transport) => { + try { + + try { + var reply = JSON.parse(transport.responseText); + } catch (e) { + Element.hide("feed_add_spinner"); + alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console.")); + console.log('quickAddFeed, backend returned:' + transport.responseText); + return; + } + + const rc = reply['result']; + + notify(''); + Element.hide("feed_add_spinner"); + + console.log(rc); + + switch (parseInt(rc['code'])) { + case 1: + dialog.hide(); + notify_info(__("Subscribed to %s").replace("%s", feed_url)); + + Feeds.reload(); + break; + case 2: + dialog.show_error(__("Specified URL seems to be invalid.")); + break; + case 3: + dialog.show_error(__("Specified URL doesn't seem to contain any feeds.")); + break; + case 4: + const feeds = rc['feeds']; + + Element.show("fadd_multiple_notify"); + + const select = dijit.byId("feedDlg_feedContainerSelect"); + + while (select.getOptions().length > 0) + select.removeOption(0); + + select.addOption({value: '', label: __("Expand to select feed")}); + + let count = 0; + for (const feedUrl in feeds) { + if (feeds.hasOwnProperty(feedUrl)) { + select.addOption({value: feedUrl, label: feeds[feedUrl]}); + count++; + } + } + + Effect.Appear('feedDlg_feedsContainer', {duration: 0.5}); + + break; + case 5: + dialog.show_error(__("Couldn't download the specified URL: %s").replace("%s", rc['message'])); + break; + case 6: + dialog.show_error(__("XML validation failed: %s").replace("%s", rc['message'])); + break; + case 0: + dialog.show_error(__("You are already subscribed to this feed.")); + break; + } + + } catch (e) { + console.error(transport.responseText); + exception_error(e); + } + }); + } + }, + href: query + }); + + dialog.show(); + }, + showFeedsWithErrors: function() { + const query = {op: "pref-feeds", method: "feedsWithErrors"}; + + if (dijit.byId("errorFeedsDlg")) + dijit.byId("errorFeedsDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "errorFeedsDlg", + title: __("Feeds with update errors"), + style: "width: 600px", + getSelectedFeeds: function () { + return Tables.getSelected("prefErrorFeedList"); + }, + removeSelected: function () { + const sel_rows = this.getSelectedFeeds(); + + if (sel_rows.length > 0) { + if (confirm(__("Remove selected feeds?"))) { + notify_progress("Removing selected feeds...", true); + + const query = { + op: "pref-feeds", method: "remove", + ids: sel_rows.toString() + }; + + xhrPost("backend.php", query, () => { + notify(''); + dialog.hide(); + Feeds.reload(); + }); + } + + } else { + alert(__("No feeds selected.")); + } + }, + execute: function () { + if (this.validate()) { + // + } + }, + href: "backend.php?" + dojo.objectToQuery(query) + }); + + dialog.show(); + }, + feedBrowser: function() { + const query = {op: "feeds", method: "feedBrowser"}; + + if (dijit.byId("feedAddDlg")) + dijit.byId("feedAddDlg").hide(); + + if (dijit.byId("feedBrowserDlg")) + dijit.byId("feedBrowserDlg").destroyRecursive(); + + // noinspection JSUnusedGlobalSymbols + const dialog = new dijit.Dialog({ + id: "feedBrowserDlg", + title: __("More Feeds"), + style: "width: 600px", + getSelectedFeedIds: function () { + const list = $$("#browseFeedList li[id*=FBROW]"); + const selected = []; + + list.each(function (child) { + const id = child.id.replace("FBROW-", ""); + + if (child.hasClassName('Selected')) { + selected.push(id); + } + }); + + return selected; + }, + getSelectedFeeds: function () { + const list = $$("#browseFeedList li.Selected"); + const selected = []; + + list.each(function (child) { + const title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML; + const url = child.getElementsBySelector("a.fb_feedUrl")[0].href; + + selected.push([title, url]); + + }); + + return selected; + }, + + subscribe: function () { + const mode = this.attr('value').mode; + let selected = []; + + if (mode == "1") + selected = this.getSelectedFeeds(); + else + selected = this.getSelectedFeedIds(); + + if (selected.length > 0) { + dijit.byId("feedBrowserDlg").hide(); + + notify_progress("Loading, please wait...", true); + + const query = { + op: "rpc", method: "massSubscribe", + payload: JSON.stringify(selected), mode: mode + }; + + xhrPost("backend.php", query, () => { + notify(''); + Feeds.reload(); + }); + + } else { + alert(__("No feeds selected.")); + } + + }, + update: function () { + Element.show('feed_browser_spinner'); + + xhrPost("backend.php", dialog.attr("value"), (transport) => { + notify(''); + + Element.hide('feed_browser_spinner'); + + const reply = JSON.parse(transport.responseText); + const mode = reply['mode']; + + if ($("browseFeedList") && reply['content']) { + $("browseFeedList").innerHTML = reply['content']; + } + + dojo.parser.parse("browseFeedList"); + + if (mode == 2) { + Element.show(dijit.byId('feed_archive_remove').domNode); + } else { + Element.hide(dijit.byId('feed_archive_remove').domNode); + } + }); + }, + removeFromArchive: function () { + const selected = this.getSelectedFeedIds(); + + if (selected.length > 0) { + if (confirm(__("Remove selected feeds from the archive? Feeds with stored articles will not be removed."))) { + Element.show('feed_browser_spinner'); + + const query = {op: "rpc", method: "remarchive", ids: selected.toString()}; + + xhrPost("backend.php", query, () => { + dialog.update(); + }); + } + } + }, + execute: function () { + if (this.validate()) { + this.subscribe(); + } + }, + href: "backend.php?" + dojo.objectToQuery(query) + }); + + dialog.show(); + }, + addLabel: function(select, callback) { + const caption = prompt(__("Please enter label caption:"), ""); + + if (caption != undefined && caption.trim().length > 0) { + + const query = {op: "pref-labels", method: "add", caption: caption.trim()}; + + if (select) + Object.extend(query, {output: "select"}); + + notify_progress("Loading, please wait...", true); + + xhrPost("backend.php", query, (transport) => { + if (callback) { + callback(transport); + } else if (App.isPrefs()) { + dijit.byId("labelTree").reload(); + } else { + Feeds.reload(); + } + }); + } + }, + unsubscribeFeed: function(feed_id, title) { + + const msg = __("Unsubscribe from %s?").replace("%s", title); + + if (title == undefined || confirm(msg)) { + notify_progress("Removing feed..."); + + const query = {op: "pref-feeds", quiet: 1, method: "remove", ids: feed_id}; + + xhrPost("backend.php", query, () => { + if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide(); + + if (App.isPrefs()) { + Feeds.reload(); + } else { + if (feed_id == Feeds.getActive()) + setTimeout(() => { + Feeds.open({feed: -5}) + }, + 100); + + if (feed_id < 0) Feeds.reload(); + } + }); + } + + return false; + }, + editFeed: function (feed) { + if (feed <= 0) + return alert(__("You can't edit this kind of feed.")); + + const query = {op: "pref-feeds", method: "editfeed", id: feed}; + + console.log("editFeed", query); + + if (dijit.byId("filterEditDlg")) + dijit.byId("filterEditDlg").destroyRecursive(); + + if (dijit.byId("feedEditDlg")) + dijit.byId("feedEditDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "feedEditDlg", + title: __("Edit Feed"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + notify_progress("Saving data...", true); + + xhrPost("backend.php", dialog.attr('value'), () => { + dialog.hide(); + notify(''); + Feeds.reload(); + }); + } + }, + href: "backend.php?" + dojo.objectToQuery(query) + }); + + dialog.show(); + }, + genUrlChangeKey: function(feed, is_cat) { + if (confirm(__("Generate new syndication address for this feed?"))) { + + notify_progress("Trying to change address...", true); + + const query = {op: "pref-feeds", method: "regenFeedKey", id: feed, is_cat: is_cat}; + + xhrJson("backend.php", query, (reply) => { + const new_link = reply.link; + const e = $('gen_feed_url'); + + if (new_link) { + e.innerHTML = e.innerHTML.replace(/&key=.*$/, + "&key=" + new_link); + + e.href = e.href.replace(/&key=.*$/, + "&key=" + new_link); + + new Effect.Highlight(e); + + notify(''); + + } else { + notify_error("Could not change feed URL."); + } + }); + } + return false; + } + }); +}); \ No newline at end of file diff --git a/js/CommonFilters.js b/js/CommonFilters.js new file mode 100644 index 000000000..28a151690 --- /dev/null +++ b/js/CommonFilters.js @@ -0,0 +1,389 @@ +define(["dojo/_base/declare"], function (declare) { + return declare("fox.CommonFilters", null, { + filterDlgCheckAction: function(sender) { + const action = sender.value; + + const action_param = $("filterDlg_paramBox"); + + if (!action_param) { + console.log("filterDlgCheckAction: can't find action param box!"); + return; + } + + // if selected action supports parameters, enable params field + if (action == 4 || action == 6 || action == 7 || action == 9) { + new Effect.Appear(action_param, {duration: 0.5}); + + Element.hide(dijit.byId("filterDlg_actionParam").domNode); + Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); + Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode); + + if (action == 7) { + Element.show(dijit.byId("filterDlg_actionParamLabel").domNode); + } else if (action == 9) { + Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode); + } else { + Element.show(dijit.byId("filterDlg_actionParam").domNode); + } + + } else { + Element.hide(action_param); + } + }, + createNewRuleElement: function(parentNode, replaceNode) { + const form = document.forms["filter_new_rule_form"]; + const query = {op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form)}; + + xhrPost("backend.php", query, (transport) => { + try { + const li = dojo.create("li"); + + const cb = dojo.create("input", {type: "checkbox"}, li); + + new dijit.form.CheckBox({ + onChange: function () { + Lists.onRowChecked(this); + }, + }, cb); + + dojo.create("input", { + type: "hidden", + name: "rule[]", + value: dojo.formToJson(form) + }, li); + + dojo.create("span", { + onclick: function () { + dijit.byId('filterEditDlg').editRule(this); + }, + innerHTML: transport.responseText + }, li); + + if (replaceNode) { + parentNode.replaceChild(li, replaceNode); + } else { + parentNode.appendChild(li); + } + } catch (e) { + exception_error(e); + } + }); + }, + createNewActionElement: function(parentNode, replaceNode) { + const form = document.forms["filter_new_action_form"]; + + if (form.action_id.value == 7) { + form.action_param.value = form.action_param_label.value; + } else if (form.action_id.value == 9) { + form.action_param.value = form.action_param_plugin.value; + } + + const query = { + op: "pref-filters", method: "printactionname", + action: dojo.formToJson(form) + }; + + xhrPost("backend.php", query, (transport) => { + try { + const li = dojo.create("li"); + + const cb = dojo.create("input", {type: "checkbox"}, li); + + new dijit.form.CheckBox({ + onChange: function () { + Lists.onRowChecked(this); + }, + }, cb); + + dojo.create("input", { + type: "hidden", + name: "action[]", + value: dojo.formToJson(form) + }, li); + + dojo.create("span", { + onclick: function () { + dijit.byId('filterEditDlg').editAction(this); + }, + innerHTML: transport.responseText + }, li); + + if (replaceNode) { + parentNode.replaceChild(li, replaceNode); + } else { + parentNode.appendChild(li); + } + + } catch (e) { + exception_error(e); + } + }); + }, + addFilterRule: function(replaceNode, ruleStr) { + if (dijit.byId("filterNewRuleDlg")) + dijit.byId("filterNewRuleDlg").destroyRecursive(); + + const query = "backend.php?op=pref-filters&method=newrule&rule=" + + param_escape(ruleStr); + + const rule_dlg = new dijit.Dialog({ + id: "filterNewRuleDlg", + title: ruleStr ? __("Edit rule") : __("Add rule"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + Filters.createNewRuleElement($("filterDlg_Matches"), replaceNode); + this.hide(); + } + }, + href: query + }); + + rule_dlg.show(); + }, + addFilterAction: function(replaceNode, actionStr) { + if (dijit.byId("filterNewActionDlg")) + dijit.byId("filterNewActionDlg").destroyRecursive(); + + const query = "backend.php?op=pref-filters&method=newaction&action=" + + param_escape(actionStr); + + const rule_dlg = new dijit.Dialog({ + id: "filterNewActionDlg", + title: actionStr ? __("Edit action") : __("Add action"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + Filters.createNewActionElement($("filterDlg_Actions"), replaceNode); + this.hide(); + } + }, + href: query + }); + + rule_dlg.show(); + }, + editFilterTest: function(query) { + + if (dijit.byId("filterTestDlg")) + dijit.byId("filterTestDlg").destroyRecursive(); + + const test_dlg = new dijit.Dialog({ + id: "filterTestDlg", + title: "Test Filter", + style: "width: 600px", + results: 0, + limit: 100, + max_offset: 10000, + getTestResults: function (query, offset) { + const updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit; + + console.log("getTestResults:" + offset); + + xhrPost("backend.php", updquery, (transport) => { + try { + const result = JSON.parse(transport.responseText); + + if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) { + test_dlg.results += result.length; + + console.log("got results:" + result.length); + + $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...") + .replace("%f", test_dlg.results) + .replace("%d", offset); + + console.log(offset + " " + test_dlg.max_offset); + + for (let i = 0; i < result.length; i++) { + const tmp = new Element("table"); + tmp.innerHTML = result[i]; + dojo.parser.parse(tmp); + + $("prefFilterTestResultList").innerHTML += tmp.innerHTML; + } + + if (test_dlg.results < 30 && offset < test_dlg.max_offset) { + + // get the next batch + window.setTimeout(function () { + test_dlg.getTestResults(query, offset + test_dlg.limit); + }, 0); + + } else { + // all done + + Element.hide("prefFilterLoadingIndicator"); + + if (test_dlg.results == 0) { + $("prefFilterTestResultList").innerHTML = ""; + $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:"; + } else { + $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:") + .replace("%d", test_dlg.results); + } + + } + + } else if (!result) { + console.log("getTestResults: can't parse results object"); + + Element.hide("prefFilterLoadingIndicator"); + + notify_error("Error while trying to get filter test results."); + + } else { + console.log("getTestResults: dialog closed, bailing out."); + } + } catch (e) { + exception_error(e); + } + + }); + }, + href: query + }); + + dojo.connect(test_dlg, "onLoad", null, function (e) { + test_dlg.getTestResults(query, 0); + }); + + test_dlg.show(); + }, + quickAddFilter: function() { + let query; + + if (!App.isPrefs()) { + query = { + op: "pref-filters", method: "newfilter", + feed: Feeds.getActive(), is_cat: Feeds.activeIsCat() + }; + } else { + query = {op: "pref-filters", method: "newfilter"}; + } + + console.log('quickAddFilter', query); + + if (dijit.byId("feedEditDlg")) + dijit.byId("feedEditDlg").destroyRecursive(); + + if (dijit.byId("filterEditDlg")) + dijit.byId("filterEditDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "filterEditDlg", + title: __("Create Filter"), + style: "width: 600px", + test: function () { + const query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test"; + + Filters.editFilterTest(query); + }, + selectRules: function (select) { + $$("#filterDlg_Matches input[type=checkbox]").each(function (e) { + e.checked = select; + if (select) + e.parentNode.addClassName("Selected"); + else + e.parentNode.removeClassName("Selected"); + }); + }, + selectActions: function (select) { + $$("#filterDlg_Actions input[type=checkbox]").each(function (e) { + e.checked = select; + + if (select) + e.parentNode.addClassName("Selected"); + else + e.parentNode.removeClassName("Selected"); + + }); + }, + editRule: function (e) { + const li = e.parentNode; + const rule = li.getElementsByTagName("INPUT")[1].value; + Filters.addFilterRule(li, rule); + }, + editAction: function (e) { + const li = e.parentNode; + const action = li.getElementsByTagName("INPUT")[1].value; + Filters.addFilterAction(li, action); + }, + addAction: function () { + Filters.addFilterAction(); + }, + addRule: function () { + Filters.addFilterRule(); + }, + deleteAction: function () { + $$("#filterDlg_Actions li[class*=Selected]").each(function (e) { + e.parentNode.removeChild(e) + }); + }, + deleteRule: function () { + $$("#filterDlg_Matches li[class*=Selected]").each(function (e) { + e.parentNode.removeChild(e) + }); + }, + execute: function () { + if (this.validate()) { + + const query = dojo.formToQuery("filter_new_form"); + + xhrPost("backend.php", query, () => { + if (App.isPrefs()) { + dijit.byId("filterTree").reload(); + } + + dialog.hide(); + }); + } + }, + href: "backend.php?" + dojo.objectToQuery(query) + }); + + if (!App.isPrefs()) { + const selectedText = getSelectionText(); + + const lh = dojo.connect(dialog, "onLoad", function () { + dojo.disconnect(lh); + + if (selectedText != "") { + + const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) : + Feeds.getActive(); + + const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1}; + + Filters.addFilterRule(null, dojo.toJson(rule)); + + } else { + + const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActive()}; + + xhrPost("backend.php", query, (transport) => { + const reply = JSON.parse(transport.responseText); + + let title = false; + + if (reply && reply.title) title = reply.title; + + if (title || Feeds.getActive() || Feeds.activeIsCat()) { + + console.log(title + " " + Feeds.getActive()); + + const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) : + Feeds.getActive(); + + const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1}; + + Filters.addFilterRule(null, dojo.toJson(rule)); + } + }); + } + }); + } + dialog.show(); + }, + }); +}); diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js new file mode 100644 index 000000000..a2451f478 --- /dev/null +++ b/js/PrefHelpers.js @@ -0,0 +1,152 @@ +define(["dojo/_base/declare"], function (declare) { + return declare("fox.PrefHelpers", null, { + clearFeedAccessKeys: function() { + if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { + notify_progress("Clearing URLs..."); + + xhrPost("backend.php", {op: "pref-feeds", method: "clearKeys"}, () => { + notify_info("Generated URLs cleared."); + }); + } + + return false; + }, + updateEventLog: function() { + xhrPost("backend.php", { op: "pref-system" }, (transport) => { + dijit.byId('systemConfigTab').attr('content', transport.responseText); + notify(""); + }); + }, + clearEventLog: function() { + if (confirm(__("Clear event log?"))) { + + notify_progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => { + this.updateEventLog(); + }); + } + }, + editProfiles: function() { + + if (dijit.byId("profileEditDlg")) + dijit.byId("profileEditDlg").destroyRecursive(); + + const query = "backend.php?op=pref-prefs&method=editPrefProfiles"; + + // noinspection JSUnusedGlobalSymbols + const dialog = new dijit.Dialog({ + id: "profileEditDlg", + title: __("Settings Profiles"), + style: "width: 600px", + getSelectedProfiles: function () { + return Tables.getSelected("prefFeedProfileList"); + }, + removeSelected: function () { + const sel_rows = this.getSelectedProfiles(); + + if (sel_rows.length > 0) { + if (confirm(__("Remove selected profiles? Active and default profiles will not be removed."))) { + notify_progress("Removing selected profiles...", true); + + const query = { + op: "rpc", method: "remprofiles", + ids: sel_rows.toString() + }; + + xhrPost("backend.php", query, () => { + notify(''); + Prefs.editProfiles(); + }); + } + + } else { + alert(__("No profiles selected.")); + } + }, + activateProfile: function () { + const sel_rows = this.getSelectedProfiles(); + + if (sel_rows.length == 1) { + if (confirm(__("Activate selected profile?"))) { + notify_progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "rpc", method: "setprofile", id: sel_rows.toString()}, () => { + window.location.reload(); + }); + } + + } else { + alert(__("Please choose a profile to activate.")); + } + }, + addProfile: function () { + if (this.validate()) { + notify_progress("Creating profile...", true); + + const query = {op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile}; + + xhrPost("backend.php", query, () => { + notify(''); + Prefs.editProfiles(); + }); + + } + }, + execute: function () { + if (this.validate()) { + } + }, + href: query + }); + + dialog.show(); + }, + customizeCSS: function() { + const query = "backend.php?op=pref-prefs&method=customizeCSS"; + + if (dijit.byId("cssEditDlg")) + dijit.byId("cssEditDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "cssEditDlg", + title: __("Customize stylesheet"), + style: "width: 600px", + execute: function () { + notify_progress('Saving data...', true); + + xhrPost("backend.php", this.attr('value'), () => { + window.location.reload(); + }); + + }, + href: query + }); + + dialog.show(); + }, + confirmReset: function() { + if (confirm(__("Reset to defaults?"))) { + xhrPost("backend.php", {op: "pref-prefs", method: "resetconfig"}, (transport) => { + Prefs.refresh(); + notify_info(transport.responseText); + }); + } + }, + clearPluginData: function(name) { + if (confirm(__("Clear stored data for this plugin?"))) { + notify_progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "pref-prefs", method: "clearplugindata", name: name}, () => { + Prefs.refresh(); + }); + } + }, + refresh: function() { + xhrPost("backend.php", { op: "pref-prefs" }, (transport) => { + dijit.byId('genConfigTab').attr('content', transport.responseText); + notify(""); + }); + } + }); +}); diff --git a/js/PrefUsers.js b/js/PrefUsers.js new file mode 100644 index 000000000..aa3c2826d --- /dev/null +++ b/js/PrefUsers.js @@ -0,0 +1,119 @@ +define(["dojo/_base/declare"], function (declare) { + + return declare("fox.PrefUsers", null, { + reload: function(sort) { + const user_search = $("user_search"); + const search = user_search ? user_search.value : ""; + + xhrPost("backend.php", { op: "pref-users", sort: sort, search: search }, (transport) => { + dijit.byId('userConfigTab').attr('content', transport.responseText); + notify(""); + }); + }, + add: function() { + const login = prompt(__("Please enter username:"), ""); + + if (login) { + notify_progress("Adding user..."); + + xhrPost("backend.php", {op: "pref-users", method: "add", login: login}, (transport) => { + alert(transport.responseText); + Users.reload(); + }); + + } + }, + edit: function(id) { + const query = "backend.php?op=pref-users&method=edit&id=" + + param_escape(id); + + if (dijit.byId("userEditDlg")) + dijit.byId("userEditDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "userEditDlg", + title: __("User Editor"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + notify_progress("Saving data...", true); + + xhrPost("backend.php", dojo.formToObject("user_edit_form"), (transport) => { + dialog.hide(); + Users.reload(); + }); + } + }, + href: query + }); + + dialog.show(); + }, + resetSelected: function() { + const rows = this.getSelection(); + + if (rows.length == 0) { + alert(__("No users selected.")); + return; + } + + if (rows.length > 1) { + alert(__("Please select one user.")); + return; + } + + if (confirm(__("Reset password of selected user?"))) { + notify_progress("Resetting password for selected user..."); + + const id = rows[0]; + + xhrPost("backend.php", {op: "pref-users", method: "resetPass", id: id}, (transport) => { + notify(''); + alert(transport.responseText); + }); + + } + }, + removeSelected: function() { + const sel_rows = this.getSelection(); + + if (sel_rows.length > 0) { + if (confirm(__("Remove selected users? Neither default admin nor your account will be removed."))) { + notify_progress("Removing selected users..."); + + const query = { + op: "pref-users", method: "remove", + ids: sel_rows.toString() + }; + + xhrPost("backend.php", query, () => { + this.reload(); + }); + } + + } else { + alert(__("No users selected.")); + } + }, + editSelected: function() { + const rows = this.getSelection(); + + if (rows.length == 0) { + alert(__("No users selected.")); + return; + } + + if (rows.length > 1) { + alert(__("Please select one user.")); + return; + } + + this.edit(rows[0]); + }, + getSelection :function() { + return Tables.getSelected("prefUserList"); + } + }); +}); + + diff --git a/js/Utils.js b/js/Utils.js new file mode 100644 index 000000000..204b3189c --- /dev/null +++ b/js/Utils.js @@ -0,0 +1,338 @@ +define(["dojo/_base/declare"], function (declare) { + return declare("fox.Utils", null, { + _rpc_seq: 0, + hotkey_prefix: 0, + hotkey_prefix_pressed: false, + hotkey_prefix_timeout: 0, + urlParam: function(param) { + return String(window.location.href).parseQuery()[param]; + }, + next_seq: function() { + this._rpc_seq += 1; + return this._rpc_seq; + }, + get_seq: function() { + return this._rpc_seq; + }, + setLoadingProgress: function(p) { + loading_progress += p; + + if (dijit.byId("loading_bar")) + dijit.byId("loading_bar").update({progress: loading_progress}); + + if (loading_progress >= 90) + Element.hide("overlay"); + + }, + keyeventToAction: function(event) { + + const hotkeys_map = getInitParam("hotkeys"); + const keycode = event.which; + const keychar = String.fromCharCode(keycode).toLowerCase(); + + if (keycode == 27) { // escape and drop prefix + this.hotkey_prefix = false; + } + + if (keycode == 16 || keycode == 17) return; // ignore lone shift / ctrl + + if (!this.hotkey_prefix && hotkeys_map[0].indexOf(keychar) != -1) { + + this.hotkey_prefix = keychar; + $("cmdline").innerHTML = keychar; + Element.show("cmdline"); + + window.clearTimeout(this.hotkey_prefix_timeout); + this.hotkey_prefix_timeout = window.setTimeout(() => { + this.hotkey_prefix = false; + Element.hide("cmdline"); + }, 3 * 1000); + + event.stopPropagation(); + + return false; + } + + Element.hide("cmdline"); + + let hotkey_name = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")"; + + // ensure ^*char notation + if (event.shiftKey) hotkey_name = "*" + hotkey_name; + if (event.ctrlKey) hotkey_name = "^" + hotkey_name; + if (event.altKey) hotkey_name = "+" + hotkey_name; + if (event.metaKey) hotkey_name = "%" + hotkey_name; + + const hotkey_full = this.hotkey_prefix ? this.hotkey_prefix + " " + hotkey_name : hotkey_name; + this.hotkey_prefix = false; + + let action_name = false; + + for (const sequence in hotkeys_map[1]) { + if (hotkeys_map[1].hasOwnProperty(sequence)) { + if (sequence == hotkey_full) { + action_name = hotkeys_map[1][sequence]; + break; + } + } + } + + console.log('keyeventToAction', hotkey_full, '=>', action_name); + + return action_name; + }, + cleanupMemory: function(root) { + const dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode); + + dijits.each(function (d) { + dojo.destroy(d.domNode); + }); + + $$("#" + root + " *").each(function (i) { + i.parentNode ? i.parentNode.removeChild(i) : true; + }); + }, + helpDialog: function(topic) { + const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); + + if (dijit.byId("helpDlg")) + dijit.byId("helpDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "helpDlg", + title: __("Help"), + style: "width: 600px", + href: query, + }); + + dialog.show(); + }, + displayDlg: function(title, id, param, callback) { + notify_progress("Loading, please wait...", true); + + const query = {op: "dlg", method: id, param: param}; + + xhrPost("backend.php", query, (transport) => { + try { + const content = transport.responseText; + + let dialog = dijit.byId("infoBox"); + + if (!dialog) { + dialog = new dijit.Dialog({ + title: title, + id: 'infoBox', + style: "width: 600px", + onCancel: function () { + return true; + }, + onExecute: function () { + return true; + }, + onClose: function () { + return true; + }, + content: content + }); + } else { + dialog.attr('title', title); + dialog.attr('content', content); + } + + dialog.show(); + + notify(""); + + if (callback) callback(transport); + } catch (e) { + exception_error(e); + } + }); + + return false; + }, + handleRpcJson: function(transport) { + + const netalert_dijit = dijit.byId("net-alert"); + let netalert = false; + + if (netalert_dijit) netalert = netalert_dijit.domNode; + + try { + const reply = JSON.parse(transport.responseText); + + if (reply) { + + const error = reply['error']; + + if (error) { + const code = error['code']; + const msg = error['msg']; + + console.warn("[handleRpcJson] received fatal error " + code + "/" + msg); + + if (code != 0) { + fatalError(code, msg); + return false; + } + } + + const seq = reply['seq']; + + if (seq && this.get_seq() != seq) { + console.log("[handleRpcJson] sequence mismatch: " + seq + + " (want: " + this.get_seq() + ")"); + return true; + } + + const message = reply['message']; + + if (message == "UPDATE_COUNTERS") { + console.log("need to refresh counters..."); + setInitParam("last_article_id", -1); + Feeds.requestCounters(true); + } + + const counters = reply['counters']; + + if (counters) + Feeds.parseCounters(counters); + + const runtime_info = reply['runtime-info']; + + if (runtime_info) + Utils.parseRuntimeInfo(runtime_info); + + if (netalert) netalert.hide(); + + return reply; + + } else { + if (netalert) + netalert.show(); + else + notify_error("Communication problem with server."); + } + + } catch (e) { + if (netalert) + netalert.show(); + else + notify_error("Communication problem with server."); + + console.error(e); + } + + return false; + }, + parseRuntimeInfo: function(data) { + + //console.log("parsing runtime info..."); + + for (const k in data) { + if (data.hasOwnProperty(k)) { + const v = data[k]; + + console.log("RI:", k, "=>", v); + + if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) { + if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) { + window.location.reload(); + } + } + + if (k == "daemon_is_running" && v != 1) { + notify_error("Update daemon is not running.", true); + return; + } + + if (k == "update_result") { + const updatesIcon = dijit.byId("updatesIcon").domNode; + + if (v) { + Element.show(updatesIcon); + } else { + Element.hide(updatesIcon); + } + } + + if (k == "daemon_stamp_ok" && v != 1) { + notify_error("Update daemon is not updating feeds.", true); + return; + } + + if (k == "max_feed_id" || k == "num_feeds") { + if (init_params[k] != v) { + console.log("feed count changed, need to reload feedlist."); + Feeds.reload(); + } + } + + init_params[k] = v; + } + } + + PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data); + }, + backendSanityCallback: function (transport) { + + const reply = JSON.parse(transport.responseText); + + if (!reply) { + fatalError(3, "Sanity check: invalid RPC reply", transport.responseText); + return; + } + + const error_code = reply['error']['code']; + + if (error_code && error_code != 0) { + return fatalError(error_code, reply['error']['message']); + } + + console.log("sanity check ok"); + + const params = reply['init-params']; + + if (params) { + console.log('reading init-params...'); + + for (const k in params) { + if (params.hasOwnProperty(k)) { + switch (k) { + case "label_base_index": + _label_base_index = parseInt(params[k]); + break; + case "hotkeys": + // filter mnemonic definitions (used for help panel) from hotkeys map + // i.e. *(191)|Ctrl-/ -> *(191) + + const tmp = []; + for (const sequence in params[k][1]) { + if (params[k][1].hasOwnProperty(sequence)) { + const filtered = sequence.replace(/\|.*$/, ""); + tmp[filtered] = params[k][1][sequence]; + } + } + + params[k][1] = tmp; + break; + } + + console.log("IP:", k, "=>", params[k]); + } + } + + init_params = params; + + // PluginHost might not be available on non-index pages + window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params); + } + + App.initSecondStage(); + }, + explainError: function(code) { + return this.displayDlg(__("Error explained"), "explainError", code); + }, + + }); +}); diff --git a/js/functions.js b/js/functions.js index 3118da0f0..0d52358ec 100755 --- a/js/functions.js +++ b/js/functions.js @@ -112,733 +112,6 @@ const Tables = { } }; -const Utils = { - _rpc_seq: 0, - hotkey_prefix: 0, - hotkey_prefix_pressed: false, - hotkey_prefix_timeout: 0, - urlParam: function(param) { - return String(window.location.href).parseQuery()[param]; - }, - next_seq: function() { - this._rpc_seq += 1; - return this._rpc_seq; - }, - get_seq: function() { - return this._rpc_seq; - }, - setLoadingProgress: function(p) { - loading_progress += p; - - if (dijit.byId("loading_bar")) - dijit.byId("loading_bar").update({progress: loading_progress}); - - if (loading_progress >= 90) - Element.hide("overlay"); - - }, - keyeventToAction: function(event) { - - const hotkeys_map = getInitParam("hotkeys"); - const keycode = event.which; - const keychar = String.fromCharCode(keycode).toLowerCase(); - - if (keycode == 27) { // escape and drop prefix - this.hotkey_prefix = false; - } - - if (keycode == 16 || keycode == 17) return; // ignore lone shift / ctrl - - if (!this.hotkey_prefix && hotkeys_map[0].indexOf(keychar) != -1) { - - this.hotkey_prefix = keychar; - $("cmdline").innerHTML = keychar; - Element.show("cmdline"); - - window.clearTimeout(this.hotkey_prefix_timeout); - this.hotkey_prefix_timeout = window.setTimeout(() => { - this.hotkey_prefix = false; - Element.hide("cmdline"); - }, 3 * 1000); - - event.stopPropagation(); - - return false; - } - - Element.hide("cmdline"); - - let hotkey_name = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")"; - - // ensure ^*char notation - if (event.shiftKey) hotkey_name = "*" + hotkey_name; - if (event.ctrlKey) hotkey_name = "^" + hotkey_name; - if (event.altKey) hotkey_name = "+" + hotkey_name; - if (event.metaKey) hotkey_name = "%" + hotkey_name; - - const hotkey_full = this.hotkey_prefix ? this.hotkey_prefix + " " + hotkey_name : hotkey_name; - this.hotkey_prefix = false; - - let action_name = false; - - for (const sequence in hotkeys_map[1]) { - if (hotkeys_map[1].hasOwnProperty(sequence)) { - if (sequence == hotkey_full) { - action_name = hotkeys_map[1][sequence]; - break; - } - } - } - - console.log('keyeventToAction', hotkey_full, '=>', action_name); - - return action_name; - }, - cleanupMemory: function(root) { - const dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode); - - dijits.each(function (d) { - dojo.destroy(d.domNode); - }); - - $$("#" + root + " *").each(function (i) { - i.parentNode ? i.parentNode.removeChild(i) : true; - }); - }, - helpDialog: function(topic) { - const query = "backend.php?op=backend&method=help&topic=" + param_escape(topic); - - if (dijit.byId("helpDlg")) - dijit.byId("helpDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "helpDlg", - title: __("Help"), - style: "width: 600px", - href: query, - }); - - dialog.show(); - }, - displayDlg: function(title, id, param, callback) { - notify_progress("Loading, please wait...", true); - - const query = {op: "dlg", method: id, param: param}; - - xhrPost("backend.php", query, (transport) => { - try { - const content = transport.responseText; - - let dialog = dijit.byId("infoBox"); - - if (!dialog) { - dialog = new dijit.Dialog({ - title: title, - id: 'infoBox', - style: "width: 600px", - onCancel: function () { - return true; - }, - onExecute: function () { - return true; - }, - onClose: function () { - return true; - }, - content: content - }); - } else { - dialog.attr('title', title); - dialog.attr('content', content); - } - - dialog.show(); - - notify(""); - - if (callback) callback(transport); - } catch (e) { - exception_error(e); - } - }); - - return false; - }, - handleRpcJson: function(transport) { - - const netalert_dijit = dijit.byId("net-alert"); - let netalert = false; - - if (netalert_dijit) netalert = netalert_dijit.domNode; - - try { - const reply = JSON.parse(transport.responseText); - - if (reply) { - - const error = reply['error']; - - if (error) { - const code = error['code']; - const msg = error['msg']; - - console.warn("[handleRpcJson] received fatal error " + code + "/" + msg); - - if (code != 0) { - fatalError(code, msg); - return false; - } - } - - const seq = reply['seq']; - - if (seq && this.get_seq() != seq) { - console.log("[handleRpcJson] sequence mismatch: " + seq + - " (want: " + this.get_seq() + ")"); - return true; - } - - const message = reply['message']; - - if (message == "UPDATE_COUNTERS") { - console.log("need to refresh counters..."); - setInitParam("last_article_id", -1); - Feeds.requestCounters(true); - } - - const counters = reply['counters']; - - if (counters) - Feeds.parseCounters(counters); - - const runtime_info = reply['runtime-info']; - - if (runtime_info) - Utils.parseRuntimeInfo(runtime_info); - - if (netalert) netalert.hide(); - - return reply; - - } else { - if (netalert) - netalert.show(); - else - notify_error("Communication problem with server."); - } - - } catch (e) { - if (netalert) - netalert.show(); - else - notify_error("Communication problem with server."); - - console.error(e); - } - - return false; - }, - parseRuntimeInfo: function(data) { - - //console.log("parsing runtime info..."); - - for (const k in data) { - if (data.hasOwnProperty(k)) { - const v = data[k]; - - console.log("RI:", k, "=>", v); - - if (k == "dep_ts" && parseInt(getInitParam("dep_ts")) > 0) { - if (parseInt(getInitParam("dep_ts")) < parseInt(v) && getInitParam("reload_on_ts_change")) { - window.location.reload(); - } - } - - if (k == "daemon_is_running" && v != 1) { - notify_error("Update daemon is not running.", true); - return; - } - - if (k == "update_result") { - const updatesIcon = dijit.byId("updatesIcon").domNode; - - if (v) { - Element.show(updatesIcon); - } else { - Element.hide(updatesIcon); - } - } - - if (k == "daemon_stamp_ok" && v != 1) { - notify_error("Update daemon is not updating feeds.", true); - return; - } - - if (k == "max_feed_id" || k == "num_feeds") { - if (init_params[k] != v) { - console.log("feed count changed, need to reload feedlist."); - Feeds.reload(); - } - } - - init_params[k] = v; - } - } - - PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data); - }, - backendSanityCallback: function (transport) { - - const reply = JSON.parse(transport.responseText); - - if (!reply) { - fatalError(3, "Sanity check: invalid RPC reply", transport.responseText); - return; - } - - const error_code = reply['error']['code']; - - if (error_code && error_code != 0) { - return fatalError(error_code, reply['error']['message']); - } - - console.log("sanity check ok"); - - const params = reply['init-params']; - - if (params) { - console.log('reading init-params...'); - - for (const k in params) { - if (params.hasOwnProperty(k)) { - switch (k) { - case "label_base_index": - _label_base_index = parseInt(params[k]); - break; - case "hotkeys": - // filter mnemonic definitions (used for help panel) from hotkeys map - // i.e. *(191)|Ctrl-/ -> *(191) - - const tmp = []; - for (const sequence in params[k][1]) { - if (params[k][1].hasOwnProperty(sequence)) { - const filtered = sequence.replace(/\|.*$/, ""); - tmp[filtered] = params[k][1][sequence]; - } - } - - params[k][1] = tmp; - break; - } - - console.log("IP:", k, "=>", params[k]); - } - } - - init_params = params; - - // PluginHost might not be available on non-index pages - window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params); - } - - App.initSecondStage(); - }, - explainError: function(code) { - return this.displayDlg(__("Error explained"), "explainError", code); - }, -}; - -const CommonDialogs = { - quickAddFeed: function() { - const query = "backend.php?op=feeds&method=quickAddFeed"; - - // overlapping widgets - if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); - if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "feedAddDlg", - title: __("Subscribe to Feed"), - style: "width: 600px", - show_error: function (msg) { - const elem = $("fadd_error_message"); - - elem.innerHTML = msg; - - if (!Element.visible(elem)) - new Effect.Appear(elem); - - }, - execute: function () { - if (this.validate()) { - console.log(dojo.objectToQuery(this.attr('value'))); - - const feed_url = this.attr('value').feed; - - Element.show("feed_add_spinner"); - Element.hide("fadd_error_message"); - - xhrPost("backend.php", this.attr('value'), (transport) => { - try { - - try { - var reply = JSON.parse(transport.responseText); - } catch (e) { - Element.hide("feed_add_spinner"); - alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console.")); - console.log('quickAddFeed, backend returned:' + transport.responseText); - return; - } - - const rc = reply['result']; - - notify(''); - Element.hide("feed_add_spinner"); - - console.log(rc); - - switch (parseInt(rc['code'])) { - case 1: - dialog.hide(); - notify_info(__("Subscribed to %s").replace("%s", feed_url)); - - Feeds.reload(); - break; - case 2: - dialog.show_error(__("Specified URL seems to be invalid.")); - break; - case 3: - dialog.show_error(__("Specified URL doesn't seem to contain any feeds.")); - break; - case 4: - const feeds = rc['feeds']; - - Element.show("fadd_multiple_notify"); - - const select = dijit.byId("feedDlg_feedContainerSelect"); - - while (select.getOptions().length > 0) - select.removeOption(0); - - select.addOption({value: '', label: __("Expand to select feed")}); - - let count = 0; - for (const feedUrl in feeds) { - if (feeds.hasOwnProperty(feedUrl)) { - select.addOption({value: feedUrl, label: feeds[feedUrl]}); - count++; - } - } - - Effect.Appear('feedDlg_feedsContainer', {duration: 0.5}); - - break; - case 5: - dialog.show_error(__("Couldn't download the specified URL: %s").replace("%s", rc['message'])); - break; - case 6: - dialog.show_error(__("XML validation failed: %s").replace("%s", rc['message'])); - break; - case 0: - dialog.show_error(__("You are already subscribed to this feed.")); - break; - } - - } catch (e) { - console.error(transport.responseText); - exception_error(e); - } - }); - } - }, - href: query - }); - - dialog.show(); - }, - showFeedsWithErrors: function() { - const query = {op: "pref-feeds", method: "feedsWithErrors"}; - - if (dijit.byId("errorFeedsDlg")) - dijit.byId("errorFeedsDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "errorFeedsDlg", - title: __("Feeds with update errors"), - style: "width: 600px", - getSelectedFeeds: function () { - return Tables.getSelected("prefErrorFeedList"); - }, - removeSelected: function () { - const sel_rows = this.getSelectedFeeds(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected feeds?"))) { - notify_progress("Removing selected feeds...", true); - - const query = { - op: "pref-feeds", method: "remove", - ids: sel_rows.toString() - }; - - xhrPost("backend.php", query, () => { - notify(''); - dialog.hide(); - Feeds.reload(); - }); - } - - } else { - alert(__("No feeds selected.")); - } - }, - execute: function () { - if (this.validate()) { - // - } - }, - href: "backend.php?" + dojo.objectToQuery(query) - }); - - dialog.show(); - }, - feedBrowser: function() { - const query = {op: "feeds", method: "feedBrowser"}; - - if (dijit.byId("feedAddDlg")) - dijit.byId("feedAddDlg").hide(); - - if (dijit.byId("feedBrowserDlg")) - dijit.byId("feedBrowserDlg").destroyRecursive(); - - // noinspection JSUnusedGlobalSymbols - const dialog = new dijit.Dialog({ - id: "feedBrowserDlg", - title: __("More Feeds"), - style: "width: 600px", - getSelectedFeedIds: function () { - const list = $$("#browseFeedList li[id*=FBROW]"); - const selected = []; - - list.each(function (child) { - const id = child.id.replace("FBROW-", ""); - - if (child.hasClassName('Selected')) { - selected.push(id); - } - }); - - return selected; - }, - getSelectedFeeds: function () { - const list = $$("#browseFeedList li.Selected"); - const selected = []; - - list.each(function (child) { - const title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML; - const url = child.getElementsBySelector("a.fb_feedUrl")[0].href; - - selected.push([title, url]); - - }); - - return selected; - }, - - subscribe: function () { - const mode = this.attr('value').mode; - let selected = []; - - if (mode == "1") - selected = this.getSelectedFeeds(); - else - selected = this.getSelectedFeedIds(); - - if (selected.length > 0) { - dijit.byId("feedBrowserDlg").hide(); - - notify_progress("Loading, please wait...", true); - - const query = { - op: "rpc", method: "massSubscribe", - payload: JSON.stringify(selected), mode: mode - }; - - xhrPost("backend.php", query, () => { - notify(''); - Feeds.reload(); - }); - - } else { - alert(__("No feeds selected.")); - } - - }, - update: function () { - Element.show('feed_browser_spinner'); - - xhrPost("backend.php", dialog.attr("value"), (transport) => { - notify(''); - - Element.hide('feed_browser_spinner'); - - const reply = JSON.parse(transport.responseText); - const mode = reply['mode']; - - if ($("browseFeedList") && reply['content']) { - $("browseFeedList").innerHTML = reply['content']; - } - - dojo.parser.parse("browseFeedList"); - - if (mode == 2) { - Element.show(dijit.byId('feed_archive_remove').domNode); - } else { - Element.hide(dijit.byId('feed_archive_remove').domNode); - } - }); - }, - removeFromArchive: function () { - const selected = this.getSelectedFeedIds(); - - if (selected.length > 0) { - if (confirm(__("Remove selected feeds from the archive? Feeds with stored articles will not be removed."))) { - Element.show('feed_browser_spinner'); - - const query = {op: "rpc", method: "remarchive", ids: selected.toString()}; - - xhrPost("backend.php", query, () => { - dialog.update(); - }); - } - } - }, - execute: function () { - if (this.validate()) { - this.subscribe(); - } - }, - href: "backend.php?" + dojo.objectToQuery(query) - }); - - dialog.show(); - }, - addLabel: function(select, callback) { - const caption = prompt(__("Please enter label caption:"), ""); - - if (caption != undefined && caption.trim().length > 0) { - - const query = {op: "pref-labels", method: "add", caption: caption.trim()}; - - if (select) - Object.extend(query, {output: "select"}); - - notify_progress("Loading, please wait...", true); - - xhrPost("backend.php", query, (transport) => { - if (callback) { - callback(transport); - } else if (App.isPrefs()) { - dijit.byId("labelTree").reload(); - } else { - Feeds.reload(); - } - }); - } - }, - unsubscribeFeed: function(feed_id, title) { - - const msg = __("Unsubscribe from %s?").replace("%s", title); - - if (title == undefined || confirm(msg)) { - notify_progress("Removing feed..."); - - const query = {op: "pref-feeds", quiet: 1, method: "remove", ids: feed_id}; - - xhrPost("backend.php", query, () => { - if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide(); - - if (App.isPrefs()) { - Feeds.reload(); - } else { - if (feed_id == Feeds.getActive()) - setTimeout(() => { - Feeds.open({feed: -5}) - }, - 100); - - if (feed_id < 0) Feeds.reload(); - } - }); - } - - return false; - }, - editFeed: function (feed) { - if (feed <= 0) - return alert(__("You can't edit this kind of feed.")); - - const query = {op: "pref-feeds", method: "editfeed", id: feed}; - - console.log("editFeed", query); - - if (dijit.byId("filterEditDlg")) - dijit.byId("filterEditDlg").destroyRecursive(); - - if (dijit.byId("feedEditDlg")) - dijit.byId("feedEditDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "feedEditDlg", - title: __("Edit Feed"), - style: "width: 600px", - execute: function () { - if (this.validate()) { - notify_progress("Saving data...", true); - - xhrPost("backend.php", dialog.attr('value'), () => { - dialog.hide(); - notify(''); - Feeds.reload(); - }); - } - }, - href: "backend.php?" + dojo.objectToQuery(query) - }); - - dialog.show(); - }, - genUrlChangeKey: function(feed, is_cat) { - if (confirm(__("Generate new syndication address for this feed?"))) { - - notify_progress("Trying to change address...", true); - - const query = {op: "pref-feeds", method: "regenFeedKey", id: feed, is_cat: is_cat}; - - xhrJson("backend.php", query, (reply) => { - const new_link = reply.link; - const e = $('gen_feed_url'); - - if (new_link) { - e.innerHTML = e.innerHTML.replace(/&key=.*$/, - "&key=" + new_link); - - e.href = e.href.replace(/&key=.*$/, - "&key=" + new_link); - - new Effect.Highlight(e); - - notify(''); - - } else { - notify_error("Could not change feed URL."); - } - }); - } - return false; - } -}; - function report_error(message, filename, lineno, colno, error) { exception_error(error, null, filename, lineno); } @@ -1109,395 +382,6 @@ function fatalError(code, msg, ext_info) { } -const Filters = { - filterDlgCheckAction: function(sender) { - const action = sender.value; - - const action_param = $("filterDlg_paramBox"); - - if (!action_param) { - console.log("filterDlgCheckAction: can't find action param box!"); - return; - } - - // if selected action supports parameters, enable params field - if (action == 4 || action == 6 || action == 7 || action == 9) { - new Effect.Appear(action_param, {duration: 0.5}); - - Element.hide(dijit.byId("filterDlg_actionParam").domNode); - Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); - Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode); - - if (action == 7) { - Element.show(dijit.byId("filterDlg_actionParamLabel").domNode); - } else if (action == 9) { - Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode); - } else { - Element.show(dijit.byId("filterDlg_actionParam").domNode); - } - - } else { - Element.hide(action_param); - } - }, - createNewRuleElement: function(parentNode, replaceNode) { - const form = document.forms["filter_new_rule_form"]; - const query = {op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form)}; - - xhrPost("backend.php", query, (transport) => { - try { - const li = dojo.create("li"); - - const cb = dojo.create("input", {type: "checkbox"}, li); - - new dijit.form.CheckBox({ - onChange: function () { - Lists.onRowChecked(this); - }, - }, cb); - - dojo.create("input", { - type: "hidden", - name: "rule[]", - value: dojo.formToJson(form) - }, li); - - dojo.create("span", { - onclick: function () { - dijit.byId('filterEditDlg').editRule(this); - }, - innerHTML: transport.responseText - }, li); - - if (replaceNode) { - parentNode.replaceChild(li, replaceNode); - } else { - parentNode.appendChild(li); - } - } catch (e) { - exception_error(e); - } - }); - }, - createNewActionElement: function(parentNode, replaceNode) { - const form = document.forms["filter_new_action_form"]; - - if (form.action_id.value == 7) { - form.action_param.value = form.action_param_label.value; - } else if (form.action_id.value == 9) { - form.action_param.value = form.action_param_plugin.value; - } - - const query = { - op: "pref-filters", method: "printactionname", - action: dojo.formToJson(form) - }; - - xhrPost("backend.php", query, (transport) => { - try { - const li = dojo.create("li"); - - const cb = dojo.create("input", {type: "checkbox"}, li); - - new dijit.form.CheckBox({ - onChange: function () { - Lists.onRowChecked(this); - }, - }, cb); - - dojo.create("input", { - type: "hidden", - name: "action[]", - value: dojo.formToJson(form) - }, li); - - dojo.create("span", { - onclick: function () { - dijit.byId('filterEditDlg').editAction(this); - }, - innerHTML: transport.responseText - }, li); - - if (replaceNode) { - parentNode.replaceChild(li, replaceNode); - } else { - parentNode.appendChild(li); - } - - } catch (e) { - exception_error(e); - } - }); - }, - addFilterRule: function(replaceNode, ruleStr) { - if (dijit.byId("filterNewRuleDlg")) - dijit.byId("filterNewRuleDlg").destroyRecursive(); - - const query = "backend.php?op=pref-filters&method=newrule&rule=" + - param_escape(ruleStr); - - const rule_dlg = new dijit.Dialog({ - id: "filterNewRuleDlg", - title: ruleStr ? __("Edit rule") : __("Add rule"), - style: "width: 600px", - execute: function () { - if (this.validate()) { - Filters.createNewRuleElement($("filterDlg_Matches"), replaceNode); - this.hide(); - } - }, - href: query - }); - - rule_dlg.show(); - }, - addFilterAction: function(replaceNode, actionStr) { - if (dijit.byId("filterNewActionDlg")) - dijit.byId("filterNewActionDlg").destroyRecursive(); - - const query = "backend.php?op=pref-filters&method=newaction&action=" + - param_escape(actionStr); - - const rule_dlg = new dijit.Dialog({ - id: "filterNewActionDlg", - title: actionStr ? __("Edit action") : __("Add action"), - style: "width: 600px", - execute: function () { - if (this.validate()) { - Filters.createNewActionElement($("filterDlg_Actions"), replaceNode); - this.hide(); - } - }, - href: query - }); - - rule_dlg.show(); - }, - editFilterTest: function(query) { - - if (dijit.byId("filterTestDlg")) - dijit.byId("filterTestDlg").destroyRecursive(); - - const test_dlg = new dijit.Dialog({ - id: "filterTestDlg", - title: "Test Filter", - style: "width: 600px", - results: 0, - limit: 100, - max_offset: 10000, - getTestResults: function (query, offset) { - const updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit; - - console.log("getTestResults:" + offset); - - xhrPost("backend.php", updquery, (transport) => { - try { - const result = JSON.parse(transport.responseText); - - if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) { - test_dlg.results += result.length; - - console.log("got results:" + result.length); - - $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...") - .replace("%f", test_dlg.results) - .replace("%d", offset); - - console.log(offset + " " + test_dlg.max_offset); - - for (let i = 0; i < result.length; i++) { - const tmp = new Element("table"); - tmp.innerHTML = result[i]; - dojo.parser.parse(tmp); - - $("prefFilterTestResultList").innerHTML += tmp.innerHTML; - } - - if (test_dlg.results < 30 && offset < test_dlg.max_offset) { - - // get the next batch - window.setTimeout(function () { - test_dlg.getTestResults(query, offset + test_dlg.limit); - }, 0); - - } else { - // all done - - Element.hide("prefFilterLoadingIndicator"); - - if (test_dlg.results == 0) { - $("prefFilterTestResultList").innerHTML = ""; - $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:"; - } else { - $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:") - .replace("%d", test_dlg.results); - } - - } - - } else if (!result) { - console.log("getTestResults: can't parse results object"); - - Element.hide("prefFilterLoadingIndicator"); - - notify_error("Error while trying to get filter test results."); - - } else { - console.log("getTestResults: dialog closed, bailing out."); - } - } catch (e) { - exception_error(e); - } - - }); - }, - href: query - }); - - dojo.connect(test_dlg, "onLoad", null, function (e) { - test_dlg.getTestResults(query, 0); - }); - - test_dlg.show(); - }, - quickAddFilter: function() { - let query; - - if (!App.isPrefs()) { - query = { - op: "pref-filters", method: "newfilter", - feed: Feeds.getActive(), is_cat: Feeds.activeIsCat() - }; - } else { - query = {op: "pref-filters", method: "newfilter"}; - } - - console.log('quickAddFilter', query); - - if (dijit.byId("feedEditDlg")) - dijit.byId("feedEditDlg").destroyRecursive(); - - if (dijit.byId("filterEditDlg")) - dijit.byId("filterEditDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "filterEditDlg", - title: __("Create Filter"), - style: "width: 600px", - test: function () { - const query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test"; - - Filters.editFilterTest(query); - }, - selectRules: function (select) { - $$("#filterDlg_Matches input[type=checkbox]").each(function (e) { - e.checked = select; - if (select) - e.parentNode.addClassName("Selected"); - else - e.parentNode.removeClassName("Selected"); - }); - }, - selectActions: function (select) { - $$("#filterDlg_Actions input[type=checkbox]").each(function (e) { - e.checked = select; - - if (select) - e.parentNode.addClassName("Selected"); - else - e.parentNode.removeClassName("Selected"); - - }); - }, - editRule: function (e) { - const li = e.parentNode; - const rule = li.getElementsByTagName("INPUT")[1].value; - Filters.addFilterRule(li, rule); - }, - editAction: function (e) { - const li = e.parentNode; - const action = li.getElementsByTagName("INPUT")[1].value; - Filters.addFilterAction(li, action); - }, - addAction: function () { - Filters.addFilterAction(); - }, - addRule: function () { - Filters.addFilterRule(); - }, - deleteAction: function () { - $$("#filterDlg_Actions li[class*=Selected]").each(function (e) { - e.parentNode.removeChild(e) - }); - }, - deleteRule: function () { - $$("#filterDlg_Matches li[class*=Selected]").each(function (e) { - e.parentNode.removeChild(e) - }); - }, - execute: function () { - if (this.validate()) { - - const query = dojo.formToQuery("filter_new_form"); - - xhrPost("backend.php", query, () => { - if (App.isPrefs()) { - dijit.byId("filterTree").reload(); - } - - dialog.hide(); - }); - } - }, - href: "backend.php?" + dojo.objectToQuery(query) - }); - - if (!App.isPrefs()) { - const selectedText = getSelectionText(); - - const lh = dojo.connect(dialog, "onLoad", function () { - dojo.disconnect(lh); - - if (selectedText != "") { - - const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) : - Feeds.getActive(); - - const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1}; - - Filters.addFilterRule(null, dojo.toJson(rule)); - - } else { - - const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActive()}; - - xhrPost("backend.php", query, (transport) => { - const reply = JSON.parse(transport.responseText); - - let title = false; - - if (reply && reply.title) title = reply.title; - - if (title || Feeds.getActive() || Feeds.activeIsCat()) { - - console.log(title + " " + Feeds.getActive()); - - const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) : - Feeds.getActive(); - - const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1}; - - Filters.addFilterRule(null, dojo.toJson(rule)); - } - }); - } - }); - } - - dialog.show(); - }, -}; - /* function strip_tags(s) { return s.replace(/<\/?[^>]+(>|$)/g, ""); } */ diff --git a/js/prefs.js b/js/prefs.js index 3578a7007..8804bdba9 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -1,4 +1,10 @@ -/* global dijit, __ */ +/* global dijit, __,fox */ + +let Utils; +let CommonDialogs; +let Filters; +let Users; +let Prefs; const App = { init: function() { @@ -39,6 +45,11 @@ const App = { "dojo/data/ItemFileWriteStore", "lib/CheckBoxStoreModel", "lib/CheckBoxTree", + "fox/Utils", + "fox/CommonDialogs", + "fox/CommonFilters", + "fox/PrefUsers", + "fox/PrefHelpers", "fox/PrefFeedStore", "fox/PrefFilterStore", "fox/PrefFeedTree", @@ -47,6 +58,12 @@ const App = { ready(function () { try { + Utils = fox.Utils(); + CommonDialogs = fox.CommonDialogs(); + Filters = fox.CommonFilters(); + Users = fox.PrefUsers(); + Prefs = fox.PrefHelpers(); + parser.parse(); Utils.setLoadingProgress(50); @@ -131,274 +148,6 @@ const App = { } }; -// noinspection JSUnusedGlobalSymbols -const Prefs = { - clearFeedAccessKeys: function() { - if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { - notify_progress("Clearing URLs..."); - - xhrPost("backend.php", {op: "pref-feeds", method: "clearKeys"}, () => { - notify_info("Generated URLs cleared."); - }); - } - - return false; - }, - updateEventLog: function() { - xhrPost("backend.php", { op: "pref-system" }, (transport) => { - dijit.byId('systemConfigTab').attr('content', transport.responseText); - notify(""); - }); - }, - clearEventLog: function() { - if (confirm(__("Clear event log?"))) { - - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => { - this.updateEventLog(); - }); - } - }, - editProfiles: function() { - - if (dijit.byId("profileEditDlg")) - dijit.byId("profileEditDlg").destroyRecursive(); - - const query = "backend.php?op=pref-prefs&method=editPrefProfiles"; - - // noinspection JSUnusedGlobalSymbols - const dialog = new dijit.Dialog({ - id: "profileEditDlg", - title: __("Settings Profiles"), - style: "width: 600px", - getSelectedProfiles: function () { - return Tables.getSelected("prefFeedProfileList"); - }, - removeSelected: function () { - const sel_rows = this.getSelectedProfiles(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected profiles? Active and default profiles will not be removed."))) { - notify_progress("Removing selected profiles...", true); - - const query = { - op: "rpc", method: "remprofiles", - ids: sel_rows.toString() - }; - - xhrPost("backend.php", query, () => { - notify(''); - Prefs.editProfiles(); - }); - } - - } else { - alert(__("No profiles selected.")); - } - }, - activateProfile: function () { - const sel_rows = this.getSelectedProfiles(); - - if (sel_rows.length == 1) { - if (confirm(__("Activate selected profile?"))) { - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", {op: "rpc", method: "setprofile", id: sel_rows.toString()}, () => { - window.location.reload(); - }); - } - - } else { - alert(__("Please choose a profile to activate.")); - } - }, - addProfile: function () { - if (this.validate()) { - notify_progress("Creating profile...", true); - - const query = {op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile}; - - xhrPost("backend.php", query, () => { - notify(''); - Prefs.editProfiles(); - }); - - } - }, - execute: function () { - if (this.validate()) { - } - }, - href: query - }); - - dialog.show(); - }, - customizeCSS: function() { - const query = "backend.php?op=pref-prefs&method=customizeCSS"; - - if (dijit.byId("cssEditDlg")) - dijit.byId("cssEditDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "cssEditDlg", - title: __("Customize stylesheet"), - style: "width: 600px", - execute: function () { - notify_progress('Saving data...', true); - - xhrPost("backend.php", this.attr('value'), () => { - window.location.reload(); - }); - - }, - href: query - }); - - dialog.show(); - }, - confirmReset: function() { - if (confirm(__("Reset to defaults?"))) { - xhrPost("backend.php", {op: "pref-prefs", method: "resetconfig"}, (transport) => { - Prefs.refresh(); - notify_info(transport.responseText); - }); - } - }, - clearPluginData: function(name) { - if (confirm(__("Clear stored data for this plugin?"))) { - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", {op: "pref-prefs", method: "clearplugindata", name: name}, () => { - Prefs.refresh(); - }); - } - }, - refresh: function() { - xhrPost("backend.php", { op: "pref-prefs" }, (transport) => { - dijit.byId('genConfigTab').attr('content', transport.responseText); - notify(""); - }); - } -}; - -// noinspection JSUnusedGlobalSymbols -const Users = { - reload: function(sort) { - const user_search = $("user_search"); - const search = user_search ? user_search.value : ""; - - xhrPost("backend.php", { op: "pref-users", sort: sort, search: search }, (transport) => { - dijit.byId('userConfigTab').attr('content', transport.responseText); - notify(""); - }); - }, - add: function() { - const login = prompt(__("Please enter username:"), ""); - - if (login) { - notify_progress("Adding user..."); - - xhrPost("backend.php", {op: "pref-users", method: "add", login: login}, (transport) => { - alert(transport.responseText); - Users.reload(); - }); - - } - }, - edit: function(id) { - const query = "backend.php?op=pref-users&method=edit&id=" + - param_escape(id); - - if (dijit.byId("userEditDlg")) - dijit.byId("userEditDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "userEditDlg", - title: __("User Editor"), - style: "width: 600px", - execute: function () { - if (this.validate()) { - notify_progress("Saving data...", true); - - xhrPost("backend.php", dojo.formToObject("user_edit_form"), (transport) => { - dialog.hide(); - Users.reload(); - }); - } - }, - href: query - }); - - dialog.show(); - }, - resetSelected: function() { - const rows = this.getSelection(); - - if (rows.length == 0) { - alert(__("No users selected.")); - return; - } - - if (rows.length > 1) { - alert(__("Please select one user.")); - return; - } - - if (confirm(__("Reset password of selected user?"))) { - notify_progress("Resetting password for selected user..."); - - const id = rows[0]; - - xhrPost("backend.php", {op: "pref-users", method: "resetPass", id: id}, (transport) => { - notify(''); - alert(transport.responseText); - }); - - } - }, - removeSelected: function() { - const sel_rows = this.getSelection(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected users? Neither default admin nor your account will be removed."))) { - notify_progress("Removing selected users..."); - - const query = { - op: "pref-users", method: "remove", - ids: sel_rows.toString() - }; - - xhrPost("backend.php", query, () => { - this.reload(); - }); - } - - } else { - alert(__("No users selected.")); - } - }, - editSelected: function() { - const rows = this.getSelection(); - - if (rows.length == 0) { - alert(__("No users selected.")); - return; - } - - if (rows.length > 1) { - alert(__("Please select one user.")); - return; - } - - this.edit(rows[0]); - }, - getSelection :function() { - return Tables.getSelected("prefUserList"); - } -}; - function opmlImportComplete(iframe) { if (!iframe.contentDocument.body.innerHTML) return false; diff --git a/js/tt-rss.js b/js/tt-rss.js index 71bb2337a..d0a97a1c0 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -1,4 +1,8 @@ -/* global dijit, __ */ +/* global dijit,__,fox */ + +let Utils; +let CommonDialogs; +let Filters; const App = { global_unread: -1, @@ -44,12 +48,19 @@ const App = { "dijit/tree/dndSource", "dijit/tree/ForestStoreModel", "dojo/data/ItemFileWriteStore", + "fox/Utils", + "fox/CommonDialogs", + "fox/CommonFilters", "fox/FeedStoreModel", "fox/FeedTree"], function (dojo, ready, parser) { ready(function () { try { + Utils = fox.Utils(); + CommonDialogs = fox.CommonDialogs(); + Filters = fox.CommonFilters(); + parser.parse(); if (!App.genericSanityCheck()) -- cgit v1.2.3-54-g00ecf From f89924f7a19871e26d5805a6c1863903c6e474bf Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 18:38:27 +0300 Subject: set use strict on JS modules; remove some mostly useless stuff like get_minified_js() --- include/functions.php | 49 ----- include/login_form.php | 2 +- index.php | 9 +- js/Article.js | 2 + js/ArticleCache.js | 2 + js/CommonDialogs.js | 2 + js/CommonFilters.js | 2 + js/Feeds.js | 2 + js/Headlines.js | 4 +- js/PluginHost.js | 4 +- js/PrefUsers.js | 2 + js/Utils.js | 8 +- js/common.js | 493 +++++++++++++++++++++++++++++++++++++++++++++++++ js/functions.js | 492 ------------------------------------------------ js/prefs.js | 1 + js/tt-rss.js | 1 + prefs.php | 11 +- register.php | 2 +- 18 files changed, 524 insertions(+), 564 deletions(-) create mode 100755 js/common.js delete mode 100755 js/functions.js (limited to 'js/functions.js') diff --git a/include/functions.php b/include/functions.php index 2ec42c7ee..baed6fb20 100755 --- a/include/functions.php +++ b/include/functions.php @@ -1310,9 +1310,6 @@ $data['last_article_id'] = Article::getLastArticleId(); $data['cdm_expanded'] = get_pref('CDM_EXPANDED'); - $data['dep_ts'] = calculate_dep_timestamp(); - $data['reload_on_ts_change'] = !defined('_NO_RELOAD_ON_TS_CHANGE'); - $data["labels"] = Labels::get_all_labels($_SESSION["uid"]); if (CHECK_FOR_UPDATES && !$disable_update_check && $_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) { @@ -2379,52 +2376,6 @@ return in_array($interface, class_implements($class)); } - function get_minified_js($files) { - - $rv = ''; - - foreach ($files as $js) { - if (!isset($_GET['debug'])) { - $cached_file = CACHE_DIR . "/js/".basename($js); - - if (file_exists($cached_file) && is_readable($cached_file) && filemtime($cached_file) >= filemtime("js/$js")) { - - list($header, $contents) = explode("\n", file_get_contents($cached_file), 2); - - if ($header && $contents) { - list($htag, $hversion) = explode(":", $header); - - if ($htag == "tt-rss" && $hversion == VERSION) { - $rv .= $contents; - continue; - } - } - } - - $minified = JShrink\Minifier::minify(file_get_contents("js/$js")); - file_put_contents($cached_file, "tt-rss:" . VERSION . "\n" . $minified); - $rv .= $minified; - - } else { - $rv .= file_get_contents("js/$js"); // no cache in debug mode - } - } - - return $rv; - } - - function calculate_dep_timestamp() { - $files = array_merge(glob("js/*.js"), glob("css/*.css")); - - $max_ts = -1; - - foreach ($files as $file) { - if (filemtime($file) > $max_ts) $max_ts = filemtime($file); - } - - return $max_ts; - } - function T_js_decl($s1, $s2) { if ($s1 && $s2) { $s1 = preg_replace("/\n/", "", $s1); diff --git a/include/login_form.php b/include/login_form.php index bb142f6c5..9c3a9b375 100644 --- a/include/login_form.php +++ b/include/login_form.php @@ -10,7 +10,7 @@ foreach (array("lib/prototype.js", "lib/dojo/dojo.js", "lib/dojo/tt-rss-layer.js", - "js/functions.js", + "js/common.js", "errors.php?mode=js") as $jsfile) { echo javascript_tag($jsfile); diff --git a/index.php b/index.php index 00bf42830..4a85ff236 100644 --- a/index.php +++ b/index.php @@ -103,6 +103,9 @@ "lib/scriptaculous/scriptaculous.js?load=effects,controls", "lib/dojo/dojo.js", "lib/dojo/tt-rss-layer.js", + "js/tt-rss.js", + "js/common.js", + "js/PluginHost.js", "errors.php?mode=js") as $jsfile) { echo javascript_tag($jsfile); @@ -110,13 +113,9 @@ } ?> + + +
    No recent articles matching this filter have been found.
    No recent articles matching this filter have been found.