forked from Techsystech/web
[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
parent
7680811cbc
commit
8cf5ba3073
|
@ -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::
|
||||
|
||||
...
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
...
|
||||
<field name="name" />
|
||||
<field name="contact_ids">
|
||||
<tree string="View name">
|
||||
...
|
||||
<field name="name"/>
|
||||
<field name="preferred" widget="radio_tree"/>
|
||||
...
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
</field>
|
||||
...
|
||||
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/OCA/web/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
|
||||
<https://github.com/OCA/
|
||||
web/issues/new?body=module:%20
|
||||
web_qweb_diff%0Aversion:%20
|
||||
9.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Images
|
||||
------
|
||||
|
||||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Cesar Lage <kaerdsar@gmail.com>
|
||||
* Robert Rübner <rruebner@bloopark.de>
|
||||
|
||||
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.
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Odoo, an open source suite of business apps
|
||||
# This module copyright (C) 2015 bloopark systems (<http://bloopark.de>).
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Odoo, an open source suite of business apps
|
||||
# This module copyright (C) 2015 bloopark systems (<http://bloopark.de>).
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
{
|
||||
'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,
|
||||
}
|
|
@ -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(
|
||||
'<input type="radio" name="<%-name%>" <%-checked%> readonly="readonly"></input>', {
|
||||
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($('<div class="boolean"></div>'));
|
||||
});
|
||||
},
|
||||
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<to_write.length; ++j) {
|
||||
if (to_write[j]['id'] == current_id) {
|
||||
to_write[j]['values'][name] = true;
|
||||
}
|
||||
else {
|
||||
to_write[j]['values'][name] = false;
|
||||
}
|
||||
if (ids.includes(to_write[j]['id'])) {
|
||||
already_added.push(to_write[j]['id']);
|
||||
}
|
||||
}
|
||||
for (var j=0; j<ids.length; ++j) {
|
||||
if (!already_added.includes(ids[j]) && ids[j] != current_id) {
|
||||
values = {};
|
||||
values[name] = false;
|
||||
this.__parentedParent.dataset.to_write.push({
|
||||
id: ids[j],
|
||||
values: values
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// updating create hash
|
||||
var to_create = this.__parentedParent.dataset.to_create;
|
||||
for (var j=0; j<to_create.length; ++j) {
|
||||
if (to_create[j]['id'] == current_id) {
|
||||
to_create[j]['values'][name] = true;
|
||||
}
|
||||
else {
|
||||
to_create[j]['values'][name] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
};
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
<t t-name="RadioTree">
|
||||
<span class="oe_form_field oe_form_field_boolean oe_form_field_boolean_radio"
|
||||
t-att-style="widget.node.attrs.style">
|
||||
<input type="radio"
|
||||
t-att-id="widget.id_for_label"
|
||||
t-att-name="widget.name"
|
||||
t-att-tabindex="widget.node.attrs.tabindex"
|
||||
t-att-autofocus="widget.node.attrs.autofocus"
|
||||
class="field_boolean"/>
|
||||
</span>
|
||||
</t>
|
||||
</templates>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<template id="assets_backend" name="web_widget_radio_tree" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/web_widget_radio_tree/static/src/js/widget.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue