2012-08-22 17:44:13 +00:00
|
|
|
openerp.base = function(instance) {
|
|
|
|
|
2012-12-19 17:21:28 +00:00
|
|
|
instance.base.apps_remote = null;
|
|
|
|
instance.base.apps_client = null;
|
2013-01-11 17:59:05 +00:00
|
|
|
|
|
|
|
var _t = instance.web._t;
|
2012-08-22 17:44:13 +00:00
|
|
|
|
2012-12-19 17:21:28 +00:00
|
|
|
instance.base.Apps = instance.web.Widget.extend({
|
2012-09-28 09:49:59 +00:00
|
|
|
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-12-19 17:21:28 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
2013-03-21 16:26:36 +00:00
|
|
|
var ts = new Date().getTime();
|
|
|
|
i.src = _.str.sprintf('%s/web/static/src/img/sep-a.gif?%s', client.origin, ts);
|
2012-12-19 17:21:28 +00:00
|
|
|
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('<a href="%s"></a>', 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);
|
|
|
|
});
|
|
|
|
}
|
2012-08-22 17:44:13 +00:00
|
|
|
},
|
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
destroy: function() {
|
2012-12-19 20:30:58 +00:00
|
|
|
if (instance.base.apps_client) {
|
|
|
|
instance.base.apps_client.destroy();
|
|
|
|
}
|
2012-09-28 09:49:59 +00:00
|
|
|
return this._super();
|
|
|
|
},
|
2012-09-21 14:30:57 +00:00
|
|
|
|
2012-09-28 09:49:59 +00:00
|
|
|
start: function() {
|
|
|
|
var self = this;
|
2012-12-19 17:21:28 +00:00
|
|
|
return self.get_client().
|
2012-09-28 09:49:59 +00:00
|
|
|
done(function(client) {
|
|
|
|
client.replace(self.$el).
|
|
|
|
done(function() {
|
|
|
|
client.$el.removeClass('openerp');
|
2013-03-14 14:50:17 +00:00
|
|
|
client.do_action(self.remote_action_id, {hide_breadcrumb: true});
|
2012-09-28 09:49:59 +00:00
|
|
|
});
|
|
|
|
}).
|
|
|
|
fail(function(client) {
|
2013-01-11 17:59:05 +00:00
|
|
|
self.do_warn(_t('OpenERP Apps Unreachable'), _t('Showing locally available modules'), true);
|
2012-11-09 17:31:46 +00:00
|
|
|
self.rpc('/web/action/load', {action_id: self.failback_action_id}).done(function(action) {
|
|
|
|
self.do_action(action);
|
|
|
|
instance.webclient.menu.open_action(action.id);
|
|
|
|
});
|
2012-09-28 09:49:59 +00:00
|
|
|
});
|
|
|
|
},
|
2012-08-22 17:44:13 +00:00
|
|
|
});
|
|
|
|
|
2012-12-19 17:21:28 +00:00
|
|
|
instance.base.AppsUpdates = instance.base.Apps.extend({
|
2012-09-28 12:58:40 +00:00
|
|
|
remote_action_id: 'loempia.action_embed_updates'
|
2012-10-15 16:26:26 +00:00
|
|
|
});
|
2012-09-28 12:58:40 +00:00
|
|
|
|
2012-12-19 17:21:28 +00:00
|
|
|
instance.web.client_actions.add("apps", "instance.base.Apps");
|
|
|
|
instance.web.client_actions.add("apps.updates", "instance.base.AppsUpdates");
|
2012-09-28 09:49:59 +00:00
|
|
|
|
2012-08-22 17:44:13 +00:00
|
|
|
};
|