migrate xhrJson invocations to the new helper
This commit is contained in:
parent
dba6dce3b3
commit
6b43b788d9
|
@ -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');
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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(", "))
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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', `
|
||||
<div dojoType='fox.Toolbar'>
|
||||
<div dojoType='fox.form.DropDownButton'>
|
||||
|
@ -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"),
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
22
js/common.js
22
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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -152,7 +152,7 @@ class Mail extends Plugin {
|
|||
<script type='dojo/method' event='onSubmit' args='evt'>
|
||||
evt.preventDefault();
|
||||
if (this.validate()) {
|
||||
xhrJson("backend.php", this.getValues(), (reply) => {
|
||||
xhr.json("backend.php", this.getValues(), (reply) => {
|
||||
if (reply && reply.error)
|
||||
Notify.error(reply.error);
|
||||
else
|
||||
|
|
|
@ -17,7 +17,7 @@ Plugins.Mail = {
|
|||
title: __("Forward article by email"),
|
||||
execute: function () {
|
||||
if (this.validate()) {
|
||||
xhrJson("backend.php", this.attr('value'), (reply) => {
|
||||
xhr.json("backend.php", this.attr('value'), (reply) => {
|
||||
if (reply) {
|
||||
const error = reply['error'];
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ Plugins.Note = {
|
|||
if (this.validate()) {
|
||||
Notify.progress("Saving article note...", true);
|
||||
|
||||
xhrJson("backend.php", this.attr('value'), (reply) => {
|
||||
xhr.json("backend.php", this.attr('value'), (reply) => {
|
||||
Notify.close();
|
||||
dialog.hide();
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ Plugins.Share = {
|
|||
|
||||
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) {
|
||||
const new_link = reply.link;
|
||||
const target = dialog.domNode.querySelector(".target-url");
|
||||
|
|
Loading…
Reference in New Issue