diff --git a/src/document.js b/src/document.js index 959430f7d7..b647c4abbe 100644 --- a/src/document.js +++ b/src/document.js @@ -223,7 +223,7 @@ const documentsMain = { }, loadRevViewerContainer() { - if (!$('revViewerContainer').length) { + if (!$('#revViewerContainer').length) { $(document.body).prepend(documentsMain.UI.viewContainer) const closeButton = $('') $('#revViewerContainer').prepend(closeButton) @@ -379,40 +379,33 @@ const documentsMain = { return } - if (documentsMain.isViewerMode) { - let { fileId, title, version } = args - switch (parsed.msgId) { - case 'Action_loadRevViewer': - documentsMain.UI.loadRevViewerContainer() - if (fileId) { - fileId += '_' + Config.get('instanceId') - if (version) { - fileId += `_${version}` - title += `_${version}` - } - documentsMain.UI.showViewer( - fileId, title - ) - } - break - case 'Host_VersionRestore': - // resolve the deferred object immediately if client doesn't support version states - if (!documentsMain.wopiClientFeatures || !documentsMain.wopiClientFeatures.VersionStates) { - console.error('No version support') - // Not forwarding message to collabora - return + let { fileId, title, version } = args + switch (parsed.msgId) { + case 'Action_loadRevViewer': + documentsMain.UI.loadRevViewerContainer() + if (fileId) { + fileId += '_' + Config.get('instanceId') + if (version) { + fileId += `_${version}` + title += `_${version}` } - documentsMain.onCloseViewer() - break - case 'App_VersionRestore': - // Status = Pre_Restore_Ack -> Ready to restore version - break - case 'UI_Share': - break - default: + documentsMain.UI.showViewer( + fileId, title + ) + } + break + case 'Host_VersionRestore': + // resolve the deferred object immediately if client doesn't support version states + if (!documentsMain.wopiClientFeatures || !documentsMain.wopiClientFeatures.VersionStates) { + console.error('No version support') + // Not forwarding message to collabora return } - + documentsMain.onCloseViewer() + break + case 'App_VersionRestore': + // Status = Pre_Restore_Ack -> Ready to restore version + break } // Pass all messages to viewer if not direct editing or diff --git a/src/view/FilesAppIntegration.js b/src/view/FilesAppIntegration.js index 139a8ce27d..d877ce4d97 100644 --- a/src/view/FilesAppIntegration.js +++ b/src/view/FilesAppIntegration.js @@ -22,7 +22,7 @@ import { generateUrl, generateRemoteUrl, getRootUrl } from '@nextcloud/router' import { getCurrentUser } from '@nextcloud/auth' -import moment from '@nextcloud/moment' +import { subscribe, unsubscribe, emit } from '@nextcloud/event-bus' import { getCurrentDirectory } from '../helpers/filesApp.js' const isPublic = document.getElementById('isPublic') && document.getElementById('isPublic').value === '1' @@ -94,6 +94,9 @@ export default { this.updateFileInfo(undefined, Date.now()) this.fileModel = null + this.fileName = null + this.fileId = null + if (!isPublic) { this.removeVersionSidebarEvents() } @@ -428,76 +431,56 @@ export default { }, addVersionSidebarEvents() { - $(document.querySelector('#content')).on('click.revisions', '.app-sidebar .preview-container', this.showVersionPreview.bind(this)) - $(document.querySelector('#content')).on('click.revisions', '.app-sidebar .downloadVersion', this.showVersionPreview.bind(this)) - $(document.querySelector('#content')).on('mousedown.revisions', '.app-sidebar .revertVersion', this.restoreVersion.bind(this)) - $(document.querySelector('#content')).on('click.revisionsTab', '.app-sidebar [data-tabid=versionsTabView]', this.addCurrentVersion.bind(this)) + subscribe('files_versions:view:open', this.handleVersionOpen.bind(this)) + subscribe('files_versions:restore:requested', this.handleVersionRestore.bind(this)) + + // $(document.querySelector('#content')).on('mousedown.revisions', '.app-sidebar .revertVersion', this.restoreVersion.bind(this)) }, removeVersionSidebarEvents() { - $(document.querySelector('#content')).off('click.revisions') - $(document.querySelector('#content')).off('click.revisions') - $(document.querySelector('#content')).off('mousedown.revisions') - $(document.querySelector('#content')).off('click.revisionsTab') - }, - - addCurrentVersion() { - $('#lastSavedVersion').remove() - $('#currentVersion').remove() - if (this.getFileModel()) { - const preview = OC.MimeType.getIconUrl(this.getFileModel().get('mimetype')) - const mtime = this.getFileModel().get('mtime') - $('.tab.versionsTabView').prepend('