From 3b87df079e74f9b84d984596a67d6a325a29dbb0 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Mon, 5 Nov 2012 14:02:32 +0100 Subject: [PATCH 1/7] [ADD] Added new widget, Many2OneButton, to view_form.js and view_list.js. bzr revid: vta@openerp.com-20121105130232-rpde2k1ihbquznmg --- addons/web/static/src/js/view_form.js | 50 +++++++++++++++++++++++++++ addons/web/static/src/js/view_list.js | 11 ++++++ addons/web/static/src/xml/base.xml | 7 ++++ 3 files changed, 68 insertions(+) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 9dd6e34c161..f50f9297072 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3148,6 +3148,54 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc }, }); +instance.web.form.Many2OneButton = instance.web.form.AbstractField.extend({ + template: 'Many2OneButton', + init: function(field_manager, node) { + this._super.apply(this, arguments); + }, + start: function() { + this._super.apply(this, arguments); + this.set_button(); + }, + set_button: function() { + var self = this; + if (this.$button) { + this.$button.remove(); + } + this.string = this.get('value') ? _t('Edit') : _t('Create'); + this.node.attrs.icon = this.get('value') ? '/web/static/src/img/icons/gtk-yes.png' : '/web/static/src/img/icons/gtk-no.png'; + this.$button = $(QWeb.render('WidgetButton', {'widget': this})); + this.$el.append(this.$button); + this.$button.on('click', self.on_click); + }, + on_click: function(ev) { + var self = this; + ev.stopPropagation(); + var popup = new instance.web.form.FormOpenPopup(this); + popup.show_element( + this.field.relation, + this.get('value'), + this.build_context(), + {title: this.string + ' ' +_t("Voucher: ")} + ); + popup.on('create_completed write_completed', self, function(r){ + self.set_value(r); + }); + }, + set_value: function(value_) { + var self = this; + if (value_ instanceof Array) { + value_ = value_[0]; + } + value_ = value_ || false; + this.set('value', value_); + this.set_button(); + if (this.is_started) { + this.render_value(); + } + }, +}); + /* # Values: (0, 0, { fields }) create # (1, ID, { fields }) update @@ -4332,6 +4380,7 @@ instance.web.form.AbstractFormPopup = instance.web.Widget.extend({ this.dataset.create_function = function(data, sup) { var fct = self.options.create_function || sup; return fct.call(this, data).then(function(r) { + self.trigger('create_completed'); self.created_elements.push(r); }); }; @@ -5130,6 +5179,7 @@ instance.web.form.widgets = new instance.web.Registry({ 'datetime' : 'instance.web.form.FieldDatetime', 'selection' : 'instance.web.form.FieldSelection', 'many2one' : 'instance.web.form.FieldMany2One', + 'many2onebutton' : 'instance.web.form.Many2OneButton', 'many2many' : 'instance.web.form.FieldMany2Many', 'many2many_tags' : 'instance.web.form.FieldMany2ManyTags', 'many2many_kanban' : 'instance.web.form.FieldMany2ManyKanban', diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index fd74fd8922b..216ad7ded6c 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -2010,6 +2010,7 @@ instance.web.list.columns = new instance.web.Registry({ 'field.progressbar': 'instance.web.list.ProgressBar', 'field.handle': 'instance.web.list.Handle', 'button': 'instance.web.list.Button', + 'field.many2onebutton': 'instance.web.list.Many2OneButton', }); instance.web.list.columns.for_ = function (id, field, node) { var description = _.extend({tag: node.tag}, field, node.attrs); @@ -2197,5 +2198,15 @@ instance.web.list.Handle = instance.web.list.Column.extend({ return '
'; } }); +instance.web.list.Many2OneButton = instance.web.list.Column.extend({ + _format: function (row_data, options) { + if (row_data.voucher_id.value) { + this.icon = '/web/static/src/img/icons/gtk-yes.png'; + } else { + this.icon = '/web/static/src/img/icons/gtk-no.png'; + } + return QWeb.render('Many2OneButton.cell', {'widget': this}); + }, +}); }; // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 275d31a9fde..fe64c1c0efa 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1029,6 +1029,13 @@ + + + + + +
From 492379e6c4155108c226d973a3268d0d5a7c8994 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Mon, 5 Nov 2012 15:54:31 +0100 Subject: [PATCH 2/7] [FIX] Added parameters to trigger. bzr revid: vta@openerp.com-20121105145431-qk01mspfvldusa13 --- addons/web/static/src/js/view_form.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index f50f9297072..0b9b5d99b9e 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -4380,14 +4380,14 @@ instance.web.form.AbstractFormPopup = instance.web.Widget.extend({ this.dataset.create_function = function(data, sup) { var fct = self.options.create_function || sup; return fct.call(this, data).then(function(r) { - self.trigger('create_completed'); + self.trigger('create_completed', r); self.created_elements.push(r); }); }; this.dataset.write_function = function(id, data, options, sup) { var fct = self.options.write_function || sup; - return fct.call(this, id, data, options).then(function() { - self.trigger('write_completed'); + return fct.call(this, id, data, options).then(function(r) { + self.trigger('write_completed', r); }); }; this.dataset.parent_view = this.options.parent_view; From 83a264ff2b5d62fd25bba9873fdd08c0b5bf8df3 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Tue, 6 Nov 2012 11:33:20 +0100 Subject: [PATCH 3/7] [FIX] Fixed list view widget as per xmo review. bzr revid: vta@openerp.com-20121106103320-zyon6mzsy9jaafj0 --- addons/web/static/src/js/view_form.js | 4 ---- addons/web/static/src/js/view_list.js | 6 +----- addons/web/static/src/xml/base.xml | 2 +- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 0b9b5d99b9e..9a8f734d2da 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3170,7 +3170,6 @@ instance.web.form.Many2OneButton = instance.web.form.AbstractField.extend({ }, on_click: function(ev) { var self = this; - ev.stopPropagation(); var popup = new instance.web.form.FormOpenPopup(this); popup.show_element( this.field.relation, @@ -3190,9 +3189,6 @@ instance.web.form.Many2OneButton = instance.web.form.AbstractField.extend({ value_ = value_ || false; this.set('value', value_); this.set_button(); - if (this.is_started) { - this.render_value(); - } }, }); diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 216ad7ded6c..871d2bc856f 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -2200,11 +2200,7 @@ instance.web.list.Handle = instance.web.list.Column.extend({ }); instance.web.list.Many2OneButton = instance.web.list.Column.extend({ _format: function (row_data, options) { - if (row_data.voucher_id.value) { - this.icon = '/web/static/src/img/icons/gtk-yes.png'; - } else { - this.icon = '/web/static/src/img/icons/gtk-no.png'; - } + this.has_value = !!row_data[this.id].value; return QWeb.render('Many2OneButton.cell', {'widget': this}); }, }); diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index fe64c1c0efa..b3c09b0359b 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -1034,7 +1034,7 @@ + >
From c2753639215fb7e52098b918fc8f9d9d7481203f Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Tue, 6 Nov 2012 16:41:41 +0100 Subject: [PATCH 4/7] [FIX] Text conflicts. bzr revid: vta@openerp.com-20121106154141-03nnje0th7cjtlqf --- addons/web/static/src/js/view_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 9a8f734d2da..9d68ef3516f 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3177,7 +3177,7 @@ instance.web.form.Many2OneButton = instance.web.form.AbstractField.extend({ this.build_context(), {title: this.string + ' ' +_t("Voucher: ")} ); - popup.on('create_completed write_completed', self, function(r){ + popup.on('create_completed write_completed', self, function(r) { self.set_value(r); }); }, From 83405dba45143d521ecffccc4d44493dd0de84c6 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Wed, 7 Nov 2012 09:17:38 +0100 Subject: [PATCH 5/7] [IMP] Make the popup accessible. bzr revid: vta@openerp.com-20121107081738-kortakwtjj7s9k80 --- addons/web/static/src/js/view_form.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 9d68ef3516f..20024c076f5 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3170,14 +3170,14 @@ instance.web.form.Many2OneButton = instance.web.form.AbstractField.extend({ }, on_click: function(ev) { var self = this; - var popup = new instance.web.form.FormOpenPopup(this); - popup.show_element( + this.popup = new instance.web.form.FormOpenPopup(this); + this.popup.show_element( this.field.relation, this.get('value'), this.build_context(), {title: this.string + ' ' +_t("Voucher: ")} ); - popup.on('create_completed write_completed', self, function(r) { + this.popup.on('create_completed write_completed', self, function(r) { self.set_value(r); }); }, From 4b0d99d6c861b171d84d816bafffb35ada699a82 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Wed, 7 Nov 2012 11:34:26 +0100 Subject: [PATCH 6/7] [IMP] Now the Many2OneButton accepts an option (label) containing a dict to set the string displayed in the button ({'create':String, 'edit':String}). If no label, the string is empty. bzr revid: vta@openerp.com-20121107103426-u6dfd1vcfu8fwap3 --- addons/web/static/src/js/view_form.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 20024c076f5..1b5ca8de730 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3162,7 +3162,12 @@ instance.web.form.Many2OneButton = instance.web.form.AbstractField.extend({ if (this.$button) { this.$button.remove(); } - this.string = this.get('value') ? _t('Edit') : _t('Create'); + var options =py.eval(this.node.attrs.options); + if (options.label) { + this.string = this.get('value') ? _t(options.label.edit) : _t(options.label.create); + } else { + this.string = ''; + } this.node.attrs.icon = this.get('value') ? '/web/static/src/img/icons/gtk-yes.png' : '/web/static/src/img/icons/gtk-no.png'; this.$button = $(QWeb.render('WidgetButton', {'widget': this})); this.$el.append(this.$button); From 064003797eb9f1cbd428d3ed416515a655708fc7 Mon Sep 17 00:00:00 2001 From: "vta vta@openerp.com" <> Date: Wed, 7 Nov 2012 11:49:33 +0100 Subject: [PATCH 7/7] [FIX] Issue with py.eval if no options passed. bzr revid: vta@openerp.com-20121107104933-a60t27t1hjyu368f --- addons/web/static/src/js/view_form.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 1b5ca8de730..da53113f9a2 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3162,7 +3162,10 @@ instance.web.form.Many2OneButton = instance.web.form.AbstractField.extend({ if (this.$button) { this.$button.remove(); } - var options =py.eval(this.node.attrs.options); + var options = {}; + try { + options = py.eval(this.node.attrs.options); + } catch (e) {} if (options.label) { this.string = this.get('value') ? _t(options.label.edit) : _t(options.label.create); } else {