From c36b2adf8488cdf88b0ef05d211c16815f8c5407 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 13 Feb 2021 21:57:02 +0300 Subject: feeds with errors: use client dialog --- js/CommonDialogs.js | 113 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 76 insertions(+), 37 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 70596539b..5a72f705b 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -188,52 +188,91 @@ const CommonDialogs = { }); }, showFeedsWithErrors: function() { - const dialog = new fox.SingleUseDialog({ - id: "errorFeedsDlg", - title: __("Feeds with update errors"), - getSelectedFeeds: function () { - return Tables.getSelected("error-feeds-list"); - }, - removeSelected: function () { - const sel_rows = this.getSelectedFeeds(); - if (sel_rows.length > 0) { - if (confirm(__("Remove selected feeds?"))) { - Notify.progress("Removing selected feeds...", true); + xhrJson("backend.php", {op: "pref-feeds", method: "feedsWithErrors"}, (reply) => { - const query = { - op: "pref-feeds", method: "remove", - ids: sel_rows.toString() - }; + const dialog = new fox.SingleUseDialog({ + id: "errorFeedsDlg", + title: __("Feeds with update errors"), + getSelectedFeeds: function () { + return Tables.getSelected("error-feeds-list"); + }, + removeSelected: function () { + const sel_rows = this.getSelectedFeeds(); - xhrPost("backend.php", query, () => { - Notify.close(); - dialog.hide(); + if (sel_rows.length > 0) { + if (confirm(__("Remove selected feeds?"))) { + Notify.progress("Removing selected feeds...", true); - if (App.isPrefs()) - dijit.byId("feedTree").reload(); - else - Feeds.reload(); + const query = { + op: "pref-feeds", method: "remove", + ids: sel_rows.toString() + }; - }); - } + xhrPost("backend.php", query, () => { + Notify.close(); + dialog.hide(); - } else { - alert(__("No feeds selected.")); - } - }, - content: __("Loading, please wait...") - }); + if (App.isPrefs()) + dijit.byId("feedTree").reload(); + else + Feeds.reload(); - const tmph = dojo.connect(dialog, 'onShow', function () { - dojo.disconnect(tmph); + }); + } - xhrPost("backend.php", {op: "pref-feeds", method: "feedsWithErrors"}, (transport) => { - dialog.attr('content', transport.responseText); - }) - }); + } else { + alert(__("No feeds selected.")); + } + }, + content: ` +
+
+ ${__('Select')} +
+
${__('All')}
+
${__('None')}
+
+
+
+ +
+ + + ${reply.map((row) => ` + + + + + + `).join("")} +
+ + + + ${App.escapeHtml(row.title)} + + + ${App.escapeHtml(row.last_error)} +
+
+ + + ` + }); - dialog.show(); + dialog.show(); + }) }, addLabel: function(select, callback) { const caption = prompt(__("Please enter label caption:"), ""); -- cgit v1.2.3-54-g00ecf From a2e688fcb2d463a5db700ebd013c783e3a8f4971 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 22:17:13 +0300 Subject: render headline-specific toolbar on the client --- classes/feeds.php | 123 +++++++++-------------------------------------- classes/pref/feeds.php | 22 ++++++--- index.php | 4 +- js/CommonDialogs.js | 13 ++--- js/Headlines.js | 61 +++++++++++++++++++++-- plugins/mail/init.php | 7 ++- plugins/mailto/init.php | 5 ++ themes/compact.css | 5 +- themes/compact_night.css | 5 +- themes/light.css | 5 +- themes/light/tt-rss.less | 4 +- themes/night.css | 5 +- themes/night_blue.css | 5 +- 13 files changed, 136 insertions(+), 128 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/classes/feeds.php b/classes/feeds.php index e6bd1459d..0a3e77a1a 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -16,103 +16,6 @@ class Feeds extends Handler_Protected { return array_search($method, $csrf_ignored) !== false; } - private function format_headline_subtoolbar($feed_site_url, $feed_title, - $feed_id, $is_cat, $search, - $error, $feed_last_updated) { - - $cat_q = $is_cat ? "&is_cat=$is_cat" : ""; - - if ($search) { - $search_q = "&q=$search"; - } else { - $search_q = ""; - } - - $reply = ""; - - $rss_link = htmlspecialchars(get_self_url_prefix() . - "/public.php?op=rss&id=${feed_id}${cat_q}${search_q}"); - - $reply .= ""; - - $reply .= " - rss_feed"; - - $reply .= ""; - - if ($feed_site_url) { - $last_updated = T_sprintf("Last updated: %s", $feed_last_updated); - - $reply .= "". - truncate_string(strip_tags($feed_title), 30).""; - } else { - $reply .= strip_tags($feed_title); - } - - if ($error) - $reply .= " error"; - - $reply .= ""; - $reply .= ""; - $reply .= ""; - - $reply .= ""; - $reply .= ""; - $reply .= " "; - - $reply .= "
- ".__("Select...")." -
-
".__('All')."
-
".__('Unread')."
-
".__('Invert')."
-
".__('None')."
-
-
".__('Toggle unread')."
-
".__('Toggle starred')."
-
".__('Toggle published')."
-
-
".__('Mark as read')."
-
".__('Set score')."
"; - - // TODO: move to mail plugin - if (PluginHost::getInstance()->get_plugin("mail")) { - $reply .= "
".__('Forward by email')."
"; - } - - // TODO: move to mailto plugin - if (PluginHost::getInstance()->get_plugin("mailto")) { - $reply .= "
".__('Forward by email')."
"; - } - - PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM, - function ($result) use (&$reply) { - $reply .= $result; - }, - $feed_id, $is_cat); - - if ($feed_id == 0 && !$is_cat) { - $reply .= "
-
".__('Delete permanently')."
"; - } - - $reply .= "
"; /* menu */ - - $reply .= "
"; /* dropdown */ - - PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_HEADLINE_TOOLBAR_BUTTON, - function ($result) use (&$reply) { - $reply .= $result; - }, - $feed_id, $is_cat); - - $reply .= "
"; - - return $reply; - } - private function format_headlines_list($feed, $method, $view_mode, $limit, $cat_view, $offset, $override_order = false, $include_children = false, $check_first_id = false, $skip_first_id_check = false, $order_by = false) { @@ -222,10 +125,28 @@ class Feeds extends Handler_Protected { $reply['search_query'] = [$search, $search_language]; $reply['vfeed_group_enabled'] = $vfeed_group_enabled; - $reply['toolbar'] = $this->format_headline_subtoolbar($feed_site_url, - $feed_title, - $feed, $cat_view, $search, - $last_error, $last_updated); + $plugin_menu_items = ""; + PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM, + function ($result) use (&$plugin_menu_items) { + $plugin_menu_items .= $result; + }, + $feed, $cat_view); + + $plugin_buttons = ""; + PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_HEADLINE_TOOLBAR_BUTTON, + function ($result) use (&$plugin_buttons) { + $plugin_buttons .= $result; + }, + $feed, $cat_view); + + $reply['toolbar'] = [ + 'site_url' => $feed_site_url, + 'title' => truncate_string(strip_tags($feed_title), 30), + 'error' => $last_error, + 'last_updated' => $last_updated, + 'plugin_menu_items' => $plugin_menu_items, + 'plugin_buttons' => $plugin_buttons, + ]; $reply['content'] = []; diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 6b5df0289..e225949f2 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1358,14 +1358,12 @@ class Pref_Feeds extends Handler_Protected { } private function index_shared() { - $rss_url = htmlspecialchars(get_self_url_prefix() . - "/public.php?op=rss&id=-2&view-mode=all_articles"); ?>

@@ -1603,11 +1601,23 @@ class Pref_Feeds extends Handler_Protected { print json_encode(["link" => $new_key]); } - function getFeedKey() { + function getsharedurl() { $feed_id = clean($_REQUEST['id']); - $is_cat = clean($_REQUEST['is_cat']); + $is_cat = clean($_REQUEST['is_cat']) == "true"; + $search = clean($_REQUEST['search']); + + $link = get_self_url_prefix() . "/public.php?" . http_build_query([ + 'op' => 'rss', + 'id' => $feed_id, + 'is_cat' => (int)$is_cat, + 'q' => $search, + 'key' => Feeds::get_feed_access_key($feed_id, $is_cat, $_SESSION["uid"]) + ]); - print json_encode(["link" => Feeds::get_feed_access_key($feed_id, $is_cat, $_SESSION["uid"])]); + print json_encode([ + "title" => Feeds::getFeedTitle($feed_id, $is_cat), + "link" => $link + ]); } private function update_feed_access_key($feed_id, $is_cat, $owner_uid) { diff --git a/index.php b/index.php index 8bfca1af2..d53fb54a8 100644 --- a/index.php +++ b/index.php @@ -176,9 +176,9 @@ }); ?> -
+
- +
diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 5a72f705b..e6b1822c2 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -433,24 +433,19 @@ const CommonDialogs = { } }); }, - generatedFeed: function(feed, is_cat, rss_url, feed_title) { + generatedFeed: function(feed, is_cat, search = "") { Notify.progress("Loading, please wait...", true); - xhrJson("backend.php", {op: "pref-feeds", method: "getFeedKey", id: feed, is_cat: is_cat}, (reply) => { + xhrJson("backend.php", {op: "pref-feeds", method: "getsharedurl", id: feed, is_cat: is_cat, search: search}, (reply) => { try { - if (!feed_title && typeof Feeds != "undefined") - feed_title = Feeds.getName(feed, is_cat); - - const secret_url = rss_url + "&key=" + encodeURIComponent(reply.link); - const dialog = new fox.SingleUseDialog({ title: __("Show as feed"), content: ` -
${__("%s can be accessed via the following secret URL:").replace("%s", feed_title)}
+
${__("%s can be accessed via the following secret URL:").replace("%s", App.escapeHtml(reply.title))}
diff --git a/js/Headlines.js b/js/Headlines.js index ea4c81a6a..954b6b45f 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -566,6 +566,58 @@ const Headlines = { } } }, + renderToolbar: function(headlines) { + + const tb = headlines['toolbar']; + const search_query = Feeds._search_query ? Feeds._search_query.query : ""; + const target = dijit.byId('toolbar-headlines'); + + target.attr('innerHTML', + ` + + + rss_feed + + ${tb.site_url ? + `${tb.title}` : + `${tb.title}`} + ${search_query ? + ` + (${__("Cancel search")}) + ` : ''} + ${tb.error ? `error` : ''} + + + + +
+ ${__("Select...")} +
+
${__('All')}
+
${__('Unread')}
+
${__('Invert')}
+
${__('None')}
+
+
${__('Toggle unread')}
+
${__('Toggle starred')}
+
${__('Toggle published')}
+
+
${__('Mark as read')}
+
${__('Set score')}
+ ${tb.plugin_menu_items} + ${headlines.id === 0 && !headlines.is_cat ? + ` +
+
${__('Delete permanently')}
+ ` : ''} +
+ ${tb.plugin_buttons} + + `); + + dojo.parser.parse(target.domNode); + }, onLoaded: function (transport, offset, append) { const reply = App.handleRpcJson(transport); @@ -613,9 +665,11 @@ const Headlines = { this.headlines = []; this.vgroup_last_feed = undefined; - dojo.html.set($("toolbar-headlines"), + /*dojo.html.set($("toolbar-headlines"), reply['headlines']['toolbar'], - {parseContent: true}); + {parseContent: true});*/ + + Headlines.renderToolbar(reply['headlines']); if (typeof reply['headlines']['content'] == 'string') { $("headlines-frame").innerHTML = reply['headlines']['content']; @@ -646,11 +700,12 @@ const Headlines = { hsp.innerHTML = "" + __("Click to open next unread feed.") + ""; + /* if (Feeds._search_query) { $("feed_title").innerHTML += "" + " (" + __("Cancel search") + ")" + ""; - } + } */ Headlines.updateCurrentUnread(); diff --git a/plugins/mail/init.php b/plugins/mail/init.php index 40d147fc9..829620ebc 100644 --- a/plugins/mail/init.php +++ b/plugins/mail/init.php @@ -15,12 +15,17 @@ class Mail extends Plugin { $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); $host->add_hook($host::HOOK_PREFS_TAB, $this); + $host->add_hook($host::HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM, $this); } function get_js() { return file_get_contents(dirname(__FILE__) . "/mail.js"); } + function hook_headline_toolbar_select_menu_item($feed_id, $is_cat) { + return "
".__('Forward by email')."
"; + } + function save() { $addresslist = $_POST["addresslist"]; @@ -32,7 +37,7 @@ class Mail extends Plugin { function hook_prefs_tab($args) { if ($args != "prefPrefs") return; - print "
mail ".__('Mail plugin')."\">"; print "

" . __("You can set predefined email addressed here (comma-separated list):") . "

"; diff --git a/plugins/mailto/init.php b/plugins/mailto/init.php index 390984b71..3e24dcf29 100644 --- a/plugins/mailto/init.php +++ b/plugins/mailto/init.php @@ -12,6 +12,11 @@ class MailTo extends Plugin { $this->host = $host; $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); + $host->add_hook($host::HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM, $this); + } + + function hook_headline_toolbar_select_menu_item($feed_id, $is_cat) { + return "
".__('Forward by email')."
"; } function get_js() { diff --git a/themes/compact.css b/themes/compact.css index 24380d428..6e4f59c84 100644 --- a/themes/compact.css +++ b/themes/compact.css @@ -704,6 +704,8 @@ body.ttrss_main #toolbar-frame #toolbar i { margin: 0 4px; } body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines { + font-size: 12px; + background: transparent; padding-right: 4px; flex-grow: 2; display: flex; @@ -713,7 +715,8 @@ body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left { display: flex; align-items: center; } -body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left #feed_title { +body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left .feed_title, +body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left .cancel_search { margin-left: 4px; } body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .right { diff --git a/themes/compact_night.css b/themes/compact_night.css index a366404a4..7dd4c0b0e 100644 --- a/themes/compact_night.css +++ b/themes/compact_night.css @@ -704,6 +704,8 @@ body.ttrss_main #toolbar-frame #toolbar i { margin: 0 4px; } body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines { + font-size: 12px; + background: transparent; padding-right: 4px; flex-grow: 2; display: flex; @@ -713,7 +715,8 @@ body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left { display: flex; align-items: center; } -body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left #feed_title { +body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left .feed_title, +body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left .cancel_search { margin-left: 4px; } body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .right { diff --git a/themes/light.css b/themes/light.css index d3f5d7978..6f70862d6 100644 --- a/themes/light.css +++ b/themes/light.css @@ -704,6 +704,8 @@ body.ttrss_main #toolbar-frame #toolbar i { margin: 0 4px; } body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines { + font-size: 12px; + background: transparent; padding-right: 4px; flex-grow: 2; display: flex; @@ -713,7 +715,8 @@ body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left { display: flex; align-items: center; } -body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left #feed_title { +body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left .feed_title, +body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left .cancel_search { margin-left: 4px; } body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .right { diff --git a/themes/light/tt-rss.less b/themes/light/tt-rss.less index d13ffff3e..4632997ba 100644 --- a/themes/light/tt-rss.less +++ b/themes/light/tt-rss.less @@ -820,6 +820,8 @@ body.ttrss_main { } #toolbar-headlines { + font-size : 12px; + background: transparent; padding-right : 4px; flex-grow : 2; display : flex; @@ -829,7 +831,7 @@ body.ttrss_main { display : flex; align-items : center; - #feed_title { + .feed_title, .cancel_search { margin-left : 4px; } } diff --git a/themes/night.css b/themes/night.css index 87a68a3c0..579f6dcdf 100644 --- a/themes/night.css +++ b/themes/night.css @@ -705,6 +705,8 @@ body.ttrss_main #toolbar-frame #toolbar i { margin: 0 4px; } body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines { + font-size: 12px; + background: transparent; padding-right: 4px; flex-grow: 2; display: flex; @@ -714,7 +716,8 @@ body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left { display: flex; align-items: center; } -body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left #feed_title { +body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left .feed_title, +body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left .cancel_search { margin-left: 4px; } body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .right { diff --git a/themes/night_blue.css b/themes/night_blue.css index 02a66656b..3697cff05 100644 --- a/themes/night_blue.css +++ b/themes/night_blue.css @@ -705,6 +705,8 @@ body.ttrss_main #toolbar-frame #toolbar i { margin: 0 4px; } body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines { + font-size: 12px; + background: transparent; padding-right: 4px; flex-grow: 2; display: flex; @@ -714,7 +716,8 @@ body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left { display: flex; align-items: center; } -body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left #feed_title { +body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left .feed_title, +body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .left .cancel_search { margin-left: 4px; } body.ttrss_main #toolbar-frame #toolbar #toolbar-headlines .right { -- cgit v1.2.3-54-g00ecf From 3c584376ca24e4bc5220c8dac4f1e238a245e7fe Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Feb 2021 07:59:11 +0300 Subject: shared opml and feed dialogs: remove unique target element id, move associated methods into dialog --- js/CommonDialogs.js | 91 ++++++++++++++++++++++++++++++++++------------------- js/PrefHelpers.js | 25 --------------- 2 files changed, 58 insertions(+), 58 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index e6b1822c2..60c3e2a84 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -369,35 +369,6 @@ const CommonDialogs = { 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.close(); - - } else { - Notify.error("Could not change feed URL."); - } - }); - } - return false; - }, publishedOPML: function() { Notify.progress("Loading, please wait...", true); @@ -406,15 +377,40 @@ const CommonDialogs = { try { const dialog = new fox.SingleUseDialog({ title: __("Public OPML URL"), + regenOPMLKey: function() { + if (confirm(__("Replace current OPML publishing address with a new one?"))) { + Notify.progress("Trying to change address...", true); + + xhrJson("backend.php", {op: "pref-feeds", method: "regenOPMLKey"}, (reply) => { + if (reply) { + const new_link = reply.link; + const target = this.domNode.querySelector('.generated_url'); + + if (new_link && target) { + target.href = new_link; + target.innerHTML = new_link; + + new Effect.Highlight(target); + + Notify.close(); + + } else { + Notify.error("Could not change feed URL."); + } + } + }); + } + return false; + }, content: `
${__("Your Public OPML URL is:")}
- - "; - - print ""; - print "
"; - - print ""; + function subscribeToFeed() { + print json_encode([ + "cat_select" => format_feed_cat_select("cat", false, 'dojoType="fox.form.Select"') + ]); } function search() { @@ -1077,6 +1002,18 @@ class Feeds extends Handler_Protected { } } + function add() { + $feed = clean($_REQUEST['feed']); + $cat = clean($_REQUEST['cat']); + $need_auth = isset($_REQUEST['need_auth']); + $login = $need_auth ? clean($_REQUEST['login']) : ''; + $pass = $need_auth ? clean($_REQUEST['pass']) : ''; + + $rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass); + + print json_encode(array("result" => $rc)); + } + /** * @return array (code => Status code, message => error message if available) * diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index e225949f2..af3877159 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1241,7 +1241,7 @@ class Pref_Feeds extends Handler_Protected {
-
diff --git a/classes/rpc.php b/classes/rpc.php index e0753a08e..2bbaf4135 100755 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -80,18 +80,6 @@ class RPC extends Handler_Protected { } } - function addfeed() { - $feed = clean($_REQUEST['feed']); - $cat = clean($_REQUEST['cat']); - $need_auth = isset($_REQUEST['need_auth']); - $login = $need_auth ? clean($_REQUEST['login']) : ''; - $pass = $need_auth ? clean($_REQUEST['pass']) : ''; - - $rc = Feeds::subscribe_to_feed($feed, $cat, $login, $pass); - - print json_encode(array("result" => $rc)); - } - function togglepref() { $key = clean($_REQUEST["key"]); set_pref($key, !get_pref($key)); diff --git a/js/App.js b/js/App.js index 3a31438c5..5c2d7726c 100644 --- a/js/App.js +++ b/js/App.js @@ -838,7 +838,7 @@ const App = { if (this.is_prefs) { this.hotkey_actions["feed_subscribe"] = () => { - CommonDialogs.quickAddFeed(); + CommonDialogs.subscribeToFeed(); }; this.hotkey_actions["create_label"] = () => { @@ -994,7 +994,7 @@ const App = { Feeds.toggleUnread(); }; this.hotkey_actions["feed_subscribe"] = () => { - CommonDialogs.quickAddFeed(); + CommonDialogs.subscribeToFeed(); }; this.hotkey_actions["feed_debug_update"] = () => { if (!Feeds.activeIsCat() && parseInt(Feeds.getActive()) > 0) { @@ -1139,7 +1139,7 @@ const App = { Feeds.search(); break; case "qmcAddFeed": - CommonDialogs.quickAddFeed(); + CommonDialogs.subscribeToFeed(); break; case "qmcDigest": window.location.href = "backend.php?op=digest"; diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 60c3e2a84..492467b7f 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -77,15 +77,93 @@ const CommonDialogs = { return false; }, - quickAddFeed: function() { - xhrPost("backend.php", - {op: "feeds", method: "quickAddFeed"}, - (transport) => { - + subscribeToFeed: function() { + xhrJson("backend.php", + {op: "feeds", method: "subscribeToFeed"}, + (reply) => { const dialog = new fox.SingleUseDialog({ - id: "feedAddDlg", title: __("Subscribe to Feed"), - content: transport.responseText, + content: ` +
+ + ${App.FormFields.hidden("op", "feeds")} + ${App.FormFields.hidden("method", "add")} + + + + + +
+
+
+ +
+ + ${App.getInitParam('enable_feed_cats') ? + ` +
+ + ${reply.cat_select} +
+ ` : ''} +
+ + + + + +
+ +
+ +
+ + +
+
+ `, show_error: function (msg) { const elem = $("fadd_error_message"); @@ -114,7 +192,7 @@ const CommonDialogs = { } 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); + console.log('subscribeToFeed, backend returned:' + transport.responseText); return; } -- cgit v1.2.3-54-g00ecf From 3887665bcbed344606f9630cd45316d56ce86203 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Feb 2021 14:13:38 +0300 Subject: CommonDialogs.addLabel: remove long unused parameters --- js/CommonDialogs.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 492467b7f..c16afed82 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -352,22 +352,17 @@ const CommonDialogs = { dialog.show(); }) }, - addLabel: function(select, callback) { + addLabel: function() { 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()) { + xhrPost("backend.php", query, () => { + if (dijit.byId("labelTree")) { dijit.byId("labelTree").reload(); } else { Feeds.reload(); -- cgit v1.2.3-54-g00ecf From b16abc157ee584f4be80a537ee24ec9e5ff25496 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Feb 2021 19:34:54 +0300 Subject: * App: rename hidden to hidden_tag * search: use client dialog * add some form field helpers --- .eslintrc.js | 2 +- classes/feeds.php | 46 ++++++---------------------------------------- js/App.js | 40 +++++++++++++++++++++++++++++++++++----- js/Article.js | 6 +++--- js/CommonDialogs.js | 4 ++-- js/CommonFilters.js | 4 ++-- js/Feeds.js | 42 +++++++++++++++++++++++++++++++++++------- js/PrefFeedTree.js | 4 ++-- js/PrefHelpers.js | 6 +++--- js/PrefLabelTree.js | 10 +++++----- js/PrefUsers.js | 16 ++++++++-------- 11 files changed, 102 insertions(+), 78 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/.eslintrc.js b/.eslintrc.js index 6d76f6082..523ada08e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { "env": { "browser": true, - "es6": true, + "ecmaVersion": 8, "jquery": true, "webextensions": true }, diff --git a/classes/feeds.php b/classes/feeds.php index 68edfbf89..30478ae39 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -588,46 +588,12 @@ class Feeds extends Handler_Protected { } function search() { - $this->params = explode(":", $_REQUEST["param"], 2); - - $active_feed_id = sprintf("%d", $this->params[0]); - $is_cat = $this->params[1] != "false"; - - print "
"; - - print "
"; - - print "
"; - print "_get_title($active_feed_id, $is_cat))."\" - name='query' type='search' value=''>"; - print "
"; - - if (DB_TYPE == "pgsql") { - print "
"; - print ""; - print \Controls\select_tag("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(), - ["title" => __('Used for word stemming')], "search_language"); - print "
"; - } - - print "
"; - - print "
"; - - if (count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0) { - print ""; - } - - print " - "; - - print "
"; - - print "
"; + print json_encode([ + "show_language" => DB_TYPE == "pgsql", + "show_syntax_help" => count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0, + "all_languages" => Pref_Feeds::get_ts_languages(), + "default_language" => get_pref('DEFAULT_SEARCH_LANGUAGE') + ]); } function updatedebugger() { diff --git a/js/App.js b/js/App.js index bb861829d..9d8f6c275 100644 --- a/js/App.js +++ b/js/App.js @@ -18,14 +18,44 @@ const App = { is_prefs: false, LABEL_BASE_INDEX: -1024, FormFields: { - hidden: function(name, value, id = "") { - return `` + attributes_to_string: function(attributes) { + return Object.keys(attributes).map((k) => + `${App.escapeHtml(k)}="${App.escapeHtml(attributes[k])}"`) + .join(" "); }, - select_hash: function(name, value, values, attributes) { + hidden_tag: function(name, value, attributes = {}, id = "") { + return `` + }, + // allow html inside because of icons + button_tag: function(value, type, attributes = {}) { + return `` + + }, + icon: function(icon, attributes = {}) { + return `${icon}`; + }, + submit_tag: function(value, attributes = {}) { + return this.button_tag(value, "submit", {...{class: "alt-primary"}, ...attributes}); + }, + cancel_dialog_tag: function(value, attributes = {}) { + return this.button_tag(value, "", {...{onclick: "App.dialogOf(this).hide()"}, ...attributes}); + }, + select_tag: function(name, value, values = [], attributes = {}, id = "") { + return ` + + ` + }, + select_hash: function(name, value, values = {}, attributes = {}, id = "") { return ` - ${Object.keys(values).map((vk) => - `` + `` ).join("")} ` diff --git a/js/Article.js b/js/Article.js index 4d400e2dc..a42d3af67 100644 --- a/js/Article.js +++ b/js/Article.js @@ -314,9 +314,9 @@ const Article = { const dialog = new fox.SingleUseDialog({ title: __("Edit article Tags"), content: ` - ${App.FormFields.hidden("id", id.toString())} - ${App.FormFields.hidden("op", "article")} - ${App.FormFields.hidden("method", "setArticleTags")} + ${App.FormFields.hidden_tag("id", id.toString())} + ${App.FormFields.hidden_tag("op", "article")} + ${App.FormFields.hidden_tag("method", "setArticleTags")}
${__("Tags for this article (separated by commas):")} diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index c16afed82..dd0d56194 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -86,8 +86,8 @@ const CommonDialogs = { content: `
- ${App.FormFields.hidden("op", "feeds")} - ${App.FormFields.hidden("method", "add")} + ${App.FormFields.hidden_tag("op", "feeds")} + ${App.FormFields.hidden_tag("method", "add")} diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 5afffafdc..e3629157b 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -45,7 +45,7 @@ const Filters = { li.innerHTML = ` ${transport.responseText} - ${App.FormFields.hidden("rule[]", rule)}`; + ${App.FormFields.hidden_tag("rule[]", rule)}`; dojo.parser.parse(li); @@ -76,7 +76,7 @@ const Filters = { li.innerHTML = ` ${transport.responseText} - ${App.FormFields.hidden("action[]", action)}`; + ${App.FormFields.hidden_tag("action[]", action)}`; dojo.parser.parse(li); diff --git a/js/Feeds.js b/js/Feeds.js index 73f1bc338..0567cf8c5 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -1,6 +1,6 @@ 'use strict' -/* global __, App, Headlines, xhrPost, dojo, dijit, Form, fox, PluginHost, Notify, $$, fox */ +/* global __, App, Headlines, xhrPost, xhrJson, dojo, dijit, Form, fox, PluginHost, Notify, $$, fox */ const Feeds = { counters_last_request: 0, @@ -566,14 +566,42 @@ const Feeds = { return tree.model.store.getValue(nuf, 'bare_id'); }, search: function() { - xhrPost("backend.php", - {op: "feeds", method: "search", - param: Feeds.getActive() + ":" + Feeds.activeIsCat()}, - (transport) => { + xhrJson("backend.php", + {op: "feeds", method: "search"}, + (reply) => { try { const dialog = new fox.SingleUseDialog({ - id: "searchDlg", - content: transport.responseText, + content: ` + +
+
+ +
+ + ${reply.show_language ? + ` +
+ + ${App.FormFields.select_tag("search_language", reply.default_language, reply.all_languages, + {title: __('Used for word stemming')}, "search_language")} +
+ ` : ''} +
+ +
+ ${reply.show_syntax_help ? + `${App.FormFields.button_tag(App.FormFields.icon("help") + " " + __("Search syntax"), "", + {class: 'alt-info pull-left', onclick: "window.open('https://tt-rss.org/wiki/SearchSyntax')"})} + ` : ''} + + ${App.FormFields.submit_tag(__('Search'), {onclick: "App.dialogOf(this).execute()"})} + ${App.FormFields.cancel_dialog_tag(__('Cancel'))} +
+
+ `, title: __("Search"), execute: function () { if (this.validate()) { diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index e0a2dd932..e081e2e31 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -405,8 +405,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b }, content: `
- ${App.FormFields.hidden("op", "pref-feeds")} - ${App.FormFields.hidden("method", "batchaddfeeds")} + ${App.FormFields.hidden_tag("op", "pref-feeds")} + ${App.FormFields.hidden_tag("method", "batchaddfeeds")}
${__("One valid feed per line (no detection is done)")} diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index f7eca59a0..96d524953 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -183,9 +183,9 @@ const Helpers = { ${__("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here.")}
- ${App.FormFields.hidden('op', 'rpc')} - ${App.FormFields.hidden('method', 'setpref')} - ${App.FormFields.hidden('key', 'USER_STYLESHEET')} + ${App.FormFields.hidden_tag('op', 'rpc')} + ${App.FormFields.hidden_tag('method', 'setpref')} + ${App.FormFields.hidden_tag('key', 'USER_STYLESHEET')}
"; } diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 40313d34f..c62e6893e 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -425,7 +425,9 @@ const CommonDialogs = { Feeds.reload(); }); + return true; } + return false; }, content: __("Loading, please wait...") }); -- cgit v1.2.3-54-g00ecf From bec35200e97adabf4880a92bad40ec5bbe4848d1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 07:29:21 +0300 Subject: fix some eslint-related stuff --- js/App.js | 121 +++++++++++++++++++++++++--------------------------- js/Article.js | 2 +- js/CommonDialogs.js | 2 +- js/CommonFilters.js | 4 +- js/PrefHelpers.js | 2 +- js/PrefUsers.js | 2 +- js/common.js | 5 ++- js/tt-rss.js | 2 +- 8 files changed, 69 insertions(+), 71 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/js/App.js b/js/App.js index f7a9254ba..d61c6ead0 100644 --- a/js/App.js +++ b/js/App.js @@ -1,9 +1,9 @@ 'use strict'; /* eslint-disable new-cap */ -/* global __, Article, Ajax, Headlines, Filters, fox */ -/* global xhrPost, xhrJson, dojo, dijit, PluginHost, Notify, $$, Feeds, Cookie */ -/* global CommonDialogs, Plugins, Effect */ +/* global __, Article, Headlines, Filters, fox */ +/* global xhrPost, xhrJson, dojo, dijit, PluginHost, Notify, Feeds, Cookie */ +/* global CommonDialogs, Plugins */ const App = { _initParams: [], @@ -234,7 +234,7 @@ const App = { }, urlParam: function(name) { try { - const results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); + const results = new RegExp('[?&]' + name + '=([^&#]*)').exec(window.location.href); return decodeURIComponent(results[1].replace(/\+/g, " ")) || 0; } catch (e) { return 0; @@ -439,40 +439,38 @@ const App = { return false; }, parseRuntimeInfo: function(data) { - for (const k in data) { - if (data.hasOwnProperty(k)) { - const v = data[k]; + Object.keys(data).forEach((k) => { + const v = data[k]; - console.log("RI:", k, "=>", v); + console.log("RI:", k, "=>", v); - if (k == "daemon_is_running" && v != 1) { - Notify.error("Update daemon is not running.", true); - return; - } + if (k == "daemon_is_running" && v != 1) { + Notify.error("Update daemon is not running.", true); + return; + } - if (k == "recent_log_events") { - const alert = App.findAll(".log-alert")[0]; + if (k == "recent_log_events") { + const alert = App.findAll(".log-alert")[0]; - if (alert) { - v > 0 ? alert.show() : alert.hide(); - } - } + if (alert) { + v > 0 ? alert.show() : alert.hide(); + } + } - if (k == "daemon_stamp_ok" && v != 1) { - Notify.error("Update daemon is not updating feeds.", true); - return; - } + 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 (this.getInitParam(k) != v) { - console.log("feed count changed, need to reload feedlist."); - Feeds.reload(); - } - } + if (k == "max_feed_id" || k == "num_feeds") { + if (this.getInitParam(k) != v) { + console.log("feed count changed, need to reload feedlist."); + Feeds.reload(); + } + } - this.setInitParam(k, v); - } - } + this.setInitParam(k, v); + }); PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data); }, @@ -500,39 +498,36 @@ const App = { if (params) { console.log('reading init-params...'); - for (const k in params) { - if (params.hasOwnProperty(k)) { - switch (k) { - case "label_base_index": - this.LABEL_BASE_INDEX = parseInt(params[k]); - break; - case "cdm_auto_catchup": - if (params[k] == 1) { - const hl = App.byId("headlines-frame"); - if (hl) hl.addClassName("auto_catchup"); - } - 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; - } + Object.keys(params).forEach((k) => { + switch (k) { + case "label_base_index": + this.LABEL_BASE_INDEX = parseInt(params[k]); + break; + case "cdm_auto_catchup": + if (params[k] == 1) { + const hl = App.byId("headlines-frame"); + if (hl) hl.addClassName("auto_catchup"); + } + break; + case "hotkeys": + // filter mnemonic definitions (used for help panel) from hotkeys map + // i.e. *(191)|Ctrl-/ -> *(191) + { + const tmp = []; + + Object.keys(params[k][1]).forEach((sequence) => { + const filtered = sequence.replace(/\|.*$/, ""); + tmp[filtered] = params[k][1][sequence]; + }); + + params[k][1] = tmp; + } + break; + } - console.log("IP:", k, "=>", params[k]); - this.setInitParam(k, params[k]); - } - } + console.log("IP:", k, "=>", params[k]); + this.setInitParam(k, params[k]); + }); // PluginHost might not be available on non-index pages if (typeof PluginHost !== 'undefined') diff --git a/js/Article.js b/js/Article.js index 15c5cac65..b1d14c390 100644 --- a/js/Article.js +++ b/js/Article.js @@ -1,7 +1,7 @@ 'use strict' /* eslint-disable no-new */ -/* global __, ngettext, App, Headlines, xhrPost, xhrJson, dojo, dijit, PluginHost, Notify, $$, Ajax, fox */ +/* global __, ngettext, App, Headlines, xhrPost, xhrJson, dojo, dijit, PluginHost, Notify, fox */ const Article = { _scroll_reset_timeout: false, diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index c62e6893e..6ace91c8c 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -3,7 +3,7 @@ /* eslint-disable new-cap */ /* eslint-disable no-new */ -/* global __, dojo, dijit, Notify, App, Feeds, $$, xhrPost, xhrJson, Tables, Effect, fox */ +/* global __, dojo, dijit, Notify, App, Feeds, xhrPost, xhrJson, Tables, fox */ /* exported CommonDialogs */ const CommonDialogs = { diff --git a/js/CommonFilters.js b/js/CommonFilters.js index d5b751f91..3fa100b9e 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -2,8 +2,8 @@ /* eslint-disable no-new */ -/* global __, App, Article, Lists, Effect, fox */ -/* global xhrPost, dojo, dijit, Notify, $$, Feeds */ +/* global __, App, Article, Lists, fox */ +/* global xhrPost, dojo, dijit, Notify, Feeds */ const Filters = { filterDlgCheckAction: function(sender) { diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index f3c44e30d..d4db15c3b 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -1,7 +1,7 @@ 'use strict'; /* eslint-disable no-new */ -/* global __, dijit, dojo, Tables, xhrPost, Notify, xhrJson, App, fox, Effect */ +/* global __, dijit, dojo, Tables, xhrPost, Notify, xhrJson, App, fox */ const Helpers = { AppPasswords: { diff --git a/js/PrefUsers.js b/js/PrefUsers.js index 2e8c9c4a8..64466ef18 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -1,7 +1,7 @@ 'use strict' /* global __ */ -/* global xhrPost, xhrJson, dojo, dijit, Notify, Tables, App, fox */ +/* global xhrPost, xhrJson, dijit, Notify, Tables, App, fox */ const Users = { reload: function(sort) { diff --git a/js/common.js b/js/common.js index 6dd5713df..a5e1e503a 100755 --- a/js/common.js +++ b/js/common.js @@ -1,6 +1,6 @@ 'use strict'; -/* global dijit, __, App, Ajax */ +/* global dijit, __, App, dojo, __csrf_token */ /* eslint-disable no-new */ function $(id) { @@ -111,6 +111,8 @@ String.prototype.stripTags = function() { /* xhr shorthand helpers */ +// TODO: this should become xhr { Post: ..., Json: ... } + /* exported xhrPost */ function xhrPost(url, params = {}, complete = undefined) { console.log("xhrPost:", params); @@ -144,6 +146,7 @@ function xhrJson(url, params = {}, complete = undefined) { obj = JSON.parse(reply.responseText); } catch (e) { console.error("xhrJson", e, reply); + reject(e); } if (complete != undefined) complete(obj); diff --git a/js/tt-rss.js b/js/tt-rss.js index a00838c43..8d7dd00a6 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -1,6 +1,6 @@ 'use strict' -/* global require, App, $H */ +/* global require, App, dojo */ /* exported Plugins */ const Plugins = {}; -- cgit v1.2.3-54-g00ecf From 6b43b788d909ce20f07f29f9f3ccd2f6a8715616 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 10:22:00 +0300 Subject: migrate xhrJson invocations to the new helper --- include/login_form.php | 2 +- js/App.js | 2 +- js/Article.js | 4 ++-- js/CommonDialogs.js | 12 ++++++------ js/Feeds.js | 2 +- js/PrefFeedTree.js | 8 ++++---- js/PrefHelpers.js | 4 ++-- js/PrefLabelTree.js | 2 +- js/PrefUsers.js | 2 +- js/common.js | 22 ++++++---------------- plugins/af_readability/init.js | 2 +- plugins/mail/init.php | 2 +- plugins/mail/mail.js | 2 +- plugins/note/note.js | 2 +- plugins/share/share.js | 2 +- 15 files changed, 30 insertions(+), 40 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/include/login_form.php b/include/login_form.php index d1af23459..211302a87 100755 --- a/include/login_form.php +++ b/include/login_form.php @@ -59,7 +59,7 @@ if (login && login != this.previousLogin) { this.previousLogin = login; - xhrJson("public.php", {op: "getprofiles", login: login}, + xhr.json("public.php", {op: "getprofiles", login: login}, (reply) => { const profile = dijit.byId('profile'); diff --git a/js/App.js b/js/App.js index d61c6ead0..0c12c7e6f 100644 --- a/js/App.js +++ b/js/App.js @@ -775,7 +775,7 @@ const App = { checkForUpdates: function() { console.log('checking for updates...'); - xhrJson("backend.php", {op: 'rpc', method: 'checkforupdates'}) + xhr.json("backend.php", {op: 'rpc', method: 'checkforupdates'}) .then((reply) => { console.log('update reply', reply); diff --git a/js/Article.js b/js/Article.js index 90be90f7b..379e05644 100644 --- a/js/Article.js +++ b/js/Article.js @@ -115,7 +115,7 @@ const Article = { displayUrl: function (id) { const query = {op: "article", method: "getmetadatabyid", id: id}; - xhrJson("backend.php", query, (reply) => { + xhr.json("backend.php", query, (reply) => { if (reply && reply.link) { prompt(__("Article URL:"), reply.link); } else { @@ -358,7 +358,7 @@ const Article = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrJson("backend.php", {op: "article", method: "printArticleTags", id: id}, (reply) => { + xhr.json("backend.php", {op: "article", method: "printArticleTags", id: id}, (reply) => { dijit.getEnclosingWidget(App.byId("tags_str")) .attr('value', reply.tags.join(", ")) diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 6ace91c8c..3acd2b577 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -78,7 +78,7 @@ const CommonDialogs = { return false; }, subscribeToFeed: function() { - xhrJson("backend.php", + xhr.json("backend.php", {op: "feeds", method: "subscribeToFeed"}, (reply) => { const dialog = new fox.SingleUseDialog({ @@ -265,7 +265,7 @@ const CommonDialogs = { }, showFeedsWithErrors: function() { - xhrJson("backend.php", {op: "pref-feeds", method: "feedsWithErrors"}, (reply) => { + xhr.json("backend.php", {op: "pref-feeds", method: "feedsWithErrors"}, (reply) => { const dialog = new fox.SingleUseDialog({ id: "errorFeedsDlg", @@ -446,7 +446,7 @@ const CommonDialogs = { Notify.progress("Loading, please wait...", true); - xhrJson("backend.php", {op: "pref-feeds", method: "getOPMLKey"}, (reply) => { + xhr.json("backend.php", {op: "pref-feeds", method: "getOPMLKey"}, (reply) => { try { const dialog = new fox.SingleUseDialog({ title: __("Public OPML URL"), @@ -454,7 +454,7 @@ const CommonDialogs = { if (confirm(__("Replace current OPML publishing address with a new one?"))) { Notify.progress("Trying to change address...", true); - xhrJson("backend.php", {op: "pref-feeds", method: "regenOPMLKey"}, (reply) => { + xhr.json("backend.php", {op: "pref-feeds", method: "regenOPMLKey"}, (reply) => { if (reply) { const new_link = reply.link; const target = this.domNode.querySelector('.generated_url'); @@ -504,7 +504,7 @@ const CommonDialogs = { Notify.progress("Loading, please wait...", true); - xhrJson("backend.php", {op: "pref-feeds", method: "getsharedurl", id: feed, is_cat: is_cat, search: search}, (reply) => { + xhr.json("backend.php", {op: "pref-feeds", method: "getsharedurl", id: feed, is_cat: is_cat, search: search}, (reply) => { try { const dialog = new fox.SingleUseDialog({ title: __("Show as feed"), @@ -515,7 +515,7 @@ const CommonDialogs = { const query = {op: "pref-feeds", method: "regenFeedKey", id: feed, is_cat: is_cat}; - xhrJson("backend.php", query, (reply) => { + xhr.json("backend.php", query, (reply) => { const new_link = reply.link; const target = this.domNode.querySelector(".generated_url"); diff --git a/js/Feeds.js b/js/Feeds.js index 67c78cbfe..7cefe2235 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -558,7 +558,7 @@ const Feeds = { return tree.model.store.getValue(nuf, 'bare_id'); }, search: function() { - xhrJson("backend.php", + xhr.json("backend.php", {op: "feeds", method: "search"}, (reply) => { try { diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index 92194e037..c7228e6ff 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -210,14 +210,14 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b return false; }, checkErrorFeeds: function() { - xhrJson("backend.php", {op: "pref-feeds", method: "feedsWithErrors"}, (reply) => { + xhr.json("backend.php", {op: "pref-feeds", method: "feedsWithErrors"}, (reply) => { if (reply.length > 0) { Element.show(dijit.byId("pref_feeds_errors_btn").domNode); } }); }, checkInactiveFeeds: function() { - xhrJson("backend.php", {op: "pref-feeds", method: "inactivefeeds"}, (reply) => { + xhr.json("backend.php", {op: "pref-feeds", method: "inactivefeeds"}, (reply) => { if (reply.length > 0) { Element.show(dijit.byId("pref_feeds_inactive_btn").domNode); } @@ -385,7 +385,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b } }, batchSubscribe: function() { - xhrJson("backend.php", {op: 'pref-feeds', method: 'batchSubscribe'}, (reply) => { + xhr.json("backend.php", {op: 'pref-feeds', method: 'batchSubscribe'}, (reply) => { const dialog = new fox.SingleUseDialog({ id: "batchSubDlg", title: __("Batch subscribe"), @@ -458,7 +458,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b }); }, showInactiveFeeds: function() { - xhrJson("backend.php", {op: 'pref-feeds', method: 'inactivefeeds'}, function (reply) { + xhr.json("backend.php", {op: 'pref-feeds', method: 'inactivefeeds'}, function (reply) { const dialog = new fox.SingleUseDialog({ id: "inactiveFeedsDlg", diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index d4db15c3b..c17966291 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -132,7 +132,7 @@ const Helpers = { } }, refresh: function() { - xhrJson("backend.php", {op: 'pref-prefs', method: 'getprofiles'}, (reply) => { + xhr.json("backend.php", {op: 'pref-prefs', method: 'getprofiles'}, (reply) => { dialog.attr('content', `
@@ -212,7 +212,7 @@ const Helpers = { }, Prefs: { customizeCSS: function() { - xhrJson("backend.php", {op: "pref-prefs", method: "customizeCSS"}, (reply) => { + xhr.json("backend.php", {op: "pref-prefs", method: "customizeCSS"}, (reply) => { const dialog = new fox.SingleUseDialog({ title: __("Customize stylesheet"), diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 4392dfc44..9d16a147c 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -61,7 +61,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f }); }, editLabel: function(id) { - xhrJson("backend.php", {op: "pref-labels", method: "edit", id: id}, (reply) => { + xhr.json("backend.php", {op: "pref-labels", method: "edit", id: id}, (reply) => { console.log(reply); diff --git a/js/PrefUsers.js b/js/PrefUsers.js index 64466ef18..5b490a2a5 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -27,7 +27,7 @@ const Users = { } }, edit: function(id) { - xhrJson('backend.php', {op: 'pref-users', method: 'edit', id: id}, (reply) => { + xhr.json('backend.php', {op: 'pref-users', method: 'edit', id: id}, (reply) => { const user = reply.user; const admin_disabled = (user.id == 1); diff --git a/js/common.js b/js/common.js index dbe1ae3c3..f3fcdd905 100755 --- a/js/common.js +++ b/js/common.js @@ -143,7 +143,7 @@ String.prototype.stripTags = function() { const xhr = { post: function(url, params = {}, complete = undefined) { - console.log("xhr.post:", params); + console.log('xhr.post', '>>>', params); return new Promise((resolve, reject) => { if (typeof __csrf_token != "undefined") @@ -156,6 +156,8 @@ const xhr = { reject(error); }, load: function(data, ioargs) { + //console.log('xhr.post', '<<<', data, ioargs); + if (complete != undefined) complete(data, ioargs.xhr); @@ -176,6 +178,8 @@ const xhr = { reject(e); } + console.log('xhr.json', '<<<', obj); + if (complete != undefined) complete(obj); resolve(obj); @@ -209,21 +213,7 @@ function xhrPost(url, params = {}, complete = undefined) { /* exported xhrJson */ function xhrJson(url, params = {}, complete = undefined) { - return new Promise((resolve, reject) => - xhrPost(url, params).then((reply) => { - let obj = null; - - try { - obj = JSON.parse(reply.responseText); - } catch (e) { - console.error("xhrJson", e, reply); - reject(e); - } - - if (complete != undefined) complete(obj); - - resolve(obj); - })); + return xhr.json(url, params, complete); } /* common helpers not worthy of separate Dojo modules */ diff --git a/plugins/af_readability/init.js b/plugins/af_readability/init.js index 6dec82f45..5297416b3 100644 --- a/plugins/af_readability/init.js +++ b/plugins/af_readability/init.js @@ -16,7 +16,7 @@ Plugins.Af_Readability = { Notify.progress("Loading, please wait..."); - xhrJson("backend.php", App.getPhArgs("af_readability", "embed", {id: id}), (reply) => { + xhr.json("backend.php", App.getPhArgs("af_readability", "embed", {id: id}), (reply) => { if (content && reply.content) { content.setAttribute(self.orig_attr_name, content.innerHTML); diff --git a/plugins/mail/init.php b/plugins/mail/init.php index d96006b21..16e22f342 100644 --- a/plugins/mail/init.php +++ b/plugins/mail/init.php @@ -152,7 +152,7 @@ class Mail extends Plugin { diff --git a/js/App.js b/js/App.js index 0c12c7e6f..1b0fa7c65 100644 --- a/js/App.js +++ b/js/App.js @@ -2,7 +2,7 @@ /* eslint-disable new-cap */ /* global __, Article, Headlines, Filters, fox */ -/* global xhrPost, xhrJson, dojo, dijit, PluginHost, Notify, Feeds, Cookie */ +/* global xhrPost, xhr, dojo, dijit, PluginHost, Notify, Feeds, Cookie */ /* global CommonDialogs, Plugins */ const App = { @@ -362,10 +362,10 @@ const App = { } }, hotkeyHelp: function() { - xhrPost("backend.php", {op: "rpc", method: "hotkeyHelp"}, (transport) => { + xhr.post("backend.php", {op: "rpc", method: "hotkeyHelp"}, (reply) => { const dialog = new fox.SingleUseDialog({ title: __("Keyboard shortcuts"), - content: transport.responseText, + content: reply, }); dialog.show(); @@ -474,11 +474,9 @@ const App = { PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data); }, - backendSanityCallback: function(transport) { - const reply = JSON.parse(transport.responseText); - + backendSanityCallback: function(reply) { if (!reply) { - this.Error.fatal(ERRORS[3], {info: transport.responseText}); + this.Error.fatal(ERRORS[3]); return; } @@ -559,14 +557,14 @@ const App = { const message = params.message ? params.message : error.toString(); try { - xhrPost("backend.php", + xhr.post("backend.php", {op: "rpc", method: "log", file: params.filename ? params.filename : error.fileName, line: params.lineno ? params.lineno : error.lineNumber, msg: message, context: error.stack}, - (transport) => { - console.warn("[Error.report] log response", transport.responseText); + (reply) => { + console.warn("[Error.report] log response", reply); }); } catch (re) { console.error("[Error.report] exception while saving logging error on server", re); @@ -645,9 +643,9 @@ const App = { hasSandbox: "sandbox" in document.createElement("iframe") }; - xhrPost("backend.php", params, (transport) => { + xhr.json("backend.php", params, (reply) => { try { - this.backendSanityCallback(transport); + this.backendSanityCallback(reply); } catch (e) { this.Error.report(e); } @@ -862,7 +860,7 @@ const App = { if (article_id) Article.view(article_id); - xhrPost("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0}); + xhr.post("backend.php", {op: "rpc", method: "setpanelmode", wide: wide ? 1 : 0}); }, initHotkeyActions: function() { if (this.is_prefs) { @@ -1058,7 +1056,7 @@ const App = { Headlines.reverse(); }; this.hotkey_actions["feed_toggle_vgroup"] = () => { - xhrPost("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => { + xhr.post("backend.php", {op: "rpc", method: "togglepref", key: "VFEED_GROUP_BY_FEED"}, () => { Feeds.reloadCurrent(); }) }; @@ -1133,7 +1131,7 @@ const App = { this.hotkey_actions["toggle_combined_mode"] = () => { const value = this.isCombinedMode() ? "false" : "true"; - xhrPost("backend.php", {op: "rpc", method: "setpref", key: "COMBINED_DISPLAY_MODE", value: value}, () => { + xhr.post("backend.php", {op: "rpc", method: "setpref", key: "COMBINED_DISPLAY_MODE", value: value}, () => { this.setInitParam("combined_display_mode", !this.getInitParam("combined_display_mode")); @@ -1144,7 +1142,7 @@ const App = { this.hotkey_actions["toggle_cdm_expanded"] = () => { const value = this.getInitParam("cdm_expanded") ? "false" : "true"; - xhrPost("backend.php", {op: "rpc", method: "setpref", key: "CDM_EXPANDED", value: value}, () => { + xhr.post("backend.php", {op: "rpc", method: "setpref", key: "CDM_EXPANDED", value: value}, () => { this.setInitParam("cdm_expanded", !this.getInitParam("cdm_expanded")); Headlines.renderAgain(); }); diff --git a/js/Article.js b/js/Article.js index 379e05644..339d26266 100644 --- a/js/Article.js +++ b/js/Article.js @@ -1,7 +1,7 @@ 'use strict' /* eslint-disable no-new */ -/* global __, ngettext, App, Headlines, xhrPost, xhrJson, dojo, dijit, PluginHost, Notify, fox */ +/* global __, ngettext, App, Headlines, xhr, dojo, dijit, PluginHost, Notify, fox */ const Article = { _scroll_reset_timeout: false, @@ -331,13 +331,11 @@ const Article = { if (this.validate()) { Notify.progress("Saving article tags...", true); - xhrPost("backend.php", this.attr('value'), (transport) => { + xhr.json("backend.php", this.attr('value'), (data) => { try { Notify.close(); dialog.hide(); - const data = JSON.parse(transport.responseText); - if (data) { const id = data.id; diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 3acd2b577..516da5c98 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -3,7 +3,7 @@ /* eslint-disable new-cap */ /* eslint-disable no-new */ -/* global __, dojo, dijit, Notify, App, Feeds, xhrPost, xhrJson, Tables, fox */ +/* global __, dojo, dijit, Notify, App, Feeds, xhrPost, xhr, Tables, fox */ /* exported CommonDialogs */ const CommonDialogs = { @@ -17,7 +17,7 @@ const CommonDialogs = { const query = {op: "pref-feeds", method: "removeicon", feed_id: id}; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { Notify.info("Feed icon removed."); if (App.isPrefs()) @@ -180,17 +180,12 @@ const CommonDialogs = { Element.show("feed_add_spinner"); Element.hide("fadd_error_message"); - xhrPost("backend.php", this.attr('value'), (transport) => { + xhr.json("backend.php", this.attr('value'), (reply) => { try { - let reply; - - try { - reply = JSON.parse(transport.responseText); - } catch (e) { + if (!reply) { 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('subscribeToFeed, backend returned:' + transport.responseText); return; } @@ -285,7 +280,7 @@ const CommonDialogs = { ids: sel_rows.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { Notify.close(); dialog.hide(); @@ -359,7 +354,7 @@ const CommonDialogs = { Notify.progress("Loading, please wait...", true); - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { if (dijit.byId("labelTree")) { dijit.byId("labelTree").reload(); } else { @@ -377,7 +372,7 @@ const CommonDialogs = { const query = {op: "pref-feeds", quiet: 1, method: "remove", ids: feed_id}; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { if (App.isPrefs()) { dijit.byId("feedTree").reload(); } else { @@ -415,7 +410,7 @@ const CommonDialogs = { if (this.validate()) { Notify.progress("Saving data...", true); - xhrPost("backend.php", dialog.attr('value'), () => { + xhr.post("backend.php", dialog.attr('value'), () => { dialog.hide(); Notify.close(); diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 3fa100b9e..9cc93d7b8 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -3,7 +3,7 @@ /* eslint-disable no-new */ /* global __, App, Article, Lists, fox */ -/* global xhrPost, dojo, dijit, Notify, Feeds */ +/* global xhr, dojo, dijit, Notify, Feeds */ const Filters = { filterDlgCheckAction: function(sender) { @@ -275,7 +275,7 @@ const Filters = { const query = {op: "pref-filters", method: "remove", ids: this.attr('value').id}; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { const tree = dijit.byId("filterTree"); if (tree) tree.reload(); @@ -303,7 +303,7 @@ const Filters = { Notify.progress("Saving data...", true); - xhrPost("backend.php", this.attr('value'), () => { + xhr.post("backend.php", this.attr('value'), () => { dialog.hide(); const tree = dijit.byId("filterTree"); diff --git a/js/Feeds.js b/js/Feeds.js index 7cefe2235..e9681953e 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -1,6 +1,6 @@ 'use strict' -/* global __, App, Headlines, xhrPost, xhrJson, dojo, dijit, Form, fox, PluginHost, Notify, $$, fox */ +/* global __, App, Headlines, xhrPost, xhr, dojo, dijit, fox, PluginHost, Notify, fox */ const Feeds = { counters_last_request: 0, @@ -299,7 +299,7 @@ const Feeds = { toggleUnread: function() { const hide = !App.getInitParam("hide_read_feeds"); - xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => { + xhr.post("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => { this.hideOrShowFeeds(hide); App.setInitParam("hide_read_feeds", hide); }); @@ -393,7 +393,7 @@ const Feeds = { Notify.progress("Marking all feeds as read..."); - xhrPost("backend.php", {op: "feeds", method: "catchupAll"}, () => { + xhr.post("backend.php", {op: "feeds", method: "catchupAll"}, () => { this.requestCounters(true); this.reloadCurrent(); }); diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index c7228e6ff..d3a4cd33d 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -1,5 +1,5 @@ /* eslint-disable prefer-rest-params */ -/* global __, lib, dijit, define, dojo, CommonDialogs, Notify, Tables, xhrPost, xhrJson, fox, App */ +/* global __, lib, dijit, define, dojo, CommonDialogs, Notify, Tables, xhrPost, xhr, fox, App */ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_base/array", "dojo/cookie"], function (declare, domConstruct, checkBoxTree, array, cookie) { @@ -164,14 +164,14 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b resetFeedOrder: function() { Notify.progress("Loading, please wait..."); - xhrPost("backend.php", {op: "pref-feeds", method: "feedsortreset"}, () => { + xhr.post("backend.php", {op: "pref-feeds", method: "feedsortreset"}, () => { this.reload(); }); }, resetCatOrder: function() { Notify.progress("Loading, please wait..."); - xhrPost("backend.php", {op: "pref-feeds", method: "catsortreset"}, () => { + xhr.post("backend.php", {op: "pref-feeds", method: "catsortreset"}, () => { this.reload(); }); }, @@ -179,7 +179,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b if (confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name))) { Notify.progress("Removing category..."); - xhrPost("backend.php", {op: "pref-feeds", method: "removeCat", ids: id}, () => { + xhr.post("backend.php", {op: "pref-feeds", method: "removeCat", ids: id}, () => { Notify.close(); this.reload(); }); @@ -198,7 +198,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b ids: sel_rows.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { this.reload(); }); } @@ -247,7 +247,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b ids: sel_rows.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { this.reload(); }); } @@ -338,7 +338,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b Notify.progress("Saving data...", true); - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { dialog.hide(); const tree = dijit.byId("feedTree"); @@ -367,7 +367,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b Notify.progress("Loading, please wait..."); - xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => { + xhr.post("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => { this.reload(); }); } @@ -378,7 +378,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b if (title) { Notify.progress("Creating category..."); - xhrPost("backend.php", {op: "pref-feeds", method: "addCat", cat: title}, () => { + xhr.post("backend.php", {op: "pref-feeds", method: "addCat", cat: title}, () => { Notify.close(); this.reload(); }); @@ -393,7 +393,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b if (this.validate()) { Notify.progress(__("Subscribing to feeds..."), true); - xhrPost("backend.php", this.attr('value'), () => { + xhr.post("backend.php", this.attr('value'), () => { Notify.close(); const tree = dijit.byId("feedTree"); @@ -478,7 +478,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b ids: sel_rows.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { Notify.close(); const tree = dijit.byId("feedTree"); diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 3d00c730c..cc37808be 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -1,5 +1,5 @@ /* eslint-disable prefer-rest-params */ -/* global __, define, lib, dijit, dojo, xhrPost, Notify */ +/* global __, define, lib, dijit, dojo, xhr, Notify */ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) { @@ -99,7 +99,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio resetFilterOrder: function() { Notify.progress("Loading, please wait..."); - xhrPost("backend.php", {op: "pref-filters", method: "filtersortreset"}, () => { + xhr.post("backend.php", {op: "pref-filters", method: "filtersortreset"}, () => { this.reload(); }); }, @@ -114,7 +114,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio if (confirm(__("Combine selected filters?"))) { Notify.progress("Joining filters..."); - xhrPost("backend.php", {op: "pref-filters", method: "join", ids: rows.toString()}, () => { + xhr.post("backend.php", {op: "pref-filters", method: "join", ids: rows.toString()}, () => { this.reload(); }); } @@ -131,7 +131,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio ids: sel_rows.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { this.reload(); }); } diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index c17966291..abf5fff51 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -1,7 +1,7 @@ 'use strict'; /* eslint-disable no-new */ -/* global __, dijit, dojo, Tables, xhrPost, Notify, xhrJson, App, fox */ +/* global __, dijit, dojo, Tables, xhrPost, Notify, xhr, App, fox */ const Helpers = { AppPasswords: { @@ -45,7 +45,7 @@ const Helpers = { if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { Notify.progress("Clearing URLs..."); - xhrPost("backend.php", {op: "pref-feeds", method: "clearKeys"}, () => { + xhr.post("backend.php", {op: "pref-feeds", method: "clearKeys"}, () => { Notify.info("Generated URLs cleared."); }); } @@ -82,7 +82,7 @@ const Helpers = { Notify.progress("Loading, please wait..."); - xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => { + xhr.post("backend.php", {op: "pref-system", method: "clearLog"}, () => { Helpers.EventLog.refresh(); }); } @@ -108,7 +108,7 @@ const Helpers = { ids: sel_rows.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { Notify.close(); dialog.refresh(); }); @@ -124,7 +124,7 @@ const Helpers = { const query = {op: "pref-prefs", method: "addprofile", title: dialog.attr('value').newprofile}; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { Notify.close(); dialog.refresh(); }); @@ -194,7 +194,7 @@ const Helpers = { if (confirm(__("Activate selected profile?"))) { Notify.progress("Loading, please wait..."); - xhrPost("backend.php", {op: "pref-prefs", method: "activateprofile", id: sel_rows.toString()}, () => { + xhr.post("backend.php", {op: "pref-prefs", method: "activateprofile", id: sel_rows.toString()}, () => { window.location.reload(); }); } @@ -217,7 +217,7 @@ const Helpers = { const dialog = new fox.SingleUseDialog({ title: __("Customize stylesheet"), apply: function() { - xhrPost("backend.php", this.attr('value'), () => { + xhr.post("backend.php", this.attr('value'), () => { Element.show("css_edit_apply_msg"); App.byId("user_css_style").innerText = this.attr('value'); }); @@ -225,7 +225,7 @@ const Helpers = { execute: function () { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.attr('value'), () => { + xhr.post("backend.php", this.attr('value'), () => { window.location.reload(); }); }, @@ -277,7 +277,7 @@ const Helpers = { if (confirm(__("Clear stored data for this plugin?"))) { Notify.progress("Loading, please wait..."); - xhrPost("backend.php", {op: "pref-prefs", method: "clearplugindata", name: name}, () => { + xhr.post("backend.php", {op: "pref-prefs", method: "clearplugindata", name: name}, () => { Helpers.Prefs.refresh(); }); } diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 9d16a147c..5e024afde 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -1,5 +1,5 @@ /* eslint-disable prefer-rest-params */ -/* global __, define, lib, dijit, dojo, xhrPost, Notify, fox, App */ +/* global __, define, lib, dijit, dojo, xhr, Notify, fox, App */ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/form/DropDownButton"], function (declare, domConstruct) { @@ -98,7 +98,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f ids: id, fg: fg, bg: bg, color: color }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { const tree = dijit.byId("filterTree"); if (tree) tree.reload(); // maybe there's labels in there }); @@ -114,7 +114,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f this.setLabelColor(id, fg_color, bg_color); this.hide(); - xhrPost("backend.php", this.attr('value'), () => { + xhr.post("backend.php", this.attr('value'), () => { const tree = dijit.byId("filterTree"); if (tree) tree.reload(); // maybe there's labels in there }); @@ -196,7 +196,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f ids: labels.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { this.reload(); }); } @@ -217,7 +217,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f ids: sel_rows.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { this.reload(); }); } diff --git a/js/PrefUsers.js b/js/PrefUsers.js index 5b490a2a5..9b9c1deaf 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -1,7 +1,7 @@ 'use strict' /* global __ */ -/* global xhrPost, xhrJson, dijit, Notify, Tables, App, fox */ +/* global xhrPost, xhr, dijit, Notify, Tables, App, fox */ const Users = { reload: function(sort) { @@ -38,7 +38,7 @@ const Users = { if (this.validate()) { Notify.progress("Saving data...", true); - xhrPost("backend.php", this.attr('value'), () => { + xhr.post("backend.php", this.attr('value'), () => { dialog.hide(); Users.reload(); }); @@ -160,7 +160,7 @@ const Users = { ids: sel_rows.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { this.reload(); }); } diff --git a/js/common.js b/js/common.js index f3fcdd905..1c9a0453c 100755 --- a/js/common.js +++ b/js/common.js @@ -140,7 +140,6 @@ String.prototype.stripTags = function() { } /* exported xhr */ - const xhr = { post: function(url, params = {}, complete = undefined) { console.log('xhr.post', '>>>', params); -- cgit v1.2.3-54-g00ecf From 660a1bbe011fef5f0fa6bb0af43521fed7598cc7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 13:44:56 +0300 Subject: * switch to xhr.post() almost everywhere * call App.handlerpcjson() automatically on json request (if possible) * show net/log indicators in prefs --- classes/pref/feeds.php | 3 +- classes/pref/prefs.php | 42 ++++++------- classes/rpc.php | 8 +++ js/App.js | 134 ++++++++++++++++++++-------------------- js/CommonDialogs.js | 4 +- js/CommonFilters.js | 28 ++++----- js/Feeds.js | 20 +++--- js/Headlines.js | 34 ++++------ js/PrefFeedTree.js | 8 +-- js/PrefFilterTree.js | 6 +- js/PrefHelpers.js | 29 +++++---- js/PrefLabelTree.js | 4 +- js/PrefUsers.js | 16 ++--- js/common.js | 5 +- js/prefs.js | 1 + plugins/af_proxy_http/init.php | 4 +- plugins/af_psql_trgm/init.js | 6 +- plugins/af_psql_trgm/init.php | 4 +- plugins/af_readability/init.php | 4 +- plugins/af_redditimgur/init.php | 4 +- plugins/mail/init.php | 4 +- plugins/mail/mail.js | 6 +- plugins/mailto/init.js | 6 +- plugins/note/note.js | 6 +- plugins/nsfw/init.php | 4 +- plugins/share/share.js | 10 +-- plugins/share/share_prefs.js | 6 +- prefs.php | 5 +- themes/compact.css | 11 ++++ themes/compact_night.css | 11 ++++ themes/light.css | 11 ++++ themes/light/tt-rss.less | 13 ++++ themes/night.css | 11 ++++ themes/night_blue.css | 11 ++++ 34 files changed, 275 insertions(+), 204 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 761a0a087..97c529d07 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -832,8 +832,7 @@ class Pref_Feeds extends Handler_Protected { print " "; - print_feed_cat_select("cat_id", false, - 'disabled="1" dojoType="fox.form.Select"'); + print \Controls\select_feeds_cats("cat_id", null, ['disabled' => '1']); $this->batch_edit_cbox("cat_id"); diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index fecec6d91..2ea2e9f01 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -295,8 +295,8 @@ class Pref_Prefs extends Handler_Protected { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } @@ -351,16 +351,16 @@ class Pref_Prefs extends Handler_Protected { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { + xhr.post("backend.php", this.getValues(), (reply) => { Notify.close(); - if (transport.responseText.indexOf('ERROR: ') == 0) { + if (reply.indexOf('ERROR: ') == 0) { App.byId('pwd_change_infobox').innerHTML = - transport.responseText.replace('ERROR: ', ''); + reply.replace('ERROR: ', ''); } else { App.byId('pwd_change_infobox').innerHTML = - transport.responseText.replace('ERROR: ', ''); + reply.replace('ERROR: ', ''); const warn = App.byId('default_pass_warning'); if (warn) Element.hide(warn); @@ -456,11 +456,11 @@ class Pref_Prefs extends Handler_Protected { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { + xhr.post("backend.php", this.getValues(), (reply) => { Notify.close(); - if (transport.responseText.indexOf('ERROR: ') == 0) { - Notify.error(transport.responseText.replace('ERROR: ', '')); + if (reply.indexOf('ERROR: ') == 0) { + Notify.error(reply.replace('ERROR: ', '')); } else { window.location.reload(); } @@ -515,11 +515,11 @@ class Pref_Prefs extends Handler_Protected { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { + xhr.post("backend.php", this.getValues(), (reply) => { Notify.close(); - if (transport.responseText.indexOf('ERROR:') == 0) { - Notify.error(transport.responseText.replace('ERROR:', '')); + if (reply.indexOf('ERROR:') == 0) { + Notify.error(reply.replace('ERROR:', '')); } else { window.location.reload(); } @@ -797,16 +797,14 @@ class Pref_Prefs extends Handler_Protected { @@ -1023,8 +1021,8 @@ class Pref_Prefs extends Handler_Protected { diff --git a/classes/rpc.php b/classes/rpc.php index 0fd06da4d..c4a1887c7 100755 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -64,6 +64,14 @@ class RPC extends Handler_Protected { print json_encode(array("message" => "UPDATE_COUNTERS")); } + function getRuntimeInfo() { + $reply = [ + 'runtime-info' => $this->make_runtime_info() + ]; + + print json_encode($reply); + } + function getAllCounters() { @$seq = (int) $_REQUEST['seq']; diff --git a/js/App.js b/js/App.js index 1b0fa7c65..544057101 100644 --- a/js/App.js +++ b/js/App.js @@ -2,7 +2,7 @@ /* eslint-disable new-cap */ /* global __, Article, Headlines, Filters, fox */ -/* global xhrPost, xhr, dojo, dijit, PluginHost, Notify, Feeds, Cookie */ +/* global xhr, dojo, dijit, PluginHost, Notify, Feeds, Cookie */ /* global CommonDialogs, Plugins */ const App = { @@ -371,72 +371,57 @@ const App = { dialog.show(); }); }, - handleRpcJson: function(transport) { + handleRpcJson: function(reply) { - const netalert = App.findAll("#toolbar .net-alert")[0]; + const netalert = App.find(".net-alert"); - try { - const reply = JSON.parse(transport.responseText); - - if (reply) { - const error = reply['error']; - - if (error) { - const code = error['code']; - const msg = error['message']; - - console.warn("[handleRpcJson] received fatal error ", code, msg); - - if (code != 0) { - /* global ERRORS */ - this.Error.fatal(ERRORS[code], {info: msg, code: code}); - return false; - } - } + if (reply) { + const error = reply['error']; + const seq = reply['seq']; + const message = reply['message']; + const counters = reply['counters']; + const runtime_info = reply['runtime-info']; - const seq = reply['seq']; + if (error) { + const code = error['code']; - if (seq && this.get_seq() != seq) { - console.log("[handleRpcJson] sequence mismatch: ", seq, '!=', this.get_seq()); - return true; - } - - const message = reply['message']; - - if (message == "UPDATE_COUNTERS") { - console.log("need to refresh counters..."); - Feeds.requestCounters(true); - } + if (code && code != 0) { + const msg = error['message']; - const counters = reply['counters']; + console.warn("[handleRpcJson] received fatal error ", code, msg); - if (counters) - Feeds.parseCounters(counters); - - const runtime_info = reply['runtime-info']; - - if (runtime_info) - this.parseRuntimeInfo(runtime_info); + /* global ERRORS */ + this.Error.fatal(ERRORS[code], {info: msg, code: code}); + return false; + } + } - if (netalert) netalert.hide(); + if (seq && this.get_seq() != seq) { + console.warn("[handleRpcJson] sequence mismatch: ", seq, '!=', this.get_seq()); + return; + } - return reply; + // not in preferences + if (typeof Feeds != "undefined") { + if (message == "UPDATE_COUNTERS") { + console.log("need to refresh counters..."); + Feeds.requestCounters(true); + } - } else { - if (netalert) netalert.show(); + if (counters) + Feeds.parseCounters(counters); + } - Notify.error("Communication problem with server."); - } + if (runtime_info) + this.parseRuntimeInfo(runtime_info); - } catch (e) { - if (netalert) netalert.show(); + if (netalert) netalert.hide(); - Notify.error("Communication problem with server."); + } else { + if (netalert) netalert.show(); - console.error(e); + Notify.error("Communication problem with server."); } - - return false; }, parseRuntimeInfo: function(data) { Object.keys(data).forEach((k) => { @@ -450,7 +435,7 @@ const App = { } if (k == "recent_log_events") { - const alert = App.findAll(".log-alert")[0]; + const alert = App.find(".log-alert"); if (alert) { v > 0 ? alert.show() : alert.hide(); @@ -462,10 +447,12 @@ const App = { return; } - if (k == "max_feed_id" || k == "num_feeds") { - if (this.getInitParam(k) != v) { - console.log("feed count changed, need to reload feedlist."); - Feeds.reload(); + if (typeof Feeds != "undefined") { + if (k == "max_feed_id" || k == "num_feeds") { + if (this.getInitParam(k) && this.getInitParam(k) != v) { + console.log("feed count changed, need to reload feedlist:", this.getInitParam(k), v); + Feeds.reload(); + } } } @@ -668,6 +655,11 @@ const App = { return errorMsg == ""; }, + updateRuntimeInfo: function() { + xhr.json("backend.php", {op: "rpc", method: "getruntimeinfo"}, () => { + // handled by xhr.json() + }); + }, initSecondStage: function() { document.onkeydown = (event) => this.hotkeyHandler(event); @@ -685,14 +677,18 @@ const App = { if (tab) { dijit.byId("pref-tabs").selectChild(tab); - switch (this.urlParam('method')) { - case "editfeed": - window.setTimeout(() => { - CommonDialogs.editFeed(this.urlParam('methodparam')) - }, 100); - break; - default: - console.warn("initSecondStage, unknown method:", this.urlParam("method")); + const method = this.urlParam("method"); + + if (method) { + switch (method) { + case "editfeed": + window.setTimeout(() => { + CommonDialogs.editFeed(this.urlParam('methodparam')) + }, 100); + break; + default: + console.warn("initSecondStage, unknown method:", method); + } } } } else { @@ -708,8 +704,14 @@ const App = { dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) { localStorage.setItem("ttrss:prefs-tab", elem.id); + App.updateRuntimeInfo(); }); + if (!this.getInitParam("bw_limit")) + window.setInterval(() => { + App.updateRuntimeInfo(); + }, 60 * 1000) + } else { Feeds.reload(); diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 516da5c98..a75b36ed8 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -430,8 +430,8 @@ const CommonDialogs = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrPost("backend.php", {op: "pref-feeds", method: "editfeed", id: feed}, (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", {op: "pref-feeds", method: "editfeed", id: feed}, (reply) => { + dialog.attr('content', reply); }) }); diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 9cc93d7b8..0fc8f87ae 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -39,12 +39,12 @@ const Filters = { createNewRuleElement: function(parentNode, replaceNode) { const rule = dojo.formToJson("filter_new_rule_form"); - xhrPost("backend.php", {op: "pref-filters", method: "printrulename", rule: rule}, (transport) => { + xhr.post("backend.php", {op: "pref-filters", method: "printrulename", rule: rule}, (reply) => { try { const li = document.createElement('li'); li.innerHTML = ` - ${transport.responseText} + ${reply} ${App.FormFields.hidden_tag("rule[]", rule)}`; dojo.parser.parse(li); @@ -70,12 +70,12 @@ const Filters = { const action = dojo.formToJson(form); - xhrPost("backend.php", { op: "pref-filters", method: "printactionname", action: action }, (transport) => { + xhr.post("backend.php", { op: "pref-filters", method: "printactionname", action: action }, (reply) => { try { const li = document.createElement('li'); li.innerHTML = ` - ${transport.responseText} + ${reply} ${App.FormFields.hidden_tag("action[]", action)}`; dojo.parser.parse(li); @@ -107,8 +107,8 @@ const Filters = { const tmph = dojo.connect(dialog, "onShow", null, function (/* e */) { dojo.disconnect(tmph); - xhrPost("backend.php", {op: 'pref-filters', method: 'newrule', rule: ruleStr}, (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", {op: 'pref-filters', method: 'newrule', rule: ruleStr}, (reply) => { + dialog.attr('content', reply); }); }); @@ -128,8 +128,8 @@ const Filters = { const tmph = dojo.connect(dialog, "onShow", null, function (/* e */) { dojo.disconnect(tmph); - xhrPost("backend.php", {op: 'pref-filters', method: 'newaction', action: actionStr}, (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", {op: 'pref-filters', method: 'newaction', action: actionStr}, (reply) => { + dialog.attr('content', reply); }); }); @@ -149,10 +149,8 @@ const Filters = { console.log("getTestResults:" + offset); - xhrPost("backend.php", params, (transport) => { + xhr.json("backend.php", params, (result) => { try { - const result = JSON.parse(transport.responseText); - if (result && dialog && dialog.open) { dialog.results += result.length; @@ -239,7 +237,7 @@ const Filters = { console.log('Filters.edit', query); - xhrPost("backend.php", query, function (transport) { + xhr.post("backend.php", query, function (reply) { try { const dialog = new fox.SingleUseDialog({ id: "filterEditDlg", @@ -311,7 +309,7 @@ const Filters = { }); } }, - content: transport.responseText + content: reply }); if (!App.isPrefs()) { @@ -334,9 +332,7 @@ const Filters = { const query = {op: "article", method: "getmetadatabyid", id: Article.getActive()}; - xhrPost("backend.php", query, (transport) => { - const reply = JSON.parse(transport.responseText); - + xhr.json("backend.php", query, (reply) => { let title = false; if (reply && reply.title) title = reply.title; diff --git a/js/Feeds.js b/js/Feeds.js index e9681953e..01d31f3c1 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -130,8 +130,8 @@ const Feeds = { this.reloadCurrent(); }, requestCounters: function() { - xhrPost("backend.php", {op: "rpc", method: "getAllCounters", seq: App.next_seq()}, (transport) => { - App.handleRpcJson(transport); + xhr.json("backend.php", {op: "rpc", method: "getAllCounters", seq: App.next_seq()}, () => { + // }); }, reload: function() { @@ -260,7 +260,7 @@ const Feeds = { // bw_limit disables timeout() so we request initial counters separately if (App.getInitParam("bw_limit")) { - this.requestCounters(true); + App.requestCounters(true); } else { setTimeout(() => { this.requestCounters(true); @@ -361,8 +361,6 @@ const Feeds = { query.m = "ForceUpdate"; } - //Form.enable("toolbar-main"); - if (!delayed) if (!this.setExpando(feed, is_cat, (is_cat) ? 'images/indicator_tiny.gif' : 'images/indicator_white.gif')) @@ -374,11 +372,11 @@ const Feeds = { window.clearTimeout(this._viewfeed_wait_timeout); this._viewfeed_wait_timeout = window.setTimeout(() => { - xhrPost("backend.php", query, (transport) => { + xhr.json("backend.php", query, (reply) => { try { window.clearTimeout(this._infscroll_timeout); this.setExpando(feed, is_cat, 'images/blank_icon.gif'); - Headlines.onLoaded(transport, offset, append); + Headlines.onLoaded(reply, offset, append); PluginHost.run(PluginHost.HOOK_FEED_LOADED, [feed, is_cat]); } catch (e) { App.Error.report(e); @@ -439,9 +437,7 @@ const Feeds = { Notify.progress("Loading, please wait...", true); - xhrPost("backend.php", catchup_query, (transport) => { - App.handleRpcJson(transport); - + xhr.json("backend.php", catchup_query, () => { const show_next_feed = App.getInitParam("on_catchup_show_next_feed"); // only select next unread feed if catching up entirely (as opposed to last week etc) @@ -633,8 +629,8 @@ const Feeds = { updateRandom: function() { console.log("in update_random_feed"); - xhrPost("backend.php", {op: "rpc", method: "updaterandomfeed"}, (transport) => { - App.handleRpcJson(transport, true); + xhr.json("backend.php", {op: "rpc", method: "updaterandomfeed"}, () => { + // }); }, }; diff --git a/js/Headlines.js b/js/Headlines.js index 34dc9385e..18e0a3687 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -1,7 +1,7 @@ 'use strict'; /* global __, ngettext, Article, App */ -/* global xhrPost, dojo, dijit, PluginHost, Notify, $$, Feeds */ +/* global dojo, dijit, PluginHost, Notify, xhr, Feeds */ /* global CommonDialogs */ const Headlines = { @@ -149,26 +149,26 @@ const Headlines = { const promises = []; if (ops.tmark.length != 0) - promises.push(xhrPost("backend.php", + promises.push(xhr.post("backend.php", {op: "rpc", method: "markSelected", ids: ops.tmark.toString(), cmode: 2})); if (ops.tpub.length != 0) - promises.push(xhrPost("backend.php", + promises.push(xhr.post("backend.php", {op: "rpc", method: "publishSelected", ids: ops.tpub.toString(), cmode: 2})); if (ops.read.length != 0) - promises.push(xhrPost("backend.php", + promises.push(xhr.post("backend.php", {op: "rpc", method: "catchupSelected", ids: ops.read.toString(), cmode: 0})); if (ops.unread.length != 0) - promises.push(xhrPost("backend.php", + promises.push(xhr.post("backend.php", {op: "rpc", method: "catchupSelected", ids: ops.unread.toString(), cmode: 1})); const scores = Object.keys(ops.rescore); if (scores.length != 0) { scores.forEach((score) => { - promises.push(xhrPost("backend.php", + promises.push(xhr.post("backend.php", {op: "article", method: "setScore", id: ops.rescore[score].toString(), score: score})); }); } @@ -622,9 +622,7 @@ const Headlines = { dojo.parser.parse(target.domNode); }, - onLoaded: function (transport, offset, append) { - const reply = App.handleRpcJson(transport); - + onLoaded: function (reply, offset, append) { console.log("Headlines.onLoaded: offset=", offset, "append=", append); let is_cat = false; @@ -785,7 +783,6 @@ const Headlines = { }); } else { - console.error("Invalid object received: " + transport.responseText); dijit.byId("headlines-frame").attr('content', "
" + __('Could not update headlines (invalid object received - see error console for details)') + "
"); @@ -1011,9 +1008,8 @@ const Headlines = { ids: ids.toString(), lid: id }; - xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); - this.onLabelsUpdated(transport); + xhr.json("backend.php", query, (reply) => { + this.onLabelsUpdated(reply); }); }, selectionAssignLabel: function (id, ids) { @@ -1029,9 +1025,8 @@ const Headlines = { ids: ids.toString(), lid: id }; - xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); - this.onLabelsUpdated(transport); + xhr.json("backend.php", query, (reply) => { + this.onLabelsUpdated(reply); }); }, deleteSelection: function () { @@ -1060,8 +1055,7 @@ const Headlines = { const query = {op: "rpc", method: "delete", ids: rows.toString()}; - xhrPost("backend.php", query, (transport) => { - App.handleRpcJson(transport); + xhr.json("backend.php", query, () => { Feeds.reloadCurrent(); }); }, @@ -1246,9 +1240,7 @@ const Headlines = { } } }, - onLabelsUpdated: function (transport) { - const data = JSON.parse(transport.responseText); - + onLabelsUpdated: function (data) { if (data) { data['info-for-headlines'].forEach(function (elem) { App.findAll(".HLLCTR-" + elem.id).forEach(function (ctr) { diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index d3a4cd33d..a2a7f9141 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -129,8 +129,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b const searchElem = App.byId("feed_search"); const search = (searchElem) ? searchElem.value : ""; - xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => { - dijit.byId('feedsTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-feeds", search: search }, (reply) => { + dijit.byId('feedsTab').attr('content', reply); Notify.close(); }); }, @@ -295,7 +295,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b Notify.progress("Loading, please wait..."); - xhrPost("backend.php", {op: "pref-feeds", method: "editfeeds", ids: rows.toString()}, (transport) => { + xhr.post("backend.php", {op: "pref-feeds", method: "editfeeds", ids: rows.toString()}, (reply) => { Notify.close(); try { @@ -347,7 +347,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b }); } }, - content: transport.responseText + content: reply }); dialog.show(); diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index cc37808be..fff58ff1a 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -1,5 +1,5 @@ /* eslint-disable prefer-rest-params */ -/* global __, define, lib, dijit, dojo, xhr, Notify */ +/* global __, define, lib, dijit, dojo, xhr, App, Notify */ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) { @@ -91,8 +91,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio let search = ""; if (user_search) { search = user_search.value; } - xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => { - dijit.byId('filtersTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-filters", search: search }, (reply) => { + dijit.byId('filtersTab').attr('content', reply); Notify.close(); }); }, diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index abf5fff51..d27e0e071 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -19,8 +19,8 @@ const Helpers = { alert("No passwords selected."); } else if (confirm(__("Remove selected app passwords?"))) { - xhrPost("backend.php", {op: "pref-prefs", method: "deleteAppPassword", ids: rows.toString()}, (transport) => { - this.updateContent(transport.responseText); + xhr.post("backend.php", {op: "pref-prefs", method: "deleteAppPassword", ids: rows.toString()}, (reply) => { + this.updateContent(reply); Notify.close(); }); @@ -31,8 +31,8 @@ const Helpers = { const title = prompt("Password description:") if (title) { - xhrPost("backend.php", {op: "pref-prefs", method: "generateAppPassword", title: title}, (transport) => { - this.updateContent(transport.responseText); + xhr.post("backend.php", {op: "pref-prefs", method: "generateAppPassword", title: title}, (reply) => { + this.updateContent(reply); Notify.close(); }); @@ -63,8 +63,13 @@ const Helpers = { this.update(); }, update: function() { - xhrPost("backend.php", { op: "pref-system", severity: dijit.byId("severity").attr('value'), page: Helpers.EventLog.log_page }, (transport) => { - dijit.byId('systemTab').attr('content', transport.responseText); + xhr.post("backend.php", { + op: "pref-system", + severity: dijit.byId("severity").attr('value'), + page: Helpers.EventLog.log_page + }, (reply) => { + + dijit.byId('systemTab').attr('content', reply); Notify.close(); }); }, @@ -164,8 +169,8 @@ const Helpers = { `${profile.title} @@ -267,9 +272,9 @@ const Helpers = { }, confirmReset: function() { if (confirm(__("Reset to defaults?"))) { - xhrPost("backend.php", {op: "pref-prefs", method: "resetconfig"}, (transport) => { + xhr.post("backend.php", {op: "pref-prefs", method: "resetconfig"}, (reply) => { Helpers.Prefs.refresh(); - Notify.info(transport.responseText); + Notify.info(reply); }); } }, @@ -283,8 +288,8 @@ const Helpers = { } }, refresh: function() { - xhrPost("backend.php", { op: "pref-prefs" }, (transport) => { - dijit.byId('prefsTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-prefs" }, (reply) => { + dijit.byId('prefsTab').attr('content', reply); Notify.close(); }); }, diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 5e024afde..627b2cfbe 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -55,8 +55,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f return rv; }, reload: function() { - xhrPost("backend.php", { op: "pref-labels" }, (transport) => { - dijit.byId('labelsTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-labels" }, (reply) => { + dijit.byId('labelsTab').attr('content', reply); Notify.close(); }); }, diff --git a/js/PrefUsers.js b/js/PrefUsers.js index 9b9c1deaf..3eb83b02a 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -8,8 +8,8 @@ const Users = { const user_search = App.byId("user_search"); const search = user_search ? user_search.value : ""; - xhrPost("backend.php", { op: "pref-users", sort: sort, search: search }, (transport) => { - dijit.byId('usersTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-users", sort: sort, search: search }, (reply) => { + dijit.byId('usersTab').attr('content', reply); Notify.close(); }); }, @@ -19,8 +19,8 @@ const Users = { if (login) { Notify.progress("Adding user..."); - xhrPost("backend.php", {op: "pref-users", method: "add", login: login}, (transport) => { - alert(transport.responseText); + xhr.post("backend.php", {op: "pref-users", method: "add", login: login}, (reply) => { + alert(reply); Users.reload(); }); @@ -99,8 +99,8 @@ const Users = {
@@ -141,9 +141,9 @@ const Users = { const id = rows[0]; - xhrPost("backend.php", {op: "pref-users", method: "resetPass", id: id}, (transport) => { + xhr.post("backend.php", {op: "pref-users", method: "resetPass", id: id}, (reply) => { Notify.close(); - Notify.info(transport.responseText, true); + Notify.info(reply, true); }); } diff --git a/js/common.js b/js/common.js index 1c9a0453c..e88b62602 100755 --- a/js/common.js +++ b/js/common.js @@ -155,7 +155,7 @@ const xhr = { reject(error); }, load: function(data, ioargs) { - //console.log('xhr.post', '<<<', data, ioargs); + console.log('xhr.post', '<<<', ioargs.xhr); if (complete != undefined) complete(data, ioargs.xhr); @@ -179,6 +179,9 @@ const xhr = { console.log('xhr.json', '<<<', obj); + if (obj && typeof App != "undefined") + App.handleRpcJson(obj); + if (complete != undefined) complete(obj); resolve(obj); diff --git a/js/prefs.js b/js/prefs.js index 803a7edf3..a23a74856 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -41,6 +41,7 @@ require(["dojo/_base/kernel", "dojo/data/ItemFileWriteStore", "lib/CheckBoxStoreModel", "lib/CheckBoxTree", + "fox/PluginHost", "fox/CommonDialogs", "fox/CommonFilters", "fox/PrefUsers", diff --git a/plugins/af_proxy_http/init.php b/plugins/af_proxy_http/init.php index 2c472a32d..a5ba1d62d 100644 --- a/plugins/af_proxy_http/init.php +++ b/plugins/af_proxy_http/init.php @@ -221,8 +221,8 @@ class Af_Proxy_Http extends Plugin { diff --git a/plugins/af_psql_trgm/init.js b/plugins/af_psql_trgm/init.js index e5bc21885..921272c4b 100644 --- a/plugins/af_psql_trgm/init.js +++ b/plugins/af_psql_trgm/init.js @@ -1,4 +1,4 @@ -/* global dijit, dojo, Plugins, xhrPost, __ */ +/* global dijit, dojo, Plugins, xhr, __ */ Plugins.Psql_Trgm = { showRelated: function (id) { @@ -10,8 +10,8 @@ Plugins.Psql_Trgm = { const tmph = dojo.connect(dialog, "onShow", null, function (/* e */) { dojo.disconnect(tmph); - xhrPost("backend.php", {op: 'pluginhandler', plugin: 'af_psql_trgm', method: 'showrelated', id: id}, (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", {op: 'pluginhandler', plugin: 'af_psql_trgm', method: 'showrelated', id: id}, (reply) => { + dialog.attr('content', reply); }); }); diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 4ecfe0cd5..3b7ed6b14 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -152,8 +152,8 @@ class Af_Psql_Trgm extends Plugin { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index 4cd72904a..be9220cda 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -71,8 +71,8 @@ class Af_Readability extends Plugin { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 827a4c310..2677fdd90 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -47,8 +47,8 @@ class Af_RedditImgur extends Plugin { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } diff --git a/plugins/mail/init.php b/plugins/mail/init.php index 16e22f342..467f8294a 100644 --- a/plugins/mail/init.php +++ b/plugins/mail/init.php @@ -51,8 +51,8 @@ class Mail extends Plugin { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } diff --git a/plugins/mail/mail.js b/plugins/mail/mail.js index fc0898085..d2bafe0e9 100644 --- a/plugins/mail/mail.js +++ b/plugins/mail/mail.js @@ -1,4 +1,4 @@ -/* global Plugins, Headlines, dojo, xhrPost, xhrJson, Notify, fox, __ */ +/* global Plugins, Headlines, dojo, App, xhr, Notify, fox, __ */ Plugins.Mail = { send: function(id) { @@ -38,8 +38,8 @@ Plugins.Mail = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrPost("backend.php", App.getPhArgs("mail", "emailArticle", {ids: id}), (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", App.getPhArgs("mail", "emailArticle", {ids: id}), (reply) => { + dialog.attr('content', reply); }); }); diff --git a/plugins/mailto/init.js b/plugins/mailto/init.js index b5e68680b..4a9557249 100644 --- a/plugins/mailto/init.js +++ b/plugins/mailto/init.js @@ -1,4 +1,4 @@ -/* global Plugins, Headlines, xhrPost, dojo, fox, __ */ +/* global Plugins, Headlines, xhr, dojo, fox, __ */ Plugins.Mailto = { send: function (id) { @@ -21,8 +21,8 @@ Plugins.Mailto = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrPost("backend.php", App.getPhArgs("mailto", "emailArticle", {ids: id}), (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", App.getPhArgs("mailto", "emailArticle", {ids: id}), (reply) => { + dialog.attr('content', reply); }); }); diff --git a/plugins/note/note.js b/plugins/note/note.js index 36bc426cd..d42fca2c1 100644 --- a/plugins/note/note.js +++ b/plugins/note/note.js @@ -1,4 +1,4 @@ -/* global dojo, xhrPost, Plugins, xhrJson, Notify, fox, __ */ +/* global dojo, Plugins, xhr, App, Notify, fox, __ */ Plugins.Note = { edit: function(id) { @@ -33,8 +33,8 @@ Plugins.Note = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrPost("backend.php", App.getPhArgs("note", "edit", {id: id}), (transport) => { - dialog.attr('content', transport.responseText); + xhr.post("backend.php", App.getPhArgs("note", "edit", {id: id}), (reply) => { + dialog.attr('content', reply); }); }); diff --git a/plugins/nsfw/init.php b/plugins/nsfw/init.php index fdc6a3974..3205b436b 100644 --- a/plugins/nsfw/init.php +++ b/plugins/nsfw/init.php @@ -56,8 +56,8 @@ class NSFW extends Plugin { evt.preventDefault(); if (this.validate()) { Notify.progress('Saving data...', true); - xhrPost("backend.php", this.getValues(), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", this.getValues(), (reply) => { + Notify.info(reply); }) } diff --git a/plugins/share/share.js b/plugins/share/share.js index d7b8cd1f9..1be9db682 100644 --- a/plugins/share/share.js +++ b/plugins/share/share.js @@ -1,4 +1,4 @@ -/* global dojo, Effect, Plugins, xhrJson, Notify, fox, xhrPost, __ */ +/* global dojo, Plugins, App, Notify, fox, xhr, __ */ Plugins.Share = { shareArticle: function(id) { @@ -40,8 +40,8 @@ Plugins.Share = { }, unshare: function () { if (confirm(__("Remove sharing for this article?"))) { - xhrPost("backend.php", App.getPhArgs("share", "unshare", {id: id}), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", App.getPhArgs("share", "unshare", {id: id}), (reply) => { + Notify.info(reply); const icon = document.querySelector(".share-icon-" + id); @@ -59,8 +59,8 @@ Plugins.Share = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhrPost("backend.php", App.getPhArgs("share", "shareDialog", {id: id}), (transport) => { - dialog.attr('content', transport.responseText) + xhr.post("backend.php", App.getPhArgs("share", "shareDialog", {id: id}), (reply) => { + dialog.attr('content', reply) const icon = document.querySelector(".share-icon-" + id); diff --git a/plugins/share/share_prefs.js b/plugins/share/share_prefs.js index 91f979daf..d974af618 100644 --- a/plugins/share/share_prefs.js +++ b/plugins/share/share_prefs.js @@ -1,12 +1,12 @@ -/* global Plugins, Notify, xhrPost */ +/* global Plugins, Notify, xhr, App */ Plugins.Share = { clearKeys: function() { if (confirm(__("This will invalidate all previously shared article URLs. Continue?"))) { Notify.progress("Clearing URLs..."); - xhrPost("backend.php", App.getPhArgs("share", "clearArticleKeys"), (transport) => { - Notify.info(transport.responseText); + xhr.post("backend.php", App.getPhArgs("share", "clearArticleKeys"), (reply) => { + Notify.info(reply); }); } diff --git a/prefs.php b/prefs.php index 2b2af8452..d11c6281e 100644 --- a/prefs.php +++ b/prefs.php @@ -124,7 +124,10 @@
diff --git a/themes/compact.css b/themes/compact.css index 0116fa45b..e92db1659 100644 --- a/themes/compact.css +++ b/themes/compact.css @@ -754,6 +754,17 @@ body.ttrss_main #header { top: 0px; z-index: 5; } +body.ttrss_main #header i.net-alert, +body.ttrss_main #header .left i.icon-error { + color: red; +} +body.ttrss_main #header i.log-alert { + color: #ddba1c; + cursor: pointer; +} +body.ttrss_main #header i { + margin: 0 4px; +} body.ttrss_main #content-insert { padding: 0px; border-color: #ddd; diff --git a/themes/compact_night.css b/themes/compact_night.css index 2709cf196..42b850536 100644 --- a/themes/compact_night.css +++ b/themes/compact_night.css @@ -754,6 +754,17 @@ body.ttrss_main #header { top: 0px; z-index: 5; } +body.ttrss_main #header i.net-alert, +body.ttrss_main #header .left i.icon-error { + color: red; +} +body.ttrss_main #header i.log-alert { + color: #ddba1c; + cursor: pointer; +} +body.ttrss_main #header i { + margin: 0 4px; +} body.ttrss_main #content-insert { padding: 0px; border-color: #222; diff --git a/themes/light.css b/themes/light.css index 492daf08f..0b69ef84b 100644 --- a/themes/light.css +++ b/themes/light.css @@ -754,6 +754,17 @@ body.ttrss_main #header { top: 0px; z-index: 5; } +body.ttrss_main #header i.net-alert, +body.ttrss_main #header .left i.icon-error { + color: red; +} +body.ttrss_main #header i.log-alert { + color: #ddba1c; + cursor: pointer; +} +body.ttrss_main #header i { + margin: 0 4px; +} body.ttrss_main #content-insert { padding: 0px; border-color: #ddd; diff --git a/themes/light/tt-rss.less b/themes/light/tt-rss.less index 3cf1a2d5e..b1895f318 100644 --- a/themes/light/tt-rss.less +++ b/themes/light/tt-rss.less @@ -877,6 +877,19 @@ body.ttrss_main { right : 0px; top : 0px; z-index : 5; + + i.net-alert, .left i.icon-error { + color : red; + } + + i.log-alert { + color : #ddba1c; + cursor : pointer; + } + + i { + margin : 0 4px; + } } #content-insert { diff --git a/themes/night.css b/themes/night.css index a52ef701d..65484b82b 100644 --- a/themes/night.css +++ b/themes/night.css @@ -755,6 +755,17 @@ body.ttrss_main #header { top: 0px; z-index: 5; } +body.ttrss_main #header i.net-alert, +body.ttrss_main #header .left i.icon-error { + color: red; +} +body.ttrss_main #header i.log-alert { + color: #ddba1c; + cursor: pointer; +} +body.ttrss_main #header i { + margin: 0 4px; +} body.ttrss_main #content-insert { padding: 0px; border-color: #222; diff --git a/themes/night_blue.css b/themes/night_blue.css index 2a7debf35..1c16a6f22 100644 --- a/themes/night_blue.css +++ b/themes/night_blue.css @@ -755,6 +755,17 @@ body.ttrss_main #header { top: 0px; z-index: 5; } +body.ttrss_main #header i.net-alert, +body.ttrss_main #header .left i.icon-error { + color: red; +} +body.ttrss_main #header i.log-alert { + color: #ddba1c; + cursor: pointer; +} +body.ttrss_main #header i { + margin: 0 4px; +} body.ttrss_main #content-insert { padding: 0px; border-color: #222; -- cgit v1.2.3-54-g00ecf From 9586c72a17dabd907becebffc938add10c4a8626 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 20 Feb 2021 10:26:09 +0300 Subject: wip: feed editor client-side --- classes/pref/feeds.php | 72 ++++++++++++++-- js/App.js | 24 +++--- js/CommonDialogs.js | 219 +++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 291 insertions(+), 24 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 97c529d07..2c275349b 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -464,8 +464,10 @@ class Pref_Feeds extends Handler_Protected { if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) { $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon'); - $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], - $tmp_file); + if (!$tmp_file) + return; + + $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], $tmp_file); if (!$result) { return; @@ -478,7 +480,7 @@ class Pref_Feeds extends Handler_Protected { $feed_id = clean($_REQUEST["feed_id"]); $rc = 2; // failed - if (is_file($icon_file) && $feed_id) { + if ($icon_file && is_file($icon_file) && $feed_id) { if (filesize($icon_file) < 65535) { $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds @@ -486,8 +488,12 @@ class Pref_Feeds extends Handler_Protected { $sth->execute([$feed_id, $_SESSION['uid']]); if ($row = $sth->fetch()) { - @unlink(ICONS_DIR . "/$feed_id.ico"); - if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) { + $new_filename = ICONS_DIR . "/$feed_id.ico"; + + if (file_exists($new_filename)) unlink($new_filename); + + if (rename($icon_file, $new_filename)) { + chmod($new_filename, 644); $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = '' @@ -502,7 +508,9 @@ class Pref_Feeds extends Handler_Protected { } } - if (is_file($icon_file)) @unlink($icon_file); + if ($icon_file && is_file($icon_file)) { + unlink($icon_file); + } print $rc; return; @@ -512,12 +520,62 @@ class Pref_Feeds extends Handler_Protected { global $purge_intervals; global $update_intervals; - $feed_id = clean($_REQUEST["id"]); + $feed_id = (int)clean($_REQUEST["id"]); $sth = $this->pdo->prepare("SELECT * FROM ttrss_feeds WHERE id = ? AND owner_uid = ?"); $sth->execute([$feed_id, $_SESSION['uid']]); + if ($row = $sth->fetch(PDO::FETCH_ASSOC)) { + + ob_start(); + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, $feed_id); + $plugin_data = trim((string)ob_get_contents()); + ob_end_clean(); + + $row["icon"] = Feeds::_get_icon($feed_id); + + $local_update_intervals = $update_intervals; + $local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]); + + if (FORCE_ARTICLE_PURGE == 0) { + $local_purge_intervals = $purge_intervals; + $default_purge_interval = get_pref("PURGE_OLD_DAYS"); + + if ($default_purge_interval > 0) + $local_purge_intervals[0] .= " " . T_nsprintf('(%d day)', '(%d days)', $default_purge_interval, $default_purge_interval); + else + $local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled")); + + } else { + $purge_interval = FORCE_ARTICLE_PURGE; + $local_purge_intervals = [ T_nsprintf('%d day', '%d days', $purge_interval, $purge_interval) ]; + } + + print json_encode([ + "feed" => $row, + "cats" => [ + "enabled" => get_pref('ENABLE_FEED_CATS'), + "select" => \Controls\select_feeds_cats("cat_id", $row["cat_id"]), + ], + "plugin_data" => $plugin_data, + "force_purge" => (int)FORCE_ARTICLE_PURGE, + "intervals" => [ + "update" => $local_update_intervals, + "purge" => $local_purge_intervals, + ], + "lang" => [ + "enabled" => DB_TYPE == "pgsql", + "default" => get_pref('DEFAULT_SEARCH_LANGUAGE'), + "all" => $this::get_ts_languages(), + ] + ]); + } else { + print json_encode(["error" => "FEED_NOT_FOUND"]); + } + + return; + if ($row = $sth->fetch()) { print '
'; diff --git a/js/App.js b/js/App.js index 764003ca9..a3618409a 100644 --- a/js/App.js +++ b/js/App.js @@ -343,16 +343,20 @@ const App = { }); }, // htmlspecialchars()-alike for headlines data-content attribute - escapeHtml: function(text) { - const map = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; - - return text.replace(/[&<>"']/g, function(m) { return map[m]; }); + escapeHtml: function(p) { + if (typeof p == "string") { + const map = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + + return p.replace(/[&<>"']/g, function(m) { return map[m]; }); + } else { + return p; + } }, displayIfChecked: function(checkbox, elemId) { if (checkbox.checked) { diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index a75b36ed8..5477e9ecd 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -389,19 +389,20 @@ const CommonDialogs = { return false; }, - editFeed: function (feed) { - if (feed <= 0) + editFeed: function (feed_id) { + if (feed_id <= 0) return alert(__("You can't edit this kind of feed.")); - const query = {op: "pref-feeds", method: "editfeed", id: feed}; + const query = {op: "pref-feeds", method: "editfeed", id: feed_id}; console.log("editFeed", query); const dialog = new fox.SingleUseDialog({ id: "feedEditDlg", title: __("Edit Feed"), - unsubscribeFeed: function(feed_id, title) { - if (confirm(__("Unsubscribe from %s?").replace("%s", title))) { + feed_title: "", + unsubscribe: function() { + if (confirm(__("Unsubscribe from %s?").replace("%s", this.feed_title))) { dialog.hide(); CommonDialogs.unsubscribeFeed(feed_id); } @@ -430,8 +431,212 @@ const CommonDialogs = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - xhr.post("backend.php", {op: "pref-feeds", method: "editfeed", id: feed}, (reply) => { - dialog.attr('content', reply); + xhr.json("backend.php", {op: "pref-feeds", method: "editfeed", id: feed_id}, (reply) => { + const feed = reply.feed; + + // for unsub prompt + dialog.feed_title = feed.title; + + dialog.attr('content', + ` +
+
+ + ${App.FormFields.hidden_tag("id", feed_id)} + ${App.FormFields.hidden_tag("op", "pref-feeds")} + ${App.FormFields.hidden_tag("method", "editSave")} + +
+
+ +
+ +
+ + + + ${feed.last_error ? + `error + ` : ""} +
+ + ${reply.cats.enabled ? + ` +
+ + ${reply.cats.select} +
+ ` : ""} + +
+ + +
+ + ${reply.lang.enabled ? + ` +
+ + ${App.FormFields.select_tag("feed_language", feed.feed_language, reply.lang.all)} +
+ ` : ""} + +
+ +
+ + ${App.FormFields.select_hash("update_interval", feed.update_interval, reply.intervals.update)} +
+
+ + + ${App.FormFields.select_hash("purge_interval", + feed.purge_interval, + reply.intervals.purge, + reply.force_purge ? {disabled: 1} : {})} + +
+
+
+
+
+
+ + +
+
+ + +
+
+
+
+ +
+ + $include_in_digest = $row["include_in_digest"]; + + if ($include_in_digest) { + $checked = "checked="1" + } else { + $checked = " + } + +
+ + + +
+ + $always_display_enclosures = $row["always_display_enclosures"]; + + if ($always_display_enclosures) { + $checked = "checked + } else { + $checked = " + } + +
+ + + +
+ + $hide_images = $row["hide_images"]; + + if ($hide_images) { + $checked = "checked="1" + } else { + $checked = " + } + +
+ + + +
+ + $cache_images = $row["cache_images"]; + + if ($cache_images) { + $checked = "checked="1" + } else { + $checked = " + } + +
+ + + +
+ + $mark_unread_on_update = $row["mark_unread_on_update"]; + + if ($mark_unread_on_update) { + $checked = "checked + } else { + $checked = " + } + +
+ + + +
+ +
+ +
+ + + +
+ + + ${App.FormFields.hidden_tag("op", "pref-feeds")} + ${App.FormFields.hidden_tag("feed_id", feed_id)} + ${App.FormFields.hidden_tag("method", "uploadIcon")} + ${App.FormFields.hidden_tag("csrf_token", App.getInitParam("csrf_token"))} + + ${App.FormFields.submit_tag(__("Replace"), {onclick: "return CommonDialogs.uploadFeedIcon()"})} + ${App.FormFields.submit_tag(__("Remove"), {class: "alt-danger", onclick: "return CommonDialogs.removeFeedIcon("+feed_id+")"})} +
+
+ +
+ ${reply.plugin_data} +
+ +
+ +
+ ${App.FormFields.button_tag(__("Unsubscribe"), "", {class: "pull-left alt-danger", onclick: "App.dialogOf(this).unsubscribe()"})} + ${App.FormFields.submit_tag(__("Save"), {onclick: "return App.dialogOf(this).execute()"})} + ${App.FormFields.cancel_dialog_tag(__("Cancel"))} +
+ `); }) }); -- cgit v1.2.3-54-g00ecf From 22fe9b54d2150e543338dbc7541f134c0a7c61f6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 20 Feb 2021 13:32:09 +0300 Subject: feed editor: use client dialog --- classes/api.php | 2 +- classes/pref/feeds.php | 310 +---------------------------------- js/CommonDialogs.js | 437 +++++++++++++++++++++---------------------------- 3 files changed, 197 insertions(+), 552 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/classes/api.php b/classes/api.php index 8c32967a2..03eea1927 100755 --- a/classes/api.php +++ b/classes/api.php @@ -843,7 +843,7 @@ class API extends Handler { $_REQUEST['force_show_empty'] = $include_empty; $this->_wrap(self::STATUS_OK, - array("categories" => $pf->makefeedtree())); + array("categories" => $pf->_makefeedtree())); } // only works for labels or uncategorized for the time being diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 2c275349b..cf9e7c95e 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1,7 +1,7 @@ makefeedtree()); + print json_encode($this->_makefeedtree()); } - function makefeedtree() { + function _makefeedtree() { if (clean($_REQUEST['mode'] ?? 0) != 2) $search = $_SESSION["prefs_feed_search"] ?? ""; @@ -500,7 +496,7 @@ class Pref_Feeds extends Handler_Protected { WHERE id = ?"); $sth->execute([$feed_id]); - $rc = 0; + $rc = Feeds::_get_icon($feed_id); } } } else { @@ -573,298 +569,6 @@ class Pref_Feeds extends Handler_Protected { } else { print json_encode(["error" => "FEED_NOT_FOUND"]); } - - return; - - if ($row = $sth->fetch()) { - print '
-
'; - - $title = htmlspecialchars($row["title"]); - - print \Controls\hidden_tag("id", "$feed_id"); - print \Controls\hidden_tag("op", "pref-feeds"); - print \Controls\hidden_tag("method", "editSave"); - - print "
".__("Feed")."
"; - print "
"; - - /* Title */ - - print "
"; - - print ""; - - print "
"; - - /* Feed URL */ - - $feed_url = htmlspecialchars($row["feed_url"]); - - print "
"; - - print " "; - print ""; - - if (!empty($row["last_error"])) { - print " error"; - } - - print "
"; - - /* Category */ - - if (get_pref('ENABLE_FEED_CATS')) { - print "
"; - - print " "; - - print \Controls\select_feeds_cats("cat_id", $row["cat_id"]); - - print "
"; - } - - /* Site URL */ - - $site_url = htmlspecialchars($row["site_url"]); - - print "
"; - - print " "; - print ""; - - print "
"; - - /* FTS Stemming Language */ - - if (DB_TYPE == "pgsql") { - $feed_language = $row["feed_language"]; - - if (!$feed_language) - $feed_language = get_pref('DEFAULT_SEARCH_LANGUAGE'); - - print "
"; - - print " "; - print \Controls\select_tag("feed_language", $feed_language, $this::get_ts_languages()); - - print "
"; - } - - print "
"; - - print "
".__("Update")."
"; - print "
"; - - /* Update Interval */ - - $update_interval = $row["update_interval"]; - - print "
"; - - print " "; - - $local_update_intervals = $update_intervals; - $local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]); - - print \Controls\select_hash("update_interval", $update_interval, $local_update_intervals); - - print "
"; - - /* Purge intl */ - - $purge_interval = $row["purge_interval"]; - - print "
"; - - print " "; - - if (FORCE_ARTICLE_PURGE == 0) { - $local_purge_intervals = $purge_intervals; - $default_purge_interval = get_pref("PURGE_OLD_DAYS"); - - if ($default_purge_interval > 0) - $local_purge_intervals[0] .= " " . T_nsprintf('(%d day)', '(%d days)', $default_purge_interval, $default_purge_interval); - else - $local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled")); - - } else { - $purge_interval = FORCE_ARTICLE_PURGE; - $local_purge_intervals = [ T_nsprintf('%d day', '%d days', $purge_interval, $purge_interval) ]; - } - - print \Controls\select_hash("purge_interval", - $purge_interval, - $local_purge_intervals, - (FORCE_ARTICLE_PURGE == 0) ? [] : ["disabled" => 1]); - - print "
"; - - print "
"; - - $auth_login = htmlspecialchars($row["auth_login"]); - $auth_pass = htmlspecialchars($row["auth_pass"]); - - $auth_enabled = $auth_login !== '' || $auth_pass !== ''; - - $auth_style = $auth_enabled ? '' : 'display: none'; - print "
"; - print "
".__("Authentication")."
"; - print "
"; - - print "
"; - - print ""; - - print "
"; - - print ""; - - print "
"; - - print "
"; - - $auth_checked = $auth_enabled ? 'checked' : ''; - print ""; - - print '
'; - - print "
"; - - $include_in_digest = $row["include_in_digest"]; - - if ($include_in_digest) { - $checked = "checked=\"1\""; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - $always_display_enclosures = $row["always_display_enclosures"]; - - if ($always_display_enclosures) { - $checked = "checked"; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - $hide_images = $row["hide_images"]; - - if ($hide_images) { - $checked = "checked=\"1\""; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - $cache_images = $row["cache_images"]; - - if ($cache_images) { - $checked = "checked=\"1\""; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - $mark_unread_on_update = $row["mark_unread_on_update"]; - - if ($mark_unread_on_update) { - $checked = "checked"; - } else { - $checked = ""; - } - - print "
"; - - print ""; - - print "
"; - - print '
'; - - /* Icon */ - - print ""; - - print "
- - - - - - - -
"; - - print ""; - - print '
'; - - PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, $feed_id); - - print "
"; - - $title = htmlspecialchars($title, ENT_QUOTES); - - print "
- - - -
"; - } } function editfeeds() { @@ -1036,7 +740,7 @@ class Pref_Feeds extends Handler_Protected { return $this->editsaveops(false); } - function editsaveops($batch) { + private function editsaveops($batch) { $feed_title = clean($_POST["title"]); $feed_url = clean($_POST["feed_url"]); @@ -1064,10 +768,6 @@ class Pref_Feeds extends Handler_Protected { $feed_language = clean($_POST["feed_language"]); if (!$batch) { - if (clean($_POST["need_auth"] ?? "") !== 'on') { - $auth_login = ''; - $auth_pass = ''; - } /* $sth = $this->pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?"); $sth->execute([$feed_id]); diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 5477e9ecd..704e797d3 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -11,72 +11,6 @@ const CommonDialogs = { const dialog = dijit.byId("infoBox"); if (dialog) dialog.hide(); }, - removeFeedIcon: function(id) { - if (confirm(__("Remove stored feed icon?"))) { - Notify.progress("Removing feed icon...", true); - - const query = {op: "pref-feeds", method: "removeicon", feed_id: id}; - - xhr.post("backend.php", query, () => { - Notify.info("Feed icon removed."); - - if (App.isPrefs()) - dijit.byId("feedTree").reload(); - else - Feeds.reload(); - - const icon = App.findAll(".feed-editor-icon")[0]; - - if (icon) - icon.src = icon.src.replace(/\?[0-9]+$/, "?" + new Date().getTime()); - - }); - } - - return false; - }, - uploadFeedIcon: function() { - const file = App.byId("icon_file"); - - if (file.value.length == 0) { - alert(__("Please select an image file to upload.")); - } else if (confirm(__("Upload new icon for this feed?"))) { - Notify.progress("Uploading, please wait...", true); - - const xhr = new XMLHttpRequest(); - - xhr.open( 'POST', 'backend.php', true ); - xhr.onload = function () { - switch (parseInt(this.responseText)) { - case 0: - { - Notify.info("Upload complete."); - - if (App.isPrefs()) - dijit.byId("feedTree").reload(); - else - Feeds.reload(); - - const icon = App.findAll(".feed-editor-icon")[0]; - - if (icon) - icon.src = icon.src.replace(/\?[0-9]+$/, "?" + new Date().getTime()); - - } - break; - case 1: - Notify.error("Upload failed: icon is too big."); - break; - case 2: - Notify.error("Upload failed."); - break; - } - }; - xhr.send(new FormData(App.byId("feed_icon_upload_form"))); - } - - return false; - }, subscribeToFeed: function() { xhr.json("backend.php", {op: "feeds", method: "subscribeToFeed"}, @@ -407,6 +341,86 @@ const CommonDialogs = { CommonDialogs.unsubscribeFeed(feed_id); } }, + uploadIcon: function(input) { + if (input.files.length != 0) { + const icon_file = input.files[0]; + + if (icon_file.type.indexOf("image/") == -1) { + alert(__("Please select an image file.")); + return; + } + + const fd = new FormData(); + fd.append('icon_file', icon_file) + fd.append('feed_id', feed_id); + fd.append('op', 'pref-feeds'); + fd.append('method', 'uploadIcon'); + fd.append('csrf_token', App.getInitParam("csrf_token")); + + const xhr = new XMLHttpRequest(); + + xhr.open( 'POST', 'backend.php', true ); + xhr.onload = function () { + console.log(this.responseText); + + // TODO: make a notice box within panel content + switch (parseInt(this.responseText)) { + case 1: + Notify.error("Upload failed: icon is too big."); + break; + case 2: + Notify.error("Upload failed."); + break; + default: + { + Notify.info("Upload complete."); + + if (App.isPrefs()) + dijit.byId("feedTree").reload(); + else + Feeds.reload(); + + const icon = dialog.domNode.querySelector(".feedIcon"); + + if (icon) { + icon.src = this.responseText; + icon.show(); + } + + input.value = ""; + } + } + }; + + xhr.send(fd); + + } + }, + removeIcon: function(id) { + if (confirm(__("Remove stored feed icon?"))) { + Notify.progress("Removing feed icon...", true); + + const query = {op: "pref-feeds", method: "removeicon", feed_id: id}; + + xhr.post("backend.php", query, () => { + Notify.info("Feed icon removed."); + + if (App.isPrefs()) + dijit.byId("feedTree").reload(); + else + Feeds.reload(); + + const icon = dialog.domNode.querySelector(".feedIcon"); + + if (icon) { + icon.src = ""; + icon.hide(); + } + }); + } + + return false; + }, execute: function () { if (this.validate()) { Notify.progress("Saving data...", true); @@ -437,205 +451,136 @@ const CommonDialogs = { // for unsub prompt dialog.feed_title = feed.title; + // options tab + const options = { + include_in_digest: [ feed.include_in_digest, __('Include in e-mail digest') ], + always_display_enclosures: [ feed.always_display_enclosures, __('Always display image attachments') ], + hide_images: [ feed.hide_images, __('Do not embed media') ], + cache_images: [ feed.cache_images, __('Cache media') ], + mark_unread_on_update: [ feed.mark_unread_on_update, __('Mark updated articles as unread') ] + }; + dialog.attr('content', ` -
-
+
+
+
- ${App.FormFields.hidden_tag("id", feed_id)} - ${App.FormFields.hidden_tag("op", "pref-feeds")} - ${App.FormFields.hidden_tag("method", "editSave")} - -
-
- -
- -
- - - - ${feed.last_error ? - `error - ` : ""} -
+ ${App.FormFields.hidden_tag("id", feed_id)} + ${App.FormFields.hidden_tag("op", "pref-feeds")} + ${App.FormFields.hidden_tag("method", "editSave")} - ${reply.cats.enabled ? - ` +
- - ${reply.cats.select} +
- ` : ""} - -
- - -
- - ${reply.lang.enabled ? - ` +
- - ${App.FormFields.select_tag("feed_language", feed.feed_language, reply.lang.all)} + + + + ${feed.last_error ? + `error + ` : ""}
- ` : ""} - -
- -
- - ${App.FormFields.select_hash("update_interval", feed.update_interval, reply.intervals.update)} -
-
- - - ${App.FormFields.select_hash("purge_interval", - feed.purge_interval, - reply.intervals.purge, - reply.force_purge ? {disabled: 1} : {})} - -
-
-
-
-
-
- - -
-
- - -
-
-
-
-
- - $include_in_digest = $row["include_in_digest"]; - - if ($include_in_digest) { - $checked = "checked="1" - } else { - $checked = " - } - -
- - - -
- - $always_display_enclosures = $row["always_display_enclosures"]; - - if ($always_display_enclosures) { - $checked = "checked - } else { - $checked = " - } - -
- - - -
- - $hide_images = $row["hide_images"]; - - if ($hide_images) { - $checked = "checked="1" - } else { - $checked = " - } - -
- - - -
- - $cache_images = $row["cache_images"]; - - if ($cache_images) { - $checked = "checked="1" - } else { - $checked = " - } - -
- - - -
- - $mark_unread_on_update = $row["mark_unread_on_update"]; - - if ($mark_unread_on_update) { - $checked = "checked - } else { - $checked = " - } + ${reply.cats.enabled ? + ` +
+ + ${reply.cats.select} +
+ ` : ""} -
+
+ + +
- + ${reply.lang.enabled ? + ` +
+ + ${App.FormFields.select_tag("feed_language", + feed.feed_language ? feed.feed_language : reply.lang.default, + reply.lang.all)} +
+ ` : ""} -
+
-
+
+ + ${App.FormFields.select_hash("update_interval", feed.update_interval, reply.intervals.update)} +
+
+ -
+ ${App.FormFields.select_hash("purge_interval", + feed.purge_interval, + reply.intervals.purge, + reply.force_purge ? {disabled: 1} : {})} - +
+ +
+
+
+
+ + +
+
+ + +
+
+
+
+
+ ${Object.keys(options).map((name) => + ` +
+ +
+ `).join("")} +
+
+
+
- -
- -
- ${reply.plugin_data} -
- + ${App.FormFields.submit_tag(__("Remove"), {class: "alt-danger", onclick: "App.dialogOf(this).removeIcon("+feed_id+")"})} +
+
+ ${reply.plugin_data} +
- -
- ${App.FormFields.button_tag(__("Unsubscribe"), "", {class: "pull-left alt-danger", onclick: "App.dialogOf(this).unsubscribe()"})} - ${App.FormFields.submit_tag(__("Save"), {onclick: "return App.dialogOf(this).execute()"})} - ${App.FormFields.cancel_dialog_tag(__("Cancel"))} -
+
+ ${App.FormFields.button_tag(__("Unsubscribe"), "", {class: "pull-left alt-danger", onclick: "App.dialogOf(this).unsubscribe()"})} + ${App.FormFields.submit_tag(__("Save"), {onclick: "App.dialogOf(this).execute()"})} + ${App.FormFields.cancel_dialog_tag(__("Cancel"))} +
+ `); }) }); -- cgit v1.2.3-54-g00ecf From 1bd5152c8016c6019a647bf995d29d81c6b731ed Mon Sep 17 00:00:00 2001 From: wn_ Date: Sat, 20 Feb 2021 13:44:42 +0000 Subject: Open the default feed after unsubscribing. Previously the UI appeared to hang, even though the backend request had already completed successfully. --- js/CommonDialogs.js | 2 +- js/Feeds.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index 704e797d3..a100a546d 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -312,7 +312,7 @@ const CommonDialogs = { } else { if (feed_id == Feeds.getActive()) setTimeout(() => { - Feeds.open({feed: -5}) + Feeds.openDefaultFeed(); }, 100); diff --git a/js/Feeds.js b/js/Feeds.js index e9ac5328d..4841fd0df 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -3,6 +3,7 @@ /* global __, App, Headlines, xhrPost, xhr, dojo, dijit, fox, PluginHost, Notify, fox */ const Feeds = { + _default_feed_id: -3, counters_last_request: 0, _active_feed_id: undefined, _active_feed_is_cat: false, @@ -109,6 +110,9 @@ const Feeds = { } return false; // block unneeded form submits }, + openDefaultFeed: function() { + this.open({feed: this._default_feed_id}); + }, openNextUnread: function() { const is_cat = this.activeIsCat(); const nuf = this.getNextUnread(this.getActive(), is_cat); @@ -215,7 +219,7 @@ const Feeds = { if (hash_feed_id != undefined) { this.open({feed: hash_feed_id, is_cat: hash_feed_is_cat}); } else { - this.open({feed: -3}); + this.openDefaultFeed(); } this.hideOrShowFeeds(App.getInitParam("hide_read_feeds")); -- cgit v1.2.3-54-g00ecf From 861a632ac7c283c55dfd947ed0152d9846fa2ac0 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 21 Feb 2021 18:04:44 +0300 Subject: move published opml JS code to pref helpers --- classes/pref/feeds.php | 2 +- js/CommonDialogs.js | 58 -------------------------------------------------- js/PrefHelpers.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 59 deletions(-) (limited to 'js/CommonDialogs.js') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index c901bc96e..e583a5f51 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1043,7 +1043,7 @@ class Pref_Feeds extends Handler_Protected {

- diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index a100a546d..321ddf6d3 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -587,64 +587,6 @@ const CommonDialogs = { dialog.show(); }, - publishedOPML: function() { - - Notify.progress("Loading, please wait...", true); - - xhr.json("backend.php", {op: "pref-feeds", method: "getOPMLKey"}, (reply) => { - try { - const dialog = new fox.SingleUseDialog({ - title: __("Public OPML URL"), - regenOPMLKey: function() { - if (confirm(__("Replace current OPML publishing address with a new one?"))) { - Notify.progress("Trying to change address...", true); - - xhr.json("backend.php", {op: "pref-feeds", method: "regenOPMLKey"}, (reply) => { - if (reply) { - const new_link = reply.link; - const target = this.domNode.querySelector('.generated_url'); - - if (new_link && target) { - target.href = new_link; - target.innerHTML = new_link; - - Notify.close(); - - } else { - Notify.error("Could not change feed URL."); - } - } - }); - } - return false; - }, - content: ` -
${__("Your Public OPML URL is:")}
-
- -
-
- - -
- ` - }); - - dialog.show(); - - Notify.close(); - - } catch (e) { - App.Error.report(e); - } - }); - }, generatedFeed: function(feed, is_cat, search = "") { Notify.progress("Loading, please wait...", true); diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index d27e0e071..62f6d91b1 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -347,5 +347,62 @@ const Helpers = { console.log("export"); window.open("backend.php?op=opml&method=export&" + dojo.formToQuery("opmlExportForm")); }, + publish: function() { + Notify.progress("Loading, please wait...", true); + + xhr.json("backend.php", {op: "pref-feeds", method: "getOPMLKey"}, (reply) => { + try { + const dialog = new fox.SingleUseDialog({ + title: __("Public OPML URL"), + regenOPMLKey: function() { + if (confirm(__("Replace current OPML publishing address with a new one?"))) { + Notify.progress("Trying to change address...", true); + + xhr.json("backend.php", {op: "pref-feeds", method: "regenOPMLKey"}, (reply) => { + if (reply) { + const new_link = reply.link; + const target = this.domNode.querySelector('.generated_url'); + + if (new_link && target) { + target.href = new_link; + target.innerHTML = new_link; + + Notify.close(); + + } else { + Notify.error("Could not change feed URL."); + } + } + }); + } + return false; + }, + content: ` +
${__("Your Public OPML URL is:")}
+
+ +
+ + ` + }); + + dialog.show(); + + Notify.close(); + + } catch (e) { + App.Error.report(e); + } + }); + }, } }; -- cgit v1.2.3-54-g00ecf