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 thedefault
type.Item can have the following options defined:
subtitle: sting | TextNodeOptions
— subtitle for item.supertitle: sting | TextNodeOptions
— supertitle for item.caption: sting | TextNodeOptions
— caption for item.textColor: string
— title text color for item.avatar: string
— avatar for item.avatarOptions: AvatarOptions
— avatar settings for item.badges: EntityBadgeOptions[]
— item badges. Defined by structure EntityBadgeOptions.link: string
— "more" link address. Link template must use macroses#id#
and#element_id#
.linkTitle: sting | TextNodeOptions
— "more" link title.captionOptions: CaptionOptions
— caption settings.badgesOptions: BadgesOptions
— settings for block with item badges.
tagOptions?: EntityTagOptions
Item external appearance settings in widget
TagSelector
.
Defined by structureEntityTagOptions
: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 asinactive
. 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 typedefault
.The following options can be defined for the item:
bgColor: string
— background color for item.textColor: string
— title color for item.maxWidth: number
— maximum width for item.fontWeight: string
— font style.avatar: string
— avatar элемента.avatarOptions: AvatarOptions
— avatar settings for item.link: string
— link at item. Link template can use the macroses#id#
и#element_id#
.
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 structureEntityBadgeOptions
:export type EntityBadgeOptions = { title: string | TextNodeOptions, textColor?: string, bgColor?: string, conditions?: { [customOption: string]: any } };
Structure
EntityBadgeOptions
inherits parameters ItemBadgeOptions, adding theconditions
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 assystem: 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
andemail
.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. |