Help

2

Can't change odoo backend css using JS

Avatar
Md. Tanzilul Hasan Khan

I have written following code in js to change the odoo menu-color:

odoo.define('cof_backend_theme.style', function (require) {'use strict';
     
var ajax = require('web.ajax');
ajax.jsonRpc("/action_get_menu_color", 'call').then(function(value){
$(document).ready(function(){
$(".o_main_navbar").css("background-color", value); //value #000 comes correctly
});
}); });


The js value #000 comes from the backend. But the color in odoo isn't changing.

If I debug the controller code in pycharm I can see the menu color change (works) but when I run the code without debugging the color doesn't change.

What to do? Please suggest.


13 التعليقات
الصورة الرمزية
تجاهل
Avatar
Shameem Babu @ iWesabe
-

I had faced the same issue

Same selector works in css, but not in js

Avatar
Shameem Babu @ iWesabe
-

I think the line

$(document).ready(function(){ }); is not required

Avatar
Md. Tanzilul Hasan Khan
-

yes, that doesn't require. I was seeing if the js loads while loading the page.

Is there any fix you know about?

Avatar
Shameem Babu @ iWesabe
-

Which is your version?

Avatar
Md. Tanzilul Hasan Khan
-

odoo 10 EE

Avatar
Md. Tanzilul Hasan Khan
-

I just tested on community edition it worked. But not works on enterprise edition. That is even more weirder :(

Avatar
Shameem Babu @ iWesabe
-

See this reference in odoo 8

https://www.odoo.com/apps/themes/8.0/editable_theme/

You download it

go to the file

/editable_theme/static/src/js/js_role.js

You can see many examples

Avatar
Shameem Babu @ iWesabe
-

Such as

$(".navbar-collapse.collapse").css("background-color", topBar_background_COLOR_CODE);

Avatar
Md. Tanzilul Hasan Khan
-

thank you very much. I will study this module tonight and let you know.

But my concern is why a code is working on debug mode or CE but not on EE. :\

Avatar
Shameem Babu @ iWesabe
-

I have no idea about EE.

Avatar
Md. Tanzilul Hasan Khan
-

ok, np. I will let you know.

Avatar
Md. Tanzilul Hasan Khan
-

@Shameem, I used the method the module used but no result. If I write static css, it works. But not from js.