From c19bc506484d162d7d85beab6d2c0efbbf474035 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 16 Apr 2013 17:20:00 +0200 Subject: [PATCH] [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 --- addons/web/static/src/js/data.js | 25 +++++++++++++++++-------- addons/web/static/src/js/view_list.js | 5 +++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index a36441add1c..d60f72c6577 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -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); }); }, diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index 3c89ef7126e..b96079d2051 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -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(); },