From 8cf5ba30733c48baffb162fb7e379846130333aa Mon Sep 17 00:00:00 2001 From: Cesar Lage Date: Wed, 4 May 2016 03:38:13 -0400 Subject: [PATCH 01/10] [ADD] web_widget_radio_tree: widget to use input radio in a tree view inside a form, in order to allow mark only one record --- web_widget_radio_tree/README.rst | 75 ++++++++++++++++ web_widget_radio_tree/__init__.py | 20 +++++ web_widget_radio_tree/__openerp__.py | 39 ++++++++ web_widget_radio_tree/static/src/js/widget.js | 90 +++++++++++++++++++ .../static/src/xml/widget.xml | 14 +++ web_widget_radio_tree/views/assets.xml | 10 +++ 6 files changed, 248 insertions(+) create mode 100644 web_widget_radio_tree/README.rst create mode 100644 web_widget_radio_tree/__init__.py create mode 100644 web_widget_radio_tree/__openerp__.py create mode 100644 web_widget_radio_tree/static/src/js/widget.js create mode 100644 web_widget_radio_tree/static/src/xml/widget.xml create mode 100644 web_widget_radio_tree/views/assets.xml diff --git a/web_widget_radio_tree/README.rst b/web_widget_radio_tree/README.rst new file mode 100644 index 00000000..35fa88b2 --- /dev/null +++ b/web_widget_radio_tree/README.rst @@ -0,0 +1,75 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +===================== +Web widget radio tree +===================== + +This module allows to use input radio in a tree view inside a form, in order to ensure the user marks only one record. + +Example: You have a partner company from with many contacts. The contacts are shown in a tree and you want to specify only one as preferred. + +Usage +===== + +In the view declaration, put widget='radio_tree' attribute in the field tag:: + + ... + +
+ ... + + + + ... + + + ... + + + +
+ ... + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Cesar Lage +* Robert Rübner + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. \ No newline at end of file diff --git a/web_widget_radio_tree/__init__.py b/web_widget_radio_tree/__init__.py new file mode 100644 index 00000000..add09d83 --- /dev/null +++ b/web_widget_radio_tree/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Odoo, an open source suite of business apps +# This module copyright (C) 2015 bloopark systems (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## diff --git a/web_widget_radio_tree/__openerp__.py b/web_widget_radio_tree/__openerp__.py new file mode 100644 index 00000000..c2c0ae36 --- /dev/null +++ b/web_widget_radio_tree/__openerp__.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Odoo, an open source suite of business apps +# This module copyright (C) 2015 bloopark systems (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': "Web Widget Radio Tree", + 'summary': """Add radio buttons for records in tree.""", + 'author': "bloopark systems GmbH & Co. KG", + 'website': "http://www.bloopark.de", + 'category': 'web', + 'version': '1.0', + 'depends': [ + 'web', + ], + 'data': [ + 'views/assets.xml', + ], + 'qweb': [ + 'static/src/xml/widget.xml', + ], + 'installable': True, + 'auto_install': False, +} diff --git a/web_widget_radio_tree/static/src/js/widget.js b/web_widget_radio_tree/static/src/js/widget.js new file mode 100644 index 00000000..fbb8b0d4 --- /dev/null +++ b/web_widget_radio_tree/static/src/js/widget.js @@ -0,0 +1,90 @@ +openerp.web_widget_radio_tree = function (instance) { + + var QWeb = instance.web.qweb; + + instance.web.list.columns.add('field.radio_tree', 'instance.web.list.RadioTreeColumn'); + + instance.web.list.RadioTreeColumn = instance.web.list.Column.extend({ + _format: function (row_data, options) { + var name = options.model + '_' + this.id; + return _.template( + ' readonly="readonly">', { + name: name, + checked: row_data[this.id].value ? 'checked' : '', + }); + } + }); + + instance.web.form.widgets.add('radio_tree', 'instance.web.form.RadioTree'); + + instance.web.form.RadioTree = instance.web.form.FieldBoolean.extend({ + template: 'RadioTree', + start: function() { + var self = this; + this.$checkbox = $('input', this.$el); + var radio_name = this.__parentedParent.model + '_' + this.$checkbox[0].name; + this.$checkbox.attr('name', radio_name); + this.setupFocus(this.$checkbox); + this.$el.click(_.bind(function() { + self.clean_radio_in_records(); + this.internal_set_value(true); + }, this)); + var check_readonly = function() { + self.$checkbox.prop('disabled', self.get('effective_readonly')); + self.click_disabled_boolean(); + }; + this.on('change:effective_readonly', this, check_readonly); + check_readonly.call(this); + this._super.apply(this, arguments); + }, + click_disabled_boolean: function(){ + var $disabled = this.$el.find('input[type=radio]:disabled'); + $disabled.each(function (){ + $(this).next('div').remove(); + $(this).closest('span').append($('
')); + }); + }, + clean_radio_in_records: function() { + var name = (this.$checkbox[0].name).split('_')[1]; + var ids = this.__parentedParent.dataset.ids; + var current_id = this.__parentedParent.datarecord.id; + + // updating write hash + var already_added = []; + var to_write = this.__parentedParent.dataset.to_write; + for (var j=0; j + + + + + + + diff --git a/web_widget_radio_tree/views/assets.xml b/web_widget_radio_tree/views/assets.xml new file mode 100644 index 00000000..c1c7d187 --- /dev/null +++ b/web_widget_radio_tree/views/assets.xml @@ -0,0 +1,10 @@ + + + + + + From 34a7ea8b2a90393d3dee6e88c5a1ae05e004ed9c Mon Sep 17 00:00:00 2001 From: Cesar Lage Date: Wed, 4 May 2016 03:41:36 -0400 Subject: [PATCH 02/10] [DOC] web_widget_radio_tree: update readme file --- web_widget_radio_tree/README.rst | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/web_widget_radio_tree/README.rst b/web_widget_radio_tree/README.rst index 35fa88b2..351eec98 100644 --- a/web_widget_radio_tree/README.rst +++ b/web_widget_radio_tree/README.rst @@ -8,7 +8,7 @@ Web widget radio tree This module allows to use input radio in a tree view inside a form, in order to ensure the user marks only one record. -Example: You have a partner company from with many contacts. The contacts are shown in a tree and you want to specify only one as preferred. +Example: You have a partner company form with many contacts. The contacts are shown in a tree and you want to specify only one as preferred. Usage ===== @@ -48,11 +48,6 @@ web_qweb_diff%0Aversion:%20 Credits ======= -Images ------- - -* Odoo Community Association: `Icon `_. - Contributors ------------ From 808599e686c2e3d1958001f3696b3711fa5bbff0 Mon Sep 17 00:00:00 2001 From: Cesar Lage Date: Wed, 4 May 2016 04:32:11 -0400 Subject: [PATCH 03/10] [FIX] some updates after first revision --- web_widget_radio_tree/README.rst | 6 ++--- web_widget_radio_tree/__init__.py | 21 ++------------- web_widget_radio_tree/__openerp__.py | 27 +++---------------- web_widget_radio_tree/static/src/js/widget.js | 2 +- 4 files changed, 10 insertions(+), 46 deletions(-) diff --git a/web_widget_radio_tree/README.rst b/web_widget_radio_tree/README.rst index 351eec98..4586a7fd 100644 --- a/web_widget_radio_tree/README.rst +++ b/web_widget_radio_tree/README.rst @@ -42,8 +42,8 @@ check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed `feedback `_. +web_widget_radio_tree%0Aversion:%20 +8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. Credits ======= @@ -67,4 +67,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit https://odoo-community.org. \ No newline at end of file +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_widget_radio_tree/__init__.py b/web_widget_radio_tree/__init__.py index add09d83..de1a96ac 100644 --- a/web_widget_radio_tree/__init__.py +++ b/web_widget_radio_tree/__init__.py @@ -1,20 +1,3 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Odoo, an open source suite of business apps -# This module copyright (C) 2015 bloopark systems (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2016 Cesar Lage (bloopark systems GmbH) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/web_widget_radio_tree/__openerp__.py b/web_widget_radio_tree/__openerp__.py index c2c0ae36..e5f040d4 100644 --- a/web_widget_radio_tree/__openerp__.py +++ b/web_widget_radio_tree/__openerp__.py @@ -1,26 +1,9 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Odoo, an open source suite of business apps -# This module copyright (C) 2015 bloopark systems (). -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2016 Cesar Lage (bloopark systems GmbH) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': "Web Widget Radio Tree", - 'summary': """Add radio buttons for records in tree.""", + 'summary': "Add radio buttons for records in tree.", 'author': "bloopark systems GmbH & Co. KG", 'website': "http://www.bloopark.de", 'category': 'web', @@ -33,7 +16,5 @@ ], 'qweb': [ 'static/src/xml/widget.xml', - ], - 'installable': True, - 'auto_install': False, + ] } diff --git a/web_widget_radio_tree/static/src/js/widget.js b/web_widget_radio_tree/static/src/js/widget.js index fbb8b0d4..db32861d 100644 --- a/web_widget_radio_tree/static/src/js/widget.js +++ b/web_widget_radio_tree/static/src/js/widget.js @@ -35,7 +35,7 @@ openerp.web_widget_radio_tree = function (instance) { }; this.on('change:effective_readonly', this, check_readonly); check_readonly.call(this); - this._super.apply(this, arguments); + return this._super.apply(this, arguments); }, click_disabled_boolean: function(){ var $disabled = this.$el.find('input[type=radio]:disabled'); From 9a7c39b6450f293507078b2911c4b28ec0604a8d Mon Sep 17 00:00:00 2001 From: Cesar Lage Date: Wed, 4 May 2016 04:44:37 -0400 Subject: [PATCH 04/10] [FIX] updating manifest to cover OCA requirements --- web_widget_radio_tree/__openerp__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web_widget_radio_tree/__openerp__.py b/web_widget_radio_tree/__openerp__.py index e5f040d4..78e1f60b 100644 --- a/web_widget_radio_tree/__openerp__.py +++ b/web_widget_radio_tree/__openerp__.py @@ -4,10 +4,12 @@ { 'name': "Web Widget Radio Tree", 'summary': "Add radio buttons for records in tree.", - 'author': "bloopark systems GmbH & Co. KG", + 'author': "bloopark systems GmbH & Co. KG, " + "Odoo Community Association (OCA)", 'website': "http://www.bloopark.de", 'category': 'web', - 'version': '1.0', + 'version': '8.0.1.0.0', + "license": "AGPL-3", 'depends': [ 'web', ], From 908f8afc19b08ee67a6c644ba47a4a204814f66c Mon Sep 17 00:00:00 2001 From: Cesar Lage Date: Thu, 5 May 2016 14:17:23 -0400 Subject: [PATCH 05/10] [IMP] improve code in method clean_radio_in_records, using method write from dataset --- web_widget_radio_tree/static/src/js/widget.js | 58 ++++--------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/web_widget_radio_tree/static/src/js/widget.js b/web_widget_radio_tree/static/src/js/widget.js index db32861d..3b436447 100644 --- a/web_widget_radio_tree/static/src/js/widget.js +++ b/web_widget_radio_tree/static/src/js/widget.js @@ -20,22 +20,16 @@ openerp.web_widget_radio_tree = function (instance) { instance.web.form.RadioTree = instance.web.form.FieldBoolean.extend({ template: 'RadioTree', start: function() { - var self = this; + this._super.apply(this, arguments); this.$checkbox = $('input', this.$el); - var radio_name = this.__parentedParent.model + '_' + this.$checkbox[0].name; + var radio_name = this.getParent().model + '_' + this.$checkbox[0].name; this.$checkbox.attr('name', radio_name); - this.setupFocus(this.$checkbox); + + var self = this; this.$el.click(_.bind(function() { self.clean_radio_in_records(); this.internal_set_value(true); }, this)); - var check_readonly = function() { - self.$checkbox.prop('disabled', self.get('effective_readonly')); - self.click_disabled_boolean(); - }; - this.on('change:effective_readonly', this, check_readonly); - check_readonly.call(this); - return this._super.apply(this, arguments); }, click_disabled_boolean: function(){ var $disabled = this.$el.find('input[type=radio]:disabled'); @@ -45,45 +39,13 @@ openerp.web_widget_radio_tree = function (instance) { }); }, clean_radio_in_records: function() { + var parent = this.getParent(); var name = (this.$checkbox[0].name).split('_')[1]; - var ids = this.__parentedParent.dataset.ids; - var current_id = this.__parentedParent.datarecord.id; - - // updating write hash - var already_added = []; - var to_write = this.__parentedParent.dataset.to_write; - for (var j=0; j Date: Thu, 5 May 2016 17:31:34 -0400 Subject: [PATCH 06/10] [IMP] restore return super's result in start function --- web_widget_radio_tree/static/src/js/widget.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web_widget_radio_tree/static/src/js/widget.js b/web_widget_radio_tree/static/src/js/widget.js index 3b436447..c0d41658 100644 --- a/web_widget_radio_tree/static/src/js/widget.js +++ b/web_widget_radio_tree/static/src/js/widget.js @@ -20,7 +20,7 @@ openerp.web_widget_radio_tree = function (instance) { instance.web.form.RadioTree = instance.web.form.FieldBoolean.extend({ template: 'RadioTree', start: function() { - this._super.apply(this, arguments); + var _super = this._super.apply(this, arguments); this.$checkbox = $('input', this.$el); var radio_name = this.getParent().model + '_' + this.$checkbox[0].name; this.$checkbox.attr('name', radio_name); @@ -30,6 +30,7 @@ openerp.web_widget_radio_tree = function (instance) { self.clean_radio_in_records(); this.internal_set_value(true); }, this)); + return _super; }, click_disabled_boolean: function(){ var $disabled = this.$el.find('input[type=radio]:disabled'); From 95d4c115d9bf7342c29e84cb0a3ba136783ed86c Mon Sep 17 00:00:00 2001 From: Cesar Lage Date: Thu, 5 May 2016 18:00:03 -0400 Subject: [PATCH 07/10] [REF] moving variable name to direct assign in the template params --- web_widget_radio_tree/static/src/js/widget.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web_widget_radio_tree/static/src/js/widget.js b/web_widget_radio_tree/static/src/js/widget.js index c0d41658..a473ac53 100644 --- a/web_widget_radio_tree/static/src/js/widget.js +++ b/web_widget_radio_tree/static/src/js/widget.js @@ -6,10 +6,9 @@ openerp.web_widget_radio_tree = function (instance) { instance.web.list.RadioTreeColumn = instance.web.list.Column.extend({ _format: function (row_data, options) { - var name = options.model + '_' + this.id; return _.template( ' readonly="readonly">', { - name: name, + name: options.model + '_' + this.id, checked: row_data[this.id].value ? 'checked' : '', }); } From 46bd5067290088733e161fac85cebff8ad45c844 Mon Sep 17 00:00:00 2001 From: Cesar Lage Date: Fri, 6 May 2016 08:50:20 -0400 Subject: [PATCH 08/10] [IMP] using qweb template in _format function instead of return the html part directly --- web_widget_radio_tree/static/src/js/widget.js | 9 ++++----- web_widget_radio_tree/static/src/xml/widget.xml | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/web_widget_radio_tree/static/src/js/widget.js b/web_widget_radio_tree/static/src/js/widget.js index a473ac53..d9c43c94 100644 --- a/web_widget_radio_tree/static/src/js/widget.js +++ b/web_widget_radio_tree/static/src/js/widget.js @@ -6,11 +6,10 @@ openerp.web_widget_radio_tree = function (instance) { instance.web.list.RadioTreeColumn = instance.web.list.Column.extend({ _format: function (row_data, options) { - return _.template( - ' readonly="readonly">', { - name: options.model + '_' + this.id, - checked: row_data[this.id].value ? 'checked' : '', - }); + return QWeb.render('RadioTreeColumn', { + name: options.model + '_' + this.id, + checked: row_data[this.id].value ? {checked: ''} : {}, + }); } }); diff --git a/web_widget_radio_tree/static/src/xml/widget.xml b/web_widget_radio_tree/static/src/xml/widget.xml index 66997333..8c38eb7d 100644 --- a/web_widget_radio_tree/static/src/xml/widget.xml +++ b/web_widget_radio_tree/static/src/xml/widget.xml @@ -1,5 +1,8 @@ + + From b645038211916f2f6f3a0527567e30e2d48989c9 Mon Sep 17 00:00:00 2001 From: Cesar Lage Date: Mon, 6 Jun 2016 09:30:11 -0400 Subject: [PATCH 09/10] [DOC] specify in the doc that field type should be boolean --- web_widget_radio_tree/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_widget_radio_tree/README.rst b/web_widget_radio_tree/README.rst index 4586a7fd..46923bbc 100644 --- a/web_widget_radio_tree/README.rst +++ b/web_widget_radio_tree/README.rst @@ -13,7 +13,7 @@ Example: You have a partner company form with many contacts. The contacts are sh Usage ===== -In the view declaration, put widget='radio_tree' attribute in the field tag:: +In the view declaration, put widget='radio_tree' attribute in the field tag. The field type should be boolean:: ... From cc7dc5c924b534d4e1924500ab1f80f1726332fe Mon Sep 17 00:00:00 2001 From: Cesar Lage Date: Mon, 6 Jun 2016 10:52:56 -0400 Subject: [PATCH 10/10] [IMP] use this.proxy instead of _.bind in the click event --- web_widget_radio_tree/static/src/js/widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_widget_radio_tree/static/src/js/widget.js b/web_widget_radio_tree/static/src/js/widget.js index d9c43c94..cf46fe70 100644 --- a/web_widget_radio_tree/static/src/js/widget.js +++ b/web_widget_radio_tree/static/src/js/widget.js @@ -24,7 +24,7 @@ openerp.web_widget_radio_tree = function (instance) { this.$checkbox.attr('name', radio_name); var self = this; - this.$el.click(_.bind(function() { + this.$el.click(this.proxy(function() { self.clean_radio_in_records(); this.internal_set_value(true); }, this));