Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
29
web_environment_ribbon/static/src/components/environment_ribbon/ribbon.css
Executable file
29
web_environment_ribbon/static/src/components/environment_ribbon/ribbon.css
Executable file
@@ -0,0 +1,29 @@
|
||||
/* Copyright 2015 Francesco OpenCode Apruzzese <cescoap@gmail.com>
|
||||
Copyright 2017 Thomas Binsfeld <thomas.binsfeld@acsone.eu>
|
||||
Copyright 2021 Andreas Perhab <a.perhab@wtioit.at>
|
||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||
|
||||
.test-ribbon {
|
||||
width: 300px;
|
||||
top: 25px;
|
||||
left: -100px;
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
line-height: 20px;
|
||||
letter-spacing: 1px;
|
||||
color: #f0f0f0;
|
||||
-webkit-transform: rotate(-45deg);
|
||||
-ms-transform: rotate(-45deg);
|
||||
-moz-transform: rotate(-45deg);
|
||||
-o-transform: rotate(-45deg);
|
||||
transform: rotate(-45deg);
|
||||
z-index: 9999;
|
||||
position: fixed;
|
||||
box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
|
||||
background: rgba(255, 0, 0, 0.6);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.test-ribbon b {
|
||||
font-size: 20px;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import {Component, xml} from "@odoo/owl";
|
||||
import {useBus, useService} from "@web/core/utils/hooks";
|
||||
import {registry} from "@web/core/registry";
|
||||
|
||||
export class WebEnvironmentRibbon extends Component {
|
||||
setup() {
|
||||
this.orm = useService("orm");
|
||||
useBus(this.env.bus, "WEB_CLIENT_READY", () => this.showRibbon());
|
||||
}
|
||||
|
||||
// Code from: http://jsfiddle.net/WK_of_Angmar/xgA5C/
|
||||
validStrColour(strToTest) {
|
||||
if (strToTest === "") {
|
||||
return false;
|
||||
}
|
||||
if (strToTest === "inherit") {
|
||||
return true;
|
||||
}
|
||||
if (strToTest === "transparent") {
|
||||
return true;
|
||||
}
|
||||
const image = document.createElement("img");
|
||||
image.style.color = "rgb(0, 0, 0)";
|
||||
image.style.color = strToTest;
|
||||
if (image.style.color !== "rgb(0, 0, 0)") {
|
||||
return true;
|
||||
}
|
||||
image.style.color = "rgb(255, 255, 255)";
|
||||
image.style.color = strToTest;
|
||||
return image.style.color !== "rgb(255, 255, 255)";
|
||||
}
|
||||
|
||||
async showRibbon() {
|
||||
const ribbon = document.getElementsByClassName("test-ribbon")[0];
|
||||
ribbon.style.display = "none";
|
||||
// Get ribbon data from backend
|
||||
const ribbon_data = await this.orm.call(
|
||||
"web.environment.ribbon.backend",
|
||||
"get_environment_ribbon"
|
||||
);
|
||||
// Ribbon name
|
||||
if (ribbon_data.name && ribbon_data.name !== "False") {
|
||||
ribbon.style.display = "block";
|
||||
ribbon.innerHTML = ribbon_data.name;
|
||||
}
|
||||
// Ribbon color
|
||||
if (ribbon_data.color && this.validStrColour(ribbon_data.color)) {
|
||||
ribbon.style.color = ribbon_data.color;
|
||||
}
|
||||
// Ribbon background color
|
||||
if (
|
||||
ribbon_data.background_color &&
|
||||
this.validStrColour(ribbon_data.background_color)
|
||||
) {
|
||||
ribbon.style.backgroundColor = ribbon_data.background_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WebEnvironmentRibbon.props = {};
|
||||
WebEnvironmentRibbon.template = xml`<div class="test-ribbon" style="display:none"/>`;
|
||||
|
||||
registry.category("main_components").add("WebEnvironmentRibbon", {
|
||||
Component: WebEnvironmentRibbon,
|
||||
});
|
||||
Reference in New Issue
Block a user