-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[18.0][IMP] web_theme_classic Add ability to toggle theme #3394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ljmnoonan
wants to merge
1
commit into
OCA:18.0
Choose a base branch
from
Pyxiris:18.0-web_theme_classic
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+441
−141
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import ir_http, res_users, res_users_settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # © 2022 Florian Kantelberg - initOS GmbH | ||
| # © 2025 Liam Noonan - Pyxiris | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import models | ||
| from odoo.http import request | ||
|
|
||
|
|
||
| class IrHttp(models.AbstractModel): | ||
| _inherit = "ir.http" | ||
|
|
||
| @classmethod | ||
| def _set_classic_theme(cls, response): | ||
| user = request.env.user | ||
| if user and user._is_internal(): | ||
| existing_transient_theme = request.httprequest.cookies.get( | ||
| "transient_classic_theme_cookie" | ||
| ) | ||
| persistent_theme = getattr(user, "persistent_classic_theme", None) | ||
| # Delete the cookie so that when persistent gets turned off the user | ||
| # will not be left wondering why nothing changed | ||
| if persistent_theme and existing_transient_theme: | ||
| response.delete_cookie("transient_classic_theme_cookie") | ||
|
|
||
| @classmethod | ||
| def _post_dispatch(cls, response): | ||
| cls._set_classic_theme(response) | ||
| return super()._post_dispatch(response) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # © 2022 Florian Kantelberg - initOS GmbH | ||
| # © 2025 Liam Noonan - Pyxiris | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsers(models.Model): | ||
| _inherit = "res.users" | ||
|
|
||
| persistent_classic_theme = fields.Boolean( | ||
| related="res_users_settings_id.persistent_classic_theme", | ||
| readonly=False, | ||
| string="Classic Theme Persistent", | ||
| help="This enables Classic Theme on this user's account across all devices. \n " | ||
| "Disabling it will will alow you to to use the toggle in the user burger menu " | ||
| "in the navbar to enable Classic Mode on a specific session/device \n" | ||
| "The toggle is not visible while Persistent Classic Theme is enabled", | ||
| ) | ||
|
|
||
| @property | ||
| def SELF_READABLE_FIELDS(self): | ||
| return super().SELF_READABLE_FIELDS + [ | ||
| "persistent_classic_theme", | ||
| ] | ||
|
|
||
| @property | ||
| def SELF_WRITEABLE_FIELDS(self): | ||
| return super().SELF_WRITEABLE_FIELDS + [ | ||
| "persistent_classic_theme", | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # © 2026 Liam Noonan - Pyxiris | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class ResUsersSettings(models.Model): | ||
| _inherit = "res.users.settings" | ||
|
|
||
| # These fields should be here in order to be accessible via in js | ||
| # as user.settings.persistent_classic_theme | ||
| persistent_classic_theme = fields.Boolean(default=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| This module allows each user to choose whether they would like input fields to be displayed the "classic" way or the new, standard way (as if this module were not installed) | ||
|
|
||
| To do this you can either: | ||
| + Check "Classic Theme Persistent" in user preferences. This will enable the classic theme for that user across all devices. | ||
| + Check the "Classic Theme" toggle in the popover menu triggered bu clicking on the user icon in the navbar. This toggle is only visible when "Classic Theme Persistent" is disabled. | ||
|
|
||
ljmnoonan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Please note that when disabling "Classic Theme Persistent" the style will not change until the page is reloaded. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // © 2022 Florian Kantelberg - initOS GmbH | ||
| // © 2025 Liam Noonan - Pyxiris | ||
| // License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| import {_t} from "@web/core/l10n/translation"; | ||
| import {browser} from "@web/core/browser/browser"; | ||
| import {cookie} from "@web/core/browser/cookie"; | ||
| import {registry} from "@web/core/registry"; | ||
| import {user} from "@web/core/user"; | ||
|
|
||
| /** | ||
| * @param {import("@web/env").OdooEnv} env | ||
| */ | ||
| function classicThemeSwitchItem(env) { | ||
| return { | ||
| type: "switch", | ||
| id: "classic_theme.switch", | ||
| description: _t("Classic Theme"), | ||
| callback: () => { | ||
| env.services.classic_theme.switchTheme(); | ||
| }, | ||
| isChecked: cookie.get("transient_classic_theme_cookie") === "classic", | ||
| sequence: 43, | ||
| }; | ||
| } | ||
|
|
||
| export const classicThemeService = { | ||
| dependencies: ["ui"], | ||
|
|
||
| start(env, {ui}) { | ||
| // Apply theme on load | ||
| if ( | ||
| cookie.get("transient_classic_theme_cookie") === "classic" || | ||
| user.settings.persistent_classic_theme | ||
| ) { | ||
| document.body.classList.add("classic-theme"); | ||
| } | ||
|
|
||
| if (!user.settings.persistent_classic_theme) { | ||
| registry | ||
| .category("user_menuitems") | ||
| .add("classic_theme.switch", classicThemeSwitchItem); | ||
| } | ||
|
|
||
| return { | ||
| async switchTheme() { | ||
| const newValue = | ||
| cookie.get("transient_classic_theme_cookie") === "classic" | ||
| ? "pure" | ||
| : "classic"; | ||
| cookie.set("transient_classic_theme_cookie", newValue); | ||
| document.body.classList.toggle("classic-theme", newValue === "classic"); | ||
|
|
||
| // We do not actually need a reload, but it does get rid of some style glitches | ||
| ui.block(); | ||
| browser.location.reload(); | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
|
|
||
| registry.category("services").add("classic_theme", classicThemeService); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.