From 1ba3a26db57c51cd9f80f4c10d2cf7150bcede10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 21 Aug 2020 16:41:42 +0200 Subject: Add preload and createNewFile handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/files.js | 10 ++------ src/services/preload.js | 3 +-- src/view/FilesAppIntegration.js | 54 +++++++++++++++++++++++++++++++++++++++-- src/view/NewFileMenu.js | 5 +++- 4 files changed, 59 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/files.js b/src/files.js index 551369bf..1fe1eba2 100644 --- a/src/files.js +++ b/src/files.js @@ -257,17 +257,11 @@ $(document).ready(function() { // Open the template picker if there was a create parameter detected on load if (Preload.create && Preload.create.type && Preload.create.filename) { - const fileType = Types.getFileType(Preload.create.type, Config.get('ooxml')) - NewFileMenu._openTemplatePicker(Preload.create.type, fileType.mime, Preload.create.filename + '.' + fileType.extension) + FilesAppIntegration.preloadCreate() } if (Preload.open) { - FileList.$fileList.one('updated', function() { - odfViewer.onEdit(Preload.open.filename, { - fileId: Preload.open.id, - dir: document.getElementById('dir').value - }) - }) + FilesAppIntegration.preloadOpen() } // Open documents if a public page is opened for a supported mimetype diff --git a/src/services/preload.js b/src/services/preload.js index 4b8c02bc..528d9855 100644 --- a/src/services/preload.js +++ b/src/services/preload.js @@ -36,8 +36,7 @@ if (preloadCreate) { if (preloadOpen) { Preload.open = { filename: preloadOpen, - id: getSearchParam('richdocuments_fileId'), - dir: getSearchParam('dir') + id: getSearchParam('richdocuments_fileId') } } diff --git a/src/view/FilesAppIntegration.js b/src/view/FilesAppIntegration.js index a3b21c30..01e41ba9 100644 --- a/src/view/FilesAppIntegration.js +++ b/src/view/FilesAppIntegration.js @@ -20,6 +20,12 @@ * */ +import Preload from '../services/preload' +import { splitPath } from '../helpers' +import Types from '../helpers/types' +import Config from '../services/config' +import NewFileMenu from './NewFileMenu' + const isPublic = document.getElementById('isPublic') && document.getElementById('isPublic').value === '1' export default { @@ -519,11 +525,19 @@ export default { }) }, - /* Ask for a new filename and open the files app in a new tab + /** + * Called when a new file creation has been triggered from collabora + * + * Ask for a new filename and open the files app in a new tab * the parameters richdocuments_create and richdocuments_filename are - * parsed by viewer.js and open a template picker in the new tab + * parsed by viewer.js and open a template picker in the new tab with + * FilesAppIntegration.preloadCreate */ createNewFile: function(type) { + if (this.handlers.createNewFile && this.handlers.createNewFile(this, { type: type })) { + return + } + OC.dialogs.prompt( t('richdocuments', 'Please enter the filename for the new document'), t('richdocuments', 'Save As'), @@ -546,5 +560,41 @@ export default { $buttons.eq(0).text(t('richdocuments', 'Cancel')) $buttons.eq(1).text(t('richdocuments', 'Create a new document')) }) + }, + + /** + * Automaically open a document on page load + */ + preloadOpen: function() { + if (this.handlers.preloadOpen && this.handlers.preloadOpen(this)) { + return + } + + const fileId = Preload.open.id + const path = Preload.open.filename + setTimeout(function() { + window.FileList.$fileList.one('updated', function() { + const [, file] = splitPath(path) + const fileModel = FileList.getModelForFile(file) + OCA.RichDocuments.open({ path, fileId, fileModel: fileModel, fileList: window.FileList }) + }) + }, 250) + }, + + /** + * Automaically open a template picker on page load + */ + preloadCreate: function() { + if (this.handlers.preloadCreate && this.handlers.preloadCreate(this)) { + return + } + + setTimeout(function() { + window.FileList.$fileList.one('updated', function() { + const fileType = Types.getFileType(Preload.create.type, Config.get('ooxml')) + NewFileMenu._openTemplatePicker(Preload.create.type, fileType.mime, Preload.create.filename + '.' + fileType.extension) + }) + }, 250) } + } diff --git a/src/view/NewFileMenu.js b/src/view/NewFileMenu.js index 5a6cb3a5..b5dc2f22 100644 --- a/src/view/NewFileMenu.js +++ b/src/view/NewFileMenu.js @@ -102,11 +102,14 @@ const NewFileMenu = { function(response) { if (response && response.status === 'success') { FileList.add(response.data, { animate: false, scrollTo: false }) + const fileModel = FileList.getModelForFile(filename) const path = document.getElementById('dir').value + '/' + filename OCA.RichDocuments.openWithTemplate({ fileId: -1, path, - templateId: templateId + templateId: templateId, + fileList: window.FileList, + fileModel }) } else { OC.dialogs.alert(response.data.message, t('core', 'Could not create file')) -- cgit v1.2.3