diff --git a/web_widget_radio_tree/README.rst b/web_widget_radio_tree/README.rst new file mode 100644 index 00000000..46923bbc --- /dev/null +++ b/web_widget_radio_tree/README.rst @@ -0,0 +1,70 @@ +.. 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 form 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. The field type should be boolean:: + + ... + +
+ ... + + + + ... + + + ... + + + +
+ ... + + +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 +======= + +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. diff --git a/web_widget_radio_tree/__init__.py b/web_widget_radio_tree/__init__.py new file mode 100644 index 00000000..de1a96ac --- /dev/null +++ b/web_widget_radio_tree/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# © 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 new file mode 100644 index 00000000..78e1f60b --- /dev/null +++ b/web_widget_radio_tree/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 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.", + 'author': "bloopark systems GmbH & Co. KG, " + "Odoo Community Association (OCA)", + 'website': "http://www.bloopark.de", + 'category': 'web', + 'version': '8.0.1.0.0', + "license": "AGPL-3", + 'depends': [ + 'web', + ], + 'data': [ + 'views/assets.xml', + ], + 'qweb': [ + 'static/src/xml/widget.xml', + ] +} 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..cf46fe70 --- /dev/null +++ b/web_widget_radio_tree/static/src/js/widget.js @@ -0,0 +1,51 @@ +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) { + return QWeb.render('RadioTreeColumn', { + name: options.model + '_' + this.id, + 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 _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); + + var self = this; + this.$el.click(this.proxy(function() { + 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'); + $disabled.each(function (){ + $(this).next('div').remove(); + $(this).closest('span').append($('
')); + }); + }, + clean_radio_in_records: function() { + var parent = this.getParent(); + var name = (this.$checkbox[0].name).split('_')[1]; + _.each(parent.dataset.ids, function(id) { + values = {} + values[name] = false; + parent.dataset.write(id, values); + }); + } + }); + +}; diff --git a/web_widget_radio_tree/static/src/xml/widget.xml b/web_widget_radio_tree/static/src/xml/widget.xml new file mode 100644 index 00000000..8c38eb7d --- /dev/null +++ b/web_widget_radio_tree/static/src/xml/widget.xml @@ -0,0 +1,17 @@ + + + + + + + + + + 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 @@ + + + + + +