added readonly fields to buffered dataset cache
bzr revid: nicolas.vanhoren@openerp.com-20130308104050-uqt5qi2n9dmcd2hb
This commit is contained in:
parent
c65d36bb65
commit
2328040c3a
|
@ -481,9 +481,12 @@ instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin,
|
||||||
* Creates a new record in db
|
* Creates a new record in db
|
||||||
*
|
*
|
||||||
* @param {Object} data field values to set on the new record
|
* @param {Object} data field values to set on the new record
|
||||||
|
* @param {Object} options Dictionary that can contain the following keys:
|
||||||
|
* - readonly_fields: Values from readonly fields that were updated by
|
||||||
|
* on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
|
||||||
* @returns {$.Deferred}
|
* @returns {$.Deferred}
|
||||||
*/
|
*/
|
||||||
create: function(data) {
|
create: function(data, options) {
|
||||||
return this._model.call('create', [data], {context: this.get_context()});
|
return this._model.call('create', [data], {context: this.get_context()});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@ -491,8 +494,10 @@ instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin,
|
||||||
*
|
*
|
||||||
* @param {Number|String} id identifier for the record to alter
|
* @param {Number|String} id identifier for the record to alter
|
||||||
* @param {Object} data field values to write into the record
|
* @param {Object} data field values to write into the record
|
||||||
* @param {Function} callback function called with operation result
|
* @param {Object} options Dictionary that can contain the following keys:
|
||||||
* @param {Function} error_callback function called in case of write error
|
* - context: The context to use in the server-side call.
|
||||||
|
* - readonly_fields: Values from readonly fields that were updated by
|
||||||
|
* on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
|
||||||
* @returns {$.Deferred}
|
* @returns {$.Deferred}
|
||||||
*/
|
*/
|
||||||
write: function (id, data, options) {
|
write: function (id, data, options) {
|
||||||
|
@ -732,10 +737,13 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({
|
||||||
self.last_default_get = res;
|
self.last_default_get = res;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
create: function(data) {
|
create: function(data, options) {
|
||||||
var cached = {id:_.uniqueId(this.virtual_id_prefix), values: data,
|
var cached = {
|
||||||
defaults: this.last_default_get};
|
id:_.uniqueId(this.virtual_id_prefix),
|
||||||
this.to_create.push(_.extend(_.clone(cached), {values: _.clone(cached.values)}));
|
values: _.extend({}, data, (options || {}).readonly_fields || {}),
|
||||||
|
defaults: this.last_default_get
|
||||||
|
};
|
||||||
|
this.to_create.push(_.extend(_.clone(cached), {values: _.clone(data)}));
|
||||||
this.cache.push(cached);
|
this.cache.push(cached);
|
||||||
return $.Deferred().resolve(cached.id).promise();
|
return $.Deferred().resolve(cached.id).promise();
|
||||||
},
|
},
|
||||||
|
@ -762,7 +770,7 @@ instance.web.BufferedDataSet = instance.web.DataSetStatic.extend({
|
||||||
cached = {id: id, values: {}};
|
cached = {id: id, values: {}};
|
||||||
this.cache.push(cached);
|
this.cache.push(cached);
|
||||||
}
|
}
|
||||||
$.extend(cached.values, record.values);
|
$.extend(cached.values, _.extend({}, record.values, (options || {}).readonly_fields || {}));
|
||||||
if (dirty)
|
if (dirty)
|
||||||
this.trigger("dataset_changed", id, data, options);
|
this.trigger("dataset_changed", id, data, options);
|
||||||
return $.Deferred().resolve(true).promise();
|
return $.Deferred().resolve(true).promise();
|
||||||
|
@ -918,9 +926,9 @@ instance.web.ProxyDataSet = instance.web.DataSetSearch.extend({
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
create: function(data) {
|
create: function(data, options) {
|
||||||
if (this.create_function) {
|
if (this.create_function) {
|
||||||
return this.create_function(data, this._super);
|
return this.create_function(data, options, this._super);
|
||||||
} else {
|
} else {
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
|
@ -810,7 +810,8 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||||
try {
|
try {
|
||||||
var form_invalid = false,
|
var form_invalid = false,
|
||||||
values = {},
|
values = {},
|
||||||
first_invalid_field = null;
|
first_invalid_field = null,
|
||||||
|
readonly_values = {};
|
||||||
for (var f in self.fields) {
|
for (var f in self.fields) {
|
||||||
if (!self.fields.hasOwnProperty(f)) { continue; }
|
if (!self.fields.hasOwnProperty(f)) { continue; }
|
||||||
f = self.fields[f];
|
f = self.fields[f];
|
||||||
|
@ -819,11 +820,15 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||||
if (!first_invalid_field) {
|
if (!first_invalid_field) {
|
||||||
first_invalid_field = f;
|
first_invalid_field = f;
|
||||||
}
|
}
|
||||||
} else if (f.name !== 'id' && !f.get("readonly") && (!self.datarecord.id || f._dirty_flag)) {
|
} else if (f.name !== 'id' && (!self.datarecord.id || f._dirty_flag)) {
|
||||||
// Special case 'id' field, do not save this field
|
// Special case 'id' field, do not save this field
|
||||||
// on 'create' : save all non readonly fields
|
// on 'create' : save all non readonly fields
|
||||||
// on 'edit' : save non readonly modified fields
|
// on 'edit' : save non readonly modified fields
|
||||||
values[f.name] = f.get_value();
|
if (!f.get("readonly")) {
|
||||||
|
values[f.name] = f.get_value();
|
||||||
|
} else {
|
||||||
|
readonly_values[f.name] = f.get_value();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (form_invalid) {
|
if (form_invalid) {
|
||||||
|
@ -836,7 +841,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||||
var save_deferral;
|
var save_deferral;
|
||||||
if (!self.datarecord.id) {
|
if (!self.datarecord.id) {
|
||||||
// Creation save
|
// Creation save
|
||||||
save_deferral = self.dataset.create(values).then(function(r) {
|
save_deferral = self.dataset.create(values, {readonly_fields: readonly_values}).then(function(r) {
|
||||||
return self.record_created(r, prepend_on_create);
|
return self.record_created(r, prepend_on_create);
|
||||||
}, null);
|
}, null);
|
||||||
} else if (_.isEmpty(values)) {
|
} else if (_.isEmpty(values)) {
|
||||||
|
@ -844,7 +849,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
|
||||||
save_deferral = $.Deferred().resolve({}).promise();
|
save_deferral = $.Deferred().resolve({}).promise();
|
||||||
} else {
|
} else {
|
||||||
// Write save
|
// Write save
|
||||||
save_deferral = self.dataset.write(self.datarecord.id, values, {}).then(function(r) {
|
save_deferral = self.dataset.write(self.datarecord.id, values, {readonly_fields: readonly_values}).then(function(r) {
|
||||||
return self.record_saved(r);
|
return self.record_saved(r);
|
||||||
}, null);
|
}, null);
|
||||||
}
|
}
|
||||||
|
@ -3700,8 +3705,8 @@ instance.web.form.One2ManyViewManager = instance.web.ViewManager.extend({
|
||||||
var pop = new instance.web.form.FormOpenPopup(this);
|
var pop = new instance.web.form.FormOpenPopup(this);
|
||||||
pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), {
|
pop.show_element(self.o2m.field.relation, id, self.o2m.build_context(), {
|
||||||
title: _t("Open: ") + self.o2m.string,
|
title: _t("Open: ") + self.o2m.string,
|
||||||
create_function: function(data) {
|
create_function: function(data, options) {
|
||||||
return self.o2m.dataset.create(data).done(function(r) {
|
return self.o2m.dataset.create(data, options).done(function(r) {
|
||||||
self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r]));
|
self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r]));
|
||||||
self.o2m.dataset.trigger("dataset_changed", r);
|
self.o2m.dataset.trigger("dataset_changed", r);
|
||||||
});
|
});
|
||||||
|
@ -3791,11 +3796,11 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({
|
||||||
title: _t("Create: ") + self.o2m.string,
|
title: _t("Create: ") + self.o2m.string,
|
||||||
initial_view: "form",
|
initial_view: "form",
|
||||||
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
|
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
|
||||||
create_function: function(data, callback, error_callback) {
|
create_function: function(data, options) {
|
||||||
return self.o2m.dataset.create(data).done(function(r) {
|
return self.o2m.dataset.create(data, options).done(function(r) {
|
||||||
self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r]));
|
self.o2m.dataset.set_ids(self.o2m.dataset.ids.concat([r]));
|
||||||
self.o2m.dataset.trigger("dataset_changed", r);
|
self.o2m.dataset.trigger("dataset_changed", r);
|
||||||
}).done(callback).fail(error_callback);
|
});
|
||||||
},
|
},
|
||||||
read_function: function() {
|
read_function: function() {
|
||||||
return self.o2m.dataset.read_ids.apply(self.o2m.dataset, arguments);
|
return self.o2m.dataset.read_ids.apply(self.o2m.dataset, arguments);
|
||||||
|
@ -4514,9 +4519,9 @@ instance.web.form.AbstractFormPopup = instance.web.Widget.extend({
|
||||||
this.created_elements = [];
|
this.created_elements = [];
|
||||||
this.dataset = new instance.web.ProxyDataSet(this, this.model, this.context);
|
this.dataset = new instance.web.ProxyDataSet(this, this.model, this.context);
|
||||||
this.dataset.read_function = this.options.read_function;
|
this.dataset.read_function = this.options.read_function;
|
||||||
this.dataset.create_function = function(data, sup) {
|
this.dataset.create_function = function(data, options, sup) {
|
||||||
var fct = self.options.create_function || sup;
|
var fct = self.options.create_function || sup;
|
||||||
return fct.call(this, data).done(function(r) {
|
return fct.call(this, data, options).done(function(r) {
|
||||||
self.trigger('create_completed saved', r);
|
self.trigger('create_completed saved', r);
|
||||||
self.created_elements.push(r);
|
self.created_elements.push(r);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue