[FIX] web: form_view: new record and FieldBinaryImage
Form views with a FieldBinaryImage produced a traceback (only visible in the server-side logs) when creating a new record from an existing one, because the fields were re-rendered before being updated (in this case reset to their defaults). In the case of the FieldBinaryImage, as the field wasn't reset yet, we tried to load the image of a null id, which produced the traceback. This rev. ensures that the fields are updated before being re-rendered when switching to another (possibly new) record. Note: this is spaghetti code, several re-rendering are triggered when switching between records (e.g., when updating the fields value, when actualizing form view mode). This should definitely be refactored/simplified.
This commit is contained in:
@@ -307,9 +307,6 @@ var FormView = View.extend(common.FieldManagerMixin, {
|
||||
return $.Deferred().reject();
|
||||
}
|
||||
this.datarecord = record;
|
||||
this._actualize_mode();
|
||||
this.set({ 'title' : record.id ? record.display_name : _t("New") });
|
||||
this.update_pager();
|
||||
|
||||
this.record_loaded = $.Deferred();
|
||||
_(this.fields).each(function (field, f) {
|
||||
@@ -319,6 +316,9 @@ var FormView = View.extend(common.FieldManagerMixin, {
|
||||
field._inhibit_on_change_flag = false;
|
||||
set_values.push(result);
|
||||
});
|
||||
this._actualize_mode(); // call after updating the fields as it may trigger a re-rendering
|
||||
this.set({ 'title' : record.id ? record.display_name : _t("New") });
|
||||
this.update_pager(); // the mode must be actualized before updating the pager
|
||||
return $.when.apply(null, set_values).then(function() {
|
||||
if (!record.id) {
|
||||
// trigger onchanges
|
||||
@@ -682,14 +682,9 @@ var FormView = View.extend(common.FieldManagerMixin, {
|
||||
return false;
|
||||
},
|
||||
on_button_new: function() {
|
||||
var self = this;
|
||||
return $.when(this.has_been_loaded).then(function() {
|
||||
return self.can_be_discarded().then(function() {
|
||||
return self.load_defaults().then(function() {
|
||||
self.to_edit_mode();
|
||||
});
|
||||
});
|
||||
});
|
||||
return $.when(this.has_been_loaded)
|
||||
.then(this.can_be_discarded.bind(this))
|
||||
.then(this.load_defaults.bind(this));
|
||||
},
|
||||
on_button_edit: function() {
|
||||
return this.to_edit_mode();
|
||||
|
||||
Reference in New Issue
Block a user