Skip to content

Commit 6e23b48

Browse files
committed
💣 compatibility with backend theme
Signed-off-by: Vildan Safin <[email protected]>
1 parent 47d5eb2 commit 6e23b48

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

theme_kit/models/theme.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,19 @@ class ThemeTopPanel(models.Model):
7777
top_panel_hover_item_bg = fields.Char('Hover item Background color', help="Hover item Background color for Top Panel")
7878
top_panel_hover_item_bg_active = fields.Boolean(default=False, help="Hover item Background color for Top Panel")
7979

80+
# Compatibility theme_kit and material backend theme modules
81+
left_panel_main_menu = fields.Char('Main Menu Font color', help="Main Menu Font colo for Left Menu Bar")
82+
left_panel_main_menu_active = fields.Boolean(default=False, help="Main Menu Font colo for Left Menu Bar")
83+
left_panel_sub_menu = fields.Char('Sub Menu Font color', help="Sub Menu Font colo for Left Menu Bar")
84+
left_panel_sub_menu_active = fields.Boolean(default=False, help="Sub Menu Font colo for Left Menu Bar")
85+
8086
less = fields.Text('less', help='technical computed field', compute='_compute_less')
8187

88+
backend_theme_installed = fields.Boolean(compute='_check_backend_theme_installed')
89+
90+
def _check_backend_theme_installed(self):
91+
self.backend_theme_installed = True if self.env['ir.module.module'].search([('name', '=', 'backend_theme_v11')]).state == 'installed' else False
92+
8293
@api.multi
8394
def _compute_less(self):
8495
for r in self:
@@ -151,7 +162,7 @@ def _compute_less(self):
151162
border-right: 0 !important;
152163
}}
153164
'''
154-
if self.top_panel_font_active:
165+
if self.top_panel_font_active and not self.backend_theme_installed:
155166
code = code + '''.o_main_navbar > ul > li > a {{
156167
color: {theme.top_panel_font}!important;
157168
}}
@@ -262,6 +273,18 @@ def _compute_less(self):
262273
background-color: {theme.top_panel_hover_item_bg}!important;
263274
}}
264275
'''
276+
# Compatibility theme_kit and material backend theme modules
277+
if self.left_panel_main_menu_active:
278+
code = code + '''ul.oe_secondary_menu[style="display: block;"] > li > a{{
279+
color: {theme.left_panel_main_menu}!important;
280+
}}
281+
'''
282+
# Compatibility theme_kit and material backend theme modules
283+
if self.left_panel_sub_menu_active:
284+
code = code + '''ul.oe_secondary_menu[style="display: block;"] > li > ul > li.dropdown-header{{
285+
color: {theme.left_panel_sub_menu}!important;
286+
}}
287+
'''
265288
code = code.format(
266289
theme=r,
267290
)
@@ -299,8 +322,17 @@ class ThemeLeftPanel(models.Model):
299322

300323
less = fields.Text('less', help='technical computed field', compute='_compute_less')
301324

325+
backend_theme_installed = fields.Boolean(compute='_check_backend_theme_installed')
326+
327+
def _check_backend_theme_installed(self):
328+
self.backend_theme_installed = True if self.env['ir.module.module'].search([('name', '=', 'backend_theme_v11')]).state == 'installed' else False
329+
330+
top_panel_font = fields.Char('Font color', help="Font color for Top Panel")
331+
top_panel_font_active = fields.Boolean(default=False, help="Font color for Top Panel")
332+
302333
@api.multi
303334
def _compute_less(self):
335+
self.backend_theme_installed = True if self.env['ir.module.module'].search([('name', '=', 'backend_theme_v11')]).state == 'installed' else False
304336
for r in self:
305337
# double {{ will be formated as single {
306338
code = ''
@@ -340,7 +372,7 @@ def _compute_less(self):
340372
}}
341373
"""
342374
)
343-
if self.left_panel_main_menu_active:
375+
if self.left_panel_main_menu_active and not self.backend_theme_installed:
344376
code = code + '''.o_sub_menu .oe_secondary_menu_section{{
345377
color: {theme.left_panel_main_menu}!important;
346378
}}
@@ -366,7 +398,7 @@ def _compute_less(self):
366398
background-color: {theme.left_panel_main_menu};
367399
}}
368400
'''
369-
if self.left_panel_sub_menu_active:
401+
if self.left_panel_sub_menu_active and not self.backend_theme_installed:
370402
code = code + '''.o_sub_menu .oe_secondary_submenu .oe_menu_text{{
371403
color: {theme.left_panel_sub_menu};
372404
}}
@@ -434,6 +466,11 @@ def _compute_less(self):
434466
border-bottom: 0;
435467
border-left: 0;
436468
}}'''
469+
if self.top_panel_font_active:
470+
code = code + '''#sidebar > li > a{{
471+
color: {theme.top_panel_font}!important
472+
}}
473+
'''
437474
code = code.format(
438475
theme=r,
439476
)
@@ -491,8 +528,14 @@ class ThemeContent(models.Model):
491528
content_required_field_back_color = fields.Char("Mandatory field background color", help="Mandatory field background color")
492529
content_required_field_back_color_active = fields.Boolean(default=False, help="Mandatory field background color")
493530

531+
backend_theme_installed = fields.Boolean(compute='_check_backend_theme_installed')
532+
533+
def _check_backend_theme_installed(self):
534+
self.backend_theme_installed = True if self.env['ir.module.module'].search([('name', '=', 'backend_theme_v11')]).state == 'installed' else False
535+
494536
@api.multi
495537
def _compute_less(self):
538+
self.backend_theme_installed = True if self.env['ir.module.module'].search([('name', '=', 'backend_theme_v11')]).state == 'installed' else False
496539
for r in self:
497540
code = ''
498541
if self.content_bg_active:

theme_kit/views/theme.xml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<form string="Color scheme">
5454
<sheet>
5555
<div class="oe_title">
56+
<field name="backend_theme_installed" invisible="1"/>
5657
<label for="name" class="oe_edit_only"/>
5758
<h1>
5859
<field name="name"/>
@@ -70,7 +71,8 @@
7071
<field name="top_panel_border_active" nolabel="1" class="oe_inline"/>
7172
<field name="top_panel_border" class="oe_inline" attrs="{'readonly':[('top_panel_border_active','=',False)]}" widget="color"/>
7273
</div>
73-
<div>
74+
<!-- Compatibility theme_kit and material backend theme modules -->
75+
<div attrs="{'invisible':[('backend_theme_installed', '=', True)]}">
7476
<label for="top_panel_font" />
7577
<field name="top_panel_font_active" nolabel="1" class="oe_inline"/>
7678
<field name="top_panel_font" widget="color" attrs="{'readonly':[('top_panel_font_active','=',False)]}" class="oe_inline"/>
@@ -95,6 +97,17 @@
9597
<field name="top_panel_hover_item_bg_active" nolabel="1" class="oe_inline"/>
9698
<field name="top_panel_hover_item_bg" widget="color" attrs="{'readonly':[('top_panel_hover_item_bg_active','=',False)]}" class="oe_inline"/>
9799
</div>
100+
<!-- Compatibility theme_kit and material backend theme modules -->
101+
<div attrs="{'invisible':[('backend_theme_installed', '=', False)]}">
102+
<label for="left_panel_main_menu"/>
103+
<field name="left_panel_main_menu_active" nolabel="1" class="oe_inline"/>
104+
<field name="left_panel_main_menu" class="oe_inline" attrs="{'readonly':[('left_panel_main_menu_active','=',False)]}" widget="color"/>
105+
</div>
106+
<div attrs="{'invisible':[('backend_theme_installed', '=', False)]}">
107+
<label for="left_panel_sub_menu"/>
108+
<field name="left_panel_sub_menu_active" nolabel="1" class="oe_inline"/>
109+
<field name="left_panel_sub_menu" widget="color" attrs="{'readonly':[('left_panel_sub_menu_active','=',False)]}" class="oe_inline"/>
110+
</div>
98111
</group>
99112
</group>
100113
</sheet>
@@ -108,6 +121,7 @@
108121
<form string="Color scheme">
109122
<sheet>
110123
<div class="oe_title">
124+
<field name="backend_theme_installed" invisible="1"/>
111125
<label for="name" class="oe_edit_only"/>
112126
<h1>
113127
<field name="name"/>
@@ -120,12 +134,12 @@
120134
<field name="left_panel_bg_active" nolabel="1" class="oe_inline"/>
121135
<field name="left_panel_bg" class="oe_inline" attrs="{'readonly':[('left_panel_bg_active','=',False)]}" widget="color"/>
122136
</div>
123-
<div>
137+
<div attrs="{'invisible':[('backend_theme_installed', '=', True)]}">
124138
<label for="left_panel_main_menu"/>
125139
<field name="left_panel_main_menu_active" nolabel="1" class="oe_inline"/>
126140
<field name="left_panel_main_menu" class="oe_inline" attrs="{'readonly':[('left_panel_main_menu_active','=',False)]}" widget="color"/>
127141
</div>
128-
<div>
142+
<div attrs="{'invisible':[('backend_theme_installed', '=', True)]}">
129143
<label for="left_panel_sub_menu"/>
130144
<field name="left_panel_sub_menu_active" nolabel="1" class="oe_inline"/>
131145
<field name="left_panel_sub_menu" widget="color" attrs="{'readonly':[('left_panel_sub_menu_active','=',False)]}" class="oe_inline"/>
@@ -155,6 +169,11 @@
155169
<field name="left_panel_right_border_active" nolabel="1" class="oe_inline"/>
156170
<field name="left_panel_right_border" widget="color" attrs="{'readonly':[('left_panel_right_border_active','=',False)]}" class="oe_inline"/>
157171
</div>
172+
<div attrs="{'invisible':[('backend_theme_installed', '=', False)]}">
173+
<label for="top_panel_font" />
174+
<field name="top_panel_font_active" nolabel="1" class="oe_inline"/>
175+
<field name="top_panel_font" widget="color" attrs="{'readonly':[('top_panel_font_active','=',False)]}" class="oe_inline"/>
176+
</div>
158177
</group>
159178
</group>
160179
</sheet>

0 commit comments

Comments
 (0)