From e0d369282d90b568935ccce069e90b868d896cb4 Mon Sep 17 00:00:00 2001 From: PEIWEN JIN Date: Wed, 18 Dec 2024 14:02:01 +0100 Subject: [PATCH] add centre ID, resolve issue 816 --- src/components/DatasetEditorForm.vue | 54 ++++++++++++++++++---------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/components/DatasetEditorForm.vue b/src/components/DatasetEditorForm.vue index dea6e43..78d10cb 100644 --- a/src/components/DatasetEditorForm.vue +++ b/src/components/DatasetEditorForm.vue @@ -964,27 +964,45 @@ export default defineComponent({ const openMessageDialog = ref(false); const copyIdentifier = () => { - const identifier = model.value.identification.identifier; - - if (navigator.clipboard && navigator.clipboard.writeText) { - - navigator.clipboard.writeText(identifier) - .then(() => { - message.value = "Identifier copied to clipboard!"; - openMessageDialog.value = true; - }) - .catch(err => { - console.error('Clipboard API error: ', err); - fallbackCopyManual(identifier); - }); - } else { - fallbackCopyManual(identifier); + const identifier = model.value?.identification?.identifier; + + if (!identifier) { + console.warn("Identifier is undefined. Cannot copy to clipboard."); + message.value = "No identifier to copy."; + openMessageDialog.value = true; + return; + } + + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(identifier) + .then(() => { + message.value = "Identifier copied to clipboard!"; + openMessageDialog.value = true; + }) + .catch(err => { + console.error('Clipboard API error: ', err); + fallbackCopyManual(identifier); + }); + } else { + fallbackCopyManual(identifier); } }; - const fallbackCopyManual = () => { - message.value = "Clipboard API not supported. Please copy the text manually."; - openMessageDialog.value = true; + const fallbackCopyManual = (text) => { + if (text) { + const textarea = document.createElement('textarea'); + textarea.value = text; + document.body.appendChild(textarea); + textarea.select(); + document.execCommand('copy'); + document.body.removeChild(textarea); + + message.value = "Text copied manually!"; + openMessageDialog.value = true; + } else { + message.value = "No text available to copy."; + openMessageDialog.value = true; + } }; const openValidationDialog = ref(false);