You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.1 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (C) 2017 MuK IT GmbH
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. ###################################################################################
  19. import re
  20. import uuid
  21. import base64
  22. from odoo import api, fields, models
  23. XML_ID = "muk_web_theme._assets_primary_variables"
  24. SCSS_URL = "/muk_web_theme/static/src/scss/colors.scss"
  25. class ResConfigSettings(models.TransientModel):
  26. _inherit = 'res.config.settings'
  27. #----------------------------------------------------------
  28. # Database
  29. #----------------------------------------------------------
  30. theme_background_image = fields.Binary(
  31. related="company_id.background_image",
  32. readonly=False,
  33. required=True)
  34. theme_background_blend_mode = fields.Selection(
  35. related="company_id.background_blend_mode",
  36. readonly=False)
  37. theme_default_sidebar_preference = fields.Selection(
  38. related="company_id.default_sidebar_preference",
  39. readonly=False)
  40. theme_default_chatter_preference = fields.Selection(
  41. related="company_id.default_chatter_preference",
  42. readonly=False)
  43. theme_color_brand = fields.Char(
  44. string="Theme Brand Color")
  45. theme_color_primary = fields.Char(
  46. string="Theme Primary Color")
  47. theme_color_menu = fields.Char(
  48. string="Theme Menu Color")
  49. theme_color_appbar_color = fields.Char(
  50. string="Theme AppBar Color")
  51. theme_color_appbar_background = fields.Char(
  52. string="Theme AppBar Background")
  53. #----------------------------------------------------------
  54. # Functions
  55. #----------------------------------------------------------
  56. @api.multi
  57. def set_values(self):
  58. res = super(ResConfigSettings, self).set_values()
  59. param = self.env['ir.config_parameter'].sudo()
  60. variables = [
  61. 'o-brand-odoo',
  62. 'o-brand-primary',
  63. 'mk-apps-color',
  64. 'mk-appbar-color',
  65. 'mk-appbar-background',
  66. ]
  67. colors = self.env['muk_utils.scss_editor'].get_values(
  68. SCSS_URL, XML_ID, variables
  69. )
  70. colors_changed = []
  71. colors_changed.append(self.theme_color_brand != colors['o-brand-odoo'])
  72. colors_changed.append(self.theme_color_primary != colors['o-brand-primary'])
  73. colors_changed.append(self.theme_color_menu != colors['mk-apps-color'])
  74. colors_changed.append(self.theme_color_appbar_color != colors['mk-appbar-color'])
  75. colors_changed.append(self.theme_color_appbar_background != colors['mk-appbar-background'])
  76. if(any(colors_changed)):
  77. variables = [
  78. {'name': 'o-brand-odoo', 'value': self.theme_color_brand or "#243742"},
  79. {'name': 'o-brand-primary', 'value': self.theme_color_primary or "#5D8DA8"},
  80. {'name': 'mk-apps-color', 'value': self.theme_color_menu or "#f8f9fa"},
  81. {'name': 'mk-appbar-color', 'value': self.theme_color_appbar_color or "#dee2e6"},
  82. {'name': 'mk-appbar-background', 'value': self.theme_color_appbar_background or "#000000"},
  83. ]
  84. self.env['muk_utils.scss_editor'].replace_values(
  85. SCSS_URL, XML_ID, variables
  86. )
  87. param.set_param('muk_web_theme.background_blend_mode', self.theme_background_blend_mode)
  88. return res
  89. @api.model
  90. def get_values(self):
  91. res = super(ResConfigSettings, self).get_values()
  92. params = self.env['ir.config_parameter'].sudo()
  93. variables = [
  94. 'o-brand-odoo',
  95. 'o-brand-primary',
  96. 'mk-apps-color',
  97. 'mk-appbar-color',
  98. 'mk-appbar-background',
  99. ]
  100. colors = self.env['muk_utils.scss_editor'].get_values(
  101. SCSS_URL, XML_ID, variables
  102. )
  103. res.update({
  104. 'theme_color_brand': colors['o-brand-odoo'],
  105. 'theme_color_primary': colors['o-brand-primary'],
  106. 'theme_color_menu': colors['mk-apps-color'],
  107. 'theme_color_appbar_color': colors['mk-appbar-color'],
  108. 'theme_color_appbar_background': colors['mk-appbar-background'],
  109. 'theme_background_blend_mode': params.get_param('muk_web_theme.background_blend_mode', 'normal'),
  110. })
  111. return res