2012-08-22 17:44:13 +00:00
|
|
|
openerp.base = function(instance) {
|
|
|
|
|
2012-11-08 16:46:11 +00:00
|
|
|
// FIXME do not work on safari
|
|
|
|
// TODO test on IE
|
|
|
|
// FIXME when apps server is not available, redirect to failback action but do not highligth the good menu
|
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
instance.base = {apps:{}};
|
2012-08-22 17:44:13 +00:00
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
instance.base.apps.remote_instance = null;
|
2012-09-21 14:30:57 +00:00
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
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() {
|
|
|
|
console.log('client is available', client);
|
2012-10-15 16:26:26 +00:00
|
|
|
|
2012-11-08 16:56:08 +00:00
|
|
|
client.session.session_bind(client.origin).done(function() {
|
2012-10-15 16:26:26 +00:00
|
|
|
// check if client can authenticate
|
|
|
|
client.authenticate().done(function() {
|
|
|
|
d.resolve(client);
|
|
|
|
}).fail(function() {
|
|
|
|
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().done(function() {
|
|
|
|
d.resolve(client);
|
|
|
|
}).fail(function() {
|
|
|
|
d.reject(client);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
};
|
|
|
|
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 {
|
2012-08-22 17:44:13 +00:00
|
|
|
//var DEFAULT_SERVER = 'http://apps.openerp.com/loempia'; // PROD
|
2012-10-19 12:29:06 +00:00
|
|
|
var DEFAULT_SERVER = 'http://apps.v7.openerp.com:8069/apps'; // TEST
|
2012-08-23 15:52:34 +00:00
|
|
|
//var DEFAULT_SERVER = 'http://localhost:8080/trunk_loempia7'; // DEV
|
2012-08-22 17:44:13 +00:00
|
|
|
var ICP = new instance.web.Model('ir.config_parameter');
|
2012-11-08 16:56:08 +00:00
|
|
|
return ICP.call('get_param', ['loempia.server', DEFAULT_SERVER]).then(function(u) {
|
2012-08-22 17:44:13 +00:00
|
|
|
var link = $(_.str.sprintf('<a href="%s"></a>', u))[0];
|
|
|
|
var host = _.str.sprintf('%s//%s', link.protocol, link.host);
|
|
|
|
var dbname = link.pathname.substr(1);
|
|
|
|
|
2012-10-11 09:22:49 +00:00
|
|
|
var login = (sessionStorage ? sessionStorage.getItem('apps.login') : null) || 'anonymous';
|
|
|
|
var passwd = (sessionStorage ? sessionStorage.getItem('apps.access_token') : null) || 'anonymous';
|
2012-08-22 17:44:13 +00:00
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
console.log('new client', client);
|
|
|
|
instance.base.apps._client = client;
|
|
|
|
return check_client_available(client);
|
2012-08-22 17:44:13 +00:00
|
|
|
});
|
2012-09-28 09:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
instance.base.apps.Apps = instance.web.Widget.extend({
|
|
|
|
template: 'EmptyComponent',
|
2012-09-28 12:58:40 +00:00
|
|
|
|
|
|
|
remote_action_id: 'loempia.action_embed',
|
|
|
|
failback_action_id: 'base.open_module_tree',
|
|
|
|
|
2012-11-06 17:06:57 +00:00
|
|
|
init: function(parent, action) {
|
|
|
|
this._super(parent, action);
|
2012-11-08 11:48:18 +00:00
|
|
|
var options = action.params || {};
|
2012-10-15 16:26:26 +00:00
|
|
|
|
2012-10-11 09:22:49 +00:00
|
|
|
if (options.apps_user) {
|
|
|
|
sessionStorage.setItem('apps.login', options.apps_user);
|
|
|
|
}
|
|
|
|
if (options.apps_access_token) {
|
|
|
|
sessionStorage.setItem('apps.access_token', options.apps_access_token);
|
|
|
|
}
|
|
|
|
|
2012-09-28 12:58:40 +00:00
|
|
|
this.params = options; // NOTE read by embedded client action
|
2012-08-22 17:44:13 +00:00
|
|
|
},
|
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
clean: function() {
|
|
|
|
instance.base.apps.get_client().always(function(client) { client.destroy(); });
|
2012-08-22 17:44:13 +00:00
|
|
|
},
|
2012-09-21 14:30:57 +00:00
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
destroy: function() {
|
|
|
|
this.clean();
|
|
|
|
return this._super();
|
|
|
|
},
|
2012-09-21 14:30:57 +00:00
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
console.time('apps');
|
|
|
|
console.time('client');
|
|
|
|
console.log('Apps.start()');
|
|
|
|
return instance.base.apps.get_client().
|
|
|
|
done(function(client) {
|
|
|
|
console.timeEnd('client');
|
|
|
|
client.replace(self.$el).
|
|
|
|
done(function() {
|
|
|
|
client.$el.removeClass('openerp');
|
|
|
|
console.timeEnd('apps');
|
2012-09-28 12:58:40 +00:00
|
|
|
client.do_action(self.remote_action_id);
|
2012-09-28 09:49:59 +00:00
|
|
|
});
|
|
|
|
}).
|
|
|
|
fail(function(client) {
|
|
|
|
self.do_warn('Apps Server not reachable.', 'Showing local modules.', true);
|
2012-09-28 12:58:40 +00:00
|
|
|
self.do_action(self.failback_action_id);
|
2012-09-28 09:49:59 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
0:0
|
2012-08-22 17:44:13 +00:00
|
|
|
});
|
|
|
|
|
2012-09-28 12:58:40 +00:00
|
|
|
instance.base.apps.UpdatesAvailable = instance.base.apps.Apps.extend({
|
|
|
|
remote_action_id: 'loempia.action_embed_updates'
|
2012-10-15 16:26:26 +00:00
|
|
|
});
|
2012-09-28 12:58:40 +00:00
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
instance.web.client_actions.add("apps", "instance.base.apps.Apps");
|
2012-09-28 12:58:40 +00:00
|
|
|
instance.web.client_actions.add("apps.updates", "instance.base.apps.UpdatesAvailable");
|
2012-09-28 09:49:59 +00:00
|
|
|
|
2012-08-22 17:44:13 +00:00
|
|
|
};
|