|
| 1 | +<template> |
| 2 | + <div |
| 3 | + :id="`${props.formId}-${props.name}`" |
| 4 | + class="pkpFormField pkpFormField--citationAuthors" |
| 5 | + > |
| 6 | + <PkpTable aria-label="CitationAuthors"> |
| 7 | + <TableHeader> |
| 8 | + <TableColumn id="">{{ t('user.givenName', []) }}</TableColumn> |
| 9 | + <TableColumn id="">{{ t('user.familyName', []) }}</TableColumn> |
| 10 | + <TableColumn id="">{{ t('user.orcid', []) }}</TableColumn> |
| 11 | + <TableColumn id="" class="w-[100px]"> </TableColumn> |
| 12 | + </TableHeader> |
| 13 | + <TableBody> |
| 14 | + <TableRow |
| 15 | + v-for="(author, authorIndex) in currentValue" |
| 16 | + :key="authorIndex" |
| 17 | + > |
| 18 | + <TableCell> |
| 19 | + <FieldText :value="author.givenName" /> |
| 20 | + </TableCell> |
| 21 | + <TableCell> |
| 22 | + <FieldText :value="author.givenName" /> |
| 23 | + </TableCell> |
| 24 | + <TableCell> |
| 25 | + <FieldText v-if="!author.orcid" :value="author.orcid" /> |
| 26 | + <a v-if="author.orcid" :href="author.orcid" target="_blank"> |
| 27 | + <Icon |
| 28 | + icon="Orcid" |
| 29 | + :class="'relative top-[-2px] inline-block h-auto w-[16px] align-middle'" |
| 30 | + :inline="true" |
| 31 | + /> |
| 32 | + {{ author.orcid }} |
| 33 | + </a> |
| 34 | + </TableCell> |
| 35 | + <TableCell> |
| 36 | + {{ authorIndex }} |
| 37 | + <a |
| 38 | + class="pkpButton flex cursor-pointer items-center border-transparent py-2 text-lg-semibold text-primary hover:enabled:underline" |
| 39 | + @click="deleteAuthor(authorIndex)" |
| 40 | + > |
| 41 | + {{ t('common.delete', []) }} |
| 42 | + </a> |
| 43 | + </TableCell> |
| 44 | + </TableRow> |
| 45 | + <TableRow> |
| 46 | + <TableCell> |
| 47 | + <Button @click="addAuthor()"> |
| 48 | + {{ t('common.add') }} |
| 49 | + </Button> |
| 50 | + </TableCell> |
| 51 | + <TableCell></TableCell> |
| 52 | + <TableCell></TableCell> |
| 53 | + <TableCell></TableCell> |
| 54 | + </TableRow> |
| 55 | + </TableBody> |
| 56 | + </PkpTable> |
| 57 | + </div> |
| 58 | +</template> |
| 59 | + |
| 60 | +<script setup> |
| 61 | +import Button from '@/components/Button/Button.vue'; |
| 62 | +import PkpTable from '@/components/Table/Table.vue'; |
| 63 | +import TableCell from '@/components/Table/TableCell.vue'; |
| 64 | +import TableRow from '@/components/Table/TableRow.vue'; |
| 65 | +import TableColumn from '@/components/Table/TableColumn.vue'; |
| 66 | +import TableHeader from '@/components/Table/TableHeader.vue'; |
| 67 | +import TableBody from '@/components/Table/TableBody.vue'; |
| 68 | +import {computed} from 'vue'; |
| 69 | +import {t} from '@/utils/i18n'; |
| 70 | +import FieldText from '@/components/Form/fields/FieldText.vue'; |
| 71 | +import Icon from '@/components/Icon/Icon.vue'; |
| 72 | +
|
| 73 | +const props = defineProps({ |
| 74 | + /** Field key used for form submission */ |
| 75 | + name: { |
| 76 | + type: String, |
| 77 | + default: null, |
| 78 | + }, |
| 79 | + /** The ID of the form this field should appear in. This is passed down from the `Form`. */ |
| 80 | + formId: { |
| 81 | + type: String, |
| 82 | + default: null, |
| 83 | + }, |
| 84 | + /** The `<label>` for this field. May be used in a `<fieldset>` when appropriate. All form fields should have an accessible label. */ |
| 85 | + label: { |
| 86 | + type: String, |
| 87 | + default: null, |
| 88 | + }, |
| 89 | + /** Adds a description to the field. Can include HTML code. */ |
| 90 | + description: { |
| 91 | + type: String, |
| 92 | + default: null, |
| 93 | + }, |
| 94 | + /** Current value of the field */ |
| 95 | + value: { |
| 96 | + type: Array, |
| 97 | + default: () => [], |
| 98 | + }, |
| 99 | + /** Default locale of the form */ |
| 100 | + primaryLocale: { |
| 101 | + type: String, |
| 102 | + default: 'en', |
| 103 | + }, |
| 104 | + /** List of supported locales */ |
| 105 | + locales: { |
| 106 | + type: Array, |
| 107 | + default: () => [], |
| 108 | + }, |
| 109 | + /** Object containing all form errors */ |
| 110 | + allErrors: { |
| 111 | + type: Object, |
| 112 | + default() { |
| 113 | + return {}; |
| 114 | + }, |
| 115 | + }, |
| 116 | +}); |
| 117 | +const authorDataModel = () => { |
| 118 | + return { |
| 119 | + displayName: '', |
| 120 | + givenName: '', |
| 121 | + familyName: '', |
| 122 | + orcid: '', |
| 123 | + }; |
| 124 | +}; |
| 125 | +const currentValue = computed({ |
| 126 | + get: () => props.value, |
| 127 | + set: (newVal) => emit('change', props.name, 'value', newVal), |
| 128 | +}); |
| 129 | +
|
| 130 | +function deleteAuthor(authorIndex) { |
| 131 | + currentValue.value.splice(authorIndex, 1); |
| 132 | +} |
| 133 | +
|
| 134 | +function addAuthor() { |
| 135 | + currentValue.value.push(authorDataModel()); |
| 136 | +} |
| 137 | +</script> |
0 commit comments