From 58291d4ab605ff5b9882bb84de537ce1ff6e73cf Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 22 Jun 2011 16:49:16 +0200 Subject: [PATCH] [imp] added unlink to dataset and list_view (currently just reloads the whole list) bzr revid: nicolas.vanhoren@openerp.com-20110622144916-cst2ad1s0gtchlxi --- addons/base/static/src/js/data.js | 21 ++++++++++++++++++--- addons/base/static/src/js/list.js | 20 +------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/addons/base/static/src/js/data.js b/addons/base/static/src/js/data.js index 736c31c1f7b..47e6d4fed3d 100644 --- a/addons/base/static/src/js/data.js +++ b/addons/base/static/src/js/data.js @@ -310,9 +310,10 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base. context: this.context }, callback); }, - unlink: function(ids) { - // to implement in children - this.notification.notify("Unlink", ids); + unlink: function(ids, callback, error_callback) { + var self = this; + return this.call_and_eval("unlink", [ids, this.context], null, 1, + callback, error_callback); }, call: function (method, args, callback, error_callback) { return this.rpc('/base/dataset/call', { @@ -362,9 +363,12 @@ openerp.base.DataSetStatic = openerp.base.DataSet.extend({ set_ids: function (ids) { this.ids = ids; this.count = this.ids.length; + this.index = this.index <= this.count - 1 ? + this.index : (this.count > 0 ? this.count - 1 : 0); }, unlink: function(ids) { this.on_unlink(ids); + return $.Deferred().resolve({result: true}); }, on_unlink: function(ids) { this.set_ids(_.without.apply(null, [this.ids].concat(ids))); @@ -438,6 +442,17 @@ openerp.base.DataSetSearch = openerp.base.DataSet.extend({ this._sort.unshift((reverse ? '-' : '') + field); return undefined; + }, + unlink: function(ids, callback, error_callback) { + var self = this; + return this._super(ids, function(result) { + self.ids = _.without.apply(_, [self.ids].concat(ids)); + self.count = self.ids.length; + self.index = self.index <= self.count - 1 ? + self.index : (self.count > 0 ? self.count -1 : 0); + if (callback) + callback(result); + }, error_callback); } }); diff --git a/addons/base/static/src/js/list.js b/addons/base/static/src/js/list.js index bd2518dcb66..38162849e08 100644 --- a/addons/base/static/src/js/list.js +++ b/addons/base/static/src/js/list.js @@ -336,25 +336,7 @@ openerp.base.ListView = openerp.base.View.extend( /** @lends openerp.base.ListVi } var self = this; return $.when(this.dataset.unlink(ids)).then(function () { - _(self.rows).chain() - .map(function (row, index) { - return { - index: index, - id: row.data.id.value - };}) - .filter(function (record) { - return _.contains(ids, record.id); - }) - .sort(function (a, b) { - // sort in reverse index order, so we delete from the end - // and don't blow up the following indexes (leading to - // removing the wrong records from the visible list) - return b.index - a.index; - }) - .each(function (record) { - self.rows.splice(record.index, 1); - }); - // TODO only refresh modified rows + self.reload_content(); }); }, /**