2013-09-06 10:05:28 +00:00
|
|
|
openerp.web_kanban_sparkline = function (instance) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kanban widgets: Sparkline
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
instance.web_kanban.SparklineBarWidget = instance.web_kanban.AbstractField.extend({
|
|
|
|
className: "oe_sparkline_bar",
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
var title = this.$node.html() || this.field.string;
|
|
|
|
setTimeout(function () {
|
2015-04-14 15:38:11 +00:00
|
|
|
var tooltipFormatter = function(sp, options, fields) {
|
|
|
|
var format = $.spformat('<div class="jqsfield">{{offset:offset}} {{formatted_value}}</div>');
|
|
|
|
var result = '';
|
|
|
|
$.each(fields, function(i, field) {
|
|
|
|
field.formatted_value = instance.web.format_value(field.value, { type : 'float' });
|
|
|
|
result += format.render(field, options.get('tooltipValueLookups'), options);
|
|
|
|
})
|
|
|
|
return result;
|
|
|
|
}
|
2014-07-04 12:36:21 +00:00
|
|
|
var field_value = JSON.parse(self.field.value);
|
|
|
|
var value = _.pluck(field_value, 'value');
|
|
|
|
var tooltips = _.pluck(field_value, 'tooltip');
|
2013-10-11 07:27:44 +00:00
|
|
|
var suffix = self.options.tooltip_suffix || "";
|
2014-01-06 13:16:05 +00:00
|
|
|
var tooltipFormat = self.options.type == 'tristate' && '{{offset:offset}}' + suffix || '{{offset:offset}} {{value:value}}' + suffix
|
2013-09-06 10:05:28 +00:00
|
|
|
var sparkline_options = _.extend({
|
|
|
|
type: 'bar',
|
|
|
|
barWidth: 5,
|
|
|
|
height: '20px',
|
|
|
|
barWidth: 4,
|
|
|
|
barSpacing: 1,
|
|
|
|
barColor: '#96d854',
|
2014-01-06 13:16:05 +00:00
|
|
|
tooltipFormat: tooltipFormat,
|
2015-04-14 15:38:11 +00:00
|
|
|
tooltipFormatter: self.options.type == 'tristate' ? undefined : tooltipFormatter,
|
2013-10-03 07:58:36 +00:00
|
|
|
chartRangeMin: 0,
|
2013-09-06 10:05:28 +00:00
|
|
|
tooltipValueLookups: {
|
|
|
|
'offset': tooltips
|
|
|
|
}
|
|
|
|
}, self.options);
|
|
|
|
self.$el.sparkline(value, sparkline_options);
|
2014-04-17 08:59:54 +00:00
|
|
|
self.$el.tooltip({delay: {show: self.options.delayIn || 0, hide: 0}, title: function(){return title}});
|
2013-09-06 10:05:28 +00:00
|
|
|
}, 0);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
instance.web_kanban.fields_registry.add("sparkline_bar", "instance.web_kanban.SparklineBarWidget");
|
|
|
|
|
|
|
|
|
|
|
|
}
|