AttributeInput.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. const props = defineProps<{
  8. attribute: ObjectAttributeInput
  9. value: string | number | { value: string | number; label: string }
  10. }>()
  11. const primitiveValue = computed(() => {
  12. if (typeof props.value === 'object' && props.value) return props.value.value
  13. return props.value
  14. })
  15. const title = computed(() => {
  16. if (typeof props.value === 'object' && props.value) return props.value.label
  17. return props.value
  18. })
  19. const link = computed(() => {
  20. const { linktemplate, type } = props.attribute.dataOption || {}
  21. // link is processed in common component
  22. if (linktemplate) return null
  23. const value = String(primitiveValue.value)
  24. // app/assets/javascripts/app/index.coffee:135
  25. if (type === 'tel') return `tel:${phoneify(value)}`
  26. if (type === 'url') return value
  27. if (type === 'email') return `mailto:${value}`
  28. return ''
  29. })
  30. </script>
  31. <template>
  32. <span v-if="!link">{{ title }}</span>
  33. <CommonLink
  34. v-else
  35. class="text-blue cursor-pointer"
  36. :external="attribute.dataOption.type !== 'url'"
  37. open-in-new-tab
  38. :link="link"
  39. >
  40. {{ title }}
  41. </CommonLink>
  42. </template>