From 6b43b788d909ce20f07f29f9f3ccd2f6a8715616 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 10:22:00 +0300 Subject: [PATCH] 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(-) 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 {