summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core/ajax.js
diff options
context:
space:
mode:
authorAdrien Dieudonne <adr@odoo.com>2018-06-13 15:21:24 +0200
committerAdrien Dieudonne <adr@odoo.com>2018-06-19 20:11:22 +0200
commitfc5d030ef2695f7d2daeb87db9697240be4b99d4 (patch)
tree3772caf00edbdbfd0a9c1882d7dfe6bd7b1072f4 /addons/web/static/src/js/core/ajax.js
parentd3e2cf5585db75de584683e48e47b92559a743c4 (diff)
[FIX] web: checks rpc responses in web.ajax
Before this commit, load_action and load_views were never resolved in case of internet connection loss. It's because the call is triggered by web.rpc direcly who uses ajax.rpc without any response check. Now the rpc response is checked in web.ajax. Thereby all responses are handled whether they come from session.rpc or rpc.query. Plus, it was not the responsibility of the session to check the rpc responses. Steps to reproduce the issue: (1) load_action: - Go to the app switcher for the first time - Force disconnected from the network -> No notification appears and the user aren't notify (2) load_views (mobile only): - Go to Sales -> Quotation (In this case, the first call is 'load_views' because we need to force to load some views like kanban view) - Force disconnected from the network -> No notification appears and the user aren't notify Note: It's now important to notify the user about connection loss because a recent improvement in mobile app replaces the 'retry screen' and lets the webclient handle connection issues by itself. The single odoo mobile app is supposed to work with all databases from 10.0.
Diffstat (limited to 'addons/web/static/src/js/core/ajax.js')
-rw-r--r--addons/web/static/src/js/core/ajax.js62
1 files changed, 57 insertions, 5 deletions
diff --git a/addons/web/static/src/js/core/ajax.js b/addons/web/static/src/js/core/ajax.js
index d6c67eacaec..fa79c65ef45 100644
--- a/addons/web/static/src/js/core/ajax.js
+++ b/addons/web/static/src/js/core/ajax.js
@@ -5,7 +5,15 @@ var core = require('web.core');
var utils = require('web.utils');
var time = require('web.time');
-function genericJsonRpc (fct_name, params, fct) {
+function genericJsonRpc (fct_name, params, settings, fct) {
+ var shadow = settings.shadow || false;
+ delete settings.shadow;
+ if (!shadow) {
+ core.bus.trigger('rpc_request');
+ }
+
+ var deferred = $.Deferred();
+
var data = {
jsonrpc: "2.0",
method: fct_name,
@@ -29,12 +37,56 @@ function genericJsonRpc (fct_name, params, fct) {
return def.reject.apply(def, ["communication"].concat(_.toArray(arguments)));
});
// FIXME: jsonp?
- result.abort = function () { if (xhr.abort) xhr.abort(); };
- return result;
+ deferred.abort = function () {
+ deferred.reject('communication', $.Event(), 'abort', 'abort');
+ if (xhr.abort) {
+ xhr.abort();
+ }
+ };
+
+ result.then(function (result) {
+ if (!shadow) {
+ core.bus.trigger('rpc_response');
+ }
+ deferred.resolve(result);
+ }, function (type, error, textStatus, errorThrown) {
+ if (type === "server") {
+ if (!shadow) {
+ core.bus.trigger('rpc_response');
+ }
+ if (error.code === 100) {
+ core.bus.trigger('invalidate_session');
+ }
+ deferred.reject(error, $.Event());
+ } else {
+ if (!shadow) {
+ core.bus.trigger('rpc_response_failed');
+ }
+ var nerror = {
+ code: -32098,
+ message: "XmlHttpRequestError " + errorThrown,
+ data: {
+ type: "xhr"+textStatus,
+ debug: error.responseText,
+ objects: [error, errorThrown]
+ },
+ };
+ deferred.reject(nerror, $.Event());
+ }
+ });
+ deferred.fail(function () { // Allow deferred user to disable rpc_error call in fail
+ deferred.fail(function (error, event) {
+ if (!event.isDefaultPrevented()) {
+ core.bus.trigger('rpc_error', error, event);
+ }
+ });
+ });
+ return deferred;
}
function jsonRpc(url, fct_name, params, settings) {
- return genericJsonRpc(fct_name, params, function(data) {
+ settings = settings || {};
+ return genericJsonRpc(fct_name, params, settings, function(data) {
return $.ajax(url, _.extend({}, settings, {
url: url,
dataType: 'json',
@@ -47,7 +99,7 @@ function jsonRpc(url, fct_name, params, settings) {
function jsonpRpc(url, fct_name, params, settings) {
settings = settings || {};
- return genericJsonRpc(fct_name, params, function(data) {
+ return genericJsonRpc(fct_name, params, settings, function(data) {
var payload_str = JSON.stringify(data, time.date_to_utc);
var payload_url = $.param({r:payload_str});
var force2step = settings.force2step || false;