[IMP] Connection minor changes
authorAntony Lesuisse <al@openerp.com>
Fri, 16 Dec 2011 15:05:41 +0000 (16:05 +0100)
committerAntony Lesuisse <al@openerp.com>
Fri, 16 Dec 2011 15:05:41 +0000 (16:05 +0100)
bzr revid: al@openerp.com-20111216150541-ogukhprtnkh7raht

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

index e7ec69c..412e74a 100644 (file)
@@ -598,7 +598,7 @@ openerp.web.Login =  openerp.web.Widget.extend(/** @lends openerp.web.Login# */{
     do_login: function (db, login, password) {
         var self = this;
         this.session.session_authenticate(db, login, password).then(function() {
-            if(self.session.is_valid()) {
+            if(self.session.session_is_valid()) {
                 if (self.has_local_storage) {
                     if(self.remember_credentials) {
                         localStorage.setItem('last_db_login_success', db);
index 7f2775c..f63c975 100644 (file)
@@ -360,18 +360,13 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
         // TODO: session store in cookie should be optional
         this.name = openerp._session_id;
     },
-    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
-
+    bind: function(origin) {
+        var window_origin = location.protocol+"//"+location.host;
+        this.origin = origin ? _.str.rtrim(origin,'/') : window_origin;
+        this.prefix = this.origin;
+        this.server = this.origin; // keep chs happy
+        openerp.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;
@@ -385,14 +380,6 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
         this.ready = $.Deferred();
         return this.session_init();
     },
-
-    /**
-     * Called when a rpc call fail due to an invalid session.
-     * By default, it's a noop
-     */
-    on_session_invalid: function(retry_callback) {
-    },
-
     /**
      * Executes an RPC call, registering the provided callbacks.
      *
@@ -566,11 +553,9 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
             return deferred;
         });
     },
-
-    is_valid: function() {
+    session_is_valid: function() {
         return !!this.uid;
     },
-
     /**
      * The session is validated either by login or by restoration of a previous session
      */
@@ -596,6 +581,12 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
         window.location.reload();
     },
     /**
+     * Called when a rpc call fail due to an invalid session.
+     * By default, it's a noop
+     */
+    on_session_invalid: function(retry_callback) {
+    },
+    /**
      * Fetches a cookie stored by an openerp session
      *
      * @private