Browse Source

manage tabindex and autofocus + flake8

pull/236/head
Pierre Verkest 9 years ago
parent
commit
a30452cdfb
  1. 6
      web_widget_boolean_switch/__openerp__.py
  2. 3
      web_widget_boolean_switch/demo/res_users_view.xml
  3. 10
      web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js

6
web_widget_boolean_switch/__openerp__.py

@ -65,7 +65,8 @@ Example
widget="boolean_switch" widget="boolean_switch"
attrs="{'readonly': [('login', '=', 'admin')]}" attrs="{'readonly': [('login', '=', 'admin')]}"
context="{'fake_parameter': 'foo'}" context="{'fake_parameter': 'foo'}"
options="{'quick_edit': True, 'extra': {'onText': 'Yes', 'offText': 'No'}}"/>
options="{'quick_edit': True, 'extra': {'onText': 'Yes',
'offText': 'No'}}"/>
``` ```
Options Options
@ -127,7 +128,8 @@ context
special needs with the quick edition. special needs with the quick edition.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
.. image:: https://odoo-community.org/website/image/ir.attachment/
5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/162/7.0 :target: https://runbot.odoo-community.org/runbot/162/7.0

3
web_widget_boolean_switch/demo/res_users_view.xml

@ -45,11 +45,12 @@
<field name="name">res.users.tree</field> <field name="name">res.users.tree</field>
<field name="model">res.users</field> <field name="model">res.users</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Users" editable="top">
<tree string="Users" editable="top" version="7.0">
<field name="name"/> <field name="name"/>
<field name="login"/> <field name="login"/>
<field name="lang"/> <field name="lang"/>
<field name="active" widget="boolean_switch" <field name="active" widget="boolean_switch"
tabindex="-1"
attrs="{'readonly': [('login', '=', 'admin')]}" attrs="{'readonly': [('login', '=', 'admin')]}"
options="{'quick_edit': True, 'extra': {'onText': 'Yes', 'offText': 'No'}}" options="{'quick_edit': True, 'extra': {'onText': 'Yes', 'offText': 'No'}}"
context="{'test': 'test value'}" /> context="{'test': 'test value'}" />

10
web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js

@ -170,11 +170,17 @@ openerp.web_widget_boolean_switch = function(instance){
}, },
_format: function (row_data, options, readonly) { _format: function (row_data, options, readonly) {
return _.str.sprintf('<input type="checkbox" %s %s data-rowid="%d"/>',
options = options ? options : {};
var autofocus = this.hasOwnProperty('autofocus') ? true : false;
var tabindex = this.hasOwnProperty('tabindex') ?
parseInt(this.tabindex) : 0;
return _.str.sprintf('<input type="checkbox" %s %s data-rowid="%d" %s %s/>',
row_data[this.id].value ? 'checked="checked"' : '', row_data[this.id].value ? 'checked="checked"' : '',
readonly ? 'readonly' : '', readonly ? 'readonly' : '',
row_data.hasOwnProperty('id') && _.isNumber(row_data.id.value) ? row_data.hasOwnProperty('id') && _.isNumber(row_data.id.value) ?
row_data.id.value : -1);
row_data.id.value : -1,
autofocus ? 'autofocus' : '',
'tabindex="' + tabindex + '"');
} }
}); });

Loading…
Cancel
Save