]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make sure there are always enough elements visible on the page
authorVincent Petry <pvince81@owncloud.com>
Fri, 4 Apr 2014 14:38:27 +0000 (16:38 +0200)
committerVincent Petry <pvince81@owncloud.com>
Mon, 28 Apr 2014 12:55:01 +0000 (14:55 +0200)
apps/files/js/filelist.js
apps/files/tests/js/filelistSpec.js

index 3bf5b2d967235976e30f9c0a50e421e9f75a5c44..0847edd02bb205670e27fc21eb02a98869fa319d 100644 (file)
@@ -570,6 +570,7 @@ window.FileList = {
                        this.fileSummary.add(fileData, true);
                        this.updateEmptyContent();
                }
+
                return $tr;
        },
 
@@ -823,6 +824,15 @@ window.FileList = {
                        FileList.updateEmptyContent();
                        this.fileSummary.remove({type: fileEl.attr('data-type'), size: fileEl.attr('data-size')}, true);
                }
+
+               var lastIndex = this.$fileList.children().length;
+               // if there are less elements visible than one page
+               // but there are still pending elements in the array,
+               // then directly append the next page
+               if (lastIndex < this.files.length && lastIndex < this.pageSize) {
+                       this._nextPage(true);
+               }
+
                return fileEl;
        },
        /**
index 7316cb75315de95c00e910de0de5b5210a0ad848..23261759d03b7b520b5e241441f8cfa748f503a3 100644 (file)
@@ -701,6 +701,14 @@ describe('FileList tests', function() {
                        FileList._nextPage(true);
                        expect($('#fileList tr').length).toEqual(81);
                });
+               it('automatically renders next page when there are not enough elements visible', function() {
+                       // delete the 15 first elements
+                       for (var i = 0; i < 15; i++) {
+                               FileList.remove(FileList.files[0].name);
+                       }
+                       // still makes sure that there are 20 elements visible, if any
+                       expect($('#fileList tr').length).toEqual(25);
+               });
        });
        describe('file previews', function() {
                var previewLoadStub;