[fix] problem in o2m form view with read only fields, now saves result of default_get

bzr revid: nicolas.vanhoren@openerp.com-20110926160057-zss7934ji5hhtq44
This commit is contained in:
niv-openerp 2011-09-26 18:00:57 +02:00
parent 0962e5b919
commit 78cdb8d1ab
2 changed files with 24 additions and 8 deletions

View File

@ -608,15 +608,23 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
init: function() {
this._super.apply(this, arguments);
this.reset_ids([]);
this.last_default_get = {};
},
default_get: function(fields, callback) {
return this._super(fields).then(this.on_default_get).then(callback);
},
on_default_get: function(res) {
this.last_default_get = res;
},
create: function(data, callback, error_callback) {
var cached = {id:_.uniqueId(this.virtual_id_prefix), values: data};
var cached = {id:_.uniqueId(this.virtual_id_prefix), values: data,
defaults: this.last_default_get};
this.to_create.push(cached);
this.cache.push(cached);
this.on_change();
var to_return = $.Deferred().then(callback);
to_return.resolve({result: cached.id});
return to_return.promise();
var prom = $.Deferred().then(callback);
setTimeout(function() {prom.resolve({result: cached.id});}, 0);
return prom.promise();
},
write: function (id, data, options, callback) {
var self = this;
@ -676,7 +684,8 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
var cached = _.detect(self.cache, function(x) {return x.id === id;});
var created = _.detect(self.to_create, function(x) {return x.id === id;});
if (created) {
_.each(fields, function(x) {if (cached.values[x] === undefined) cached.values[x] = false;});
_.each(fields, function(x) {if (cached.values[x] === undefined)
cached.values[x] = created.defaults[x] || false;});
} else {
if (!cached || !_.all(fields, function(x) {return cached.values[x] !== undefined}))
to_get.push(id);
@ -716,6 +725,10 @@ openerp.web.BufferedDataSet = openerp.web.DataSetStatic.extend({
}
});
openerp.web.ReadOnlyDataSetSearch = openerp.web.DataSetSearch.extend({
default_get: function(fields, callback) {
return this._super(fields, callback).then(this.on_default_get);
},
on_default_get: function(result) {},
create: function(data, callback, error_callback) {
this.on_create(data);
var to_return = $.Deferred().then(callback);

View File

@ -474,8 +474,8 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
recursive_save: function() {
var self = this;
return $.when(this.do_save()).pipe(function(res) {
if (self.parent_form_view)
return self.parent_form_view.recursive_save();
if (self.dataset.parent_view)
return self.dataset.parent_view.recursive_save();
});
}
});
@ -2004,6 +2004,7 @@ openerp.web.form.One2ManyListView = openerp.web.ListView.extend({
} else {
var self = this;
var pop = new openerp.web.form.SelectCreatePopup(this);
pop.on_default_get.add(self.dataset.on_default_get);
pop.select_element(self.o2m.field.relation,{
initial_view: "form",
alternative_form_view: self.o2m.field.views ? self.o2m.field.views["form"] : undefined,
@ -2165,6 +2166,7 @@ openerp.web.form.SelectCreatePopup = openerp.web.OldWidget.extend(/** @lends ope
this.dataset = new openerp.web.ReadOnlyDataSetSearch(this, this.model,
this.context);
this.dataset.parent_view = this.options.parent_view;
this.dataset.on_default_get.add(this.on_default_get);
if (this.options.initial_view == "search") {
this.setup_search_view();
} else { // "form"
@ -2287,7 +2289,8 @@ openerp.web.form.SelectCreatePopup = openerp.web.OldWidget.extend(/** @lends ope
this.on_select_elements(this.created_elements);
}
this.stop();
}
},
on_default_get: function(res) {}
});
openerp.web.form.SelectCreateListView = openerp.web.ListView.extend({