-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature 22921 mig colorize field in tree views jpr (#4)
[MIG] web_tree_dynamic_colored_field: Migration to 17.0 - Implementation now is based on updating `style` attribute of `cell/td` instead of directly manipulating element's CSS value. - Cleanup docs about no more implemented `colors` parameter for `tree`
- Loading branch information
Showing
10 changed files
with
119 additions
and
246 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
The development of this module has been financially supported by: | ||
|
||
- Camptocamp | ||
- Versada |
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
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
78 changes: 78 additions & 0 deletions
78
web_tree_dynamic_colored_field/static/src/js/list_renderer.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,78 @@ | ||
/** @odoo-module **/ | ||
|
||
import {patch} from "@web/core/utils/patch"; | ||
import {ListRenderer} from "@web/views/list/list_renderer"; | ||
import {evaluateBooleanExpr} from "@web/core/py_js/py"; | ||
|
||
patch(ListRenderer.prototype, { | ||
/** | ||
* @param {Object} column represents field | ||
* @param {Record} record | ||
* @returns {String} style code for the html element | ||
*/ | ||
getDynamicColoredStyle(column, record) { | ||
let style = ""; | ||
|
||
let color = this.getDynamicColor(column, record, "bg_color"); | ||
if (color !== undefined) { | ||
style += `background-color: ${color};`; | ||
} | ||
|
||
color = this.getDynamicColor(column, record, "fg_color"); | ||
if (color !== undefined) { | ||
// $td.css('color', color); | ||
style += `color: ${color};`; | ||
} | ||
|
||
return style; | ||
}, | ||
|
||
/** | ||
* Return the `color` that has truthfull expresssion | ||
* | ||
* @param column {Object} represents field | ||
* @param record {Record} | ||
* @param color_target {String} 'bg_color' or 'fg_color' | ||
* @returns {String | undefined} color | ||
*/ | ||
getDynamicColor(column, record, color_target) { | ||
if (color_target in column.options) { | ||
const definition = column.options[color_target]; | ||
let result = ""; | ||
for (const color_def of definition.split(";")) { | ||
const color_to_expression = this.pairColorParse(color_def); | ||
if (color_to_expression !== undefined) { | ||
const [color, expression] = color_to_expression; | ||
if ( | ||
evaluateBooleanExpr( | ||
expression, | ||
record.evalContextWithVirtualIds | ||
) | ||
) { | ||
// We don't return first match, | ||
// as it can be default color (with "True" expression), | ||
// and later more precise condition may be found. | ||
result = color; | ||
} | ||
} | ||
} | ||
return result | undefined; | ||
} | ||
}, | ||
|
||
/** | ||
* @param {String} pairColor `color: expression` pair | ||
* @returns {Array} undefined or array of color, expression | ||
*/ | ||
pairColorParse: function (pairColor) { | ||
if (pairColor !== "") { | ||
var pairList = pairColor.split(":"), | ||
color = pairList[0], | ||
// If one passes a bare color instead of an expression, | ||
// then we consider that color is to be shown in any case | ||
expression = pairList[1] ? pairList[1] : "True"; | ||
return [color, expression]; | ||
} | ||
return undefined; | ||
}, | ||
}); |
Oops, something went wrong.