Browse Source

Merge b3864b910e into dff1d64a13

pull/499/merge
Cesar Lage 5 years ago
committed by GitHub
parent
commit
5772d04b7e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 70
      web_widget_radio_tree/README.rst
  2. 3
      web_widget_radio_tree/__init__.py
  3. 22
      web_widget_radio_tree/__openerp__.py
  4. 72
      web_widget_radio_tree/static/src/js/widget.js
  5. 17
      web_widget_radio_tree/static/src/xml/widget.xml
  6. 10
      web_widget_radio_tree/views/assets.xml

70
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::
...
<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_widget_radio_tree%0Aversion:%20
9.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
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.

3
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).

22
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': '9.0.1.0.0',
"license": "AGPL-3",
'depends': [
'web',
],
'data': [
'views/assets.xml',
],
'qweb': [
'static/src/xml/widget.xml',
]
}

72
web_widget_radio_tree/static/src/js/widget.js

@ -0,0 +1,72 @@
odoo.define('web_widget_radio_tree.radio_tree', function(require){
'use strict';
var core = require('web.core');
var ListView = require('web.ListView');
function path(element) {
return element.parents().map(function() {
return this.id || '';
}).filter(function() {
return this.length > 0;
}).get().reverse().join("_");
}
ListView.include({
setup_columns: function(fields, grouped) {
this._super(fields, grouped);
for (var i=0; i<this.columns.length; i++) {
this.columns[i]['view'] = this.$el;
}
}
});
var QWeb = core.qweb;
var Column = core.list_widget_registry.get('field');
var RadioTreeColumn = Column.extend({
_format: function (row_data, options) {
return QWeb.render('RadioTreeColumn', {
name: [path(this.view), options.model, this.id].join('_'),
checked: row_data[this.id].value ? {checked: ''} : {},
});
}
});
core.list_widget_registry.add('field.radio_tree', RadioTreeColumn);
var FieldBoolean = core.form_widget_registry.get('boolean');
var RadioTree = FieldBoolean.extend({
template: 'RadioTree',
start: function() {
var _super = this._super.apply(this, arguments);
this.$checkbox = $('input', this.$el);
var radio_name = [path(this.view.$el), this.getParent().model, this.$checkbox[0].name].join('_');
this.$checkbox.attr('name', radio_name);
var self = this;
this.$el.click(_.bind(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($('<div class="boolean"></div>'));
});
},
clean_radio_in_records: function() {
var parent = this.getParent();
var name_parts = (this.$checkbox[0].name).split('_');
var name = name_parts[name_parts.length - 1];
_.each(parent.dataset.ids, function(id) {
var values = {};
values[name] = false;
parent.dataset.write(id, values);
});
}
});
core.form_widget_registry.add('radio_tree', RadioTree);
});

17
web_widget_radio_tree/static/src/xml/widget.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="RadioTreeColumn"
><input type="radio" t-att-name="name" t-att="checked" readonly="readonly"></input>
</t>
<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>

10
web_widget_radio_tree/views/assets.xml

@ -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…
Cancel
Save