[fix] problem with form view, does not prevent multiple creates/saves
bzr revid: nicolas.vanhoren@openerp.com-20111011153535-ojo8qqpzlg3ap9fy
This commit is contained in:
parent
7f34a19db6
commit
b819542c8f
|
@ -639,6 +639,10 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
|
||||||
self.to_write.push(record);
|
self.to_write.push(record);
|
||||||
}
|
}
|
||||||
var cached = _.detect(this.cache, function(x) {return x.id === id;});
|
var cached = _.detect(this.cache, function(x) {return x.id === id;});
|
||||||
|
if (!cached) {
|
||||||
|
cached = {id: id, values: {}};
|
||||||
|
this.cache.push(cached);
|
||||||
|
}
|
||||||
$.extend(cached.values, record.values);
|
$.extend(cached.values, record.values);
|
||||||
if (dirty)
|
if (dirty)
|
||||||
this.on_change();
|
this.on_change();
|
||||||
|
|
|
@ -44,6 +44,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
|
||||||
this.translatable_fields = [];
|
this.translatable_fields = [];
|
||||||
_.defaults(this.options, {"always_show_new_button": true,
|
_.defaults(this.options, {"always_show_new_button": true,
|
||||||
"not_interactible_on_create": false});
|
"not_interactible_on_create": false});
|
||||||
|
this.save_lock = $.Deferred().resolve();
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
this._super();
|
this._super();
|
||||||
|
@ -365,42 +366,45 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
|
||||||
*/
|
*/
|
||||||
do_save: function(success, prepend_on_create) {
|
do_save: function(success, prepend_on_create) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (!this.ready) {
|
var action = function() {
|
||||||
return $.Deferred().reject();
|
if (!self.ready) {
|
||||||
}
|
return $.Deferred().reject();
|
||||||
var form_dirty = false,
|
}
|
||||||
form_invalid = false,
|
var form_dirty = false,
|
||||||
values = {},
|
form_invalid = false,
|
||||||
first_invalid_field = null;
|
values = {},
|
||||||
for (var f in this.fields) {
|
first_invalid_field = null;
|
||||||
f = this.fields[f];
|
for (var f in self.fields) {
|
||||||
if (!f.is_valid()) {
|
f = self.fields[f];
|
||||||
form_invalid = true;
|
if (!f.is_valid()) {
|
||||||
f.update_dom();
|
form_invalid = true;
|
||||||
if (!first_invalid_field) {
|
f.update_dom();
|
||||||
first_invalid_field = f;
|
if (!first_invalid_field) {
|
||||||
|
first_invalid_field = f;
|
||||||
|
}
|
||||||
|
} else if (f.is_dirty()) {
|
||||||
|
form_dirty = true;
|
||||||
|
values[f.name] = f.get_value();
|
||||||
}
|
}
|
||||||
} else if (f.is_dirty()) {
|
|
||||||
form_dirty = true;
|
|
||||||
values[f.name] = f.get_value();
|
|
||||||
}
|
}
|
||||||
}
|
if (form_invalid) {
|
||||||
if (form_invalid) {
|
first_invalid_field.focus();
|
||||||
first_invalid_field.focus();
|
self.on_invalid();
|
||||||
this.on_invalid();
|
return $.Deferred().reject();
|
||||||
return $.Deferred().reject();
|
|
||||||
} else {
|
|
||||||
console.log("About to save", values);
|
|
||||||
if (!this.datarecord.id) {
|
|
||||||
return this.dataset.create(values).pipe(function(r) {
|
|
||||||
return self.on_created(r, undefined, prepend_on_create);
|
|
||||||
}).then(success);
|
|
||||||
} else {
|
} else {
|
||||||
return this.dataset.write(this.datarecord.id, values, {}).pipe(function(r) {
|
console.log("About to save", values);
|
||||||
return self.on_saved(r);
|
if (!self.datarecord.id) {
|
||||||
}).then(success);
|
return self.dataset.create(values).pipe(function(r) {
|
||||||
|
return self.on_created(r, undefined, prepend_on_create);
|
||||||
|
}).then(success);
|
||||||
|
} else {
|
||||||
|
return self.dataset.write(self.datarecord.id, values, {}).pipe(function(r) {
|
||||||
|
return self.on_saved(r);
|
||||||
|
}).then(success);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
this.save_lock = this.save_lock.pipe(action, action);
|
||||||
},
|
},
|
||||||
do_save_edit: function() {
|
do_save_edit: function() {
|
||||||
this.do_save();
|
this.do_save();
|
||||||
|
|
Loading…
Reference in New Issue