diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/PrefUsers.js | 27 | ||||
-rwxr-xr-x | js/common.js | 15 |
2 files changed, 29 insertions, 13 deletions
diff --git a/js/PrefUsers.js b/js/PrefUsers.js index 3eb83b02a..109782f6c 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -1,16 +1,18 @@ 'use strict' -/* global __ */ -/* global xhrPost, xhr, dijit, Notify, Tables, App, fox */ +/* global __, xhr, dijit, Notify, Tables, App, fox */ const Users = { reload: function(sort) { - const user_search = App.byId("user_search"); - const search = user_search ? user_search.value : ""; + return new Promise((resolve, reject) => { + const user_search = App.byId("user_search"); + const search = user_search ? user_search.value : ""; - xhr.post("backend.php", { op: "pref-users", sort: sort, search: search }, (reply) => { - dijit.byId('usersTab').attr('content', reply); - Notify.close(); + xhr.post("backend.php", { op: "pref-users", sort: sort, search: search }, (reply) => { + dijit.byId('usersTab').attr('content', reply); + Notify.close(); + resolve(); + }, (e) => { reject(e) }); }); }, add: function() { @@ -20,8 +22,9 @@ const Users = { Notify.progress("Adding user..."); xhr.post("backend.php", {op: "pref-users", method: "add", login: login}, (reply) => { - alert(reply); - Users.reload(); + Users.reload().then(() => { + Notify.info(reply); + }) }); } @@ -38,9 +41,11 @@ const Users = { if (this.validate()) { Notify.progress("Saving data...", true); - xhr.post("backend.php", this.attr('value'), () => { + xhr.post("backend.php", this.attr('value'), (reply) => { dialog.hide(); - Users.reload(); + Users.reload().then(() => { + Notify.info(reply); + }); }); } }, diff --git a/js/common.js b/js/common.js index 1544e6d0b..59231010e 100755 --- a/js/common.js +++ b/js/common.js @@ -154,7 +154,7 @@ String.prototype.stripTags = function() { /* exported xhr */ const xhr = { - post: function(url, params = {}, complete = undefined) { + post: function(url, params = {}, complete = undefined, failed = undefined) { console.log('xhr.post', '>>>', params); return new Promise((resolve, reject) => { @@ -165,6 +165,9 @@ const xhr = { postData: dojo.objectToQuery(params), handleAs: "text", error: function(error) { + if (failed != undefined) + failed(error); + reject(error); }, load: function(data, ioargs) { @@ -178,7 +181,7 @@ const xhr = { ); }); }, - json: function(url, params = {}, complete = undefined) { + json: function(url, params = {}, complete = undefined, failed = undefined) { return new Promise((resolve, reject) => this.post(url, params).then((data) => { let obj = null; @@ -187,6 +190,10 @@ const xhr = { obj = JSON.parse(data); } catch (e) { console.error("xhr.json", e, xhr); + + if (failed != undefined) + failed(e); + reject(e); } @@ -194,6 +201,10 @@ const xhr = { if (obj && typeof App != "undefined") if (!App.handleRpcJson(obj)) { + + if (failed != undefined) + failed(obj); + reject(obj); return; } |