diff --git a/web_widget_boolean_switch/README.rst b/web_widget_boolean_switch/README.rst
index be1cff955..0bd24001a 100644
--- a/web_widget_boolean_switch/README.rst
+++ b/web_widget_boolean_switch/README.rst
@@ -22,19 +22,14 @@ Example
```
```
-.. note::
-
- ``context`` is sent to the ``write`` method of the field model in case of
- special needs with the quick edition.
-
Options
-------
-
quick_edit
~~~~~~~~~~
@@ -60,7 +55,7 @@ extra
* **wrapperClass**: Container element class(es) - default: `"wrapper"`,
-..warning::
+.. warning::
Those parameters are overwritten by this module or highly discouraged:
@@ -71,6 +66,17 @@ extra
* **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
diff --git a/web_widget_boolean_switch/demo/res_users_view.xml b/web_widget_boolean_switch/demo/res_users_view.xml
index d61e1ac33..1c9aca19e 100644
--- a/web_widget_boolean_switch/demo/res_users_view.xml
+++ b/web_widget_boolean_switch/demo/res_users_view.xml
@@ -20,6 +20,7 @@
@@ -31,7 +32,8 @@
res.users
-
@@ -48,6 +50,7 @@
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 c5c06b512..5c4407fb4 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
@@ -9,8 +9,8 @@ openerp.web_widget_boolean_switch = function(instance){
instance.web.BooleanSwitchWidget = instance.web.Class.extend({
- init: function(checkboxes, options, quick_edit_callback){
- options = options ? options : {};
+ init: function(checkboxes, opts, quick_edit_callback){
+ var options = _.extend({}, opts ? opts : {});
this.checkboxes = checkboxes;
this.quick_edit = options.hasOwnProperty('quick_edit') ?
@@ -20,12 +20,23 @@ openerp.web_widget_boolean_switch = function(instance){
var switchOptions = options.hasOwnProperty('extra') ?
options.extra : {};
+ // in case of domain (using attrs={...}), readonly is set afterward
+ if(!_.isBoolean(options.readonly)){
+ options.readonly = false;
+ }
_.extend(switchOptions, {
'readonly': options.hasOwnProperty('readonly') ?
options.readonly : readonly,
'disabled': options.hasOwnProperty('disabled') ?
options.disabled : !this.quick_edit,
});
+
+ //finnaly if readonly is false, we remove it to init widget
+ //with the value of its attributes well managed by qweb and
+ //FieldBooleanSwitch class
+ if(!switchOptions.readonly){
+ delete switchOptions.readonly;
+ }
if(options.hasOwnProperty('onSwitchChange')){
switchOptions.onSwitchChange = options.onSwitchChange;
}
@@ -73,7 +84,7 @@ openerp.web_widget_boolean_switch = function(instance){
this.switcher = new openerp.instances.instance0.web.BooleanSwitchWidget(
this.$checkbox, options, _.bind(function(event, state) {
- // get in mind that in case of view list editable
+ // keep in mind that in case of view list editable
// actual_mode is undefined...
if(this.view.get('actual_mode') === 'view'){
var id = this.view.dataset.ids[this.view.dataset.index];
@@ -87,8 +98,9 @@ openerp.web_widget_boolean_switch = function(instance){
this.internal_set_value(state, {'silent': true});
}
}, this));
- this.on("change:effective_readonly", this, this.switcher_states);
+ this.on("change:readonly", this, this.switcher_states);
this._super();
+ this.switcher_states.call(this);
},
internal_set_value: function(value_, options) {
var tmp = this.no_rerender;
@@ -97,9 +109,10 @@ openerp.web_widget_boolean_switch = function(instance){
this.no_rerender = tmp;
},
switcher_states: function () {
- if (this.switcher.quick_edit)
- return;
- this.switcher.set_disabled(this.get('effective_readonly'));
+ this.switcher.set_readonly(this.get('readonly'));
+ if (!this.switcher.quick_edit){
+ this.switcher.set_disabled(this.get('effective_readonly'));
+ }
},
render_value: function() {
this.switcher.set_value(this.get('value'));
@@ -155,10 +168,26 @@ openerp.web_widget_boolean_switch = function(instance){
instance.web.list.columns.add('field.boolean_switch', 'instance.web.list.FieldBooleanSwitch');
instance.web.list.FieldBooleanSwitch = instance.web.list.Column.extend({
+ format: function (row_data, options) {
+ options = options || {};
+ var attrs = {};
+ if (options.process_modifiers !== false) {
+ attrs = this.modifiers_for(row_data);
+ }
+ if (attrs.invisible) { return ''; }
- _format: function (row_data, options) {
- return _.str.sprintf('',
+ if (!row_data[this.id]) {
+ return options.value_if_empty === undefined ?
+ '' : options.value_if_empty;
+ }
+ var readonly = attrs.hasOwnProperty('readonly') ? attrs.readonly : false;
+ return this._format(row_data, options, readonly);
+ },
+
+ _format: function (row_data, options, readonly) {
+ return _.str.sprintf('',
row_data[this.id].value ? 'checked="checked"' : '',
+ readonly ? 'readonly' : '',
row_data.hasOwnProperty('id') ? row_data.id.value : -1);
}
});