Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-08-21 17:41:42 +0300
committerJulius Härtl <jus@bitgrid.net>2020-08-21 17:41:42 +0300
commitdccfdf69e7f823084debd22580c934dc6cb3c504 (patch)
treefff0cb959d5c66afb23ee17653bbffe3aace030b
parent30cf65298d7b0fc41430df29e5bb141eb9a10a47 (diff)
Add preload and createNewFile handlersv3.7.3-frontendapi-5
Signed-off-by: Julius Härtl <jus@bitgrid.net>
-rw-r--r--src/files.js10
-rw-r--r--src/services/preload.js3
-rw-r--r--src/view/FilesAppIntegration.js54
-rw-r--r--src/view/NewFileMenu.js5
4 files changed, 59 insertions, 13 deletions
diff --git a/src/files.js b/src/files.js
index 1653c81c..71b617b1 100644
--- a/src/files.js
+++ b/src/files.js
@@ -256,17 +256,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'))