[imp] made all relations accept the same value in input than the one created in output

bzr revid: nicolas.vanhoren@openerp.com-20110627090532-lrp05fal50sy0vna
This commit is contained in:
niv-openerp 2011-06-27 11:05:32 +02:00
parent 3a2b31a128
commit 8ccc412493
1 changed files with 42 additions and 7 deletions

View File

@ -1387,19 +1387,51 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
},
set_value_from_ui: function() {},
set_value: function(value) {
value = value || []
this._super(value);
this.dataset.reset_ids(value);
value = value || [];
var self = this;
if(value.length >= 1 && value[0] instanceof Array) {
var ids = [];
_each(value, function(command) {
if(command[0] == 0) {
var obj = {id: _.uniqueId(self.dataset.virtual_id_prefix), values: command[2]};
self.dataset.to_create.push(obj);
self.dataset.cache.push(_.clone(obj));
ids.push(obj.id);
} else if(command[0] == 1) {
var obj = {id: command[1], values: command[2]};
self.dataset.to_write.push(obj);
self.dataset.cache.push(_.clone(obj));
ids.push(obj.id);
} else if(command[0] == 2) {
self.dataset.to_delete.push({id: command[1]});
} else if(command[0] == 4) {
ids.push(command[1]);
}
});
this._super(ids);
this.dataset.set_ids(ids);
} else {
this._super(value);
this.dataset.reset_ids(value);
}
$.when(this.is_started).then(function() {
self.reload_current_view();
});
},
get_value: function() {
var val = _.map(this.dataset.to_delete, function(v, k) {return [2, x.id];});
val = val.concat(_.map(this.dataset.to_create, function(x) {return [0, 0, x.values];}));
val = val.concat(_.map(this.dataset.to_write, function(x) {return [1, x.id, x.values];}));
debugger;
var self = this;
var val = _.map(this.dataset.ids, function(id) {
var alter_order = _.detect(self.dataset.to_create, function(x) {return x.id === id;});
if (alter_order) {
return [0, 0, alter_order.values];
}
alter_order = _.detect(self.dataset.to_write, function(x) {return x.id === id;});
if (alter_order) {
return [1, alter_order.id, alter_order.values];
}
return [4, id];
});
val = val.concat(_.map(this.dataset.to_delete, function(v, k) {return [2, x.id];}));
return val;
},
validate: function() {
@ -1458,6 +1490,9 @@ openerp.base.form.FieldMany2Many = openerp.base.form.Field.extend({
},
set_value: function(value) {
value = value || [];
if (value.length >= 1 && value[0] instanceof Array) {
value = value[0][2];
}
this._super(value);
this.dataset.set_ids(value);
var self = this;