Skip to Content
Menu
This question has been flagged

 I do change for UserMenu.js script to display Database name in cosole my assets file loaded whiteout error but it have no effect on interface , in the flowing my assets file and custom scrip :

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- create an inherited view of the assets bundle, and add the js file to display Datebase name with For example,-->
<template id="assets_backend" name="database_name assets" inherit_id="web.assets_backend">
<xpath expr="//script[last()]" position="after">
<script type="text/javascript" src="/backend_customization_12/static/src/js/chrome/database.js"></script>
</xpath>
</template>
</odoo>

javascript module

odoo.define('backend_customization_12.NewHomeMenu', function (require) {
"use strict";

/**
this Js script to inherit HomeMenu widget to Modifying to dispay database name
*/

var UserMenu = require('web.UserMenu');
var Widget = require('web.Widget');

var NewHomeMenu. = UserMenu.extend({
template: 'NewHomeMenu',


start: function () {
var self = this;
var session = this.getSession();
this.$el.on('click', '[data-menu]', function (ev) {
ev.preventDefault();
var menu = $(this).data('menu');
self['_onMenu' + menu.charAt(0).toUpperCase() + menu.slice(1)]();
});
return this._super.apply(this, arguments).then(function () {
var $avatar = self.$('.oe_topbar_avatar');
if (!session.uid) {
$avatar.attr('src', $avatar.data('default-src'));
return $.when();
}
var topbar_name = session.name;
// if (session.debug) {
// topbar_name = _.str.sprintf("%s (%s)", topbar_name, session.db);
// }
topbar_name = _.str.sprintf("%s (%s)", topbar_name, session.db);
self.$('.oe_topbar_name').text(topbar_name);
var avatar_src = session.url('/web/image', {
model:'res.users',
field: 'image_small',
id: session.uid,
});
$avatar.attr('src', avatar_src);
});
},

var dog = new NewHomeMenu();


return dog.start();

});






Avatar
Discard
Best Answer

I think you need to use UserMenu.include instead of UserMenu.extend and do not define a new template ('NewHomeMenu') for it 

Here you create a new instance of NewHomeMenu but you don't append it to DOM so it's not working and start method will automatically call when widget added to dom you don't have to call it explicitly but in this case, just used include instead of extend and it will work fine.

Avatar
Discard
Author

thank for respond , exactly I want move out (topbar_name = _.str.sprintf("%s (%s)", topbar_name, session.db);) line out of if condition how I can do this in my custom scrip after using include instead of extend is the only this I need to do is cope all the default code whit change that line @Ravi Gadhia

the correct way is inherit UserMenu using include and override the start method,

in start method call the super using this._super.apply(this, arguments) after that re assigns the value of topbar using

var topbar_name = _.str.sprintf("%s (%s)", topbar_name, session.db);

self.$('.oe_topbar_name').text(topbar_name);

but there will be no error if you override the whole method without calling super

Author

I appreciate your support , still has no result and this is latest code

odoo.define('backend_customization_12.NewHomeMenu', function (require) {

"use strict";

/**

this Js script to inherit HomeMenu widget to Modifying to dispay database name

*/

var NewUserMenu = require('web.UserMenu');

var Widget = require('web.Widget');

NewUserMenu.include({({

template: 'NewHomeMenu',

start: function () {

this._super.apply(this, arguments)

var topbar_name = _.str.sprintf("%s (%s)", topbar_name, session.db);

self.$('.oe_topbar_name').text(topbar_name);

},

return NewUserMenu;

});

odoo.define('backend_customization_12.NewHomeMenu', function (require) {

"use strict";

/**

this Js script to inherit HomeMenu widget to Modifying to dispay database name

*/

var NewUserMenu = require('web.UserMenu');

NewUserMenu.include({

start: function () {

var self = this;

var def = this._super.apply(this, arguments);

def.then(function () {

var session = self.getSession();

var topbar_name = _.str.sprintf("%s (%s)", session.name, session.db);

self.$('.oe_topbar_name').text(topbar_name);

});

return def;

},

});

});

Related Posts Replies Views Activity
0
Oct 20
2518
4
Oct 19
3064
2
Feb 22
6902
0
Aug 20
2830
2
Jan 20
3057