From 975c1982a0fcaaed41db85b2d4ec37eb5fefce0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Julius=20H=C3=A4rtl?= Date: Mon, 19 Aug 2019 11:40:42 +0200 Subject: [PATCH] Allow registering header sections in the file lists MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/files/js/filelist.js | 60 +++++++++++++++++++++++++++++++++++ apps/files/templates/list.php | 2 ++ 2 files changed, 62 insertions(+) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 0e24c09ec07..58e2bfae7ff 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -58,6 +58,12 @@ */ $fileList: null, + $header: null, + headers: [], + + $footer: null, + footers: [], + /** * @type OCA.Files.BreadCrumb */ @@ -262,6 +268,8 @@ this.$container = options.scrollContainer || $(window); this.$table = $el.find('table:first'); this.$fileList = $el.find('#fileList'); + this.$header = $el.find('#filelist-header'); + this.$footer = $el.find('#filelist-footer'); if (!_.isUndefined(this._filesConfig)) { this._filesConfig.on('change:showhidden', function() { @@ -408,6 +416,46 @@ OC.Plugins.attach('OCA.Files.FileList', this); + + this.initHeadersAndFooters() + }, + + initHeadersAndFooters: function() { + this.headers.sort(function(a, b) { + return a.order - b.order; + }) + this.footers.sort(function(a, b) { + return a.order - b.order; + }) + var uniqueIds = []; + var self = this; + this.headers.forEach(function(header) { + if (header.id) { + if (uniqueIds.indexOf(header.id) !== -1) { + return + } + uniqueIds.push(header.id) + } + self.$header.append(header.el) + + setTimeout(function() { + header.render(self) + }, 0) + }) + + uniqueIds = []; + this.footers.forEach(function(footer) { + if (footer.id) { + if (uniqueIds.indexOf(footer.id) !== -1) { + return + } + uniqueIds.push(footer.id) + } + self.$footer.append(footer.el) + setTimeout(function() { + footer.render(self) + }, 0) + }) }, /** @@ -3642,6 +3690,18 @@ } return null; + }, + + registerHeader: function(header) { + this.headers.push( + _.defaults(header, { order: 0 }) + ); + }, + + registerFooter: function(footer) { + this.footers.push( + _.defaults(footer, { order: 0 }) + ); } }; diff --git a/apps/files/templates/list.php b/apps/files/templates/list.php index 8b20c84e008..697a0a9cf44 100644 --- a/apps/files/templates/list.php +++ b/apps/files/templates/list.php @@ -19,6 +19,7 @@ +