From 0b08bf2eedc19d85471924017ca72c1d576191d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 18 Jan 2019 11:17:07 +0100 Subject: [PATCH] Reduce offset when no search result issue7966 review60461002 --- CHANGELOG | 1 + src/screen.js | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d90ec24c1b..87560aafc7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Reduce offset when no search result * Add support for plugins * Add support for expand, height and width attributes * Add drag & drop support on attachment button diff --git a/src/screen.js b/src/screen.js index a135a20226..c98742abbd 100644 --- a/src/screen.js +++ b/src/screen.js @@ -907,9 +907,20 @@ if (this.screen_container.but_active.hasClass('active')) { context.active_test = false; } - return this.model.execute( - 'search', [domain, this.offset, this.limit, this.order], - context).then(function(ids) { + var search = function() { + return this.model.execute( + 'search', [domain, this.offset, this.limit, this.order], + context) + .then(function(ids) { + if (ids.length || this.offset <= 0) { + return ids; + } else { + this.offset = Math.max(this.offset - this.limit, 0); + return search(); + } + }.bind(this)); + }.bind(this); + return search().then(function(ids) { this.search_count = ids.length; var count_prm = jQuery.when(this.search_count); if ((!only_ids) && @@ -1579,7 +1590,7 @@ }, search_prev: function(search_string) { if (this.limit) { - this.offset -= this.limit; + this.offset = Math.max(this.offset - this.limit, 0); } this.search_filter(search_string); },