From 101092b5aa017fb846abdfcc090c9e33f71e68f1 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Wed, 13 May 2015 15:13:34 +0200 Subject: [PATCH] [IMP] web_kanban: KanbanProgressBar changes to use ProgressBar widget --- addons/web_kanban/static/src/css/kanban.css | 12 ++ addons/web_kanban/static/src/css/kanban.sass | 12 ++ .../web_kanban/static/src/js/kanban_common.js | 126 ++++++------------ .../web_kanban/static/src/xml/web_kanban.xml | 16 --- 4 files changed, 64 insertions(+), 102 deletions(-) diff --git a/addons/web_kanban/static/src/css/kanban.css b/addons/web_kanban/static/src/css/kanban.css index ca396a32df9..840597606dd 100644 --- a/addons/web_kanban/static/src/css/kanban.css +++ b/addons/web_kanban/static/src/css/kanban.css @@ -559,6 +559,18 @@ background-color: #FFC7F1; color: #6d2c70; } +.openerp .oe_kanban_view .o_progressbar .o_progressbar_title { + width: 20%; +} +.openerp .oe_kanban_view .o_progressbar .o_progress { + width: 60%; + height: 20px; +} +.openerp .oe_kanban_view .o_progressbar .o_progressbar_value { + width: 20%; + height: 20px; + text-align: right; +} .openerp .oe_form .oe_kanban_view .oe_kanban_column, .openerp .oe_form .oe_kanban_view .oe_kanban_group_header { padding: 0px; diff --git a/addons/web_kanban/static/src/css/kanban.sass b/addons/web_kanban/static/src/css/kanban.sass index 1f95b04e2d9..b229c8c9d41 100644 --- a/addons/web_kanban/static/src/css/kanban.sass +++ b/addons/web_kanban/static/src/css/kanban.sass @@ -497,6 +497,18 @@ color: #6d2c70 // }}} + // KanbanProgressBar + .o_progressbar + .o_progressbar_title + width: 20% + .o_progress + width: 60% + height: 20px + .o_progressbar_value + width: 20% + height: 20px + text-align: right + .openerp .oe_form .oe_kanban_view .oe_kanban_column, .oe_kanban_group_header padding: 0px diff --git a/addons/web_kanban/static/src/js/kanban_common.js b/addons/web_kanban/static/src/js/kanban_common.js index 6be0e2175f3..725612e5394 100644 --- a/addons/web_kanban/static/src/js/kanban_common.js +++ b/addons/web_kanban/static/src/js/kanban_common.js @@ -6,6 +6,7 @@ var data = require('web.data'); var form_common = require('web.form_common'); var formats = require('web.formats'); var framework = require('web.framework'); +var ProgressBar = require('web.ProgressBar'); var pyeval = require('web.pyeval'); var Registry = require('web.Registry'); var session = require('web.session'); @@ -847,110 +848,63 @@ var KanbanGroup = Widget.extend({ * Kanban widgets: ProgressBar * options * - editable: boolean if current_value is editable - * - editable_value: if set, get the editable_value from the field that must be present in the view - * [default: current_value] * - current_value: get the current_value from the field that must be present in the view * - max_value: get the max_value from the field that must be present in the view * - title: title of the gauge, displayed on top of the gauge * - on_change: action to call when cliking and setting a value - * */ -var ProgressBar = AbstractField.extend({ - template: "KanbanProgressBar", +var KanbanProgressBar = AbstractField.extend({ + events: { + 'click': function() { + if(this.progressbar.readonly) { + this.toggle_progressbar(); + } + } + }, init: function (parent, field, node) { this._super(parent, field, node); - var editable = this.options.editable; - var on_change = this.options.on_change; - var title = this.options.title; - var current_value = this.getParent().record[this.options.current_value].raw_value; - var editable_value = current_value; - if (editable && this.options.editable_value){ - editable_value = this.getParent().record[this.options.editable_value].raw_value; - } - var max_value = this.getParent().record[this.options.max_value].raw_value; - this.state = { - editable: editable, - on_change: on_change, - title: title, - current_value: current_value, - max_value: max_value, - editable_value: editable_value, - width_complete : 0, - width_over : 0, - }; + var record = this.getParent().record; + this.progressbar = new ProgressBar(this, { + readonly: true, + value: record[this.options.current_value].raw_value, + max_value: record[this.options.max_value].raw_value, + title: this.options.title + }); - var current_value = this.state.current_value; - var max_value = this.state.max_value; - if (current_value <= max_value){ - this.state.width_complete = current_value/max_value * 100; - } - else { - this.state.width_complete = max_value/current_value * 100; - this.state.width_over = (current_value - max_value) / current_value * 100; - } + this.readonly = !this.options.editable; + this.on_change = this.options.on_change; }, start: function () { - var self = this; - this.$el.click(function (event){ - var parent = self.getParent(); - var value = self.state.editable_value || self.state.current_value; - - event.stopPropagation(); - - if (!parent.view.is_action_enabled('edit')) { - return; - } - if (!self.state.editable) { - return; - } - - // add input - if (!self.$el.find(".o_progress_bar_edit").size()) { - var $div = $('
'); - $div.css({ - 'text-align': 'center', - 'position': 'absolute', - 'width': $(this).outerWidth() + 'px', - }); - var $input = $('').val(value); - $input.css({ - 'text-align': 'center', - 'margin': 'auto', - }); - $div.append($input); - $(this).prepend($div); - - $input.focus() - .keydown(function (event) { - event.stopPropagation(); - if(isNaN($input.val())){ - self.do_warn(_t("Wrong value entered!"), _t("Only Integer Value should be valid.")); - $div.remove(); - } else { - if (event.keyCode == 13 || event.keyCode == 9) { - if ($input.val() != value) { - parent.view.dataset.call(self.state.on_change, [parent.id, $input.val()]).then(function () { - parent.do_reload(); - }); - } else { - $div.remove(); - } - } - } - }) - } + var def = this.progressbar.appendTo('
').done(function() { + self.progressbar.$el.addClass(self.$el.attr('class')); + self.replaceElement(self.progressbar.$el); }); - return this._super(); + return $.when(this._super(), def).then(function() { + if(!self.readonly) { + var parent = self.getParent(); + self.progressbar.on('change:value', self, function(e) { + var value = this.progressbar.get('value') || 0; + if(!isNaN(value)) { + parent.view.dataset.call(this.on_change, [parent.id, value]).then(function() { + self.toggle_progressbar(); + }); + } + }); + } + }); }, - _format_number: function(number) { - return utils.human_number(number, this.type) + toggle_progressbar: function() { + this.progressbar.readonly = !this.progressbar.readonly; + var $div = $('
').insertAfter(this.$el); + this.progressbar.replace($div); + this.setElement(this.progressbar.$el); }, }); @@ -959,7 +913,7 @@ var fields_registry = new Registry(); fields_registry .add('priority', Priority) .add('kanban_state_selection', KanbanSelection) - .add("progress", ProgressBar); + .add("progress", KanbanProgressBar); return { diff --git a/addons/web_kanban/static/src/xml/web_kanban.xml b/addons/web_kanban/static/src/xml/web_kanban.xml index b4d1a9c5932..0a7bbcdcffb 100644 --- a/addons/web_kanban/static/src/xml/web_kanban.xml +++ b/addons/web_kanban/static/src/xml/web_kanban.xml @@ -105,20 +105,4 @@
- -
-
- : -
-
-
-
-
-
-
-
- / -
-
-