[IMP] session_bind is done by openerp.init(). As result, Clients can have template like any other widget as qweb template are loaded. This make the code cleaner as show_common() does not return a deferred anymore.
bzr revid: chs@openerp.com-20120718131004-gvn63r3ihzxyzvy3
This commit is contained in:
parent
c7491d99d8
commit
5a918cf01d
|
@ -21,10 +21,10 @@
|
||||||
*
|
*
|
||||||
* @param {Array} modules list of modules to initialize
|
* @param {Array} modules list of modules to initialize
|
||||||
*/
|
*/
|
||||||
init: function(modules) {
|
init: function(modules, origin) {
|
||||||
// By default only web will be loaded, the rest will be by loaded
|
// By default only web will be loaded, the rest will be by loaded
|
||||||
// by openerp.web.Session on the first session_authenticate
|
// by openerp.web.Session on the first session_authenticate
|
||||||
modules = modules || ["web"];
|
modules = _.union(['web'], modules || []);
|
||||||
var new_instance = {
|
var new_instance = {
|
||||||
// links to the global openerp
|
// links to the global openerp
|
||||||
_openerp: openerp,
|
_openerp: openerp,
|
||||||
|
@ -39,6 +39,9 @@
|
||||||
for(var i=0; i < modules.length; i++) {
|
for(var i=0; i < modules.length; i++) {
|
||||||
openerp[modules[i]](new_instance,new_instance[modules[i]]);
|
openerp[modules[i]](new_instance,new_instance[modules[i]]);
|
||||||
}
|
}
|
||||||
|
new_instance.connection.synchronized_mode(function() {
|
||||||
|
new_instance.connection.session_bind(origin);
|
||||||
|
});
|
||||||
return new_instance;
|
return new_instance;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -857,31 +857,17 @@ instance.web.UserMenu = instance.web.Widget.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.web.Client = instance.web.Widget.extend({
|
instance.web.Client = instance.web.Widget.extend({
|
||||||
name: 'Client',
|
init: function(parent) {
|
||||||
init: function(parent, origin) {
|
|
||||||
if (instance.webclient) {
|
if (instance.webclient) {
|
||||||
throw new Error('Only one client per instance');
|
throw new Error('Only one client per instance');
|
||||||
}
|
}
|
||||||
instance.client = instance.webclient = this;
|
instance.client = instance.webclient = this;
|
||||||
this._super(parent);
|
this._super(parent);
|
||||||
this._origin = origin;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
start: function() {
|
start: function() {
|
||||||
var self = this;
|
this.bind_events();
|
||||||
return this.session.session_bind(this._origin).pipe(function() {
|
this.show_common();
|
||||||
// now that we are bound, we can render the real template
|
|
||||||
var $e = undefined;
|
|
||||||
try {
|
|
||||||
$e = $(QWeb.render(self.name, {}));
|
|
||||||
} catch (e) {}
|
|
||||||
if ($e) {
|
|
||||||
self.$element.append($e);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.bind_events();
|
|
||||||
return self.show_common();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
bind_events: function() {
|
bind_events: function() {
|
||||||
|
@ -928,7 +914,7 @@ instance.web.Client = instance.web.Widget.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.web.WebClient = instance.web.Client.extend({
|
instance.web.WebClient = instance.web.Client.extend({
|
||||||
name: 'WebClient',
|
template: 'WebClient',
|
||||||
init: function(parent) {
|
init: function(parent) {
|
||||||
this._super(parent);
|
this._super(parent);
|
||||||
this._current_state = null;
|
this._current_state = null;
|
||||||
|
@ -947,8 +933,7 @@ instance.web.WebClient = instance.web.Client.extend({
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return this._super().pipe(function() {
|
return $.when(this._super()).pipe(function() {
|
||||||
self.$element.addClass("openerp openerp_webclient_container");
|
|
||||||
if (jQuery.param !== undefined && jQuery.deparam(jQuery.param.querystring()).kitten !== undefined) {
|
if (jQuery.param !== undefined && jQuery.deparam(jQuery.param.querystring()).kitten !== undefined) {
|
||||||
$("body").addClass("kitten-mode-activated");
|
$("body").addClass("kitten-mode-activated");
|
||||||
if ($.blockUI) {
|
if ($.blockUI) {
|
||||||
|
@ -964,17 +949,16 @@ instance.web.WebClient = instance.web.Client.extend({
|
||||||
},
|
},
|
||||||
show_common: function() {
|
show_common: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return $.when(this._super()).pipe(function() {
|
this._super();
|
||||||
window.onerror = function (message, file, line) {
|
window.onerror = function (message, file, line) {
|
||||||
self.crashmanager.on_traceback({
|
self.crashmanager.on_traceback({
|
||||||
type: _t("Client Error"),
|
type: _t("Client Error"),
|
||||||
message: message,
|
message: message,
|
||||||
data: {debug: file + ':' + line}
|
data: {debug: file + ':' + line}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
self.login = new instance.web.Login(self);
|
self.login = new instance.web.Login(self);
|
||||||
self.login.on("login",self,self.show_application);
|
self.login.on("login",self,self.show_application);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
show_login: function() {
|
show_login: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -1097,9 +1081,9 @@ instance.web.WebClient = instance.web.Client.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.web.EmbeddedClient = instance.web.Client.extend({
|
instance.web.EmbeddedClient = instance.web.Client.extend({
|
||||||
name: 'EmbedClient',
|
template: 'EmbedClient',
|
||||||
init: function(parent, origin, dbname, login, key, action_id, options) {
|
init: function(parent, dbname, login, key, action_id, options) {
|
||||||
this._super(parent, origin);
|
this._super(parent);
|
||||||
|
|
||||||
this.dbname = dbname;
|
this.dbname = dbname;
|
||||||
this.login = login;
|
this.login = login;
|
||||||
|
@ -1110,6 +1094,7 @@ instance.web.EmbeddedClient = instance.web.Client.extend({
|
||||||
start: function() {
|
start: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return $.when(this._super()).pipe(function() {
|
return $.when(this._super()).pipe(function() {
|
||||||
|
return instance.connection.session_authenticate(self.dbname, self.login, self.key, true).pipe(function() {
|
||||||
return self.rpc("/web/action/load", { action_id: self.action_id }, function(result) {
|
return self.rpc("/web/action/load", { action_id: self.action_id }, function(result) {
|
||||||
var action = result.result;
|
var action = result.result;
|
||||||
action.flags = _.extend({
|
action.flags = _.extend({
|
||||||
|
@ -1120,22 +1105,14 @@ instance.web.EmbeddedClient = instance.web.Client.extend({
|
||||||
//pager : false
|
//pager : false
|
||||||
}, self.options, action.flags || {});
|
}, self.options, action.flags || {});
|
||||||
|
|
||||||
self.am.do_action(action);
|
self.action_manager.do_action(action);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
show_common: function() {
|
|
||||||
var self = this;
|
|
||||||
return $.when(this._super()).pipe(function() {
|
|
||||||
self.am = self.action_manager;
|
|
||||||
return instance.connection.session_authenticate(self.dbname, self.login, self.key, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
instance.web.embed = function (origin, dbname, login, key, action, options) {
|
instance.web.embed = function (dbname, login, key, action, options) {
|
||||||
$('head').append($('<link>', {
|
$('head').append($('<link>', {
|
||||||
'rel': 'stylesheet',
|
'rel': 'stylesheet',
|
||||||
'type': 'text/css',
|
'type': 'text/css',
|
||||||
|
@ -1146,7 +1123,7 @@ instance.web.embed = function (origin, dbname, login, key, action, options) {
|
||||||
var sc = document.getElementsByTagName('script');
|
var sc = document.getElementsByTagName('script');
|
||||||
currentScript = sc[sc.length-1];
|
currentScript = sc[sc.length-1];
|
||||||
}
|
}
|
||||||
var client = new instance.web.EmbeddedClient(null, origin, dbname, login, key, action, options);
|
var client = new instance.web.EmbeddedClient(null, dbname, login, key, action, options);
|
||||||
client.insertAfter(currentScript);
|
client.insertAfter(currentScript);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -371,6 +371,7 @@
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="WebClient">
|
<t t-name="WebClient">
|
||||||
|
<div class="openerp openerp_webclient_container">
|
||||||
<table class="oe_webclient">
|
<table class="oe_webclient">
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2" class="oe_topbar">
|
<td colspan="2" class="oe_topbar">
|
||||||
|
@ -394,10 +395,13 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="EmbedClient">
|
<t t-name="EmbedClient">
|
||||||
<div class="oe_application"></div>
|
<div class="openerp">
|
||||||
|
<div class="oe_application"></div>
|
||||||
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="ViewManager">
|
<t t-name="ViewManager">
|
||||||
|
|
Loading…
Reference in New Issue