Browse Source

web_tree_dynamic_colored_field: Assume that color may not start with 'color_field'

The index at 0 in the following code:
  var colorField = this.arch.attrs.colors.split(';')
  .filter(color => color.trim().startsWith('color_field'))[0]
Was failing on such valid xml:
  <tree string="Buffer monitor"
        colors="red:procure_recommended_qty &gt; 0">
pull/886/head
Guewen Baconnier 7 years ago
parent
commit
9e99022497
  1. 27
      web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js

27
web_tree_dynamic_colored_field/static/src/js/web_tree_dynamic_colored_field.js

@ -12,20 +12,21 @@ odoo.define('web_tree_dynamic_colored_field', function (require) {
*/ */
_renderBody: function () { _renderBody: function () {
if (this.arch.attrs.colors) { if (this.arch.attrs.colors) {
var colorField = this.arch.attrs.colors.split(';')
.filter(color => color.trim().startsWith('color_field'))[0]
.split(':')[1]
.trim();
// validate the presence of that field in tree view
var fieldNames = _(this.columns).map(
(value) => { return value.attrs.name; }
);
if (fieldNames.indexOf(colorField) === -1) {
console.warn(
"No field named '" + colorField + "' present in view."
var colorAttr = this.arch.attrs.colors.split(';')
.filter(color => color.trim().startsWith('color_field'));
if (colorAttr.length > 0) {
var colorField = colorAttr[0].split(':')[1].trim();
// validate the presence of that field in tree view
var fieldNames = _(this.columns).map(
(value) => { return value.attrs.name; }
); );
} else {
this.colorField = colorField;
if (fieldNames.indexOf(colorField) === -1) {
console.warn(
"No field named '" + colorField + "' present in view."
);
} else {
this.colorField = colorField;
}
} }
} }
return this._super(); return this._super();

Loading…
Cancel
Save