From 3e3fcd8b56d0767e06471bee4f8bcc946b3b521d Mon Sep 17 00:00:00 2001 From: greta Date: Thu, 28 Dec 2023 13:00:13 +0100 Subject: [PATCH] Add confirmation dialog before importing contacts Signed-off-by: greta --- src/components/ConfirmationDialog.vue | 73 +++++++++++++++++++++++++++ src/files-action.js | 36 +++++++++++-- 2 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 src/components/ConfirmationDialog.vue diff --git a/src/components/ConfirmationDialog.vue b/src/components/ConfirmationDialog.vue new file mode 100644 index 000000000..d42e8f262 --- /dev/null +++ b/src/components/ConfirmationDialog.vue @@ -0,0 +1,73 @@ + + + + + diff --git a/src/files-action.js b/src/files-action.js index 2db84c8e4..1c4adb854 100644 --- a/src/files-action.js +++ b/src/files-action.js @@ -20,11 +20,16 @@ * along with this program. If not, see . * */ +import ConfirmationDialog from './components/ConfirmationDialog.vue' + import { generateUrl } from '@nextcloud/router' import { translate as t } from '@nextcloud/l10n' -import { registerFileAction, FileAction, Permission, DefaultType } from '@nextcloud/files' +import { DefaultType, FileAction, Permission, registerFileAction } from '@nextcloud/files' /* eslint-disable-next-line import/no-unresolved */ import ContactSvg from '@mdi/svg/svg/account-multiple.svg?raw' +import Vue from 'vue' + +Vue.prototype.t = t const mime = 'text/vcard' const name = 'contacts-import' @@ -44,8 +49,33 @@ if (nextcloudVersionIsGreaterThanOr28) { }, iconSvgInline: () => ContactSvg, async exec(file) { - window.location = generateUrl(`/apps/contacts/import?file=${file.path}`) - return true + let dialog + try { + // Open the confirmation dialog + const containerId = 'confirmation-' + Math.random().toString(16).slice(2) + const container = document.createElement('div') + container.id = containerId + document.body.appendChild(container) + await new Promise((resolve, reject) => { + const ImportConfirmationDialog = Vue.extend(ConfirmationDialog) + dialog = new ImportConfirmationDialog({ + propsData: { + title: t('contacts', 'Are you sure you want to import this contact file?'), + resolve, + reject, + }, + }) + dialog.$mount(`#${containerId}`) + }) + + // Redirect to the import page if the user confirmed + window.location = generateUrl(`/apps/contacts/import?file=${file.path}`) + } catch (e) { + // Do nothing if the user cancels + } + + // Destroy confirmation modal (div element is removed from the DOM by vue) + dialog.$destroy() }, })) } else {