Documentation

Entity class

Class represents entity for items of dialog and widget TagSelector.

Constructor

constructor(entityOptions: EntityOptions): Entity

Creates a class object Entity.

For adding an entity to dialog, use the option entities in the class constructor Dialog.

entityOptions — dialog options, defined by the structure EntityOptions.

export type EntityOptions = {
  id: string,
  options?: { [key: string]: any },
  itemOptions?: { [key: string]: any },
  tagOptions?: { [key: string]: any },
  badgeOptions?: ItemBadgeOptions[],
  searchable?: boolean,
  searchFields?: SearchField[],
  searchCacheLimits?: [],
  dynamicLoad?: boolean,
  dynamicSearch?: boolean
};

  • id: string

    Entity ID.


  • options?: { [key: string]: any }

    Entity options. Random set of parameters, passed to data provider when dynamically loading the items.


  • itemOptions?: EntityItemOptions

    Defines item external appearance settings in the dialog by default. Specified by the structure EntityItemOptions:

    export type EntityItemOptions = { [entityType: string]: { [option: string]: any } };
    

    Item settings are grouped by entity type (entityType) in itemOptions:

    const itemOptions = {
      default: {
         textColor: 'black',
         avatar: '/path/to/avatar.svg'
      },
      inactive: {
         textColor: 'grey'
      }
    };
    

    The title color will be set as gray within he example above for items with entityType set as inactive. For all the rest of entity types color will be black. When option is not found in the setting group of specific type, it will be searched in the default type.

    Item can have the following options defined:


  • tagOptions?: EntityTagOptions

    Item external appearance settings in widget TagSelector.
    Defined by structure EntityTagOptions:

    export type EntityTagOptions = { [entityType: string]: { [option: string]: any } };
    

    TagSelector widget item settings are grouped by entity type (entityType) в tagOptions:

    const tagOptions = {
      default: {
         textColor: 'black',
         bgColor: 'red',
         maxWidth: 150
      },
      inactive: {
         textColor: 'grey'
      }
    };
    

    Title color is set as grey in the example above for items in widget TagSelector, having entityType set as inactive. Color is black for all the rest of entity types. When option is not found in settings group for specific type, searches for it in the type default.

    The following options can be defined for the item:


  • badgeOptions?: EntityBadgeOptions[]

    Settings and external appearance for additional item badges. Usually, badges are set in settings itemOptions for various entity types. Situations occur when badges must be displayed according to random conditions without entity type context.

    Each badge in badgeOptions is defined by structure EntityBadgeOptions:

    export type EntityBadgeOptions = {
      title: string | TextNodeOptions,
      textColor?: string,
      bgColor?: string,
      conditions?: { [customOption: string]: any }
    };
    

    Structure EntityBadgeOptions inherits parameters ItemBadgeOptions, adding the conditions option. This parameter specifies conditions for badge display. The key indicates the field name from collection of additional item data (customData). Badge will be displayed, if the value of indicated field matches with item data.

    const badgeOptions = {
      title: 'My badge',
      conditions: { 
        isOnVacation: true
      }
    };
    


  • searchable?: boolean

    When set as false item search for this entity is not performed. Default value: true.


  • searchFields?: SearchField[]

    Defines list of fields for dialog item to be searched. Each field is defined by structure SearchFieldOptions:

    export type SearchFieldOptions = {
      name: string,
      type?: 'string' | 'email',
      searchable?: boolean,
      system?: boolean,
      sort?: number
    }
    

    • name: string

      Field name.


    • type?: 'string' | 'email'

      Field type. Default value: string.


    • searchable?: boolean

      When set as false, no search is performed for a field. Default value: true. Option can used for cancelling default behaviour (see. below).


    • system?: boolean

      By default, the name field, specified in the option is searched in additional item data (customData). When set as system: true, field is deemed a system field. The following system fields are supported:

      • title.
      • subtitle.
      • supertitle.

    • sort?: number

      Defines search sorting. When not specified, sorting is defined by item sorting in array searchFields.

    By default, searches by item title (title field) and subtitle (subtitle field). searchFields settings add fields for indexing; they do not re-define default behavor.

    The next example show search will be performed by item title, subtitle as well as by additional data from customData: position and email.

    searchFields: [
      { name: 'position' },
      { name: 'email', type: 'email' }
    ]
    

    This example below cancels search by item title.

    searchFields: [
      { name: 'title', searchable: false, system: true }
    ]
    


  • searchCacheLimits?: string[]

    Array with regular expression templates, excluded from search query caching.


  • dynamicLoad?: boolean

    Defines dynamic load for backend items. Default value: false.


  • dynamicSearch?: boolean

    Defines dynamic search of backend items. Default value: false.

Methods

Method Description Available from version
getId(): string Returns entity ID.
getItemOption(option: string, entityType?: string): any Returns settings value (option) for item external appearance with account of entity type (entityType).
getTagOption(option: string, entityType?: string): any Returns settings value (option) for item external appearance in the TagSelelctor widget with account of entity type (entityType).
getBadges(item: Item): ItemBadgeOptions[] Returns merged collection of entity badges.
isSearchable(): boolean Returns true when entity items participate in search.
setSearchable(flag: boolean): void Sets or cancels entity item participation in search.
setSearchCacheLimits(limits: string[]): void Sets array with patterns, excluded from search query caching.
getSearchCacheLimits(): RegExp[] Returns array with patterns, excluded from search query caching.
hasDynamicLoad(): boolean Returns true if entity has dynamic load of backend items.
setDynamicLoad(flag: boolean): void Sets or cancels dynamic load of items.
hasDynamicSearch(): boolean Returns true when entity has dynamic search of items from backend.
setDynamicSearch(flag: boolean): void Sets or cancels item dynamic search.

© «Bitrix24», 2001-2024