[IMP] [FIX] kanban: updated justgage and sparklin libraries; fixed gauge widget showing 0 as value by forcing a refresh

bzr revid: tde@openerp.com-20130906093221-n94whqrrj2meknwf
This commit is contained in:
Thibault Delavallée 2013-09-06 11:32:21 +02:00
parent 60b0c0ae95
commit a937b5679b
4 changed files with 53 additions and 35 deletions

View File

@ -36,7 +36,7 @@ This module provides the core of the OpenERP Web Client.
"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.1.0.1.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",

View File

@ -2,7 +2,7 @@
* *
* jquery.sparkline.js * jquery.sparkline.js
* *
* v2.1.1 * v2.1.2
* (c) Splunk, Inc * (c) Splunk, Inc
* Contact: Gareth Watts (gareth@splunk.com) * Contact: Gareth Watts (gareth@splunk.com)
* http://omnipotent.net/jquery.sparkline/ * http://omnipotent.net/jquery.sparkline/
@ -202,11 +202,11 @@
/*jslint regexp: true, browser: true, jquery: true, white: true, nomen: false, plusplus: false, maxerr: 500, indent: 4 */ /*jslint regexp: true, browser: true, jquery: true, white: true, nomen: false, plusplus: false, maxerr: 500, indent: 4 */
(function(document, Math, undefined) { // performance/minified-size optimization
(function(factory) { (function(factory) {
if(typeof define === 'function' && define.amd) { if(typeof define === 'function' && define.amd) {
define(['jquery'], factory); define(['jquery'], factory);
} } else if (jQuery && !jQuery.fn.sparkline) {
else {
factory(jQuery); factory(jQuery);
} }
} }
@ -597,19 +597,41 @@
if (useExisting && (target = this.data('_jqs_vcanvas'))) { if (useExisting && (target = this.data('_jqs_vcanvas'))) {
return target; return target;
} }
if ($.fn.sparkline.canvas === false) {
// We've already determined that neither Canvas nor VML are available
return false;
} else if ($.fn.sparkline.canvas === undefined) {
// No function defined yet -- need to see if we support Canvas or VML
var el = document.createElement('canvas');
if (!!(el.getContext && el.getContext('2d'))) {
// Canvas is available
$.fn.sparkline.canvas = function(width, height, target, interact) {
return new VCanvas_canvas(width, height, target, interact);
};
} else if (document.namespaces && !document.namespaces.v) {
// VML is available
document.namespaces.add('v', 'urn:schemas-microsoft-com:vml', '#default#VML');
$.fn.sparkline.canvas = function(width, height, target, interact) {
return new VCanvas_vml(width, height, target);
};
} else {
// Neither Canvas nor VML are available
$.fn.sparkline.canvas = false;
return false;
}
}
if (width === undefined) { if (width === undefined) {
width = $(this).innerWidth(); width = $(this).innerWidth();
} }
if (height === undefined) { if (height === undefined) {
height = $(this).innerHeight(); height = $(this).innerHeight();
} }
if ($.fn.sparkline.hasCanvas) {
target = new VCanvas_canvas(width, height, this, interact); target = $.fn.sparkline.canvas(width, height, this, interact);
} else if ($.fn.sparkline.hasVML) {
target = new VCanvas_vml(width, height, this);
} else {
return false;
}
mhandler = $(this).data('_jqs_mhandler'); mhandler = $(this).data('_jqs_mhandler');
if (mhandler) { if (mhandler) {
mhandler.registerCanvas(target); mhandler.registerCanvas(target);
@ -977,8 +999,7 @@
mhandler.registerSparkline(sp); mhandler.registerSparkline(sp);
} }
}; };
// jQuery 1.3.0 completely changed the meaning of :hidden :-/ if (($(this).html() && !options.get('disableHiddenCheck') && $(this).is(':hidden')) || !$(this).parents('body').length) {
if (($(this).html() && !options.get('disableHiddenCheck') && $(this).is(':hidden')) || ($.fn.jquery < '1.3.0' && $(this).parents().is(':hidden')) || !$(this).parents('body').length) {
if (!options.get('composite') && $.data(this, '_jqs_pending')) { if (!options.get('composite') && $.data(this, '_jqs_pending')) {
// remove any existing references to the element // remove any existing references to the element
for (i = pending.length; i; i--) { for (i = pending.length; i; i--) {
@ -2528,20 +2549,6 @@
// Setup a very simple "virtual canvas" to make drawing the few shapes we need easier // Setup a very simple "virtual canvas" to make drawing the few shapes we need easier
// This is accessible as $(foo).simpledraw() // This is accessible as $(foo).simpledraw()
// Detect browser renderer support
(function() {
if (document.namespaces && !document.namespaces.v) {
$.fn.sparkline.hasVML = true;
document.namespaces.add('v', 'urn:schemas-microsoft-com:vml', '#default#VML');
} else {
$.fn.sparkline.hasVML = false;
}
var el = document.createElement('canvas');
$.fn.sparkline.hasCanvas = !!(el.getContext && el.getContext('2d'));
})()
VShape = createClass({ VShape = createClass({
init: function (target, id, type, args) { init: function (target, id, type, args) {
this.target = target; this.target = target;
@ -3044,4 +3051,4 @@
} }
}); });
})); }))}(document, Math));

View File

@ -1276,6 +1276,7 @@ instance.web_kanban.GaugeWidget = instance.web_kanban.AbstractField.extend({
className: "oe_gauge", className: "oe_gauge",
start: function() { start: function() {
var self = this; var self = this;
var parent = this.getParent();
var max = 100; var max = 100;
if (this.options.max_field) { if (this.options.max_field) {
max = this.getParent().record[this.options.max_field].raw_value; max = this.getParent().record[this.options.max_field].raw_value;
@ -1287,33 +1288,43 @@ instance.web_kanban.GaugeWidget = instance.web_kanban.AbstractField.extend({
var val = this.field.value; var val = this.field.value;
var value = _.isArray(val) && val.length ? val[val.length-1]['value'] : val; var value = _.isArray(val) && val.length ? val[val.length-1]['value'] : val;
var title = this.$node.html() || this.field.string; 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({ this.gage = new JustGage({
parentNode: this.$el[0], parentNode: this.$el[0],
// id: unique_id,
value: value, value: value,
title: title, title: title,
min: 0, min: 0,
max: max, max: max,
relativeGaugeSize: true, relativeGaugeSize: true,
humanFriendly: true, humanFriendly: true,
titleFontColor: '#333333',
valueFontColor: '#333333',
labelFontColor: '#000',
label: label, label: label,
levelColors: [ levelColors: [
"#ff0000", "#ff0000",
"#f9c802", "#f9c802",
"#a9d70b" "#a9d70b"
] ],
}); });
this.gage.refresh(value, max);
var flag_open = false; var flag_open = false;
if (self.options.action_change) { if (this.options.action_change) {
var $svg = self.$el.find('svg'); var $svg = this.$el.find('svg');
var css = { var css = {
'text-align': 'center', 'text-align': 'center',
'position': 'absolute', 'position': 'absolute',
'width': self.$el.outerWidth() + 'px', 'width': this.$el.outerWidth() + 'px',
'top': (self.$el.outerHeight()/2-5) + 'px' 'top': (this.$el.outerHeight()/2-5) + 'px'
}; };
self.$el.click(function (event) { this.$el.click(function (event) {
event.stopPropagation(); event.stopPropagation();
flag_open = false; flag_open = false;
if (!parent.view.is_action_enabled('edit')) { if (!parent.view.is_action_enabled('edit')) {
@ -1364,7 +1375,7 @@ instance.web_kanban.GaugeWidget = instance.web_kanban.AbstractField.extend({
$svg.fadeTo(0, 0.3); $svg.fadeTo(0, 0.3);
$div = $('<div/>').text(_t("Click to change value")); $div = $('<div/>').text(_t("Click to change value"));
$div.css(css); $div.css(css);
self.$el.append($div); this.$el.append($div);
} }
} }
}, },