autocompletion.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { FieldResolverModule } from '#shared/entities/object-attributes/types/resolver.ts'
  3. import { camelize } from '#shared/utils/formatter.ts'
  4. import FieldResolver from '../FieldResolver.ts'
  5. export class FieldResolverAutocompletion extends FieldResolver {
  6. fieldType = () => {
  7. switch (this.attributeConfig.relation) {
  8. case 'Organization':
  9. return 'organization'
  10. case 'User':
  11. return 'customer'
  12. case 'Group':
  13. case 'TicketState':
  14. case 'TicketPriority':
  15. throw new Error(
  16. `Relation ${this.attributeConfig.relation} is not implemented yet`,
  17. )
  18. // TODO which relation is recipient?
  19. default:
  20. throw new Error(`Unknown relation ${this.attributeConfig.relation}`)
  21. }
  22. }
  23. public fieldTypeAttributes() {
  24. return {
  25. props: {
  26. clearable: !!this.attributeConfig.nulloption,
  27. noOptionsLabelTranslation: !this.attributeConfig.translate,
  28. belongsToObjectField: camelize(
  29. (this.attributeConfig.belongs_to as string) || '',
  30. ),
  31. multiple: this.attributeConfig.multiple,
  32. },
  33. }
  34. }
  35. }
  36. export default <FieldResolverModule>{
  37. type: 'autocompletion_ajax',
  38. resolver: FieldResolverAutocompletion,
  39. }