diff --git a/openerp/addons/base/static/src/js/apps.js b/openerp/addons/base/static/src/js/apps.js
index 343ca24f9ba..ab056ae2567 100644
--- a/openerp/addons/base/static/src/js/apps.js
+++ b/openerp/addons/base/static/src/js/apps.js
@@ -1,74 +1,10 @@
openerp.base = function(instance) {
- instance.base = {apps:{}};
+ instance.base.apps_remote = null;
+ instance.base.apps_client = null;
- instance.base.apps.remote_instance = null;
-
- instance.base.apps.get_client = function() {
- // return the client via a deferred, resolved or rejected depending if the remote host is available or not.
- var check_client_available = function(client) {
- var d = $.Deferred();
- var i = new Image();
- i.onerror = function() {
- d.reject(client);
- };
- i.onload = function() {
- client.session.session_bind(client.origin).then(function() {
- // check if client can authenticate
- client.authenticate().then(
- function() { /* done */
- d.resolve(client);
- }, function() { /* fail */
- if (client.login === 'anonymous') {
- d.reject(client);
- } else {
- sessionStorage.removeItem('apps.login');
- sessionStorage.removeItem('apps.access_token');
- client.bind(client.dbname, 'anonymous', 'anonymous');
- client.authenticate().then(
- function() { /* done */
- d.resolve(client);
- }, function() { /* fail */
- d.reject(client);
- });
- }
- });
- });
-
- };
- i.src = _.str.sprintf('%s/web/static/src/img/sep-a.gif', client.origin);
- return d.promise();
- };
- if (instance.base.apps._client) {
- return check_client_available(instance.base.apps._client);
- } else {
- var ICP = new instance.web.Model('ir.config_parameter');
- return ICP.call('get_param', ['apps.server', 'https://apps.openerp.com/apps']).then(function(u) {
- var link = $(_.str.sprintf('', u))[0];
- var host = _.str.sprintf('%s//%s', link.protocol, link.host);
- var dbname = link.pathname;
- if (dbname[0] === '/') {
- dbname = dbname.substr(1);
- }
-
- var login = (sessionStorage ? sessionStorage.getItem('apps.login') : null) || 'anonymous';
- var passwd = (sessionStorage ? sessionStorage.getItem('apps.access_token') : null) || 'anonymous';
-
- if (_.isNull(instance.base.apps.remote_instance)) {
- instance.base.apps.remote_instance = new openerp.init();
- }
- var client = new instance.base.apps.remote_instance.web.EmbeddedClient(null, host,
- dbname, login, passwd);
- instance.base.apps._client = client;
- return check_client_available(client);
- });
- }
-
- };
-
- instance.base.apps.Apps = instance.web.Widget.extend({
+ instance.base.Apps = instance.web.Widget.extend({
template: 'EmptyComponent',
-
remote_action_id: 'loempia.action_embed',
failback_action_id: 'base.open_module_tree',
@@ -83,11 +19,69 @@ openerp.base = function(instance) {
sessionStorage.setItem('apps.access_token', options.apps_access_token);
}
- this.params = options; // NOTE read by embedded client action
+ this.params = options; // NOTE read by embedded client action
+ },
+
+ get_client: function() {
+ // return the client via a deferred, resolved or rejected depending if the remote host is available or not.
+ var check_client_available = function(client) {
+ var d = $.Deferred();
+ var i = new Image();
+ i.onerror = function() {
+ d.reject(client);
+ };
+ i.onload = function() {
+ client.session.session_bind(client.origin).then(function() {
+ // check if client can authenticate
+ client.authenticate().then(
+ function() { /* done */
+ d.resolve(client);
+ }, function() { /* fail */
+ if (client.login === 'anonymous') {
+ d.reject(client);
+ } else {
+ sessionStorage.removeItem('apps.login');
+ sessionStorage.removeItem('apps.access_token');
+ client.bind_crendentials(client.dbname, 'anonymous', 'anonymous');
+ client.authenticate().then(
+ function() { /* done */
+ d.resolve(client);
+ }, function() { /* fail */
+ d.reject(client);
+ });
+ }
+ });
+ });
+
+ };
+ i.src = _.str.sprintf('%s/web/static/src/img/sep-a.gif', client.origin);
+ return d.promise();
+ };
+ if (instance.base.apps_client) {
+ return check_client_available(instance.base.apps_client);
+ } else {
+ var ICP = new instance.web.Model('ir.config_parameter');
+ return ICP.call('get_param', ['apps.server', 'https://apps.openerp.com/apps']).then(function(u) {
+ var link = $(_.str.sprintf('', u))[0];
+ var host = _.str.sprintf('%s//%s', link.protocol, link.host);
+ var dbname = link.pathname;
+ if (dbname[0] === '/') {
+ dbname = dbname.substr(1);
+ }
+ var login = (sessionStorage ? sessionStorage.getItem('apps.login') : null) || 'anonymous';
+ var passwd = (sessionStorage ? sessionStorage.getItem('apps.access_token') : null) || 'anonymous';
+ if (_.isNull(instance.base.apps_remote)) {
+ instance.base.apps_remote = new openerp.init();
+ }
+ var client = new instance.base.apps_remote.web.EmbeddedClient(null, host, dbname, login, passwd);
+ instance.base.apps_client = client;
+ return check_client_available(client);
+ });
+ }
},
clean: function() {
- instance.base.apps.get_client().always(function(client) { client.destroy(); });
+ self.get_client().always(function(client) { client.destroy(); });
},
destroy: function() {
@@ -97,7 +91,7 @@ openerp.base = function(instance) {
start: function() {
var self = this;
- return instance.base.apps.get_client().
+ return self.get_client().
done(function(client) {
client.replace(self.$el).
done(function() {
@@ -113,15 +107,13 @@ openerp.base = function(instance) {
});
});
},
-
- 0:0
});
- instance.base.apps.UpdatesAvailable = instance.base.apps.Apps.extend({
+ instance.base.AppsUpdates = instance.base.Apps.extend({
remote_action_id: 'loempia.action_embed_updates'
});
- instance.web.client_actions.add("apps", "instance.base.apps.Apps");
- instance.web.client_actions.add("apps.updates", "instance.base.apps.UpdatesAvailable");
+ instance.web.client_actions.add("apps", "instance.base.Apps");
+ instance.web.client_actions.add("apps.updates", "instance.base.AppsUpdates");
};