From 01ae5b1fed246ac25e15e8efe2ba75fd0c5b9516 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 15 Oct 2014 10:55:53 +0200 Subject: [PATCH] SONAR-5736 The select list component does not fetch more than one page --- .../src/main/js/common/select-list.js | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/server/sonar-web/src/main/js/common/select-list.js b/server/sonar-web/src/main/js/common/select-list.js index e19dea825ec..30ca5e50a6f 100644 --- a/server/sonar-web/src/main/js/common/select-list.js +++ b/server/sonar-web/src/main/js/common/select-list.js @@ -51,8 +51,10 @@ requirejs(['backbone'], function (Backbone) { settings = $.extend(this.settings, options); settings.data.page = nextPage; - + settings.remove = false; this.fetch(settings); + } else { + options.error(); } } @@ -171,6 +173,28 @@ requirejs(['backbone'], function (Backbone) { this.listenTo(this.collection, 'remove', this.removeModel); this.listenTo(this.collection, 'change:selected', this.confirmFilter); this.settings = options.settings; + + var that = this; + this.showFetchSpinner = function () { + that.$listContainer.addClass('loading'); + }; + this.hideFetchSpinner = function () { + that.$listContainer.removeClass('loading'); + }; + + var onScroll = function () { + that.showFetchSpinner(); + + that.collection.fetchNextPage({ + success: function () { + that.hideFetchSpinner(); + }, + error: function () { + that.hideFetchSpinner(); + } + }); + }; + this.onScroll = _.throttle(onScroll, 1000); }, render: function () { @@ -331,29 +355,12 @@ requirejs(['backbone'], function (Backbone) { this.filterBySelection(); }, - showFetchSpinner: function () { - this.$listContainer.addClass('loading'); - }, - - hideFetchSpinner: function () { - this.$listContainer.removeClass('loading'); - }, - scroll: function () { var scrollBottom = this.$listContainer.scrollTop() >= - this.$list[0].scrollHeight - this.$listContainer.outerHeight(), - that = this; + this.$list[0].scrollHeight - this.$listContainer.outerHeight(); if (scrollBottom && this.collection.more) { - $.throttle(250, function () { - that.showFetchSpinner(); - - that.collection.fetchNextPage({ - success: function () { - that.hideFetchSpinner(); - } - }); - })(); + this.onScroll(); } } -- 2.39.5