[MOV] [ADD] Moved gauge and sparkline widgets into their own modules.
Introducing two new web modules: web_kanban_gauge and web_kanban_sparkline. bzr revid: tde@openerp.com-20130906100528-rfk9u9op5u8kadl9
This commit is contained in:
parent
a937b5679b
commit
5245e732bc
|
@ -32,11 +32,9 @@ This module provides the core of the OpenERP Web Client.
|
||||||
"static/lib/jquery.ui.notify/js/jquery.notify.js",
|
"static/lib/jquery.ui.notify/js/jquery.notify.js",
|
||||||
"static/lib/jquery.deferred-queue/jquery.deferred-queue.js",
|
"static/lib/jquery.deferred-queue/jquery.deferred-queue.js",
|
||||||
"static/lib/jquery.scrollTo/jquery.scrollTo-min.js",
|
"static/lib/jquery.scrollTo/jquery.scrollTo-min.js",
|
||||||
"static/lib/jquery.sparkline/jquery.sparkline.js",
|
|
||||||
"static/lib/jquery.tipsy/jquery.tipsy.js",
|
"static/lib/jquery.tipsy/jquery.tipsy.js",
|
||||||
"static/lib/jquery.textext/jquery.textext.js",
|
"static/lib/jquery.textext/jquery.textext.js",
|
||||||
"static/lib/jquery.timeago/jquery.timeago.js",
|
"static/lib/jquery.timeago/jquery.timeago.js",
|
||||||
"static/lib/justgage/justgage.js",
|
|
||||||
"static/lib/qweb/qweb2.js",
|
"static/lib/qweb/qweb2.js",
|
||||||
"static/lib/underscore/underscore.js",
|
"static/lib/underscore/underscore.js",
|
||||||
"static/lib/underscore.string/lib/underscore.string.js",
|
"static/lib/underscore.string/lib/underscore.string.js",
|
||||||
|
|
|
@ -1232,157 +1232,6 @@ instance.web_kanban.AbstractField = instance.web.Widget.extend(instance.web_kanb
|
||||||
|
|
||||||
instance.web_kanban.fields_registry = new instance.web.Registry({});
|
instance.web_kanban.fields_registry = new instance.web.Registry({});
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 () {
|
|
||||||
var value = _.pluck(self.field.value, 'value');
|
|
||||||
var tooltips = _.pluck(self.field.value, 'tooltip');
|
|
||||||
var sparkline_options = _.extend({
|
|
||||||
type: 'bar',
|
|
||||||
barWidth: 5,
|
|
||||||
height: '20px',
|
|
||||||
barWidth: 4,
|
|
||||||
barSpacing: 1,
|
|
||||||
barColor: '#96d854',
|
|
||||||
tooltipFormat: '{{offset:offset}} {{value}}',
|
|
||||||
tooltipValueLookups: {
|
|
||||||
'offset': tooltips
|
|
||||||
}
|
|
||||||
}, self.options);
|
|
||||||
self.$el.sparkline(value, sparkline_options);
|
|
||||||
self.$el.tipsy({'delayIn': 0, 'html': true, 'title': function(){return title}, 'gravity': 'n'});
|
|
||||||
}, 0);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
instance.web_kanban.fields_registry.add("sparkline_bar", "instance.web_kanban.SparklineBarWidget");
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Kanban widgets: GaugeWidget
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
instance.web_kanban.GaugeWidget = instance.web_kanban.AbstractField.extend({
|
|
||||||
className: "oe_gauge",
|
|
||||||
start: function() {
|
|
||||||
var self = this;
|
|
||||||
var parent = this.getParent();
|
|
||||||
var max = 100;
|
|
||||||
if (this.options.max_field) {
|
|
||||||
max = this.getParent().record[this.options.max_field].raw_value;
|
|
||||||
}
|
|
||||||
var label = this.options.label || "";
|
|
||||||
if (this.options.label_field) {
|
|
||||||
label = this.getParent().record[this.options.label_field].raw_value;
|
|
||||||
}
|
|
||||||
var val = this.field.value;
|
|
||||||
var value = _.isArray(val) && val.length ? val[val.length-1]['value'] : val;
|
|
||||||
var title = this.$node.html() || this.field.string;
|
|
||||||
// var unique_id = _.uniqueId("JustGage");
|
|
||||||
|
|
||||||
this.$el.empty()
|
|
||||||
.attr('style', this.$node.attr('style') + ';position:relative; display:inline-block;');
|
|
||||||
|
|
||||||
this.gage = new JustGage({
|
|
||||||
parentNode: this.$el[0],
|
|
||||||
// id: unique_id,
|
|
||||||
value: value,
|
|
||||||
title: title,
|
|
||||||
min: 0,
|
|
||||||
max: max,
|
|
||||||
relativeGaugeSize: true,
|
|
||||||
humanFriendly: true,
|
|
||||||
titleFontColor: '#333333',
|
|
||||||
valueFontColor: '#333333',
|
|
||||||
labelFontColor: '#000',
|
|
||||||
label: label,
|
|
||||||
levelColors: [
|
|
||||||
"#ff0000",
|
|
||||||
"#f9c802",
|
|
||||||
"#a9d70b"
|
|
||||||
],
|
|
||||||
});
|
|
||||||
this.gage.refresh(value, max);
|
|
||||||
|
|
||||||
var flag_open = false;
|
|
||||||
if (this.options.action_change) {
|
|
||||||
var $svg = this.$el.find('svg');
|
|
||||||
var css = {
|
|
||||||
'text-align': 'center',
|
|
||||||
'position': 'absolute',
|
|
||||||
'width': this.$el.outerWidth() + 'px',
|
|
||||||
'top': (this.$el.outerHeight()/2-5) + 'px'
|
|
||||||
};
|
|
||||||
|
|
||||||
this.$el.click(function (event) {
|
|
||||||
event.stopPropagation();
|
|
||||||
flag_open = false;
|
|
||||||
if (!parent.view.is_action_enabled('edit')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!self.$el.find(".oe_justgage_edit").size()) {
|
|
||||||
$div = $('<div class="oe_justgage_edit" style="z-index:1"/>');
|
|
||||||
$div.css(css);
|
|
||||||
$input = $('<input/>').val(value);
|
|
||||||
$input.css({
|
|
||||||
'text-align': 'center',
|
|
||||||
'margin': 'auto',
|
|
||||||
'width': ($svg.outerWidth()-40) + 'px'
|
|
||||||
});
|
|
||||||
$div.append($input);
|
|
||||||
self.$el.prepend($div)
|
|
||||||
$input.focus()
|
|
||||||
.keydown(function (event) {
|
|
||||||
event.stopPropagation();
|
|
||||||
if (event.keyCode == 13 || event.keyCode == 9) {
|
|
||||||
if ($input.val() != value) {
|
|
||||||
parent.view.dataset.call(self.options.action_change, [parent.id, $input.val()]).then(function () {
|
|
||||||
parent.do_reload();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$div.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.click(function (event) {
|
|
||||||
event.stopPropagation();
|
|
||||||
flag_open = false;
|
|
||||||
})
|
|
||||||
.blur(function (event) {
|
|
||||||
if(!flag_open) {
|
|
||||||
self.$el.find(".oe_justgage_edit").remove();
|
|
||||||
} else {
|
|
||||||
flag_open = false;
|
|
||||||
setTimeout(function () {$input.focus();}, 0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).mousedown(function () {
|
|
||||||
flag_open = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!+value) {
|
|
||||||
$svg.fadeTo(0, 0.3);
|
|
||||||
$div = $('<div/>').text(_t("Click to change value"));
|
|
||||||
$div.css(css);
|
|
||||||
this.$el.append($div);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
instance.web_kanban.fields_registry.add("gauge", "instance.web_kanban.GaugeWidget");
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
'name': 'Gauge Widget for Kanban',
|
||||||
|
'category': 'Hidden',
|
||||||
|
'description': """
|
||||||
|
This widget allows to display gauges using jquery.sparkline library.
|
||||||
|
""",
|
||||||
|
'version': '1.0',
|
||||||
|
'depends': ['web_kanban'],
|
||||||
|
'js': [
|
||||||
|
'static/lib/justgage/justgage.js',
|
||||||
|
'static/src/js/kanban_gauge.js'
|
||||||
|
],
|
||||||
|
'css': [
|
||||||
|
],
|
||||||
|
'qweb': [
|
||||||
|
],
|
||||||
|
'auto_install': False,
|
||||||
|
}
|
|
@ -0,0 +1,119 @@
|
||||||
|
openerp.web_kanban_gauge = function (instance) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kanban widgets: GaugeWidget
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
instance.web_kanban.GaugeWidget = instance.web_kanban.AbstractField.extend({
|
||||||
|
className: "oe_gauge",
|
||||||
|
start: function() {
|
||||||
|
var self = this;
|
||||||
|
var parent = this.getParent();
|
||||||
|
var max = 100;
|
||||||
|
if (this.options.max_field) {
|
||||||
|
max = this.getParent().record[this.options.max_field].raw_value;
|
||||||
|
}
|
||||||
|
var label = this.options.label || "";
|
||||||
|
if (this.options.label_field) {
|
||||||
|
label = this.getParent().record[this.options.label_field].raw_value;
|
||||||
|
}
|
||||||
|
var val = this.field.value;
|
||||||
|
var value = _.isArray(val) && val.length ? val[val.length-1]['value'] : val;
|
||||||
|
var title = this.$node.html() || this.field.string;
|
||||||
|
// var unique_id = _.uniqueId("JustGage");
|
||||||
|
|
||||||
|
this.$el.empty()
|
||||||
|
.attr('style', this.$node.attr('style') + ';position:relative; display:inline-block;');
|
||||||
|
|
||||||
|
this.gage = new JustGage({
|
||||||
|
parentNode: this.$el[0],
|
||||||
|
// id: unique_id,
|
||||||
|
value: value,
|
||||||
|
title: title,
|
||||||
|
min: 0,
|
||||||
|
max: max,
|
||||||
|
relativeGaugeSize: true,
|
||||||
|
humanFriendly: true,
|
||||||
|
titleFontColor: '#333333',
|
||||||
|
valueFontColor: '#333333',
|
||||||
|
labelFontColor: '#000',
|
||||||
|
label: label,
|
||||||
|
levelColors: [
|
||||||
|
"#ff0000",
|
||||||
|
"#f9c802",
|
||||||
|
"#a9d70b"
|
||||||
|
],
|
||||||
|
});
|
||||||
|
this.gage.refresh(value, max);
|
||||||
|
|
||||||
|
var flag_open = false;
|
||||||
|
if (this.options.action_change) {
|
||||||
|
var $svg = this.$el.find('svg');
|
||||||
|
var css = {
|
||||||
|
'text-align': 'center',
|
||||||
|
'position': 'absolute',
|
||||||
|
'width': this.$el.outerWidth() + 'px',
|
||||||
|
'top': (this.$el.outerHeight()/2-5) + 'px'
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$el.click(function (event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
flag_open = false;
|
||||||
|
if (!parent.view.is_action_enabled('edit')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!self.$el.find(".oe_justgage_edit").size()) {
|
||||||
|
$div = $('<div class="oe_justgage_edit" style="z-index:1"/>');
|
||||||
|
$div.css(css);
|
||||||
|
$input = $('<input/>').val(value);
|
||||||
|
$input.css({
|
||||||
|
'text-align': 'center',
|
||||||
|
'margin': 'auto',
|
||||||
|
'width': ($svg.outerWidth()-40) + 'px'
|
||||||
|
});
|
||||||
|
$div.append($input);
|
||||||
|
self.$el.prepend($div)
|
||||||
|
$input.focus()
|
||||||
|
.keydown(function (event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
if (event.keyCode == 13 || event.keyCode == 9) {
|
||||||
|
if ($input.val() != value) {
|
||||||
|
parent.view.dataset.call(self.options.action_change, [parent.id, $input.val()]).then(function () {
|
||||||
|
parent.do_reload();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$div.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.click(function (event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
flag_open = false;
|
||||||
|
})
|
||||||
|
.blur(function (event) {
|
||||||
|
if(!flag_open) {
|
||||||
|
self.$el.find(".oe_justgage_edit").remove();
|
||||||
|
} else {
|
||||||
|
flag_open = false;
|
||||||
|
setTimeout(function () {$input.focus();}, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).mousedown(function () {
|
||||||
|
flag_open = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!+value) {
|
||||||
|
$svg.fadeTo(0, 0.3);
|
||||||
|
$div = $('<div/>').text(_t("Click to change value"));
|
||||||
|
$div.css(css);
|
||||||
|
this.$el.append($div);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.web_kanban.fields_registry.add("gauge", "instance.web_kanban.GaugeWidget");
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
'name': 'Sparkline Widget for Kanban',
|
||||||
|
'category': 'Hidden',
|
||||||
|
'description': """
|
||||||
|
This widget allows to display sparklines using jquery.sparkline library.
|
||||||
|
""",
|
||||||
|
'version': '1.0',
|
||||||
|
'depends': ['web_kanban'],
|
||||||
|
'js': [
|
||||||
|
"static/lib/jquery.sparkline/jquery.sparkline.js",
|
||||||
|
'static/src/js/kanban_sparkline.js'
|
||||||
|
],
|
||||||
|
'css': [
|
||||||
|
],
|
||||||
|
'qweb': [
|
||||||
|
],
|
||||||
|
'auto_install': False,
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
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 () {
|
||||||
|
var value = _.pluck(self.field.value, 'value');
|
||||||
|
var tooltips = _.pluck(self.field.value, 'tooltip');
|
||||||
|
var sparkline_options = _.extend({
|
||||||
|
type: 'bar',
|
||||||
|
barWidth: 5,
|
||||||
|
height: '20px',
|
||||||
|
barWidth: 4,
|
||||||
|
barSpacing: 1,
|
||||||
|
barColor: '#96d854',
|
||||||
|
tooltipFormat: '{{offset:offset}} {{value}}',
|
||||||
|
tooltipValueLookups: {
|
||||||
|
'offset': tooltips
|
||||||
|
}
|
||||||
|
}, self.options);
|
||||||
|
self.$el.sparkline(value, sparkline_options);
|
||||||
|
self.$el.tipsy({'delayIn': 0, 'html': true, 'title': function(){return title}, 'gravity': 'n'});
|
||||||
|
}, 0);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
instance.web_kanban.fields_registry.add("sparkline_bar", "instance.web_kanban.SparklineBarWidget");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue