From a8fe471b36a40272569e01b870665a38017c25e7 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Thu, 26 Apr 2012 17:24:41 +0200 Subject: [PATCH 1/5] [IMP] corelib.js: Create a new object "BaseConnection", this object does not handle the session. It's the job of the Connection object. bzr revid: stw@openerp.com-20120426152441-0laj03nnl67jvj68 --- addons/web/static/src/js/corelib.js | 65 +++++++++++++++++++---------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index 32e35575933..05a312cac6f 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -865,9 +865,9 @@ instance.web.Registry = instance.web.Class.extend({ } }); -instance.web.Connection = instance.web.CallbackEnabled.extend( /** @lends instance.web.Connection# */{ +instance.web.BaseConnection = instance.web.CallbackEnabled.extend( /** @lends instance.web.BaseConnection# */{ /** - * @constructs instance.web.Connection + * @constructs instance.web.BaseConnection * @extends instance.web.CallbackEnabled * * @param {String} [server] JSON-RPC endpoint hostname @@ -877,32 +877,20 @@ instance.web.Connection = instance.web.CallbackEnabled.extend( /** @lends instan this._super(); this.server = null; this.debug = ($.deparam($.param.querystring()).debug != undefined); - // TODO: session store in cookie should be optional - this.name = instance._session_id; - this.qweb_mutex = new $.Mutex(); }, - session_bind: function(origin) { + bind: function(origin) { var window_origin = location.protocol+"//"+location.host, self=this; this.origin = origin ? _.str.rtrim(origin,'/') : window_origin; this.prefix = this.origin; this.server = this.origin; // keep chs happy - instance.web.qweb.default_dict['_s'] = this.origin; this.rpc_function = (this.origin == window_origin) ? this.rpc_json : this.rpc_jsonp; - this.session_id = false; - this.uid = false; - this.username = false; - this.user_context= {}; - this.db = false; - this.openerp_entreprise = false; - this.module_list = instance._modules.slice(); - this.module_loaded = {}; - _(this.module_list).each(function (mod) { - self.module_loaded[mod] = true; - }); - this.context = {}; - this.shortcuts = []; - this.active_id = null; - return this.session_init(); + return this.on_bind(); + }, + on_bind: function() { + // FIXME + var deferred = $.Deferred(); + deferred.resolve(); + return deferred; }, test_eval_get_context: function () { var asJS = function (arg) { @@ -1359,6 +1347,39 @@ instance.web.Connection = instance.web.CallbackEnabled.extend( /** @lends instan }, on_rpc_error: function(error) { }, +}); + +instance.web.Connection = instance.web.BaseConnection.extend( /** @lends instance.web.Connection# */{ + init: function() { + this._super.apply(this, arguments); + // TODO: session store in cookie should be optional + this.name = instance._session_id; + this.qweb_mutex = new $.Mutex(); + }, + + on_bind: function() { + var self = this; + instance.web.qweb.default_dict['_s'] = this.origin; + this.session_id = false; + this.uid = false; + this.username = false; + this.user_context= {}; + this.db = false; + this.openerp_entreprise = false; + this.module_list = instance._modules.slice(); + this.module_loaded = {}; + _(this.module_list).each(function (mod) { + self.module_loaded[mod] = true; + }); + this.context = {}; + this.shortcuts = []; + this.active_id = null; + return this.session_init(); + }, + + session_bind: function(origin) { + return this.bind(origin); + }, /** * Init a session, reloads from cookie, if it exists */ From 4ea7057b5dd24559cd20da417d6cef59a7e8447b Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 27 Apr 2012 00:08:18 +0200 Subject: [PATCH 2/5] [FIX] rename intro JsonRPC and session_id cleanup bzr revid: al@openerp.com-20120426220818-yvsr4zwlj824ql1q --- addons/web/static/src/js/corelib.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index 05a312cac6f..e3842d54def 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -865,9 +865,9 @@ instance.web.Registry = instance.web.Class.extend({ } }); -instance.web.BaseConnection = instance.web.CallbackEnabled.extend( /** @lends instance.web.BaseConnection# */{ +instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ /** - * @constructs instance.web.BaseConnection + * @constructs instance.web.JsonRPC * @extends instance.web.CallbackEnabled * * @param {String} [server] JSON-RPC endpoint hostname @@ -1199,7 +1199,6 @@ instance.web.BaseConnection = instance.web.CallbackEnabled.extend( /** @lends in url = { url: url }; } // Construct a JSON-RPC2 request, method is currently unused - params.session_id = this.session_id; if (this.debug) params.debug = 1; var payload = { @@ -1349,14 +1348,13 @@ instance.web.BaseConnection = instance.web.CallbackEnabled.extend( /** @lends in }, }); -instance.web.Connection = instance.web.BaseConnection.extend( /** @lends instance.web.Connection# */{ +instance.web.Connection = instance.web.JsonRPC.extend( /** @lends instance.web.Connection# */{ init: function() { this._super.apply(this, arguments); // TODO: session store in cookie should be optional this.name = instance._session_id; this.qweb_mutex = new $.Mutex(); }, - on_bind: function() { var self = this; instance.web.qweb.default_dict['_s'] = this.origin; @@ -1376,7 +1374,10 @@ instance.web.Connection = instance.web.BaseConnection.extend( /** @lends instanc this.active_id = null; return this.session_init(); }, - + rpc: function(url, params, success_callback, error_callback) { + params.session_id = this.session_id; + return this._super(url, params, success_callback, error_callback); + }, session_bind: function(origin) { return this.bind(origin); }, @@ -1787,6 +1788,7 @@ instance.web.OldWidget = instance.web.Widget.extend({ } }); + } // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: From 3bf883c95e3a5e1698a0016440793ecd42d57927 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 27 Apr 2012 00:17:32 +0200 Subject: [PATCH 3/5] [FIX] cleanup remove some useless chspaghetti bzr revid: al@openerp.com-20120426221732-qh642zduso1kl8fl --- addons/web/static/src/js/corelib.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index e3842d54def..ba37451700b 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -884,13 +884,6 @@ instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ this.prefix = this.origin; this.server = this.origin; // keep chs happy this.rpc_function = (this.origin == window_origin) ? this.rpc_json : this.rpc_jsonp; - return this.on_bind(); - }, - on_bind: function() { - // FIXME - var deferred = $.Deferred(); - deferred.resolve(); - return deferred; }, test_eval_get_context: function () { var asJS = function (arg) { @@ -1355,8 +1348,16 @@ instance.web.Connection = instance.web.JsonRPC.extend( /** @lends instance.web.C this.name = instance._session_id; this.qweb_mutex = new $.Mutex(); }, - on_bind: function() { + rpc: function(url, params, success_callback, error_callback) { + params.session_id = this.session_id; + return this._super(url, params, success_callback, error_callback); + }, + /** + * Setup a sessionm + */ + session_bind: function(origin) { var self = this; + this.bind(origin); instance.web.qweb.default_dict['_s'] = this.origin; this.session_id = false; this.uid = false; @@ -1374,13 +1375,6 @@ instance.web.Connection = instance.web.JsonRPC.extend( /** @lends instance.web.C this.active_id = null; return this.session_init(); }, - rpc: function(url, params, success_callback, error_callback) { - params.session_id = this.session_id; - return this._super(url, params, success_callback, error_callback); - }, - session_bind: function(origin) { - return this.bind(origin); - }, /** * Init a session, reloads from cookie, if it exists */ From fb83a403c4b47ce34a8d34552f53eed522f798f2 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 27 Apr 2012 00:25:52 +0200 Subject: [PATCH 4/5] rename Connection into Session, now that we use instance bzr revid: al@openerp.com-20120426222552-rqm974o8c9v1s4lk --- addons/web/static/src/js/boot.js | 12 ++++++------ addons/web/static/src/js/corelib.js | 4 ++-- addons/web/static/src/js/coresetup.js | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js index 1251975f41c..29d953aadd8 100644 --- a/addons/web/static/src/js/boot.js +++ b/addons/web/static/src/js/boot.js @@ -14,8 +14,8 @@ var openerp = this.openerp = { // Per session namespace // openerp. will map to - // openerp.sessions.sessionname. using a closure - sessions: {}, + // openerp.instances.sessionname. using a closure + instances: {}, /** * OpenERP instance constructor * @@ -23,19 +23,19 @@ */ init: function(modules) { // By default only web will be loaded, the rest will be by loaded - // by openerp.web.Connection on the first session_authenticate + // by openerp.web.Session on the first session_authenticate modules = modules || ["web"]; var new_instance = { // links to the global openerp _openerp: openerp, // this unique id will be replaced by hostname_databasename by - // openerp.web.Connection on the first connection - _session_id: "session" + session_counter++, + // openerp.web.Session on the first connection + _session_id: "instance" + session_counter++, _modules: modules, web: {}, web_mobile: {} }; - openerp.sessions[new_instance._session_id] = new_instance; + openerp.instances[new_instance._session_id] = new_instance; for(var i=0; i < modules.length; i++) { openerp[modules[i]](new_instance); } diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index ba37451700b..94aa82d6ddb 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -756,7 +756,7 @@ instance.web.Registry = instance.web.Class.extend({ * registry was created. * * An object path is simply a dotted name from the instance root to the - * object pointed to (e.g. ``"instance.web.Connection"`` for an OpenERP + * object pointed to (e.g. ``"instance.web.Session"`` for an OpenERP * connection object). * * @constructs instance.web.Registry @@ -1341,7 +1341,7 @@ instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ }, }); -instance.web.Connection = instance.web.JsonRPC.extend( /** @lends instance.web.Connection# */{ +instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Session# */{ init: function() { this._super.apply(this, arguments); // TODO: session store in cookie should be optional diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js index 86040302668..e2b06d0bbd3 100644 --- a/addons/web/static/src/js/coresetup.js +++ b/addons/web/static/src/js/coresetup.js @@ -98,8 +98,8 @@ $.Mutex = (function() { return Mutex; })(); -/** Setup default connection */ -instance.connection = new instance.web.Connection(); +/** Setup default session */ +instance.connection = new instance.web.Session(); instance.web.qweb.default_dict['__debug__'] = instance.connection.debug; $.async_when = function() { From f7e3de54834f7f83c5f6690608ecf01bbccf0337 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 27 Apr 2012 00:29:28 +0200 Subject: [PATCH 5/5] fix rename bind into setup to avoid collision with events bzr revid: al@openerp.com-20120426222928-vmzv2jcmaiic3ll4 --- addons/web/static/src/js/corelib.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index 94aa82d6ddb..4dea72bfc9c 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -878,7 +878,7 @@ instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ this.server = null; this.debug = ($.deparam($.param.querystring()).debug != undefined); }, - bind: function(origin) { + setup: function(origin) { var window_origin = location.protocol+"//"+location.host, self=this; this.origin = origin ? _.str.rtrim(origin,'/') : window_origin; this.prefix = this.origin; @@ -1357,7 +1357,7 @@ instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Sess */ session_bind: function(origin) { var self = this; - this.bind(origin); + this.setup(origin); instance.web.qweb.default_dict['_s'] = this.origin; this.session_id = false; this.uid = false;