diff options
author | Greta <gretadoci@gmail.com> | 2023-11-01 16:30:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-01 16:30:21 +0100 |
commit | 6cd8952f2b094d99f0246173b0ec3a4e1722498c (patch) | |
tree | dd9446a3b55b669dd4648194f3765777654a5b1d /src | |
parent | 1b161c28496cbe05bc2ebb65d5c898c431d131c5 (diff) | |
parent | 5493404f7dd4d6cd88c1a2ed35b4569b5c5a2c4d (diff) |
Merge pull request #3669 from nextcloud/migrate/contacts-newfile-api
Import file FileAction 28 compatibility
Diffstat (limited to 'src')
-rw-r--r-- | src/files-action.js | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/src/files-action.js b/src/files-action.js index d2aff3df..3b62764a 100644 --- a/src/files-action.js +++ b/src/files-action.js @@ -2,6 +2,7 @@ * @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com> * * @author John Molakvoæ <skjnldsv@protonmail.com> + * @author Richard Steinmetz <richard@steinmetz.cloud> * * @license GNU AGPL version 3 or any later version * @@ -20,25 +21,47 @@ * */ import { generateUrl } from '@nextcloud/router' +import { translate as t } from '@nextcloud/l10n' +import { registerFileAction, FileAction, Permission, DefaultType } from '@nextcloud/files' +/* eslint-disable-next-line import/no-unresolved */ +import ContactSvg from '@mdi/svg/svg/account-multiple.svg?raw' const mime = 'text/vcard' const name = 'contacts-import' +const nextcloudVersionIsGreaterThanOr28 = parseInt(OC.config.version.split('.')[0]) >= 28 -window.addEventListener('DOMContentLoaded', () => { - if (OCA.Files && OCA.Files.fileActions) { - OCA.Files.fileActions.registerAction({ - name, - displayName: t('contacts', 'Import'), - mime, - permissions: OC.PERMISSION_READ, - iconClass: 'icon-contacts-dark', - actionHandler(fileName, context) { - const absPath = `${context.dir === '/' ? '' : context.dir}/${fileName}` - window.location = generateUrl(`/apps/contacts/import?file=${absPath}`) - }, - }) - OCA.Files.fileActions.setDefault(mime, name) - return - } - console.error('Unable to register vcf import action') -}) +if (nextcloudVersionIsGreaterThanOr28) { + registerFileAction(new FileAction({ + id: name, + displayName: () => t('contacts', 'Import'), + default: DefaultType.DEFAULT, + mime, + enabled: (nodes) => { + return nodes.every((node) => node.mime === mime && (node.permissions & Permission.READ)) + }, + iconSvgInline: () => ContactSvg, + async exec(file) { + window.location = generateUrl(`/apps/contacts/import?file=${file.path}`) + return true + }, + })) +} else { + window.addEventListener('DOMContentLoaded', () => { + if (OCA.Files && OCA.Files.fileActions) { + OCA.Files.fileActions.registerAction({ + name, + displayName: t('contacts', 'Import'), + mime, + permissions: OC.PERMISSION_READ, + iconClass: 'icon-contacts-dark', + actionHandler(fileName, context) { + const absPath = `${context.dir === '/' ? '' : context.dir}/${fileName}` + window.location = generateUrl(`/apps/contacts/import?file=${absPath}`) + }, + }) + OCA.Files.fileActions.setDefault(mime, name) + return + } + console.error('Unable to register vcf import action') + }) +} |