[FIX] web: wait onchanges to be processed before save
This commit is contained in:
@@ -103,6 +103,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
this.fields_order = [];
|
||||
this.datarecord = {};
|
||||
this._onchange_specs = {};
|
||||
this.onchanges_defs = [];
|
||||
this.default_focus_field = null;
|
||||
this.default_focus_button = null;
|
||||
this.fields_registry = instance.web.form.widgets;
|
||||
@@ -507,7 +508,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
def = self.alive(new instance.web.Model(self.dataset.model).call(
|
||||
"onchange", [ids, values, trigger_field_name, onchange_specs, context]));
|
||||
}
|
||||
return def.then(function(response) {
|
||||
var onchange_def = def.then(function(response) {
|
||||
if (widget && widget.field['change_default']) {
|
||||
var fieldname = widget.name;
|
||||
var value_;
|
||||
@@ -543,6 +544,8 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
}).then(function(response) {
|
||||
return self.on_processed_onchange(response);
|
||||
});
|
||||
this.onchanges_defs.push(onchange_def);
|
||||
return onchange_def;
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
instance.webclient.crashmanager.show_message(e);
|
||||
@@ -642,6 +645,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
* if the current record is not yet saved. It will then stay in create mode.
|
||||
*/
|
||||
to_edit_mode: function() {
|
||||
this.onchanges_defs = [];
|
||||
this._actualize_mode("edit");
|
||||
},
|
||||
/**
|
||||
@@ -790,12 +794,14 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||
var self = this;
|
||||
var save_obj = {prepend_on_create: prepend_on_create, ret: null};
|
||||
this.save_list.push(save_obj);
|
||||
return this._process_operations().then(function() {
|
||||
if (save_obj.error)
|
||||
return $.Deferred().reject();
|
||||
return $.when.apply($, save_obj.ret);
|
||||
}).done(function() {
|
||||
self.$el.removeClass('oe_form_dirty');
|
||||
return $.when.apply($, self.onchanges_defs).then(function(){
|
||||
return self._process_operations().then(function() {
|
||||
if (save_obj.error)
|
||||
return $.Deferred().reject();
|
||||
return $.when.apply($, save_obj.ret);
|
||||
}).done(function() {
|
||||
self.$el.removeClass('oe_form_dirty');
|
||||
});
|
||||
});
|
||||
},
|
||||
_process_save: function(save_obj) {
|
||||
|
||||
@@ -6,6 +6,9 @@ openerp.testing.section('editor', {
|
||||
mock('test.model:create', function () {
|
||||
return 42;
|
||||
});
|
||||
mock('test.model:onchange', function () {
|
||||
return {};
|
||||
});
|
||||
}
|
||||
}, function (test) {
|
||||
/**
|
||||
@@ -203,6 +206,9 @@ openerp.testing.section('list.edition', {
|
||||
arch: '<tree><field name="a"/><field name="b"/><field name="c"/></tree>',
|
||||
};
|
||||
});
|
||||
mock('demo:onchange', function () {
|
||||
return {};
|
||||
});
|
||||
}
|
||||
}, function (test) {
|
||||
test('newrecord', {asserts: 6}, function (instance, $fix, mock) {
|
||||
@@ -311,6 +317,11 @@ openerp.testing.section('list.edition.onwrite', {
|
||||
dependencies: ['web.list_editable'],
|
||||
rpc: 'mock',
|
||||
templates: true,
|
||||
setup: function (instance, $s, mock) {
|
||||
mock('demo:onchange', function () {
|
||||
return {};
|
||||
});
|
||||
}
|
||||
}, function (test) {
|
||||
test('record-to-read', {asserts: 4}, function (instance, $fix, mock) {
|
||||
mock('demo:fields_view_get', function () {
|
||||
|
||||
Reference in New Issue
Block a user