[IMP] rename Session to Connection and create one at initialisation

bzr revid: chs@openerp.com-20111027153132-qoj0fiwoj813gsda
This commit is contained in:
Christophe Simonis
2011-10-27 17:31:32 +02:00
parent 9d4602fcb8
commit 6f899d86c0
4 changed files with 45 additions and 50 deletions
+24 -1
View File
@@ -21,7 +21,16 @@
*
* @param {Array} modules list of modules to initialize
*/
init: function(modules) {
init: function(modules, connection, callback) {
if (/^(function|undefined)$/.test(typeof connection)) {
callback = connection;
connection = {
host: document.location.protocol + '//' + document.location.host,
};
}
var new_instance = {
// links to the global openerp
_openerp: openerp,
@@ -39,6 +48,20 @@
for(var i=0; i < modules.length; i++) {
openerp[modules[i]](new_instance);
}
new_instance.connector = new new_instance.web.Connection(connection.host);
if (connection.login) {
new_instance.connector.login(connection.database, connection.login, connection.password, function() {
if (callback) {
callback(new_instance);
}
});
} else {
if (callback) {
callback(new_instance);
}
}
return new_instance;
}
};
+3 -5
View File
@@ -136,10 +136,9 @@ openerp.web.Dialog = openerp.web.OldWidget.extend(/** @lends openerp.web.Dialog#
}
});
openerp.web.CrashManager = openerp.web.SessionAware.extend({
init: function(parent) {
this._super((parent || {}).session);
this.session.on_rpc_error.add(this.on_rpc_error);
openerp.web.CrashManager = openerp.web.CallbackEnabled.extend({
init: function() {
openerp.connector.on_rpc_error.add(this.on_rpc_error);
},
on_rpc_error: function(error) {
this.error = error;
@@ -951,7 +950,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
this.$element.html(QWeb.render("Interface", params));
this.notification = new openerp.web.Notification();
this.session = new openerp.web.Session();
this.loading = new openerp.web.Loading(this,"oe_loading");
this.crashmanager = new openerp.web.CrashManager(this);
+10 -40
View File
@@ -237,8 +237,8 @@ openerp.web.Registry = openerp.web.Class.extend( /** @lends openerp.web.Registry
* registry was created.
*
* An object path is simply a dotted name from the openerp root to the
* object pointed to (e.g. ``"openerp.web.Session"`` for an OpenERP
* session object).
* object pointed to (e.g. ``"openerp.web.Connection"`` for an OpenERP
* connection object).
*
* @constructs openerp.web.Registry
* @param {Object} mapping a mapping of keys to object-paths
@@ -338,9 +338,9 @@ openerp.web.CallbackEnabled = openerp.web.Class.extend(/** @lends openerp.web.Ca
}
});
openerp.web.Session = openerp.web.CallbackEnabled.extend( /** @lends openerp.web.Session# */{
openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.web.Connection# */{
/**
* @constructs openerp.web.Session
* @constructs openerp.web.Connection
* @extends openerp.web.CallbackEnabled
*
* @param {String} [server] JSON-RPC endpoint hostname
@@ -490,6 +490,7 @@ openerp.web.Session = openerp.web.CallbackEnabled.extend( /** @lends openerp.web
return true;
}).then(success_callback);
},
login: function() { this.session_login.apply(this, arguments); },
/**
* Reloads uid and session_id from local storage, if they exist
*/
@@ -716,36 +717,6 @@ openerp.web.Session = openerp.web.CallbackEnabled.extend( /** @lends openerp.web
}
});
openerp.web.SessionAware = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.SessionAware# */{
/**
* Utility class that any class is allowed to extend to easy common manipulations.
*
* It provides rpc calls, callback on all methods preceded by "on_" or "do_" and a
* logging facility.
*
* @constructs openerp.web.SessionAware
* @extends openerp.web.CallbackEnabled
*
* @param {openerp.web.Session} session
*/
init: function(session) {
this._super();
this.session = session;
},
/**
* Performs a JSON-RPC call
*
* @param {String} url endpoint url
* @param {Object} data RPC parameters
* @param {Function} success RPC call success callback
* @param {Function} error RPC call error callback
* @returns {jQuery.Deferred} deferred object for the RPC call
*/
rpc: function(url, data, success, error) {
return this.session.rpc(url, data, success, error);
}
});
/**
* Base class for all visual components. Provides a lot of functionalities helpful
* for the management of a part of the DOM.
@@ -756,8 +727,6 @@ openerp.web.SessionAware = openerp.web.CallbackEnabled.extend(/** @lends openerp
* destroyed too).
* - Insertion in DOM.
*
* Widget also extends SessionAware for ease of use.
*
* Guide to create implementations of the Widget class:
* ==============================================
*
@@ -798,7 +767,7 @@ openerp.web.SessionAware = openerp.web.CallbackEnabled.extend(/** @lends openerp
*
* That will kill the widget in a clean way and erase its content from the dom.
*/
openerp.web.Widget = openerp.web.SessionAware.extend(/** @lends openerp.web.Widget# */{
openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.Widget# */{
/**
* The name of the QWeb template that will be used for rendering. Must be
* redefined in subclasses or the default render() method can not be used.
@@ -817,7 +786,7 @@ openerp.web.Widget = openerp.web.SessionAware.extend(/** @lends openerp.web.Widg
* Construct the widget and set its parent if a parent is given.
*
* @constructs openerp.web.Widget
* @extends openerp.web.SessionAware
* @extends openerp.web.CallbackEnabled
*
* @param {openerp.web.Widget} parent Binds the current instance to the given Widget instance.
* When that widget is destroyed by calling stop(), the current instance will be
@@ -828,7 +797,8 @@ openerp.web.Widget = openerp.web.SessionAware.extend(/** @lends openerp.web.Widg
* for new components this argument should not be provided any more.
*/
init: function(parent, /** @deprecated */ element_id) {
this._super((parent || {}).session);
this._super();
this.session = openerp.connector;
// if given an element_id, try to get the associated DOM element and save
// a reference in this.$element. Else just generate a unique identifier.
this.element_id = element_id;
@@ -967,7 +937,7 @@ openerp.web.Widget = openerp.web.SessionAware.extend(/** @lends openerp.web.Widg
rpc: function(url, data, success, error) {
var def = $.Deferred().then(success, error);
var self = this;
this._super(url, data). then(function() {
openerp.connector.rpc(url, data). then(function() {
if (!self.widget_is_stopped)
def.resolve.apply(def, arguments);
}, function() {
+8 -4
View File
@@ -32,7 +32,7 @@ openerp.web.DataGroup = openerp.web.Widget.extend( /** @lends openerp.web.DataG
* @constructs openerp.web.DataGroup
* @extends openerp.web.Widget
*
* @param {openerp.web.Session} session Current OpenERP session
* @param {openerp.web.Widget} parent widget
* @param {String} model name of the model managed by this DataGroup
* @param {Array} domain search domain for this DataGroup
* @param {Object} context context of the DataGroup's searches
@@ -785,11 +785,15 @@ openerp.web.ProxyDataSet = openerp.web.DataSetSearch.extend({
on_unlink: function(ids) {}
});
openerp.web.Model = openerp.web.SessionAware.extend({
init: function(session, model_name) {
this._super(session);
openerp.web.Model = openerp.web.CallbackEnabled.extend({
init: function(_, model_name) {
this._super();
this.model_name = model_name;
},
rpc: function() {
var c = openerp.connector;
return c.rpc.apply(c, arguments);
},
get_func: function(method_name) {
var self = this;
return function() {