1 openerp.web_kanban_gauge = function (instance) {
4 * Kanban widgets: GaugeWidget
7 var _t = instance.web._t,
8 _lt = instance.web._lt;
9 instance.web_kanban.GaugeWidget = instance.web_kanban.AbstractField.extend({
10 className: "oe_gauge",
13 var parent = this.getParent();
15 if (this.options.max_field) {
16 max = this.getParent().record[this.options.max_field].raw_value;
18 var label = this.options.label || "";
19 if (this.options.label_field) {
20 label = this.getParent().record[this.options.label_field].raw_value;
22 var val = this.field.value;
23 var value = _.isArray(val) && val.length ? val[val.length-1]['value'] : val;
24 var title = this.$node.html() || this.field.string;
25 // var unique_id = _.uniqueId("JustGage");
28 .attr('style', this.$node.attr('style') + ';position:relative; display:inline-block;');
30 this.gage = new JustGage({
31 parentNode: this.$el[0],
37 relativeGaugeSize: true,
39 titleFontColor: '#333333',
40 valueFontColor: '#333333',
41 labelFontColor: '#000',
49 this.gage.refresh(value, max);
51 var flag_open = false;
52 if (this.options.action_change) {
53 var $svg = this.$el.find('svg');
55 'text-align': 'center',
56 'position': 'absolute',
57 'width': this.$el.outerWidth() + 'px',
58 'top': (this.$el.outerHeight()/2-5) + 'px'
61 this.$el.click(function (event) {
62 event.stopPropagation();
64 if (!parent.view.is_action_enabled('edit')) {
67 if (!self.$el.find(".oe_justgage_edit").size()) {
68 $div = $('<div class="oe_justgage_edit" style="z-index:1"/>');
70 $input = $('<input/>').val(value);
72 'text-align': 'center',
74 'width': ($svg.outerWidth()-40) + 'px'
77 self.$el.prepend($div)
79 .keydown(function (event) {
80 event.stopPropagation();
81 if(isNaN($input.val())){
82 self.do_warn(_t("Wrong value entered!"), _t("Only Integer Value should be valid."));
85 if (event.keyCode == 13 || event.keyCode == 9) {
86 var val = self.parse_client($input.val());
87 if ($input.val() != value) {
88 parent.view.dataset.call(self.options.action_change, [parent.id, $input.val()]).then(function () {
97 .click(function (event) {
98 event.stopPropagation();
101 .blur(function (event) {
103 self.$el.find(".oe_justgage_edit").remove();
106 setTimeout(function () {$input.focus();}, 0);
110 }).mousedown(function () {
116 $div = $('<div/>').text(_t("Click to change value"));
118 this.$el.append($div);
123 parse_client: function(value) {
124 return openerp.web.parse_value(value, { type:"float" });
129 instance.web_kanban.fields_registry.add("gauge", "instance.web_kanban.GaugeWidget");