Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3881 Visualizzazioni

 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
Abbandona
Risposta migliore

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
Abbandona
Autore

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

Autore

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;

},

});

});

Post correlati Risposte Visualizzazioni Attività
0
ott 20
2939
4
ott 19
3702
2
feb 22
7961
0
ago 20
3567
2
gen 20
3651