Skip to content

Commit

Permalink
💣 compatibility with backend theme
Browse files Browse the repository at this point in the history
Signed-off-by: Vildan Safin <safin@it-projects.info>
  • Loading branch information
Enigma228322 committed Sep 4, 2020
1 parent 47d5eb2 commit 45885ab
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
49 changes: 46 additions & 3 deletions theme_kit/models/theme.py
Expand Up @@ -77,8 +77,19 @@ class ThemeTopPanel(models.Model):
top_panel_hover_item_bg = fields.Char('Hover item Background color', help="Hover item Background color for Top Panel")
top_panel_hover_item_bg_active = fields.Boolean(default=False, help="Hover item Background color for Top Panel")

# Compatibility theme_kit and material backend theme modules
left_panel_main_menu = fields.Char('Main Menu Font color', help="Main Menu Font colo for Left Menu Bar")
left_panel_main_menu_active = fields.Boolean(default=False, help="Main Menu Font colo for Left Menu Bar")
left_panel_sub_menu = fields.Char('Sub Menu Font color', help="Sub Menu Font colo for Left Menu Bar")
left_panel_sub_menu_active = fields.Boolean(default=False, help="Sub Menu Font colo for Left Menu Bar")

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

backend_theme_installed = fields.Boolean(compute='_check_backend_theme_installed')

def _check_backend_theme_installed(self):
self.backend_theme_installed = True if self.env['ir.module.module'].search([('name', '=', 'backend_theme_v11')]).state == 'installed' else False

@api.multi
def _compute_less(self):
for r in self:
Expand Down Expand Up @@ -151,7 +162,7 @@ def _compute_less(self):
border-right: 0 !important;
}}
'''
if self.top_panel_font_active:
if self.top_panel_font_active and not self.backend_theme_installed:
code = code + '''.o_main_navbar > ul > li > a {{
color: {theme.top_panel_font}!important;
}}
Expand Down Expand Up @@ -262,6 +273,18 @@ def _compute_less(self):
background-color: {theme.top_panel_hover_item_bg}!important;
}}
'''
# Compatibility theme_kit and material backend theme modules
if self.left_panel_main_menu_active:
code = code + '''ul.oe_secondary_menu > li > a{{
color: {theme.left_panel_main_menu}!important;
}}
'''
# Compatibility theme_kit and material backend theme modules
if self.left_panel_sub_menu_active:
code = code + '''ul.oe_secondary_menu > li > ul > li.dropdown-header{{
color: {theme.left_panel_sub_menu}!important;
}}
'''
code = code.format(
theme=r,
)
Expand Down Expand Up @@ -299,8 +322,17 @@ class ThemeLeftPanel(models.Model):

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

backend_theme_installed = fields.Boolean(compute='_check_backend_theme_installed')

def _check_backend_theme_installed(self):
self.backend_theme_installed = True if self.env['ir.module.module'].search([('name', '=', 'backend_theme_v11')]).state == 'installed' else False

top_panel_font = fields.Char('Font color', help="Font color for Top Panel")
top_panel_font_active = fields.Boolean(default=False, help="Font color for Top Panel")

@api.multi
def _compute_less(self):
self.backend_theme_installed = True if self.env['ir.module.module'].search([('name', '=', 'backend_theme_v11')]).state == 'installed' else False
for r in self:
# double {{ will be formated as single {
code = ''
Expand Down Expand Up @@ -340,7 +372,7 @@ def _compute_less(self):
}}
"""
)
if self.left_panel_main_menu_active:
if self.left_panel_main_menu_active and not self.backend_theme_installed:
code = code + '''.o_sub_menu .oe_secondary_menu_section{{
color: {theme.left_panel_main_menu}!important;
}}
Expand All @@ -366,7 +398,7 @@ def _compute_less(self):
background-color: {theme.left_panel_main_menu};
}}
'''
if self.left_panel_sub_menu_active:
if self.left_panel_sub_menu_active and not self.backend_theme_installed:
code = code + '''.o_sub_menu .oe_secondary_submenu .oe_menu_text{{
color: {theme.left_panel_sub_menu};
}}
Expand Down Expand Up @@ -434,6 +466,11 @@ def _compute_less(self):
border-bottom: 0;
border-left: 0;
}}'''
if self.top_panel_font_active:
code = code + '''#sidebar > li > a{{
color: {theme.top_panel_font}!important
}}
'''
code = code.format(
theme=r,
)
Expand Down Expand Up @@ -491,8 +528,14 @@ class ThemeContent(models.Model):
content_required_field_back_color = fields.Char("Mandatory field background color", help="Mandatory field background color")
content_required_field_back_color_active = fields.Boolean(default=False, help="Mandatory field background color")

backend_theme_installed = fields.Boolean(compute='_check_backend_theme_installed')

def _check_backend_theme_installed(self):
self.backend_theme_installed = True if self.env['ir.module.module'].search([('name', '=', 'backend_theme_v11')]).state == 'installed' else False

@api.multi
def _compute_less(self):
self.backend_theme_installed = True if self.env['ir.module.module'].search([('name', '=', 'backend_theme_v11')]).state == 'installed' else False
for r in self:
code = ''
if self.content_bg_active:
Expand Down
25 changes: 22 additions & 3 deletions theme_kit/views/theme.xml
Expand Up @@ -53,6 +53,7 @@
<form string="Color scheme">
<sheet>
<div class="oe_title">
<field name="backend_theme_installed" invisible="1"/>
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name"/>
Expand All @@ -70,7 +71,8 @@
<field name="top_panel_border_active" nolabel="1" class="oe_inline"/>
<field name="top_panel_border" class="oe_inline" attrs="{'readonly':[('top_panel_border_active','=',False)]}" widget="color"/>
</div>
<div>
<!-- Compatibility theme_kit and material backend theme modules -->
<div attrs="{'invisible':[('backend_theme_installed', '=', True)]}">
<label for="top_panel_font" />
<field name="top_panel_font_active" nolabel="1" class="oe_inline"/>
<field name="top_panel_font" widget="color" attrs="{'readonly':[('top_panel_font_active','=',False)]}" class="oe_inline"/>
Expand All @@ -95,6 +97,17 @@
<field name="top_panel_hover_item_bg_active" nolabel="1" class="oe_inline"/>
<field name="top_panel_hover_item_bg" widget="color" attrs="{'readonly':[('top_panel_hover_item_bg_active','=',False)]}" class="oe_inline"/>
</div>
<!-- Compatibility theme_kit and material backend theme modules -->
<div attrs="{'invisible':[('backend_theme_installed', '=', False)]}">
<label for="left_panel_main_menu"/>
<field name="left_panel_main_menu_active" nolabel="1" class="oe_inline"/>
<field name="left_panel_main_menu" class="oe_inline" attrs="{'readonly':[('left_panel_main_menu_active','=',False)]}" widget="color"/>
</div>
<div attrs="{'invisible':[('backend_theme_installed', '=', False)]}">
<label for="left_panel_sub_menu"/>
<field name="left_panel_sub_menu_active" nolabel="1" class="oe_inline"/>
<field name="left_panel_sub_menu" widget="color" attrs="{'readonly':[('left_panel_sub_menu_active','=',False)]}" class="oe_inline"/>
</div>
</group>
</group>
</sheet>
Expand All @@ -108,6 +121,7 @@
<form string="Color scheme">
<sheet>
<div class="oe_title">
<field name="backend_theme_installed" invisible="1"/>
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name"/>
Expand All @@ -120,12 +134,12 @@
<field name="left_panel_bg_active" nolabel="1" class="oe_inline"/>
<field name="left_panel_bg" class="oe_inline" attrs="{'readonly':[('left_panel_bg_active','=',False)]}" widget="color"/>
</div>
<div>
<div attrs="{'invisible':[('backend_theme_installed', '=', True)]}">
<label for="left_panel_main_menu"/>
<field name="left_panel_main_menu_active" nolabel="1" class="oe_inline"/>
<field name="left_panel_main_menu" class="oe_inline" attrs="{'readonly':[('left_panel_main_menu_active','=',False)]}" widget="color"/>
</div>
<div>
<div attrs="{'invisible':[('backend_theme_installed', '=', True)]}">
<label for="left_panel_sub_menu"/>
<field name="left_panel_sub_menu_active" nolabel="1" class="oe_inline"/>
<field name="left_panel_sub_menu" widget="color" attrs="{'readonly':[('left_panel_sub_menu_active','=',False)]}" class="oe_inline"/>
Expand Down Expand Up @@ -155,6 +169,11 @@
<field name="left_panel_right_border_active" nolabel="1" class="oe_inline"/>
<field name="left_panel_right_border" widget="color" attrs="{'readonly':[('left_panel_right_border_active','=',False)]}" class="oe_inline"/>
</div>
<div attrs="{'invisible':[('backend_theme_installed', '=', False)]}">
<label for="top_panel_font" />
<field name="top_panel_font_active" nolabel="1" class="oe_inline"/>
<field name="top_panel_font" widget="color" attrs="{'readonly':[('top_panel_font_active','=',False)]}" class="oe_inline"/>
</div>
</group>
</group>
</sheet>
Expand Down

0 comments on commit 45885ab

Please sign in to comment.