Skip to content

Commit

Permalink
Emit events on files_versions frontend actions to allow apps to hook …
Browse files Browse the repository at this point in the history
…into them

Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Mar 9, 2021
1 parent 615721d commit 446ae93
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion apps/files_versions/src/versionstabview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
/**
Expand All @@ -25,6 +26,7 @@ import Template from './templates/template.handlebars';

events: {
'click .revertVersion': '_onClickRevertVersion',
'click .downloadVersion': '_onClickDownloadVersion',
},

initialize() {
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand All @@ -101,6 +116,10 @@ import Template from './templates/template.handlebars';
type: 'error',
}
)
emit('files_versions:restore:failed', {
fileInfoModel,
versionModel,
})
},
})

Expand All @@ -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)
Expand Down

0 comments on commit 446ae93

Please sign in to comment.