[IMP] connection bind via direct server (no split between host and protocol)
authorChristophe Simonis <chs@openerp.com>
Fri, 16 Dec 2011 14:03:16 +0000 (15:03 +0100)
committerChristophe Simonis <chs@openerp.com>
Fri, 16 Dec 2011 14:03:16 +0000 (15:03 +0100)
bzr revid: chs@openerp.com-20111216140316-m4adjubcs8e46dli

addons/web/static/src/js/core.js

index 3122d37..aa29373 100644 (file)
@@ -355,18 +355,23 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
      */
     init: function() {
         this._super();
+        this.server = null;
+        this.debug = ($.deparam($.param.querystring()).debug != undefined);
         // TODO: session store in cookie should be optional
         this.name = openerp._session_id;
     },
-    bind: function(host, protocol) {
-        var self = this;
-        this.host = (host == undefined) ? location.host : host;
-        this.protocol = (protocol == undefined) ? location.protocol : protocol;
-        this.prefix = this.protocol + '//' + this.host;
-        openerp.web.qweb.default_dict['_s'] = this.prefix
-        this.rpc_mode = (this.host == location.host) ? "json" : "jsonp";
-        this.rpc_function = (this.host == location.host) ? this.rpc_json : this.rpc_jsonp;
-        this.debug = (window.location.search.indexOf('?debug') !== -1);
+    bind: function(server) {
+        if (this.server) {
+            throw new Error("Connection already bound to " + this.server);
+        } 
+        
+        var hostname = _.str.sprintf('%s//%s', location.protocol, location.host);
+        this.server = _.str.rtrim((!server) ? hostname : server, '/');
+        openerp.web.qweb.default_dict['_s'] = this.server;
+        this.rpc_function = (this.server == hostname) ? this.rpc_json : this.rpc_jsonp;
+
+        this.prefix = this.server;  // make al happy
+
         this.session_id = false;
         this.uid = false;
         this.username = false;