From 5245e732bc31dfe65d2480565bf0b9f3be307dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 6 Sep 2013 12:05:28 +0200 Subject: [PATCH] [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 --- addons/web/__openerp__.py | 2 - addons/web_kanban/static/src/js/kanban.js | 151 ------------------ addons/web_kanban_gauge/__init__.py | 0 addons/web_kanban_gauge/__openerp__.py | 18 +++ .../static/lib/justgage/justgage.js | 0 .../static/src/js/kanban_gauge.js | 119 ++++++++++++++ addons/web_kanban_sparkline/__init__.py | 0 addons/web_kanban_sparkline/__openerp__.py | 18 +++ .../lib/jquery.sparkline/jquery.sparkline.js | 0 .../static/src/js/kanban_sparkline.js | 37 +++++ 10 files changed, 192 insertions(+), 153 deletions(-) create mode 100644 addons/web_kanban_gauge/__init__.py create mode 100644 addons/web_kanban_gauge/__openerp__.py rename addons/{web => web_kanban_gauge}/static/lib/justgage/justgage.js (100%) create mode 100644 addons/web_kanban_gauge/static/src/js/kanban_gauge.js create mode 100644 addons/web_kanban_sparkline/__init__.py create mode 100644 addons/web_kanban_sparkline/__openerp__.py rename addons/{web => web_kanban_sparkline}/static/lib/jquery.sparkline/jquery.sparkline.js (100%) create mode 100644 addons/web_kanban_sparkline/static/src/js/kanban_sparkline.js diff --git a/addons/web/__openerp__.py b/addons/web/__openerp__.py index 9b13fd48b0a..5c8d27e11cb 100644 --- a/addons/web/__openerp__.py +++ b/addons/web/__openerp__.py @@ -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.deferred-queue/jquery.deferred-queue.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.textext/jquery.textext.js", "static/lib/jquery.timeago/jquery.timeago.js", - "static/lib/justgage/justgage.js", "static/lib/qweb/qweb2.js", "static/lib/underscore/underscore.js", "static/lib/underscore.string/lib/underscore.string.js", diff --git a/addons/web_kanban/static/src/js/kanban.js b/addons/web_kanban/static/src/js/kanban.js index 9bc8e3bd785..8ec11e37d25 100644 --- a/addons/web_kanban/static/src/js/kanban.js +++ b/addons/web_kanban/static/src/js/kanban.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({}); - -/** - * 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.css(css); - $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 = $('
').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: diff --git a/addons/web_kanban_gauge/__init__.py b/addons/web_kanban_gauge/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/addons/web_kanban_gauge/__openerp__.py b/addons/web_kanban_gauge/__openerp__.py new file mode 100644 index 00000000000..19b2d6f0da3 --- /dev/null +++ b/addons/web_kanban_gauge/__openerp__.py @@ -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, +} diff --git a/addons/web/static/lib/justgage/justgage.js b/addons/web_kanban_gauge/static/lib/justgage/justgage.js similarity index 100% rename from addons/web/static/lib/justgage/justgage.js rename to addons/web_kanban_gauge/static/lib/justgage/justgage.js diff --git a/addons/web_kanban_gauge/static/src/js/kanban_gauge.js b/addons/web_kanban_gauge/static/src/js/kanban_gauge.js new file mode 100644 index 00000000000..cb2faf6874b --- /dev/null +++ b/addons/web_kanban_gauge/static/src/js/kanban_gauge.js @@ -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.css(css); + $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 = $('
').text(_t("Click to change value")); + $div.css(css); + this.$el.append($div); + } + } + }, +}); + +instance.web_kanban.fields_registry.add("gauge", "instance.web_kanban.GaugeWidget"); + +} diff --git a/addons/web_kanban_sparkline/__init__.py b/addons/web_kanban_sparkline/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/addons/web_kanban_sparkline/__openerp__.py b/addons/web_kanban_sparkline/__openerp__.py new file mode 100644 index 00000000000..3fb4e13b4f7 --- /dev/null +++ b/addons/web_kanban_sparkline/__openerp__.py @@ -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, +} diff --git a/addons/web/static/lib/jquery.sparkline/jquery.sparkline.js b/addons/web_kanban_sparkline/static/lib/jquery.sparkline/jquery.sparkline.js similarity index 100% rename from addons/web/static/lib/jquery.sparkline/jquery.sparkline.js rename to addons/web_kanban_sparkline/static/lib/jquery.sparkline/jquery.sparkline.js diff --git a/addons/web_kanban_sparkline/static/src/js/kanban_sparkline.js b/addons/web_kanban_sparkline/static/src/js/kanban_sparkline.js new file mode 100644 index 00000000000..de21cbba945 --- /dev/null +++ b/addons/web_kanban_sparkline/static/src/js/kanban_sparkline.js @@ -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"); + + +}