-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] web_environment_ribbon: Migration to 17.0
- Loading branch information
Showing
5 changed files
with
83 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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 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
79 changes: 79 additions & 0 deletions
79
web_environment_ribbon/static/src/components/environment_ribbon/ribbon.esm.js
This file contains 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,79 @@ | ||
/** @odoo-module **/ | ||
|
||
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.bind(this)); | ||
} | ||
|
||
// 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)"; | ||
} | ||
|
||
showRibbon() { | ||
const ribbon = $(".test-ribbon"); | ||
const self = this; | ||
ribbon.hide(); | ||
// Get ribbon data from backend | ||
self.orm | ||
.call("web.environment.ribbon.backend", "get_environment_ribbon") | ||
.then(function (ribbon_data) { | ||
// Ribbon name | ||
if (ribbon_data.name && ribbon_data.name !== "False") { | ||
ribbon.show(); | ||
ribbon.html(ribbon_data.name); | ||
} | ||
// Ribbon color | ||
if (ribbon_data.color && self.validStrColour(ribbon_data.color)) { | ||
ribbon.css("color", ribbon_data.color); | ||
} | ||
// Ribbon background color | ||
if ( | ||
ribbon_data.background_color && | ||
self.validStrColour(ribbon_data.background_color) | ||
) { | ||
ribbon.css("background-color", ribbon_data.background_color); | ||
} | ||
}); | ||
} | ||
/** | ||
* @private | ||
* @param {InputEvent} ev | ||
*/ | ||
onMouseOver(ev) { | ||
ev.target.style.display = "none"; | ||
} | ||
onMouseDown(ev) { | ||
ev.target.style.display = "none"; | ||
} | ||
|
||
} | ||
|
||
WebEnvironmentRibbon.props = {}; | ||
WebEnvironmentRibbon.template = xml`<div class="test-ribbon hidden" />`; | ||
|
||
registry.category("main_components").add("WebEnvironmentRibbon", { | ||
Component: WebEnvironmentRibbon, | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains 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