[IMP] anonymous: change UserMenu when logged as anonymous

bzr revid: chs@openerp.com-20120605124637-2h2ln3211yqlpxcp
This commit is contained in:
Christophe Simonis 2012-06-05 14:46:37 +02:00
parent f90e53c96a
commit 4de3f2032e
3 changed files with 44 additions and 1 deletions

View File

@ -12,4 +12,7 @@
'js': [
'static/src/js/anonymous.js',
],
'qweb': [
'static/src/xml/anonymous.xml',
],
}

View File

@ -1,5 +1,6 @@
openerp.anonymous = function(instance) {
// TODO change User menu
instance.web.client_actions.add("login", "instance.web.Login");
instance.web.WebClient.include({
show_login: function() {
@ -7,6 +8,7 @@ openerp.anonymous = function(instance) {
this.login.load_db_list().then(function() {
var dblist = self.login._db_list;
if (dblist && dblist.length === 1) {
self.login.remember_credentials = false;
// XXX get login/pass from server (via a rpc call) ?
self.login.do_login(dblist[0], 'anonymous', 'anonymous').fail(function() {
_super.apply(self, []);
@ -18,4 +20,25 @@ openerp.anonymous = function(instance) {
},
});
instance.web.UserMenu.include({
init: function(parent) {
this._super(parent);
if (this.session.username == 'anonymous') {
this.template = 'UserMenu.anonymous';
this.do_update = function() {}; // avoid change of avatar
}
},
start: function() {
var self = this;
this._super.apply(this, arguments);
this.$element.find('.oe_topbar_anonymous_login').click(function() {
var p = self.getParent();
var am = p.action_manager;
am.do_action({type:'ir.actions.client', tag:'login'});
am.client_widget.on('login', p, p.show_application);
});
}
});
};

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- vim:fdl=1:
-->
<templates id="template" xml:space="preserve">
<t t-name="UserMenu.anonymous">
<ul class="oe_user_menu oe_topbar_item">
<li>
<a href="#" class="oe_topbar_anonymous_login">
<img class="oe_topbar_avatar" t-att-src="_s + '/web/static/src/img/icons/gtk-dialog-authentication.png'"/>
Login
</a>
</li>
</ul>
</t>
</templates>