From 8924d84ad7354ffd8bb4b8353c303ae36c737f46 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 20 Apr 2017 14:59:08 +0200 Subject: [PATCH] Reload file list when leaving hidden state Whenever a file list is already initialized and was hidden when switching to another file list in the navigation bar, if the user comes back to this list it gets redisplayed. At this point the list needs to be refreshed to be able to reflect any potential file changes done from the other lists. --- apps/files/js/filelist.js | 8 ++++++++ apps/files/tests/js/filelistSpec.js | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 051de3468394..6002cdd34ddb 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -322,6 +322,7 @@ this.$fileList.on('click','td.filename>a.name, td.filesize, td.date', _.bind(this._onClickFile, this)); this.$fileList.on('change', 'td.filename>.selectCheckBox', _.bind(this._onClickFileCheckbox, this)); + this.$el.on('show', _.bind(this._onShow, this)); this.$el.on('urlChanged', _.bind(this._onUrlChanged, this)); this.$el.find('.select-all').click(_.bind(this._onClickSelectAll, this)); this.$el.find('.download').click(_.bind(this._onClickDownloadSelected, this)); @@ -544,6 +545,13 @@ this.$table.find('>thead').width($('#app-content').width() - OC.Util.getScrollBarWidth()); }, + /** + * Event handler when leaving previously hidden state + */ + _onShow: function(e) { + this.reload(); + }, + /** * Event handler for when the URL changed */ diff --git a/apps/files/tests/js/filelistSpec.js b/apps/files/tests/js/filelistSpec.js index c5186a65c78c..d6a0d459d4ea 100644 --- a/apps/files/tests/js/filelistSpec.js +++ b/apps/files/tests/js/filelistSpec.js @@ -1501,6 +1501,12 @@ describe('OCA.Files.FileList tests', function() { $('#app-content-files').trigger(new $.Event('urlChanged', {view: 'files', dir: '/somedir'})); expect(fileList.getCurrentDirectory()).toEqual('/somedir'); }); + it('reloads the list when leaving hidden state', function() { + var reloadStub = sinon.stub(fileList, 'reload'); + $('#app-content-files').trigger(new $.Event('show')); + expect(reloadStub.calledOnce).toEqual(true); + reloadStub.restore(); + }); it('refreshes breadcrumb after update', function() { var setDirSpy = sinon.spy(fileList.breadcrumb, 'setDirectory'); fileList.changeDirectory('/anothersubdir');