migrate xhrJson invocations to the new helper

This commit is contained in:
Andrew Dolgov 2021-02-19 10:22:00 +03:00
parent dba6dce3b3
commit 6b43b788d9
15 changed files with 30 additions and 40 deletions

View File

@ -59,7 +59,7 @@
if (login && login != this.previousLogin) { if (login && login != this.previousLogin) {
this.previousLogin = login; this.previousLogin = login;
xhrJson("public.php", {op: "getprofiles", login: login}, xhr.json("public.php", {op: "getprofiles", login: login},
(reply) => { (reply) => {
const profile = dijit.byId('profile'); const profile = dijit.byId('profile');

View File

@ -775,7 +775,7 @@ const App = {
checkForUpdates: function() { checkForUpdates: function() {
console.log('checking for updates...'); console.log('checking for updates...');
xhrJson("backend.php", {op: 'rpc', method: 'checkforupdates'}) xhr.json("backend.php", {op: 'rpc', method: 'checkforupdates'})
.then((reply) => { .then((reply) => {
console.log('update reply', reply); console.log('update reply', reply);

View File

@ -115,7 +115,7 @@ const Article = {
displayUrl: function (id) { displayUrl: function (id) {
const query = {op: "article", method: "getmetadatabyid", id: id}; const query = {op: "article", method: "getmetadatabyid", id: id};
xhrJson("backend.php", query, (reply) => { xhr.json("backend.php", query, (reply) => {
if (reply && reply.link) { if (reply && reply.link) {
prompt(__("Article URL:"), reply.link); prompt(__("Article URL:"), reply.link);
} else { } else {
@ -358,7 +358,7 @@ const Article = {
const tmph = dojo.connect(dialog, 'onShow', function () { const tmph = dojo.connect(dialog, 'onShow', function () {
dojo.disconnect(tmph); 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")) dijit.getEnclosingWidget(App.byId("tags_str"))
.attr('value', reply.tags.join(", ")) .attr('value', reply.tags.join(", "))

View File

@ -78,7 +78,7 @@ const CommonDialogs = {
return false; return false;
}, },
subscribeToFeed: function() { subscribeToFeed: function() {
xhrJson("backend.php", xhr.json("backend.php",
{op: "feeds", method: "subscribeToFeed"}, {op: "feeds", method: "subscribeToFeed"},
(reply) => { (reply) => {
const dialog = new fox.SingleUseDialog({ const dialog = new fox.SingleUseDialog({
@ -265,7 +265,7 @@ const CommonDialogs = {
}, },
showFeedsWithErrors: function() { 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({ const dialog = new fox.SingleUseDialog({
id: "errorFeedsDlg", id: "errorFeedsDlg",
@ -446,7 +446,7 @@ const CommonDialogs = {
Notify.progress("Loading, please wait...", true); 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 { try {
const dialog = new fox.SingleUseDialog({ const dialog = new fox.SingleUseDialog({
title: __("Public OPML URL"), title: __("Public OPML URL"),
@ -454,7 +454,7 @@ const CommonDialogs = {
if (confirm(__("Replace current OPML publishing address with a new one?"))) { if (confirm(__("Replace current OPML publishing address with a new one?"))) {
Notify.progress("Trying to change address...", true); 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) { if (reply) {
const new_link = reply.link; const new_link = reply.link;
const target = this.domNode.querySelector('.generated_url'); const target = this.domNode.querySelector('.generated_url');
@ -504,7 +504,7 @@ const CommonDialogs = {
Notify.progress("Loading, please wait...", true); 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 { try {
const dialog = new fox.SingleUseDialog({ const dialog = new fox.SingleUseDialog({
title: __("Show as feed"), title: __("Show as feed"),
@ -515,7 +515,7 @@ const CommonDialogs = {
const query = {op: "pref-feeds", method: "regenFeedKey", id: feed, is_cat: is_cat}; 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 new_link = reply.link;
const target = this.domNode.querySelector(".generated_url"); const target = this.domNode.querySelector(".generated_url");

View File

@ -558,7 +558,7 @@ const Feeds = {
return tree.model.store.getValue(nuf, 'bare_id'); return tree.model.store.getValue(nuf, 'bare_id');
}, },
search: function() { search: function() {
xhrJson("backend.php", xhr.json("backend.php",
{op: "feeds", method: "search"}, {op: "feeds", method: "search"},
(reply) => { (reply) => {
try { try {

View File

@ -210,14 +210,14 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b
return false; return false;
}, },
checkErrorFeeds: function() { 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) { if (reply.length > 0) {
Element.show(dijit.byId("pref_feeds_errors_btn").domNode); Element.show(dijit.byId("pref_feeds_errors_btn").domNode);
} }
}); });
}, },
checkInactiveFeeds: function() { 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) { if (reply.length > 0) {
Element.show(dijit.byId("pref_feeds_inactive_btn").domNode); 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() { 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({ const dialog = new fox.SingleUseDialog({
id: "batchSubDlg", id: "batchSubDlg",
title: __("Batch subscribe"), title: __("Batch subscribe"),
@ -458,7 +458,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b
}); });
}, },
showInactiveFeeds: function() { 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({ const dialog = new fox.SingleUseDialog({
id: "inactiveFeedsDlg", id: "inactiveFeedsDlg",

View File

@ -132,7 +132,7 @@ const Helpers = {
} }
}, },
refresh: function() { refresh: function() {
xhrJson("backend.php", {op: 'pref-prefs', method: 'getprofiles'}, (reply) => { xhr.json("backend.php", {op: 'pref-prefs', method: 'getprofiles'}, (reply) => {
dialog.attr('content', ` dialog.attr('content', `
<div dojoType='fox.Toolbar'> <div dojoType='fox.Toolbar'>
<div dojoType='fox.form.DropDownButton'> <div dojoType='fox.form.DropDownButton'>
@ -212,7 +212,7 @@ const Helpers = {
}, },
Prefs: { Prefs: {
customizeCSS: function() { 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({ const dialog = new fox.SingleUseDialog({
title: __("Customize stylesheet"), title: __("Customize stylesheet"),

View File

@ -61,7 +61,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f
}); });
}, },
editLabel: function(id) { 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); console.log(reply);

View File

@ -27,7 +27,7 @@ const Users = {
} }
}, },
edit: function(id) { 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 user = reply.user;
const admin_disabled = (user.id == 1); const admin_disabled = (user.id == 1);

View File

@ -143,7 +143,7 @@ String.prototype.stripTags = function() {
const xhr = { const xhr = {
post: function(url, params = {}, complete = undefined) { post: function(url, params = {}, complete = undefined) {
console.log("xhr.post:", params); console.log('xhr.post', '>>>', params);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (typeof __csrf_token != "undefined") if (typeof __csrf_token != "undefined")
@ -156,6 +156,8 @@ const xhr = {
reject(error); reject(error);
}, },
load: function(data, ioargs) { load: function(data, ioargs) {
//console.log('xhr.post', '<<<', data, ioargs);
if (complete != undefined) if (complete != undefined)
complete(data, ioargs.xhr); complete(data, ioargs.xhr);
@ -176,6 +178,8 @@ const xhr = {
reject(e); reject(e);
} }
console.log('xhr.json', '<<<', obj);
if (complete != undefined) complete(obj); if (complete != undefined) complete(obj);
resolve(obj); resolve(obj);
@ -209,21 +213,7 @@ function xhrPost(url, params = {}, complete = undefined) {
/* exported xhrJson */ /* exported xhrJson */
function xhrJson(url, params = {}, complete = undefined) { function xhrJson(url, params = {}, complete = undefined) {
return new Promise((resolve, reject) => return xhr.json(url, params, complete);
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);
}));
} }
/* common helpers not worthy of separate Dojo modules */ /* common helpers not worthy of separate Dojo modules */

View File

@ -16,7 +16,7 @@ Plugins.Af_Readability = {
Notify.progress("Loading, please wait..."); 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) { if (content && reply.content) {
content.setAttribute(self.orig_attr_name, content.innerHTML); content.setAttribute(self.orig_attr_name, content.innerHTML);

View File

@ -152,7 +152,7 @@ class Mail extends Plugin {
<script type='dojo/method' event='onSubmit' args='evt'> <script type='dojo/method' event='onSubmit' args='evt'>
evt.preventDefault(); evt.preventDefault();
if (this.validate()) { if (this.validate()) {
xhrJson("backend.php", this.getValues(), (reply) => { xhr.json("backend.php", this.getValues(), (reply) => {
if (reply && reply.error) if (reply && reply.error)
Notify.error(reply.error); Notify.error(reply.error);
else else

View File

@ -17,7 +17,7 @@ Plugins.Mail = {
title: __("Forward article by email"), title: __("Forward article by email"),
execute: function () { execute: function () {
if (this.validate()) { if (this.validate()) {
xhrJson("backend.php", this.attr('value'), (reply) => { xhr.json("backend.php", this.attr('value'), (reply) => {
if (reply) { if (reply) {
const error = reply['error']; const error = reply['error'];

View File

@ -8,7 +8,7 @@ Plugins.Note = {
if (this.validate()) { if (this.validate()) {
Notify.progress("Saving article note...", true); Notify.progress("Saving article note...", true);
xhrJson("backend.php", this.attr('value'), (reply) => { xhr.json("backend.php", this.attr('value'), (reply) => {
Notify.close(); Notify.close();
dialog.hide(); dialog.hide();

View File

@ -10,7 +10,7 @@ Plugins.Share = {
Notify.progress("Trying to change URL...", true); Notify.progress("Trying to change URL...", true);
xhrJson("backend.php", App.getPhArgs("share", "newkey", {id: id}), (reply) => { xhr.json("backend.php", App.getPhArgs("share", "newkey", {id: id}), (reply) => {
if (reply) { if (reply) {
const new_link = reply.link; const new_link = reply.link;
const target = dialog.domNode.querySelector(".target-url"); const target = dialog.domNode.querySelector(".target-url");