[FIX] Apply same behavior as gtk+ and old web clients concerning fields to be saved/created

Special case 'id' field, do not save this field
on 'create' : save all non readonly fields
on 'edit' : save non readonly modified fields

lp bug: https://launchpad.net/bugs/891164 fixed

bzr revid: fme@openerp.com-20111121124030-egiajgy6fgokwmm1
This commit is contained in:
Fabien Meghazi 2011-11-21 13:40:30 +01:00
parent 3565ea546e
commit 8ca42daf0a
1 changed files with 9 additions and 5 deletions

View File

@ -176,7 +176,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
this.datarecord = record; this.datarecord = record;
_(this.fields).each(function (field, f) { _(this.fields).each(function (field, f) {
field.dirty = false; field.reset();
var result = field.set_value(self.datarecord[f] || false); var result = field.set_value(self.datarecord[f] || false);
if (result && _.isFunction(result.promise)) { if (result && _.isFunction(result.promise)) {
deferred_stack.push(result); deferred_stack.push(result);
@ -438,7 +438,10 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
if (!first_invalid_field) { if (!first_invalid_field) {
first_invalid_field = f; first_invalid_field = f;
} }
} else if (f.is_dirty()) { } else if (f.name !== 'id' && !f.readonly && (!self.datarecord.id || f.is_dirty())) {
// Special case 'id' field, do not save this field
// on 'create' : save all non readonly fields
// on 'edit' : save non readonly modified fields
values[f.name] = f.get_value(); values[f.name] = f.get_value();
} }
} }
@ -1191,8 +1194,7 @@ openerp.web.form.Field = openerp.web.form.Widget.extend(/** @lends openerp.web.f
this.nolabel = (this.field.nolabel || node.attrs.nolabel) === '1'; this.nolabel = (this.field.nolabel || node.attrs.nolabel) === '1';
this.readonly = this.modifiers['readonly'] === true; this.readonly = this.modifiers['readonly'] === true;
this.required = this.modifiers['required'] === true; this.required = this.modifiers['required'] === true;
this.invalid = false; this.invalid = this.dirty = false;
this.dirty = false;
this.classname = 'oe_form_field_' + this.type; this.classname = 'oe_form_field_' + this.type;
}, },
@ -1262,6 +1264,9 @@ openerp.web.form.Field = openerp.web.form.Widget.extend(/** @lends openerp.web.f
this.invalid = false; this.invalid = false;
}, },
focus: function() { focus: function() {
},
reset: function() {
this.dirty = false;
} }
}); });
@ -1351,7 +1356,6 @@ openerp.web.form.FieldFloat = openerp.web.form.FieldChar.extend({
if (value === false || value === undefined) { if (value === false || value === undefined) {
// As in GTK client, floats default to 0 // As in GTK client, floats default to 0
value = 0; value = 0;
this.dirty = true;
} }
this._super.apply(this, [value]); this._super.apply(this, [value]);
} }