1
openerp.web_kanban_gauge = function (instance) {
4
* Kanban widgets: GaugeWidget
8
instance.web_kanban.GaugeWidget = instance.web_kanban.AbstractField.extend({
12
var parent = this.getParent();
14
if (this.options.max_field) {
15
max = this.getParent().record[this.options.max_field].raw_value;
17
var label = this.options.label || "";
18
if (this.options.label_field) {
19
label = this.getParent().record[this.options.label_field].raw_value;
21
var val = this.field.value;
22
var value = _.isArray(val) && val.length ? val[val.length-1]['value'] : val;
23
var title = this.$node.html() || this.field.string;
24
// var unique_id = _.uniqueId("JustGage");
27
.attr('style', this.$node.attr('style') + ';position:relative; display:inline-block;');
29
this.gage = new JustGage({
30
parentNode: this.$el[0],
36
relativeGaugeSize: true,
38
titleFontColor: '#333333',
39
valueFontColor: '#333333',
40
labelFontColor: '#000',
48
this.gage.refresh(value, max);
50
var flag_open = false;
51
if (this.options.action_change) {
52
var $svg = this.$el.find('svg');
54
'text-align': 'center',
55
'position': 'absolute',
56
'width': this.$el.outerWidth() + 'px',
57
'top': (this.$el.outerHeight()/2-5) + 'px'
60
this.$el.click(function (event) {
61
event.stopPropagation();
63
if (!parent.view.is_action_enabled('edit')) {
66
if (!self.$el.find(".oe_justgage_edit").size()) {
67
$div = $('<div class="oe_justgage_edit" style="z-index:1"/>');
69
$input = $('<input/>').val(value);
71
'text-align': 'center',
73
'width': ($svg.outerWidth()-40) + 'px'
76
self.$el.prepend($div)
78
.keydown(function (event) {
79
event.stopPropagation();
80
if (event.keyCode == 13 || event.keyCode == 9) {
81
if ($input.val() != value) {
82
parent.view.dataset.call(self.options.action_change, [parent.id, $input.val()]).then(function () {
90
.click(function (event) {
91
event.stopPropagation();
94
.blur(function (event) {
96
self.$el.find(".oe_justgage_edit").remove();
99
setTimeout(function () {$input.focus();}, 0);
103
}).mousedown(function () {
109
$div = $('<div/>').text(_t("Click to change value"));
111
this.$el.append($div);
117
instance.web_kanban.fields_registry.add("gauge", "instance.web_kanban.GaugeWidget");