From 2d33bf02cd17d4358fabb7e7ba2581b6848ba8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 16 May 2012 13:50:14 +0200 Subject: [PATCH 01/16] [ADD] view_form: added FieldStatusO2M field, that will behave like the FieldStatus widget, taking as a basis a o2m relationship instead of a selection. bzr revid: tde@openerp.com-20120516115014-pqa21egi369id0jf --- addons/web/static/src/js/view_form.js | 68 ++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index b0cf4df6b78..5c4d787a195 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3925,6 +3925,71 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({ } }); +instance.web.form.FieldStatusO2M = instance.web.form.AbstractField.extend({ + template: "EmptyComponent", + start: function() { + this._super(); + this.selected_value = null; + + this.render_list(); + }, + set_value: function(value_) { + this._super(value_); + this.selected_value = value_; + + this.render_list(); + }, + render_list: function() { + var self = this; + var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","), + function(x) { return _.str.trim(x); }); + shown = _.select(shown, function(x) { return x.length > 0; }); + + if (shown.length == 0) { + this.to_show = this.field.selection; + } else { + this.to_show = _.select(this.field.selection, function(x) { + return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value; + }); + } + + var content = instance.web.qweb.render("FieldStatus.content", {widget: this, _:_}); + this.$element.html(content); + + var colors = JSON.parse((this.node.attrs || {}).statusbar_colors || "{}"); + var color = colors[this.selected_value]; + if (color) { + var elem = this.$element.find("li.oe-arrow-list-selected span"); + elem.css("border-color", color); + if (this.check_white(color)) + elem.css("color", "white"); + elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-before"); + elem.css("border-left-color", "rgba(0,0,0,0)"); + elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-after"); + elem.css("border-color", "rgba(0,0,0,0)"); + elem.css("border-left-color", color); + } + }, + check_white: function(color) { + var div = $("
"); + div.css("display", "none"); + div.css("color", color); + div.appendTo($("body")); + var ncolor = div.css("color"); + div.remove(); + var res = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/.exec(ncolor); + if (!res) { + return false; + } + var comps = [parseInt(res[1]), parseInt(res[2]), parseInt(res[3])]; + var lum = comps[0] * 0.3 + comps[1] * 0.59 + comps[1] * 0.11; + if (lum < 128) { + return true; + } + return false; + } +}); + instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ template: "EmptyComponent", start: function() { @@ -4018,7 +4083,8 @@ instance.web.form.widgets = new instance.web.Registry({ 'progressbar': 'instance.web.form.FieldProgressBar', 'image': 'instance.web.form.FieldBinaryImage', 'binary': 'instance.web.form.FieldBinaryFile', - 'statusbar': 'instance.web.form.FieldStatus' + 'statusbar': 'instance.web.form.FieldStatus', + 'statusbaro2m': 'instance.web.form.FieldStatusO2M', }); /** From e256af698eb18707fdd3088736f6797895b02801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 16 May 2012 17:29:52 +0200 Subject: [PATCH 02/16] [IMP] StatusBarO2M widget: added basic data fetch for display bzr revid: tde@openerp.com-20120516152952-sehetnhm1uyd1t83 --- addons/web/static/src/js/view_form.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 5c4d787a195..2bbdf4a3b22 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3952,7 +3952,31 @@ instance.web.form.FieldStatusO2M = instance.web.form.AbstractField.extend({ return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value; }); } - + + // get a DataSet on the current model (ex: crm.lead) + this.model = new instance.web.DataSet(this, this.field_manager.dataset.model); + + // get the domain of the current field (ex: crm.lead.stage_id -> section_ids = section_id) + var fields_get_defer = this.model.call('fields_get', [[this.name]]).pipe( function (record) { + this.field_domain = record.domain; + }); + + // get a DataSetSearch on the current field relation (ex: crm.lead.stage_id -> crm.case.stage) + this.model_ext = new instance.web.DataSetSearch(this, this.field.relation); + + // search in the external relation for all possible values, then render them + var rendering_done = $.when(fields_get_defer).pipe( function () { + self.model_ext.read_slice(['name'], {'domain': self.field_domain}).pipe( function (records) { + self.to_show = []; + _(records).each(function (record) { + self.to_show.push([record.id, record.name]); + }); + }).then(self.proxy('render_elements')); + }); + + return rendering_done; + }, + render_elements: function () { var content = instance.web.qweb.render("FieldStatus.content", {widget: this, _:_}); this.$element.html(content); From a43bd1d9040f0b4a2bf62832d527a2303564eed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 18 May 2012 13:47:31 +0200 Subject: [PATCH 03/16] [IMP] Statusbar widget: merged the two versions into a generic one. bzr revid: tde@openerp.com-20120518114731-k765gtrja6djp0h0 --- addons/web/static/src/js/view_form.js | 133 ++++++++------------------ 1 file changed, 40 insertions(+), 93 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 99344e11217..0c8b74e04b7 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3873,95 +3873,6 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({ } }); -instance.web.form.FieldStatusO2M = instance.web.form.AbstractField.extend({ - template: "EmptyComponent", - start: function() { - this._super(); - this.selected_value = null; - - this.render_list(); - }, - set_value: function(value_) { - this._super(value_); - this.selected_value = value_; - - this.render_list(); - }, - render_list: function() { - var self = this; - var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","), - function(x) { return _.str.trim(x); }); - shown = _.select(shown, function(x) { return x.length > 0; }); - - if (shown.length == 0) { - this.to_show = this.field.selection; - } else { - this.to_show = _.select(this.field.selection, function(x) { - return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value; - }); - } - - // get a DataSet on the current model (ex: crm.lead) - this.model = new instance.web.DataSet(this, this.field_manager.dataset.model); - - // get the domain of the current field (ex: crm.lead.stage_id -> section_ids = section_id) - var fields_get_defer = this.model.call('fields_get', [[this.name]]).pipe( function (record) { - this.field_domain = record.domain; - }); - - // get a DataSetSearch on the current field relation (ex: crm.lead.stage_id -> crm.case.stage) - this.model_ext = new instance.web.DataSetSearch(this, this.field.relation); - - // search in the external relation for all possible values, then render them - var rendering_done = $.when(fields_get_defer).pipe( function () { - self.model_ext.read_slice(['name'], {'domain': self.field_domain}).pipe( function (records) { - self.to_show = []; - _(records).each(function (record) { - self.to_show.push([record.id, record.name]); - }); - }).then(self.proxy('render_elements')); - }); - - return rendering_done; - }, - render_elements: function () { - var content = instance.web.qweb.render("FieldStatus.content", {widget: this, _:_}); - this.$element.html(content); - - var colors = JSON.parse((this.node.attrs || {}).statusbar_colors || "{}"); - var color = colors[this.selected_value]; - if (color) { - var elem = this.$element.find("li.oe-arrow-list-selected span"); - elem.css("border-color", color); - if (this.check_white(color)) - elem.css("color", "white"); - elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-before"); - elem.css("border-left-color", "rgba(0,0,0,0)"); - elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-after"); - elem.css("border-color", "rgba(0,0,0,0)"); - elem.css("border-left-color", color); - } - }, - check_white: function(color) { - var div = $("
"); - div.css("display", "none"); - div.css("color", color); - div.appendTo($("body")); - var ncolor = div.css("color"); - div.remove(); - var res = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/.exec(ncolor); - if (!res) { - return false; - } - var comps = [parseInt(res[1]), parseInt(res[2]), parseInt(res[3])]; - var lum = comps[0] * 0.3 + comps[1] * 0.59 + comps[1] * 0.11; - if (lum < 128) { - return true; - } - return false; - } -}); - instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ template: "EmptyComponent", start: function() { @@ -3982,14 +3893,51 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ function(x) { return _.str.trim(x); }); shown = _.select(shown, function(x) { return x.length > 0; }); + var selection_done = this.get_selection(); + if (shown.length == 0) { - this.to_show = this.field.selection; + this.to_show = this.selection; } else { - this.to_show = _.select(this.field.selection, function(x) { + this.to_show = _.select(this.selection, function(x) { return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value; }); } - + + // search in the external relation for all possible values, then render them + var rendering_done = $.when(selection_done).then(function () { + console.log(self.selection); + self.to_show = self.selection; + }).pipe(self.proxy('render_elements')); + + return rendering_done; + }, + get_selection: function() { + var self = this; + if (this.field.type == "many2one") { + this.selection = []; + // get a DataSet on the current model (ex: crm.lead) + var model = new instance.web.DataSet(this, this.field_manager.dataset.model); + // get the domain of the current field (ex: crm.lead.stage_id -> section_ids = section_id) + var fields_get_defer = model.call('fields_get', [[this.name]]).pipe( function (record) { + var field_domain = record.domain; + }); + // get a DataSetSearch on the current field relation (ex: crm.lead.stage_id -> crm.case.stage) + var model_ext = new instance.web.DataSetSearch(this, this.field.relation); + // fetch selection + var read_defer = model_ext.read_slice(['name'], {'domain': self.field_domain}).pipe( function (records) { + self.to_show = []; + _(records).each(function (record) { + self.selection.push([record.id, record.name]); + }); + }); + return read_defer; + } + else { + this.selection = this.field.selection; + } + return true; + }, + render_elements: function () { var content = instance.web.qweb.render("FieldStatus.content", {widget: this, _:_}); this.$element.html(content); @@ -4056,7 +4004,6 @@ instance.web.form.widgets = new instance.web.Registry({ 'image': 'instance.web.form.FieldBinaryImage', 'binary': 'instance.web.form.FieldBinaryFile', 'statusbar': 'instance.web.form.FieldStatus', - 'statusbaro2m': 'instance.web.form.FieldStatusO2M', }); /** From 4f34df3f85190c8df254f95f771315153bf05391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 18 May 2012 14:22:32 +0200 Subject: [PATCH 04/16] [IMP] Statusbar widget: moved filtering to a dedicated method. bzr revid: tde@openerp.com-20120518122232-fh80935istq2244l --- addons/web/static/src/js/view_form.js | 32 +++++++++++++++------------ 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 0c8b74e04b7..bf449af98c7 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3889,24 +3889,15 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ }, render_list: function() { var self = this; - var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","), - function(x) { return _.str.trim(x); }); - shown = _.select(shown, function(x) { return x.length > 0; }); - + + // get selection values var selection_done = this.get_selection(); - if (shown.length == 0) { - this.to_show = this.selection; - } else { - this.to_show = _.select(this.selection, function(x) { - return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value; - }); - } - // search in the external relation for all possible values, then render them - var rendering_done = $.when(selection_done).then(function () { - console.log(self.selection); + var rendering_done = $.when(selection_done).pipe(function () { + //self.filter_selection(); self.to_show = self.selection; + console.log(self.to_show); }).pipe(self.proxy('render_elements')); return rendering_done; @@ -3937,6 +3928,19 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ } return true; }, + filter_selection: function() { + var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","), + function(x) { return _.str.trim(x); }); + shown = _.select(shown, function(x) { return x.length > 0; }); + + if (shown.length == 0) { + this.to_show = this.selection; + } else { + this.to_show = _.select(this.selection, function(x) { + return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value; + }); + } + }, render_elements: function () { var content = instance.web.qweb.render("FieldStatus.content", {widget: this, _:_}); this.$element.html(content); From 813ad817fb40820677b36d5c00c6e5d3d3826475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 18 May 2012 14:23:48 +0200 Subject: [PATCH 05/16] [IMP] Statusbar widget: made the selected_value of the element correct for many2one fields. bzr revid: tde@openerp.com-20120518122348-urtb44twaksen4e0 --- addons/web/static/src/js/view_form.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index bf449af98c7..ba1f611d945 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3883,8 +3883,15 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ }, set_value: function(value_) { this._super(value_); - this.selected_value = value_; - + /** find selected value: ex: + * - many2one: [2, "New"] + * - selection: new */ + if (this.field.type == "many2one") { + this.selected_value = value_[0]; + } + else { + this.selected_value = value_; + } this.render_list(); }, render_list: function() { From 962a5932cc9f78c89cd41ae2ef5776d64c89f583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 18 May 2012 14:34:20 +0200 Subject: [PATCH 06/16] [FIX] Fixed field value out of 'to show' list not showed anymore, due to a not defined self. bzr revid: tde@openerp.com-20120518123420-xid16y12kwgyatr3 --- addons/web/static/src/js/view_form.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index ba1f611d945..d9ad778956b 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3902,9 +3902,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ // search in the external relation for all possible values, then render them var rendering_done = $.when(selection_done).pipe(function () { - //self.filter_selection(); - self.to_show = self.selection; - console.log(self.to_show); + self.filter_selection(); }).pipe(self.proxy('render_elements')); return rendering_done; @@ -3936,6 +3934,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ return true; }, filter_selection: function() { + var self = this; var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","), function(x) { return _.str.trim(x); }); shown = _.select(shown, function(x) { return x.length > 0; }); From fcff2bc356412f9e9ac3b1eef6fdf319eec58066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 18 May 2012 15:37:03 +0200 Subject: [PATCH 07/16] [FIX] Fixed use of statusbar_visible for o2m fields. Also added some doc in the code. bzr revid: tde@openerp.com-20120518133703-307z79uce2haitdr --- addons/web/static/src/js/view_form.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index d9ad778956b..409f92b13eb 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3884,8 +3884,8 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ set_value: function(value_) { this._super(value_); /** find selected value: ex: - * - many2one: [2, "New"] - * - selection: new */ + * - many2one: [2, "New"] -> 2 + * - selection: new -> new */ if (this.field.type == "many2one") { this.selected_value = value_[0]; } @@ -3894,6 +3894,12 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ } this.render_list(); }, + /** Get the status list and render them + * to_show: [[identifier, value_to_displaty]] where + * - identifier = db value for a selection, id for a many2one + * - display_val = value that will be displayed + * - ex: [[0, "New"]] (selection) or [["new", "new"]] (many2one) + */ render_list: function() { var self = this; @@ -3933,8 +3939,23 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ } return true; }, + /** Filters this.selection, according to values coming from the statusbar_visible + * attribute of the field. For example: statusbar_visible="draft,open" + * There is however two main possibilities : + * - the value is the identifier, for a selection (new for [new, "New"]) + * -> in this case, the options values refer to list[x][0] + * - the value is the name or displayed value, for a many2one + * (Draft for [0, "Draft"]) + * -> in this case, the options values refer to list[x][0] + */ filter_selection: function() { var self = this; + if (this.field.type == "many2one") { + var index = 1; + } + else { + var index = 0; + } var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","), function(x) { return _.str.trim(x); }); shown = _.select(shown, function(x) { return x.length > 0; }); @@ -3943,7 +3964,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ this.to_show = this.selection; } else { this.to_show = _.select(this.selection, function(x) { - return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value; + return _.indexOf(shown, x[index]) !== -1 || x[index] === self.selected_value; }); } }, From e2d3403e7c3ce52d1fc9aaed01f7885319b9ab11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 18 May 2012 16:38:41 +0200 Subject: [PATCH 08/16] [REM] Removed duplicated FieldStatus.content template. bzr revid: tde@openerp.com-20120518143841-ykvblfiutbber44j --- addons/web/static/src/xml/base.xml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 97eeab36657..f9211745122 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1095,22 +1095,12 @@ - -
    - - -
  • - -
  • -
    -
-
  • - +
  • From b344bc09a73d290a4196814cf289f8d7c1405a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 18 May 2012 16:41:42 +0200 Subject: [PATCH 09/16] [REM] Removed check_white method, whose interest was quite low: 1/ it was not working anymore due to template changes (refer to previous commit abotu removing duplicate template) 2/ interest of replacing by white colors whose luminance is < 128 is yet to be proved. bzr revid: tde@openerp.com-20120518144142-oms1loax102s9p91 --- addons/web/static/src/js/view_form.js | 34 +++------------------------ 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 409f92b13eb..fe2b34c2049 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3902,15 +3902,12 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ */ render_list: function() { var self = this; - // get selection values var selection_done = this.get_selection(); - // search in the external relation for all possible values, then render them var rendering_done = $.when(selection_done).pipe(function () { self.filter_selection(); }).pipe(self.proxy('render_elements')); - return rendering_done; }, get_selection: function() { @@ -3964,7 +3961,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ this.to_show = this.selection; } else { this.to_show = _.select(this.selection, function(x) { - return _.indexOf(shown, x[index]) !== -1 || x[index] === self.selected_value; + return _.indexOf(shown, x[index]) !== -1 || x[0] === self.selected_value; }); } }, @@ -3975,35 +3972,10 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ var colors = JSON.parse((this.node.attrs || {}).statusbar_colors || "{}"); var color = colors[this.selected_value]; if (color) { - var elem = this.$element.find("li.oe-arrow-list-selected span"); - elem.css("border-color", color); - if (this.check_white(color)) - elem.css("color", "white"); - elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-before"); - elem.css("border-left-color", "rgba(0,0,0,0)"); - elem = this.$element.find("li.oe-arrow-list-selected .oe-arrow-list-after"); - elem.css("border-color", "rgba(0,0,0,0)"); - elem.css("border-left-color", color); + var elem = this.$element.find("li.oe_form_steps_active span"); + elem.css("color", color); } }, - check_white: function(color) { - var div = $("
    "); - div.css("display", "none"); - div.css("color", color); - div.appendTo($("body")); - var ncolor = div.css("color"); - div.remove(); - var res = /^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)\s*$/.exec(ncolor); - if (!res) { - return false; - } - var comps = [parseInt(res[1]), parseInt(res[2]), parseInt(res[3])]; - var lum = comps[0] * 0.3 + comps[1] * 0.59 + comps[1] * 0.11; - if (lum < 128) { - return true; - } - return false; - } }); /** From 29b82e8d434eb03e5e23f55a6ac60e9fa3f05c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 25 May 2012 09:29:43 +0200 Subject: [PATCH 10/16] [TMP] Tmp upgrade of FieldStatus. bzr revid: tde@openerp.com-20120525072943-egm3glsr8zwvn3es --- addons/web/static/src/js/view_form.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 8a9068520ad..a3695cfb246 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3874,7 +3874,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ this._super(); this.selected_value = null; - this.render_list(); + //this.render_list(); }, set_value: function(value_) { this._super(value_); @@ -3911,25 +3911,34 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ this.selection = []; // get a DataSet on the current model (ex: crm.lead) var model = new instance.web.DataSet(this, this.field_manager.dataset.model); - // get the domain of the current field (ex: crm.lead.stage_id -> section_ids = section_id) - var fields_get_defer = model.call('fields_get', [[this.name]]).pipe( function (record) { - var field_domain = record.domain; - }); // get a DataSetSearch on the current field relation (ex: crm.lead.stage_id -> crm.case.stage) - var model_ext = new instance.web.DataSetSearch(this, this.field.relation); + console.log('this'); + console.log(this); + var context = self.build_context(); + console.log('context'); + console.log(context); + var domain = self.build_domain(); + console.log('domain'); + console.log(domain); + //var new_domain = new instance.web.CompoundDomain(['|'], domain, [['case_default', '=', 'True']]); + //console.log(new_domain); + var model_ext = new instance.web.DataSetSearch(this, this.field.relation, context); // fetch selection - var read_defer = model_ext.read_slice(['name'], {'domain': self.field_domain}).pipe( function (records) { + //var read_defer = model_ext.read_slice(['name'], {'domain': domain, 'context': context}).pipe( function (records) { + var read_defer = model_ext.read_slice(['name'], {'domain': []}).pipe( function (records) { self.to_show = []; _(records).each(function (record) { self.selection.push([record.id, record.name]); }); + console.log('to_show'); + console.log(self.to_show); }); - return read_defer; } else { this.selection = this.field.selection; + var read_defer = true; } - return true; + return read_defer; }, /** Filters this.selection, according to values coming from the statusbar_visible * attribute of the field. For example: statusbar_visible="draft,open" From 97921508924f5dd04958789e5208e5e13869e22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 25 May 2012 10:01:24 +0200 Subject: [PATCH 11/16] [CLEAN] Statusbar widget: cleaned filter_selection code and comments. bzr revid: tde@openerp.com-20120525080124-c4pmsiu76wfb3ave --- addons/web/static/src/js/view_form.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index a3695cfb246..638ec4d9c4d 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3942,21 +3942,12 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ }, /** Filters this.selection, according to values coming from the statusbar_visible * attribute of the field. For example: statusbar_visible="draft,open" - * There is however two main possibilities : - * - the value is the identifier, for a selection (new for [new, "New"]) - * -> in this case, the options values refer to list[x][0] - * - the value is the name or displayed value, for a many2one - * (Draft for [0, "Draft"]) - * -> in this case, the options values refer to list[x][0] + * Currently, the key of (key, label) pairs has to be used in the + * selection of visible items. This feature is not meant to be used + * with many2one fields. */ filter_selection: function() { var self = this; - if (this.field.type == "many2one") { - var index = 1; - } - else { - var index = 0; - } var shown = _.map(((this.node.attrs || {}).statusbar_visible || "").split(","), function(x) { return _.str.trim(x); }); shown = _.select(shown, function(x) { return x.length > 0; }); @@ -3965,7 +3956,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ this.to_show = this.selection; } else { this.to_show = _.select(this.selection, function(x) { - return _.indexOf(shown, x[index]) !== -1 || x[0] === self.selected_value; + return _.indexOf(shown, x[0]) !== -1 || x[0] === self.selected_value; }); } }, From ea11df383822097f67b0744b1129eca8b650871e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 25 May 2012 12:10:57 +0200 Subject: [PATCH 12/16] [IMP] [CLEAN] [REF] Statusbar widget: now working, cleaned code. bzr revid: tde@openerp.com-20120525101057-62o01luqdfl3oo53 --- addons/web/static/src/js/view_form.js | 75 ++++++++++++++++----------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 638ec4d9c4d..7d2175bf45d 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -1485,7 +1485,6 @@ instance.web.form.FormWidget = instance.web.Widget.extend(_.extend({}, instance. if (! v_context) { v_context = (this.field || {}).context || {}; } - if (v_context.__ref || true) { //TODO: remove true var fields_values = this._build_eval_context(blacklist); v_context = new instance.web.CompoundContext(v_context).set_eval_context(fields_values); @@ -3874,9 +3873,14 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ this._super(); this.selected_value = null; - //this.render_list(); + /** preview before set_value only for selection fields, because of + * the dynamic behavior of many2one fields. */ + if (this.field.type == 'selection') { + this.render_list(); + } }, set_value: function(value_) { + var self = this; this._super(value_); /** find selected value: ex: * - many2one: [2, "New"] -> 2 @@ -3887,51 +3891,57 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ else { this.selected_value = value_; } - this.render_list(); + // trick to be sure all values are loaded in the form, therefore + // enabling the evaluation of dynamic domains + $.async_when().then(function() { + return self.render_list(); + }); }, + /** Get the status list and render them * to_show: [[identifier, value_to_displaty]] where * - identifier = db value for a selection, id for a many2one - * - display_val = value that will be displayed - * - ex: [[0, "New"]] (selection) or [["new", "new"]] (many2one) + * - display_val = label that will be displayed + * - ex: [[0, "New"]] (many2one) or [["new", "In Progress"]] (selection) */ render_list: function() { var self = this; - // get selection values - var selection_done = this.get_selection(); - // search in the external relation for all possible values, then render them - var rendering_done = $.when(selection_done).pipe(function () { - self.filter_selection(); - }).pipe(self.proxy('render_elements')); - return rendering_done; + // get selection values, filter them and render them + return this.get_selection().pipe(self.proxy('filter_selection')).pipe(self.proxy('render_elements')); }, + + /** Get the selection list to be displayed in the statusbar widget. + * For selection fields: this is directly given by this.field.selection + * For many2one fields : + * - perform a search on the relation of the many2one field (given by + * field.relation ) + * - get the field domain for the search + * - self.build_domain() gives the domain given by the view or by + * the field + * - if the optional statusbar_fold attribute is set to true, make + * an AND with build_domain to hide all 'fold=true' columns + * - make an OR with current value, to be sure it is displayed, + * with the correct order, even if it is folded + */ get_selection: function() { var self = this; if (this.field.type == "many2one") { this.selection = []; - // get a DataSet on the current model (ex: crm.lead) - var model = new instance.web.DataSet(this, this.field_manager.dataset.model); + // get fold information from widget + var fold = ((this.node.attrs || {}).statusbar_fold || true); + // build final domain: if fold option required, add the + if (fold == true) + var domain = new instance.web.CompoundDomain(['|'], ['&'], self.build_domain(), [['fold', '=', false]], [['id', '=', self.selected_value]]) + else { + var domain = new instance.web.CompoundDomain(['|'], self.build_domain(), [['id', '=', self.selected_value]]) + } // get a DataSetSearch on the current field relation (ex: crm.lead.stage_id -> crm.case.stage) - console.log('this'); - console.log(this); - var context = self.build_context(); - console.log('context'); - console.log(context); - var domain = self.build_domain(); - console.log('domain'); - console.log(domain); - //var new_domain = new instance.web.CompoundDomain(['|'], domain, [['case_default', '=', 'True']]); - //console.log(new_domain); - var model_ext = new instance.web.DataSetSearch(this, this.field.relation, context); + var model_ext = new instance.web.DataSetSearch(this, this.field.relation, self.build_context(), domain); // fetch selection - //var read_defer = model_ext.read_slice(['name'], {'domain': domain, 'context': context}).pipe( function (records) { - var read_defer = model_ext.read_slice(['name'], {'domain': []}).pipe( function (records) { - self.to_show = []; + var read_defer = model_ext.read_slice(['name'], {}).pipe( function (records) { _(records).each(function (record) { self.selection.push([record.id, record.name]); }); - console.log('to_show'); - console.log(self.to_show); }); } else { @@ -3940,6 +3950,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ } return read_defer; }, + /** Filters this.selection, according to values coming from the statusbar_visible * attribute of the field. For example: statusbar_visible="draft,open" * Currently, the key of (key, label) pairs has to be used in the @@ -3960,6 +3971,10 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ }); } }, + + /** Renders the widget. This function also check for statusbar_colors='{"pending": "blue"}' + * attribute in the widget. This allows to set a given color to a given + * state (given by the key of (key, label)). */ render_elements: function () { var content = instance.web.qweb.render("FieldStatus.content", {widget: this, _:_}); this.$element.html(content); From 527d2c52608c7f1fd56a06b44e3b452e2afac952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 25 May 2012 12:27:44 +0200 Subject: [PATCH 13/16] [FIX] issue with deferred. bzr revid: tde@openerp.com-20120525102744-1wbu5499p0nmr3or --- addons/web/static/src/js/view_form.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 7d2175bf45d..ed11a63fde3 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3907,7 +3907,8 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ render_list: function() { var self = this; // get selection values, filter them and render them - return this.get_selection().pipe(self.proxy('filter_selection')).pipe(self.proxy('render_elements')); + var selection_done = this.get_selection(); + return $.when(selection_done).pipe(self.proxy('filter_selection')).pipe(self.proxy('render_elements')); }, /** Get the selection list to be displayed in the statusbar widget. From 00749f2d206ca487961cd0a6a946df3c24f690e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 30 May 2012 09:52:52 +0200 Subject: [PATCH 14/16] [CLEAN] Cleaned some typos in comments. bzr revid: tde@openerp.com-20120530075252-cp9d1lbm45cl81xb --- addons/web/static/src/js/view_form.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 6d310743cae..360131fd596 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -4084,9 +4084,9 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ this._super(); this.selected_value = null; - /** preview before set_value only for selection fields, because of + /** preview in start only for selection fields, because of * the dynamic behavior of many2one fields. */ - if (this.field.type == 'selection') { + if (this.field.type in ['selection']) { this.render_list(); } }, @@ -4110,8 +4110,8 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ }, /** Get the status list and render them - * to_show: [[identifier, value_to_displaty]] where - * - identifier = db value for a selection, id for a many2one + * to_show: [[identifier, value_to_display]] where + * - identifier = key for a selection, id for a many2one * - display_val = label that will be displayed * - ex: [[0, "New"]] (many2one) or [["new", "In Progress"]] (selection) */ @@ -4184,7 +4184,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ } }, - /** Renders the widget. This function also check for statusbar_colors='{"pending": "blue"}' + /** Renders the widget. This function also checks for statusbar_colors='{"pending": "blue"}' * attribute in the widget. This allows to set a given color to a given * state (given by the key of (key, label)). */ render_elements: function () { From 3cb2fb85349fb75f10e6a1c76fa28f224f5fd8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 31 May 2012 16:28:54 +0200 Subject: [PATCH 15/16] [IMP] FieldStatus for selection get_selection now always return a true deferred; for a selection it is resolved, because nothing asynchronous has to be done. bzr revid: tde@openerp.com-20120531142854-qrr3zlh5m5wrjtcf --- addons/web/static/src/js/view_form.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index e5cb5d34593..9dfcb6c77ce 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -4126,8 +4126,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ render_list: function() { var self = this; // get selection values, filter them and render them - var selection_done = this.get_selection(); - return $.when(selection_done).pipe(self.proxy('filter_selection')).pipe(self.proxy('render_elements')); + var selection_done = this.get_selection().pipe(self.proxy('filter_selection')).pipe(self.proxy('render_elements')); }, /** Get the selection list to be displayed in the statusbar widget. @@ -4166,7 +4165,7 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ } else { this.selection = this.field.selection; - var read_defer = true; + var read_defer = new $.Deferred().resolve(); } return read_defer; }, From 0a2718cce8327355f47855ef5d83e93f6c3f11fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 31 May 2012 16:39:44 +0200 Subject: [PATCH 16/16] [CLEAN] FieldStatud widget: added missing ';' and '{}'. bzr revid: tde@openerp.com-20120531143944-q41ktw0kahiryvnj --- addons/web/static/src/js/view_form.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 9dfcb6c77ce..52614527111 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -4149,10 +4149,11 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({ // get fold information from widget var fold = ((this.node.attrs || {}).statusbar_fold || true); // build final domain: if fold option required, add the - if (fold == true) - var domain = new instance.web.CompoundDomain(['|'], ['&'], self.build_domain(), [['fold', '=', false]], [['id', '=', self.selected_value]]) + if (fold == true) { + var domain = new instance.web.CompoundDomain(['|'], ['&'], self.build_domain(), [['fold', '=', false]], [['id', '=', self.selected_value]]); + } else { - var domain = new instance.web.CompoundDomain(['|'], self.build_domain(), [['id', '=', self.selected_value]]) + var domain = new instance.web.CompoundDomain(['|'], self.build_domain(), [['id', '=', self.selected_value]]); } // get a DataSetSearch on the current field relation (ex: crm.lead.stage_id -> crm.case.stage) var model_ext = new instance.web.DataSetSearch(this, this.field.relation, self.build_context(), domain);