AttributeInput.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. // TODO: check external data input output
  4. import { computed } from 'vue'
  5. import { phoneify } from '#shared/utils/formatter.ts'
  6. import type { ObjectAttributeInput } from './attributeInputTypes.ts'
  7. import type { ObjectAttributeProps } from '../../types.ts'
  8. const props =
  9. defineProps<
  10. ObjectAttributeProps<
  11. ObjectAttributeInput,
  12. string | number | { value: string | number; label: string }
  13. >
  14. >()
  15. const primitiveValue = computed(() => {
  16. if (typeof props.value === 'object' && props.value) return props.value.value
  17. return props.value
  18. })
  19. const title = computed(() => {
  20. if (typeof props.value === 'object' && props.value) return props.value.label
  21. return props.value
  22. })
  23. const link = computed(() => {
  24. const { linktemplate, type } = props.attribute.dataOption || {}
  25. // link is processed in common component
  26. if (linktemplate) return null
  27. const value = String(primitiveValue.value)
  28. // app/assets/javascripts/app/index.coffee:135
  29. if (type === 'tel') return `tel:${phoneify(value)}`
  30. if (type === 'url') return value
  31. if (type === 'email') return `mailto:${value}`
  32. return ''
  33. })
  34. </script>
  35. <template>
  36. <span v-if="!link">{{ title }}</span>
  37. <CommonLink
  38. v-else
  39. :class="config?.classes?.link"
  40. :external="attribute.dataOption.type !== 'url'"
  41. open-in-new-tab
  42. :link="link"
  43. >
  44. {{ title }}
  45. </CommonLink>
  46. </template>