summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorMartin Geubelle <mge@odoo.com>2019-01-10 13:20:18 +0000
committerMartin Geubelle <mge@odoo.com>2019-02-13 09:38:30 +0000
commit016f9612ba4688fb940910c74f13f9cbd5b115e0 (patch)
treedfb29d48c507aac0e39ff1f12ff12746579cf6c7 /addons/web/static/src/js
parent31664422c11ab1e9c34ad6b2eb1dfba2af72e359 (diff)
[REF] web: clean ajax and session
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/core/ajax.js8
-rw-r--r--addons/web/static/src/js/core/session.js96
2 files changed, 21 insertions, 83 deletions
diff --git a/addons/web/static/src/js/core/ajax.js b/addons/web/static/src/js/core/ajax.js
index 1821d5a3be4..67b47add1e2 100644
--- a/addons/web/static/src/js/core/ajax.js
+++ b/addons/web/static/src/js/core/ajax.js
@@ -113,8 +113,6 @@ function jsonpRpc(url, fct_name, params, settings) {
var payload_url = $.param({r:payload_str});
var force2step = settings.force2step || false;
delete settings.force2step;
- var session_id = settings.session_id || null;
- delete settings.session_id;
if (payload_url.length < 2000 && ! force2step) {
return $.ajax(url, _.extend({}, settings, {
url: url,
@@ -122,10 +120,10 @@ function jsonpRpc(url, fct_name, params, settings) {
jsonp: 'jsonp',
type: 'GET',
cache: false,
- data: {r: payload_str, session_id: session_id}
+ data: {r: payload_str}
}));
} else {
- var args = {session_id: session_id, id: data.id};
+ var args = {id: data.id};
var ifid = _.uniqueId('oe_rpc_iframe');
var html = "<iframe src='javascript:false;' name='" + ifid + "' id='" + ifid + "' style='display:none'></iframe>";
var $iframe = $(html);
@@ -156,7 +154,7 @@ function jsonpRpc(url, fct_name, params, settings) {
jsonp: 'jsonp',
type: 'GET',
cache: false,
- data: {session_id: session_id, id: data.id}
+ data: {id: data.id}
}).always(function() {
cleanUp();
}).done(function() {
diff --git a/addons/web/static/src/js/core/session.js b/addons/web/static/src/js/core/session.js
index 968496c2a6d..a9479d5a690 100644
--- a/addons/web/static/src/js/core/session.js
+++ b/addons/web/static/src/js/core/session.js
@@ -22,11 +22,8 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
or `null` if the server to contact is the origin server.
@param {Dict} options A dictionary that can contain the following options:
- * "override_session": Default to false. If true, the current session object will
- not try to re-use a previously created session id stored in a cookie.
- * "session_id": Default to null. If specified, the specified session_id will be used
- by this session object. Specifying this option automatically implies that the option
- "override_session" is set to true.
+ * "modules"
+ * "use_cors"
*/
init: function (parent, origin, options) {
mixins.EventDispatcherMixin.init.call(this);
@@ -34,8 +31,6 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
options = options || {};
this.module_list = (options.modules && options.modules.slice()) || (window.odoo._modules && window.odoo._modules.slice()) || [];
this.server = null;
- this.session_id = options.session_id || null;
- this.override_session = options.override_session || !!options.session_id || false;
this.avoid_recursion = false;
this.use_cors = options.use_cors || false;
this.setup(origin);
@@ -61,7 +56,6 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
this.origin = origin;
this.prefix = this.origin;
this.server = this.origin; // keep chs happy
- this.origin_server = this.origin === window_origin;
options = options || {};
if ('use_cors' in options) {
this.use_cors = options.use_cors;
@@ -275,9 +269,6 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
return this.currencies[currency_id];
},
get_file: function (options) {
- if (this.override_session){
- options.data.session_id = this.session_id;
- }
options.session = this;
return ajax.get_file(options);
},
@@ -292,25 +283,6 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
_.extend(this, result);
return $.when();
},
- check_session_id: function () {
- var self = this;
- if (this.avoid_recursion)
- return $.when();
- if (this.session_id)
- return $.when(); // we already have the session id
- if (!this.use_cors && (this.override_session || ! this.origin_server)) {
- // If we don't use the origin server we consider we should always create a new session.
- // Even if some browsers could support cookies when using jsonp that behavior is
- // not consistent and the browser creators are tending to removing that feature.
- this.avoid_recursion = true;
- return this.rpc("/gen_session_id", {}).then(function (result) {
- self.session_id = result;
- }).always(function () {
- self.avoid_recursion = false;
- });
- }
- return $.when();
- },
/**
* Executes an RPC call, registering the provided callbacks.
*
@@ -331,57 +303,25 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
options.headers["X-Debug-Mode"] = $.deparam($.param.querystring()).debug;
}
- var deferred = self.check_session_id();
- var aborted = false;
- var xhrDef;
- deferred.abort = function () {
- if (xhrDef) {
- xhrDef.abort();
- } else {
- aborted = true;
- }
- };
-
- var promise = deferred.then(function () {
- if (aborted) {
- var def = $.Deferred().reject({message: "XmlHttpRequestError abort"}, $.Event('abort'));
- def.abort = function () {};
- return def;
- }
- // TODO: remove
- if (! _.isString(url)) {
- _.extend(options, url);
- url = url.url;
- }
- var fct;
- if (self.origin_server) {
- fct = ajax.jsonRpc;
- if (self.override_session) {
- options.headers["X-Openerp-Session-Id"] = self.session_id || '';
- }
- } else if (self.use_cors) {
- fct = ajax.jsonRpc;
- url = self.url(url, null);
- options.session_id = self.session_id || '';
- if (self.override_session) {
- options.headers["X-Openerp-Session-Id"] = self.session_id || '';
- }
- } else {
- fct = ajax.jsonpRpc;
- url = self.url(url, null);
- options.session_id = self.session_id || '';
- }
- xhrDef = fct(url, "call", params, options);
- return xhrDef;
- });
-
- promise.abort = deferred.abort;
- return promise;
+ // TODO: remove
+ if (! _.isString(url)) {
+ _.extend(options, url);
+ url = url.url;
+ }
+ var fct;
+ if (self.origin_server) {
+ fct = ajax.jsonRpc;
+ } else if (self.use_cors) {
+ fct = ajax.jsonRpc;
+ url = self.url(url, null);
+ } else {
+ fct = ajax.jsonpRpc;
+ url = self.url(url, null);
+ }
+ return fct(url, "call", params, options);
},
url: function (path, params) {
params = _.extend(params || {});
- if (this.override_session || (! this.origin_server))
- params.session_id = this.session_id;
var qs = $.param(params);
if (qs.length > 0)
qs = "?" + qs;