]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5736 The select list component does not fetch more than one page
authorStas Vilchik <vilchiks@gmail.com>
Wed, 15 Oct 2014 08:55:53 +0000 (10:55 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Wed, 15 Oct 2014 09:10:12 +0000 (11:10 +0200)
server/sonar-web/src/main/js/common/select-list.js

index e19dea825ec158744db8fb26a1c2b283ee6ddcb8..30ca5e50a6f589a1c220a84ad53c1ddba73cdae9 100644 (file)
@@ -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();
         }
       }