From 446ae939043615128e1fcd61cebc56a6c8a5f5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 9 Mar 2021 14:17:08 +0100 Subject: [PATCH] Emit events on files_versions frontend actions to allow apps to hook into them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- apps/files_versions/src/versionstabview.js | 41 +++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/apps/files_versions/src/versionstabview.js b/apps/files_versions/src/versionstabview.js index 65e1351396896..dc5f5895692dc 100644 --- a/apps/files_versions/src/versionstabview.js +++ b/apps/files_versions/src/versionstabview.js @@ -9,7 +9,8 @@ */ import ItemTemplate from './templates/item.handlebars' -import Template from './templates/template.handlebars'; +import Template from './templates/template.handlebars' +import { emit } from '@nextcloud/event-bus' (function() { /** @@ -25,6 +26,7 @@ import Template from './templates/template.handlebars'; events: { 'click .revertVersion': '_onClickRevertVersion', + 'click .downloadVersion': '_onClickDownloadVersion', }, initialize() { @@ -68,6 +70,15 @@ import Template from './templates/template.handlebars'; const revision = $target.attr('data-revision') const versionModel = this.collection.get(revision) + const restoreStartedEventState = { + preventDefault: false, + fileInfoModel, + versionModel, + } + emit('files_versions:restore:started', restoreStartedEventState) + if (restoreStartedEventState.preventDefault) { + return + } versionModel.revert({ success() { // reset and re-fetch the updated collection @@ -86,6 +97,10 @@ import Template from './templates/template.handlebars'; // temp dummy, until we can do a PROPFIND etag: versionModel.get('id') + versionModel.get('timestamp'), }) + emit('files_versions:restore:finished', { + fileInfoModel, + versionModel, + }) }, error() { @@ -101,6 +116,10 @@ import Template from './templates/template.handlebars'; type: 'error', } ) + emit('files_versions:restore:failed', { + fileInfoModel, + versionModel, + }) }, }) @@ -109,6 +128,26 @@ import Template from './templates/template.handlebars'; fileInfoModel.trigger('busy', fileInfoModel, true) }, + _onClickDownloadVersion(e) { + let $target = $(ev.target) + const fileInfoModel = this.collection.getFileInfo() + if (!$target.is('li')) { + $target = $target.closest('li') + } + const revision = $target.attr('data-revision') + const versionModel = this.collection.get(revision) + + const downloadVersionEventState = { + preventDefault: false, + fileInfoModel, + versionModel, + } + emit('files_versions:download:triggered', downloadVersionEventState) + if (downloadVersionEventState.preventDefault) { + e.preventDefault() + } + }, + _toggleLoading(state) { this._loading = state this.$el.find('.loading').toggleClass('hidden', !state)