[imp] added possibility to set value of a one2many using an on_change
bzr revid: nicolas.vanhoren@openerp.com-20110629153526-ewu12haop290o6ru
This commit is contained in:
parent
c2ceeb2c6f
commit
6df623519b
|
@ -527,6 +527,7 @@ openerp.base.BufferedDataSet = openerp.base.DataSetStatic.extend({
|
|||
this.to_create = [];
|
||||
this.to_write = [];
|
||||
this.cache = [];
|
||||
this.delete_all = false;
|
||||
},
|
||||
on_change: function() {},
|
||||
read_ids: function (ids, fields, callback) {
|
||||
|
|
|
@ -1396,8 +1396,8 @@ var commands = {
|
|||
return [commands.LINK_TO, id, false];
|
||||
},
|
||||
// (5[, _[, _]])
|
||||
FORGET_ALL: 5,
|
||||
'forget_all': function () {
|
||||
DELETE_ALL: 5,
|
||||
'delete_all': function () {
|
||||
return [5, false, false];
|
||||
},
|
||||
// (6, _, ids) replaces all linked records with provided ids
|
||||
|
@ -1469,6 +1469,7 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
|||
set_value: function(value) {
|
||||
value = value || [];
|
||||
var self = this;
|
||||
this.dataset.reset_ids([]);
|
||||
if(value.length >= 1 && value[0] instanceof Array) {
|
||||
var ids = [];
|
||||
_.each(value, function(command) {
|
||||
|
@ -1492,10 +1493,25 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
|||
case commands.LINK_TO:
|
||||
ids.push(command[1]);
|
||||
return;
|
||||
case commands.DELETE_ALL:
|
||||
self.dataset.delete_all = true;
|
||||
return;
|
||||
}
|
||||
});
|
||||
this._super(ids);
|
||||
this.dataset.set_ids(ids);
|
||||
} else if (value.length >= 1 && typeof(value[0]) === "object") {
|
||||
var ids = [];
|
||||
this.dataset.delete_all = true;
|
||||
_.each(value, function(command) {
|
||||
var obj = {values: command};
|
||||
obj['id'] = _.uniqueId(self.dataset.virtual_id_prefix);
|
||||
self.dataset.to_create.push(obj);
|
||||
self.dataset.cache.push(_.clone(obj));
|
||||
ids.push(obj.id);
|
||||
});
|
||||
this._super(ids);
|
||||
this.dataset.set_ids(ids);
|
||||
} else {
|
||||
this._super(value);
|
||||
this.dataset.reset_ids(value);
|
||||
|
@ -1508,7 +1524,8 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
|||
var self = this;
|
||||
if (!this.dataset)
|
||||
return [];
|
||||
var val = _.map(this.dataset.ids, function(id) {
|
||||
var val = this.dataset.delete_all ? [commands.delete_all()] : [];
|
||||
val = val.concat(_.map(this.dataset.ids, function(id) {
|
||||
var alter_order = _.detect(self.dataset.to_create, function(x) {return x.id === id;});
|
||||
if (alter_order) {
|
||||
return commands.create(alter_order.values);
|
||||
|
@ -1518,7 +1535,7 @@ openerp.base.form.FieldOne2Many = openerp.base.form.Field.extend({
|
|||
return commands.update(alter_order.id, alter_order.values);
|
||||
}
|
||||
return commands.link_to(id);
|
||||
});
|
||||
}));
|
||||
return val.concat(_.map(
|
||||
this.dataset.to_delete, function(x) {
|
||||
return commands['delete'](x.id);}));
|
||||
|
|
Loading…
Reference in New Issue