summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/widgets/priority.js
diff options
context:
space:
mode:
authorAdrien Dieudonne <adr@odoo.com>2017-02-23 14:03:31 +0100
committerAdrien Dieudonne <adr@odoo.com>2017-02-24 14:38:20 +0100
commited1abc43d15d8f5b1a4ffc9b767fcf22637a3639 (patch)
treed69eba49393b41d44be256c3505aa556a5bc3517 /addons/web/static/src/js/widgets/priority.js
parentf5d61986998a110ed4a28efac074e29a8fa8c398 (diff)
[FIX] web: string values in priority widget
(1) The priority widget is based on a selection field. So, this priority widget must support string values. Before this commit, the widget worked correctly with numeric values. For example: '0', '1', '2', '3' was converted to 0, 1, 2, 3. But sometimes, we have non-numerical values. For example: 'Normal', 'Low', 'High', 'Very High'. In this case, we can not compare the elements to each other according to their values. If you select 'High', we don't know if the star of the value 'Low' must be filled. To fix this, we base the comparison on the indexes of the table of possible values. For example: [('A', 'A'), ('B', 'B'), ('C', 'C'), ('D', 'D')] Now, if you select D, we know that A (with index 0) is smaller than D (with index 3). This could be a behavioral change if you had [('1', '1'), ('0', '0'), ('2', '2')] (2) When the selection field had no value, the 'o_form_field_empty' class was added. In this case, the stars must be displayed without being filled.
Diffstat (limited to 'addons/web/static/src/js/widgets/priority.js')
-rw-r--r--addons/web/static/src/js/widgets/priority.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/addons/web/static/src/js/widgets/priority.js b/addons/web/static/src/js/widgets/priority.js
index fbe7b61bb43..44ff3b50c1e 100644
--- a/addons/web/static/src/js/widgets/priority.js
+++ b/addons/web/static/src/js/widgets/priority.js
@@ -66,13 +66,15 @@ var Priority = Widget.extend({
this._render_value();
},
_render_value: function() {
- var current_value = this.value;
+ var self = this;
+ var index_value = this.value ? _.findIndex(this.values, function (v) {
+ return v[0] === self.value;
+ }) : 0;
this.$stars = this.$('.o_priority_star');
this.$stars.each(function(i, el) {
var $star = $(el);
- var star_value = $star.data('value');
- $star.toggleClass('fa-star', (star_value <= current_value))
- .toggleClass('fa-star-o', (star_value > current_value));
+ $star.toggleClass('fa-star', (i+1 <= index_value))
+ .toggleClass('fa-star-o', (i+1 > index_value));
});
},
});