diff --git a/web_widget_boolean_switch/README.rst b/web_widget_boolean_switch/README.rst
index 0bd24001a..aee88be05 100644
--- a/web_widget_boolean_switch/README.rst
+++ b/web_widget_boolean_switch/README.rst
@@ -7,7 +7,8 @@ Web widget boolean switch
=========================
This module add a widget ``boolean_switch`` to render boolean fields. One
-of it's main features is to quick edit that field without enter in edit mode.
+of it's main features is to quick edit that field without enter in edit mode
+from list view or form view.
Configuration
@@ -24,7 +25,7 @@ Example
widget="boolean_switch"
attrs="{'readonly': [('login', '=', 'admin')]}"
context="{'fake_parameter': 'foo'}"
- options="{'quick_edit': True, 'extra': {'onText': 'Yes', 'offText': 'No' }}"/>
+ options="{'quick_edit': True, 'extra': {'onText': 'Yes', 'offText': 'No'}}"/>
```
Options
@@ -40,31 +41,39 @@ extra
*Available options*:
- * **size**: The checkbox size - default: `null` - values: null, 'mini', 'small', 'normal', 'large'
+ * **size**: The checkbox size - default: `null` - values: null, 'mini',
+ 'small', 'normal', 'large'
* **animate**: Animate the switch - default: `true`
* **indeterminate**: Indeterminate state - default: `false`
* **inverse**: Inverse switch direction - default: `false`
- * **onColor**: Color of the left side of the switch - default: `"primary"` - values: 'primary', 'info', 'success', 'warning', 'danger', 'default'
- * **offColor**: Color of the right side of the switch - default: `default` - values: 'primary', 'info', 'success', 'warning', 'danger', 'default'
+ * **onColor**: Color of the left side of the switch - default: `"primary"` -
+ values: 'primary', 'info', 'success', 'warning', 'danger', 'default'
+ * **offColor**: Color of the right side of the switch - default: `default` -
+ values: 'primary', 'info', 'success', 'warning', 'danger', 'default'
* **onText**: Text of the left side of the switch - default: `"ON"`
- * **offText**: Text of the right side of the switch - default: `"OFF"`,
- * **labelText**: Text of the center handle of the switch - default: `" "`,
- * **handleWidth**: Width of the left and right sides in pixels - default: `"auto"`,
- * **labelWidth**: Width of the center handle in pixels - default: `"auto"`,
- * **baseClass**: Global class prefix - default: `"bootstrap-switch"`,
- * **wrapperClass**: Container element class(es) - default: `"wrapper"`,
+ * **offText**: Text of the right side of the switch - default: `"OFF"`
+ * **labelText**: Text of the center handle of the switch - default:
+ `" "`,
+ * **handleWidth**: Width of the left and right sides in pixels - default:
+ `"auto"`,
+ * **labelWidth**: Width of the center handle in pixels - default: `"auto"`
+ * **baseClass**: Global class prefix - default: `"bootstrap-switch"`
+ * **wrapperClass**: Container element class(es) - default: `"wrapper"`
.. warning::
Those parameters are overwritten by this module or highly discouraged:
- * **radioAllOff**: Allow this radio button to be unchecked by the user - default: `false`
+ * **radioAllOff**: Allow this radio button to be unchecked by the user -
+ default: `false`
* **state**: The checkbox state - default: `true`
* **disabled**: Disable state - default: `false`
* **readonly**: Readonly state - default: `false`
- * **onInit**: Callback function to execute on initialization - default: `function() {}`,
- * **onSwitchChange**: Callback function to execute on switch state change - default: `function() {}`
+ * **onInit**: Callback function to execute on initialization - default:
+ `function() {}`,
+ * **onSwitchChange**: Callback function to execute on switch state change -
+ default: `function() {}`
attrs
-----
diff --git a/web_widget_boolean_switch/__openerp__.py b/web_widget_boolean_switch/__openerp__.py
index a4c085dfd..5c1fe9b9d 100644
--- a/web_widget_boolean_switch/__openerp__.py
+++ b/web_widget_boolean_switch/__openerp__.py
@@ -25,6 +25,9 @@
'static/lib/bootstrap-switch/bootstrap-switch.js',
'static/src/js/web_widget_boolean_switch.js',
],
+ 'test': [
+ 'static/test/web_widget_boolean_switch.js',
+ ],
"css": [
'static/lib/bootstrap-switch/bootstrap-switch.css',
],
@@ -34,5 +37,139 @@
"demo": [
'demo/res_users_view.xml',
],
- 'description': """""", # TODO: copy README.rst
+ 'description': """
+.. 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 boolean switch
+=========================
+
+This module add a widget ``boolean_switch`` to render boolean fields. One
+of it's main features is to quick edit that field without enter in edit mode
+from list view or form view.
+
+
+Configuration
+=============
+
+In the view (test on tree view and form view), you can declare any boolean
+field using this widget.
+
+Example
+-------
+
+```
+
+```
+
+Options
+-------
+
+quick_edit
+~~~~~~~~~~
+
+extra
+~~~~~
+``extra`` is used to set
+`bootstrap-switch `_ options.
+
+*Available options*:
+
+ * **size**: The checkbox size - default: `null` - values: null, 'mini',
+ 'small', 'normal', 'large'
+ * **animate**: Animate the switch - default: `true`
+ * **indeterminate**: Indeterminate state - default: `false`
+ * **inverse**: Inverse switch direction - default: `false`
+ * **onColor**: Color of the left side of the switch - default: `"primary"` -
+ values: 'primary', 'info', 'success', 'warning', 'danger', 'default'
+ * **offColor**: Color of the right side of the switch - default: `default` -
+ values: 'primary', 'info', 'success', 'warning', 'danger', 'default'
+ * **onText**: Text of the left side of the switch - default: `"ON"`
+ * **offText**: Text of the right side of the switch - default: `"OFF"`
+ * **labelText**: Text of the center handle of the switch - default:
+ `" "`,
+ * **handleWidth**: Width of the left and right sides in pixels - default:
+ `"auto"`,
+ * **labelWidth**: Width of the center handle in pixels - default: `"auto"`
+ * **baseClass**: Global class prefix - default: `"bootstrap-switch"`
+ * **wrapperClass**: Container element class(es) - default: `"wrapper"`
+
+
+.. warning::
+
+ Those parameters are overwritten by this module or highly discouraged:
+
+ * **radioAllOff**: Allow this radio button to be unchecked by the user -
+ default: `false`
+ * **state**: The checkbox state - default: `true`
+ * **disabled**: Disable state - default: `false`
+ * **readonly**: Readonly state - default: `false`
+ * **onInit**: Callback function to execute on initialization - default:
+ `function() {}`,
+ * **onSwitchChange**: Callback function to execute on switch state change -
+ default: `function() {}`
+
+attrs
+-----
+
+This attribute is supported as expected!
+
+context
+-------
+
+``context`` is sent to the ``write`` method of the field model in case of
+special needs with the quick edition.
+
+
+.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
+ :alt: Try me on Runbot
+ :target: https://runbot.odoo-community.org/runbot/162/7.0
+
+Known issues / Roadmap
+======================
+
+* Manage Null values
+*
+
+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 `here `_.
+
+
+Credits
+=======
+
+Contributors
+------------
+
+* Pierre Verkest
+
+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 http://odoo-community.org.
+
+ """,
}
diff --git a/web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js b/web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js
index fb47b9fd4..a8eb54c67 100644
--- a/web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js
+++ b/web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js
@@ -18,22 +18,21 @@ openerp.web_widget_boolean_switch = function(instance){
var switchOptions = options.hasOwnProperty('extra') ?
options.extra : {};
- _.extend(switchOptions, {
- 'disabled': options.hasOwnProperty('disabled') ?
- options.disabled : !this.quick_edit,
- });
if(options.hasOwnProperty('onSwitchChange')){
switchOptions.onSwitchChange = options.onSwitchChange;
}
this.checkboxes.bootstrapSwitch(switchOptions);
+ this.set_disabled(options.hasOwnProperty('disabled') ?
+ options.disabled : !this.quick_edit);
if(this.quick_edit && quick_edit_callback){
this.checkboxes.on('switchChange.bootstrapSwitch',
quick_edit_callback);
}
},
set_value: function(value){
- // the third parameter tell if we should skip to fire evnets
+ // the third parameter tell if we should skip to fire events
+ // and force change the state whatever it's readonly or disabled
this.checkboxes.bootstrapSwitch('state', value, true);
},
set_readonly: function(value){
diff --git a/web_widget_boolean_switch/static/test/web_widget_boolean_switch.js b/web_widget_boolean_switch/static/test/web_widget_boolean_switch.js
new file mode 100644
index 000000000..fa7e98100
--- /dev/null
+++ b/web_widget_boolean_switch/static/test/web_widget_boolean_switch.js
@@ -0,0 +1,139 @@
+openerp.testing.section('web_widget_boolean_switch',
+ {'dependences': ['web.web_widget_boolean_switch'],
+ }, function(test){
+ "use strict";
+ var check_values = function (scratchpad, value, readonly, disabled,
+ message){
+ var $container = scratchpad.children();
+ var $input = $container.find('input');
+ strictEqual($input[0].checked, value, message + " - Input value");
+ strictEqual($input[0].readOnly && $input[0].readOnly ? true : false,
+ readonly, message + " - Input readonly");
+ strictEqual($input[0].disabled && $input[0].disabled ? true : false, disabled,
+ message + " - Input disabled");
+
+ var prefix = 'bootstrap-switch-';
+ ok($container[0].classList.contains(prefix + (value ? 'on' : 'off')),
+ message + " - Bootstrap-switch value class");
+ strictEqual($container[0].classList.contains(prefix + "readonly"),
+ readonly, message + " - Bootstrap-switch readonly class");
+ strictEqual($container[0].classList.contains(prefix + "disabled"),
+ disabled, message + " - Bootstrap-switch disabled class");
+
+ };
+
+ var init_check_values = function(instance, scratchpad, html, options,
+ checked, readonly, disabled, message){
+ scratchpad.html(html);
+ var widget = new instance.web.BooleanSwitchWidget(
+ scratchpad.find('input'), options, null);
+ check_values(scratchpad, checked, readonly, disabled, message);
+ return widget;
+ };
+
+ test('BooleanSwitchWidget Class test method', function(instance, $scratchpad){
+
+ var numTest = 1;
+ var widget = init_check_values(
+ instance, $scratchpad, '', {},
+ false, false, true, numTest++ + " - init values");
+
+ ok($scratchpad.children()[0].classList.contains('bootstrap-switch'),
+ "Basic bootstrap-switch init using BooleanSwitchWidget class");
+
+ widget.set_disabled(false);
+ check_values($scratchpad, false, false, false,
+ numTest++ + " - Enable");
+
+ widget.set_value(true);
+ check_values($scratchpad, true, false, false,
+ numTest++ + " - Set true");
+
+ widget.set_readonly(true);
+ check_values($scratchpad, true, true, false,
+ numTest++ + " - Set readonly");
+
+ widget.set_disabled(true);
+ check_values($scratchpad, true, true, true,
+ numTest++ + " - Disabled");
+
+ widget.set_value(false);
+ check_values($scratchpad, false, true, true,
+ numTest++ + " - set value whatever its Disabled and readonly");
+ widget.set_readonly(false);
+ widget.set_value(true);
+ check_values($scratchpad, true, false, true,
+ numTest++ + " - set value whatever its Disabled");
+ widget.set_disabled(false);
+ widget.set_readonly(true);
+ widget.set_value(false);
+ check_values($scratchpad, false, true, false,
+ numTest++ + " - set value whatever its readonly");
+ });
+
+ test('BooleanSwitchWidget Class test init', function(instance, $scratchpad){
+ var numTest = 1;
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {}, true, true, true,
+ numTest++ + " - init values disabled readonly checked");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {}, false, true, true,
+ numTest++ + " - init values disabled readonly");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {}, true, false, true,
+ numTest++ + " - init values disabled checked");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {'disabled': false}, true, true, false,
+ numTest++ + " - init values checked readonly");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {}, false, false, true,
+ numTest++ + " - By default input is disabled without any parameter");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {'disabled': false}, true, false, false,
+ numTest++ + " - init values checked");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {'disabled': false, 'quick_edit': true},
+ false, true, false,
+ numTest++ + " - init values disabled readonly");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {'disabled': false}, false, false, false,
+ numTest++ + " - every thing is false");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {'quick_edit': true}, true, false, false,
+ numTest++ + " - quick edit enable widget");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {'quick_edit': true}, true, false, false,
+ numTest++ + " - quick edit enable widget case initial element is disabled");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {}, true, false, true,
+ numTest++ + " - By default widget is disabled test with checked");
+
+ init_check_values(instance, $scratchpad,
+ '',
+ {}, true, true, true,
+ numTest++ + " - By default widget is disabled test with checked and readonly");
+ });
+
+});