콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

 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();

});






아바타
취소
베스트 답변

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.

아바타
취소
작성자

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

작성자

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;

},

});

});

관련 게시물 답글 화면 활동
0
10월 20
3252
4
10월 19
4050
2
2월 22
8435
0
8월 20
3884
2
1월 20
3966