Browse Source

fix issue on form view when: quick edit the value, them move to edit mode

the form, change the value then cancel the change, the value was keeping the initial values without taking account the quick edition.
find by @JonathanNEMRY
pull/236/head
Pierre Verkest 9 years ago
parent
commit
ca4b39e8a5
  1. 1
      web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js
  2. 76
      web_widget_boolean_switch/static/test/web_widget_boolean_switch.js

1
web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js

@ -81,6 +81,7 @@ openerp.web_widget_boolean_switch = function(instance){
model.call('write', [[id], values], model.call('write', [[id], values],
{'context': this.build_context()}); {'context': this.build_context()});
this.internal_set_value(state, {'silent': true}); this.internal_set_value(state, {'silent': true});
this.getParent().datarecord[this.name] = state;
} }
}, this)); }, this));
this.on("change:readonly", this, this.switcher_states); this.on("change:readonly", this, this.switcher_states);

76
web_widget_boolean_switch/static/test/web_widget_boolean_switch.js

@ -1,8 +1,69 @@
openerp.testing.section('web_widget_boolean_switch',
{'dependences': ['web.web_widget_boolean_switch'],
openerp.testing.section('BooleanSwitchWidget.behaviors',
{dependences: ['web.web_widget_boolean_switch'],
rpc: 'mock',
templates: true,
}, function(test){ }, function(test){
"use strict";
var check_values = function (scratchpad, value, readonly, disabled,
test('BooleanSwitchWidget quick edit - enter in edit mode - cancel',
{asserts: 30}, function (instance, $fix, mock) {
mock('demo:read', function () {
console.log("read data");
return [{ id: 1, a: true, b: 'bar', c: 'baz' }];
});
mock('demo:fields_view_get', function () {
return {
type: 'form',
fields: {
a: {type: 'boolean', string: "A"},
b: {type: 'char', string: "B"},
c: {type: 'char', string: "C"}
},
arch: '<form>' +
' <field name="a" widget="boolean_switch" options="{\'quick_edit\': True}"/>' +
' <field name="b"/>' +
' <field name="c"/>' +
'</form>',
};
});
var ds = new instance.web.DataSetStatic(null, 'demo', null, [1]);
ds.index = 0;
var form = new instance.web.FormView({}, ds, false, {
initial_mode: 'view',
disable_autofocus: false,
$buttons: $(),
$pager: $()
});
var numTest = 1;
form.appendTo($fix);
var promise = form.do_show();
check_values(form.$el.find(".oe_form_field_boolean_switch"),
true, false, false,
numTest++ + " - Init state: quick editable with true value");
form.fields.a.switcher.checkboxes.click();
check_values(form.$el.find('.oe_form_field_boolean_switch'),
false, false, false,
numTest++ + " - Quick edit to `false` value");
form.to_edit_mode();
check_values(form.$el.find('.oe_form_field_boolean_switch'),
false, false, false,
numTest++ + " - Move to edit mode value still false");
form.fields.a.switcher.checkboxes.click();
check_values(form.$el.find('.oe_form_field_boolean_switch'),
true, false, false,
numTest++ + " - edit to True");
// remove class oe_form_dirty to avoid popup in unit test while canceling
form.$el.removeClass('oe_form_dirty');
form.on_button_cancel.call(form);
check_values(form.$el.find('.oe_form_field_boolean_switch'),
false, false, false,
numTest++ + " - Cancel edit mode return still False");
return promise;
});
});
var check_values = function (scratchpad, value, readonly, disabled,
message){ message){
var $container = scratchpad.children(); var $container = scratchpad.children();
var $input = $container.find('input'); var $input = $container.find('input');
@ -20,7 +81,12 @@ openerp.testing.section('web_widget_boolean_switch',
strictEqual($container[0].classList.contains(prefix + "disabled"), strictEqual($container[0].classList.contains(prefix + "disabled"),
disabled, message + " - Bootstrap-switch disabled class"); disabled, message + " - Bootstrap-switch disabled class");
};
};
openerp.testing.section('BooleanSwitchWidget.tests',
{'dependences': ['web.web_widget_boolean_switch'],
}, function(test){
"use strict";
var init_check_values = function(instance, scratchpad, html, options, var init_check_values = function(instance, scratchpad, html, options,
checked, readonly, disabled, message){ checked, readonly, disabled, message){

Loading…
Cancel
Save