diff options
author | Julius Härtl <jus@bitgrid.net> | 2020-05-20 22:24:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-20 22:24:39 +0300 |
commit | d0eba26c7c54b93329b24907240480ecda44dd78 (patch) | |
tree | 674196c532a08caec010ca3a9217b0cf30d8c44b | |
parent | eda633dd83820eb02c7feb4a5cd3962b2edd9009 (diff) | |
parent | ef3ec7483d52edfa23c61c6389905b620b317cf0 (diff) |
Merge pull request #975 from nextcloud/enh/capabiltities
-rw-r--r-- | lib/Capabilities.php | 13 | ||||
-rw-r--r-- | src/helpers/types.js | 40 | ||||
-rw-r--r-- | src/viewer.js | 35 |
3 files changed, 54 insertions, 34 deletions
diff --git a/lib/Capabilities.php b/lib/Capabilities.php index 43eb427b..fc0d9d5f 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -81,6 +81,8 @@ class Capabilities implements ICapability { /** @var IL10N */ private $l10n; + /** @var AppConfig */ + private $config; /** * Capabilities constructor. @@ -88,8 +90,9 @@ class Capabilities implements ICapability { * @param IAppData $appData * @throws \OCP\Files\NotPermittedException */ - public function __construct(IAppData $appData, IL10N $l10n) { + public function __construct(IAppData $appData, IL10N $l10n, AppConfig $config) { $this->l10n = $l10n; + $this->config = $config; try { $this->appData = $appData->getFolder('richdocuments'); } catch (NotFoundException $e) { @@ -107,6 +110,14 @@ class Capabilities implements ICapability { 'direct_editing' => isset($collaboraCapabilities['hasMobileSupport']) ? : false, 'templates' => isset($collaboraCapabilities['hasTemplateSaveAs']) || isset($collaboraCapabilities['hasTemplateSource']) ? : false, 'productName' => isset($collaboraCapabilities['productName']) ? $collaboraCapabilities['productName'] : $this->l10n->t('Collabora Online'), + 'config' => [ + 'wopi_url' => $this->config->getAppValue('wopi_url'), + 'public_wopi_url' => $this->config->getAppValue('public_wopi_url'), + 'disable_certificate_verification' => $this->config->getAppValue('disable_certificate_verification'), + 'edit_groups' => $this->config->getAppValue('edit_groups'), + 'use_groups' => $this->config->getAppValue('use_groups'), + 'doc_format' => $this->config->getAppValue('doc_format'), + ] ], ]; } diff --git a/src/helpers/types.js b/src/helpers/types.js index 597f7c06..22ec61fb 100644 --- a/src/helpers/types.js +++ b/src/helpers/types.js @@ -21,23 +21,11 @@ * */ -const getFileType = (document, ooxml) => { - let documentTypes = { - document: { - extension: 'odt', - mime: 'application/vnd.oasis.opendocument.text' - }, - spreadsheet: { - extension: 'ods', - mime: 'application/vnd.oasis.opendocument.spreadsheet' - }, - presentation: { - extension: 'odp', - mime: 'application/vnd.oasis.opendocument.presentation' - } - } +const ooxml = OC.getCapabilities()['richdocuments']['config']['doc_format'] === 'ooxml' + +const getFileTypes = () => { if (ooxml) { - documentTypes = { + return { document: { extension: 'docx', mime: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' @@ -52,9 +40,27 @@ const getFileType = (document, ooxml) => { } } } - return documentTypes[document] + return { + document: { + extension: 'odt', + mime: 'application/vnd.oasis.opendocument.text' + }, + spreadsheet: { + extension: 'ods', + mime: 'application/vnd.oasis.opendocument.spreadsheet' + }, + presentation: { + extension: 'odp', + mime: 'application/vnd.oasis.opendocument.presentation' + } + } +} + +const getFileType = (document) => { + return getFileTypes()[document] } export default { + getFileTypes, getFileType } diff --git a/src/viewer.js b/src/viewer.js index 4118564f..5c9e2b4d 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -86,9 +86,11 @@ const odfViewer = { var fileDir = context.dir var fileId = context.fileId || context.$file.attr('data-id') var templateId = context.templateId - context.fileList.setViewerMode(true) - context.fileList.setPageTitle(fileName) - context.fileList.showMask() + if (context.fileList) { + context.fileList.setViewerMode(true) + context.fileList.setPageTitle(fileName) + context.fileList.showMask() + } } odfViewer.receivedLoading = false @@ -216,17 +218,15 @@ const odfViewer = { FilesAppIntegration.close() }, - registerFilesMenu: function(response) { - Config.update('ooxml', response.doc_format === 'ooxml') + registerFilesMenu: function() { const registerFilesMenu = (OCA) => { OCA.FilesLOMenu = { attach: function(newFileMenu) { var self = this - const ooxml = Config.get('ooxml') - const document = Types.getFileType('document', ooxml) - const spreadsheet = Types.getFileType('spreadsheet', ooxml) - const presentation = Types.getFileType('presentation', ooxml) + const document = Types.getFileType('document') + const spreadsheet = Types.getFileType('spreadsheet') + const presentation = Types.getFileType('presentation') newFileMenu.addMenuEntry({ id: 'add-' + document.extension, @@ -409,7 +409,15 @@ const odfViewer = { } } -window.OCA.RichDocuments = {} +const settings = OC.getCapabilities()['richdocuments']['config'] || {} +Config.update('ooxml', settings['doc_format'] === 'ooxml') + +window.OCA.RichDocuments = { + config: { + create: Types.getFileTypes() + } +} + $(document).ready(function() { // register file actions and menu if (typeof OCA !== 'undefined' @@ -421,12 +429,7 @@ $(document).ready(function() { odfViewer.supportedMimes.push('text/plain') } odfViewer.register() - - $.get(OC.filePath('richdocuments', 'ajax', 'settings.php')).done(function(settings) { - // TODO: move ooxml setting to capabilities so we don't need this request - odfViewer.registerFilesMenu(settings) - }) - + odfViewer.registerFilesMenu() } // Open documents if a public page is opened for a supported mimetype |