[FIX] ids of deleted records living in shared dataset when clicking on list row

When a record is activated, the listview will do some jiggling around
assigning the ids of internal dataset to the one shared between all
views, this is mostly for the case where one switches from a "grouped"
list view, so the form view only cycles on the "current" group.

Problem is, that internal dataset is not correctly synchronized with
the shared one, so when the id is removed from the shared dataset it
is *not* removed from the internal one(s), and when the switch is made
the ids from the internal dataset are set on the shared one and
reintroduce the deleted record, leading to the form view's incorrect
state.

Fix the issue by updating the dataset's ids list when a record is
deleted from the records tree.

Also extracted some stuff from DataSetSearch's unlink callback so it
can be overridden and is more stable across datasets.

lp bug: https://launchpad.net/bugs/1161210 fixed

bzr revid: xmo@openerp.com-20130416152000-06dbwkgdb8zlf9pc
This commit is contained in:
Xavier Morel 2013-04-16 17:20:00 +02:00
parent a455d6c2b2
commit c19bc50648
2 changed files with 20 additions and 10 deletions

View File

@ -607,6 +607,9 @@ instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin,
alter_ids: function(n_ids) {
this.ids = n_ids;
},
remove_ids: function (ids) {
this.alter_ids(_(this.ids).difference(ids));
},
/**
* Resequence records.
*
@ -704,17 +707,23 @@ instance.web.DataSetSearch = instance.web.DataSet.extend({
get_domain: function (other_domain) {
this._model.domain(other_domain);
},
alter_ids: function (ids) {
this._super(ids);
if (this.index !== null && this.index >= this.ids.length) {
this.index = this.ids.length > 0 ? this.ids.length - 1 : 0;
}
},
remove_ids: function (ids) {
var before = this.ids.length;
this._super(ids);
if (this._length) {
this._length -= (before - this.ids.length);
}
},
unlink: function(ids, callback, error_callback) {
var self = this;
return this._super(ids).done(function(result) {
self.ids = _(self.ids).difference(ids);
if (self._length) {
self._length -= 1;
}
if (self.index !== null) {
self.index = self.index <= self.ids.length - 1 ?
self.index : (self.ids.length > 0 ? self.ids.length -1 : 0);
}
self.remove_ids( ids);
self.trigger("dataset_changed", ids, callback, error_callback);
});
},

View File

@ -895,8 +895,9 @@ instance.web.ListView.List = instance.web.Class.extend( /** @lends instance.web.
this.record_callbacks = {
'remove': function (event, record) {
var $row = self.$current.children(
'[data-id=' + record.get('id') + ']');
var id = record.get('id');
self.dataset.remove_ids([id])
var $row = self.$current.children('[data-id=' + id + ']');
var index = $row.data('index');
$row.remove();
},