diff --git a/src/helpers/filesApp.js b/src/helpers/filesApp.js new file mode 100644 index 0000000000..658e8a0272 --- /dev/null +++ b/src/helpers/filesApp.js @@ -0,0 +1,32 @@ +/* + * @copyright Copyright (c) 2022 Julius Härtl + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +/** + * @returns {string} + */ +export const getCurrentDirectory = () => { + if (OCA.Sharing?.PublicApp) { + return OCA.Sharing.PublicApp.fileList.getCurrentDirectory() + } + + return OCA.Files.App.currentFileList.getCurrentDirectory() +} diff --git a/src/services/api.js b/src/services/api.js index cd5d98add0..8efe54b633 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -22,10 +22,11 @@ import axios from '@nextcloud/axios' import { generateOcsUrl } from '@nextcloud/router' +import { getCurrentDirectory } from '../helpers/filesApp' export const createEmptyFile = async(mimeType, fileName) => { const shareToken = document.getElementById('sharingToken')?.value - const directoryPath = document.getElementById('dir')?.value + const directoryPath = getCurrentDirectory() const response = await axios.post(generateOcsUrl('apps/richdocuments/api/v1', 2) + 'file', { mimeType, diff --git a/src/view/FilesAppIntegration.js b/src/view/FilesAppIntegration.js index a634ac834c..db9a30795c 100644 --- a/src/view/FilesAppIntegration.js +++ b/src/view/FilesAppIntegration.js @@ -23,6 +23,7 @@ import { generateUrl, generateRemoteUrl, getRootUrl } from '@nextcloud/router' import { getCurrentUser } from '@nextcloud/auth' import moment from '@nextcloud/moment' +import { getCurrentDirectory } from '../helpers/filesApp' const isPublic = document.getElementById('isPublic') && document.getElementById('isPublic').value === '1' @@ -549,8 +550,7 @@ export default { if (type === 'text') { type = 'document' } - const dir = parent.$('#dir').val() - const url = generateUrl('/apps/files/?dir=' + dir + '&richdocuments_create=' + type + '&richdocuments_filename=' + encodeURI(value)) + const url = generateUrl('/apps/files/?dir=' + getCurrentDirectory() + '&richdocuments_create=' + type + '&richdocuments_filename=' + encodeURI(value)) window.open(url, '_blank') } }, diff --git a/src/view/NewFileMenu.js b/src/view/NewFileMenu.js index 0130fce6d3..74be0a0efc 100644 --- a/src/view/NewFileMenu.js +++ b/src/view/NewFileMenu.js @@ -20,6 +20,7 @@ * */ +import { getCurrentDirectory } from '../helpers/filesApp' import Types from '../helpers/types' import { createEmptyFile } from '../services/api' import { generateUrl, generateFilePath, generateOcsUrl } from '@nextcloud/router' @@ -91,7 +92,7 @@ const NewFileMenu = { const fileAction = OCA.Files.fileActions.getDefaultFileAction(fileModel.get('mimetype'), 'file', OC.PERMISSION_ALL) fileAction.action(filename, { $file: null, - dir: FileList.getCurrentDirectory(), + dir: getCurrentDirectory(), FileList, fileActions: FileList.fileActions, }) @@ -102,16 +103,18 @@ const NewFileMenu = { }, _createDocumentFromTemplate(templateId, mimetype, filename) { + const dir = getCurrentDirectory() OCA.Files.Files.isFileNameValid(filename) filename = FileList.getUniqueName(filename) + $.post( generateUrl('apps/richdocuments/ajax/documents/create'), - { mimetype, filename, dir: document.getElementById('dir').value }, + { mimetype, filename, dir }, 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 + const path = dir + '/' + filename OCA.RichDocuments.openWithTemplate({ fileId: -1, path,