Documentation

Dialog class

Description

Main class for handling entity selector dialog and its items.

Import to ES6

import { Dialog } from 'ui.entity-selector';

Use in ES5

var dialog = new BX.UI.EntitySelector.Dialog(options);

Events

Dialog class is descendant for class EventEmitter. Event handers can be set using either the events option, or using the standard method EventEmitter.subscribe.

Event Description Available from version
onShow Called on each dialog display.

Example

onFirstShow Called once upon the first dialog display.

Example

onHide Called on closed dialog.

Example

onDestroy Called before destroying a dialog.

Example

onSearch Called when searching items.

Example

onLoad Called when loading data from backend.

Example

onLoadError Called on error when loading data from backend. Event data contains error in the property error.

Example

Item:onSelect Called after selecting an item. Event data contains selected item in the event's item property.
You can get full the list of all selected items using the method dialog.getSelectedItems().

Example

Item:onBeforeSelect Called before selecting an item. You can restrict item selecting in this event.

Example

Item:onDeselect Called after deselecting item.
Event data in the property item contain the item with removed selection. You can get list of all selected items using the method dialog.getSelectedItems().

Example

Item:onBeforeDeselect Called before deselecting an item. This event can restrict item deselection.

Example

Tab:onSelect Called when switching to a new tab (tab becomes active).
Event data tab property contains a target tab object.

Example

Tab:onDeselect Called when tab becomes inactive.
Event data tab property contains a source tab object.

Example

Search:onItemCreateAsync Asynchronous event, triggered at the moment of creating item via search.

Example

ItemNode:onFocus Called when focus is set to item.
Event data node property contains the item node (class object ItemNode).
ItemNode:onUnfocus Called when focus is removed from item.
Event data node property contains item node (class object ItemNode).
ItemNode:onLinkClick Called when clicking at "details" link.
Event data node property property contains item node (class object ItemNode), and event — event object MouseEvent.

Constructor

constructor(dialogOptions: DialogOptions): Dialog

Creates Dialog class object.

dialogOptions — dialog options, refined by the structure DialogOptions.

export type DialogOptions = {
	targetNode?: HTMLElement,
	id?: string,
	context?: string,
	items?: ItemOptions[],
	selectedItems?: ItemOptions[],
	preselectedItems?: ItemId[],
	undeselectedItems?: ItemId[],
	tabs?: TabOptions[],
	entities?: EntityOptions[],
	popupOptions?: PopupOptions,
	multiple?: boolean,
	preload?: boolean,
	dropdownMode?: boolean,
	enableSearch?: boolean,
	searchOptions?: SearchOptions,
	searchTabOptions?: TabOptions,
	recentTabOptions?: TabOptions,
	tagSelectorOptions?: TagSelectorOptions,
	events?: { [eventName: string]: (event: BaseEvent) => void },
	hideOnSelect?: boolean,
	hideOnDeselect?: boolean,
	clearSearchOnSelect?: boolean,
	width?: number,
	height?: number,
	autoHide?: boolean,
	hideByEsc?: boolean,
	offsetTop?: number,
	offsetLeft?: number,
	cacheable?: boolean,
	focusOnFirst?: boolean,
	footer?: FooterContent,
	footerOptions?: { [option: string]: any },
	showAvatars?: boolean,
	compactView?: boolean,
	clearUnavailableItems?: boolean,
}

  • targetNode?: HTMLElement

    HTML item, with popup dialog near it.


  • id?: string

    Dialog ID.
    Can be used for getting dialog object in the method Dialog.getById(id).


  • context?: string

    Context ID.
    Can be used for saving selected items in the "Recent" tab. When context is not set, user selection is not saved, the "Recent" tab items are sorted based on their selection in other contexts.


  • items?: ItemOptions[]

    Array with dialog items. Each item is defined by the structure ItemOptions.


  • selectedItems?: ItemOptions[]

    Array with dialog items (similar to option items). All items are automatically defined as "selected".


  • preselectedItems?: ItemId[]

    Array with selected item IDs, with data to be retrieved by dialog from entity providers. Each item is defined by the structure ItemId.

    type ItemId = [
      string,
      string | number
    ];
    

    ItemId — is an array with two items. First item provides item entity ID (entityId) and the second - the item ID itself (id).

    const options = {
      preselectedItems: [
          ['user', 1],
          ['department', 1],
          ['meta-user', 'all-users'],
          ['project', 2],
          ['department', '2:F'],
      ]
    }
    

    This option is usually used for completing the TagSelector widget with items, known to be selected beforehand. Dialog automatically completes dynamic loading of items (when creating the object new Dialog) with the set option preselectedItems.


  • undeselectedItems?: ItemId[]

    Array with item IDs that cannot have the removed selection. Each item is defined by the structure ItemId.


  • tabs?: TabOptions[]

    Array with dialog tabs. Each tab is defined by structure TabOptions.

    const options = {
      tabs: [
          { id: 'cities', title: 'Города', itemOrder: { title: 'asc' } },
          { id: 'countries', title: 'Страны', itemOrder: { id: 'desc' } },
      ],
    }
    


  • entities?: EntityOptions[]

    Array with dialog entity settings. Each entity is defined by the structure EntityOptions.

    const options = {
      entities: [
          {
              id: 'meta-user',
              options: {
                  'all-users': true
              }
          },
          {
              id: 'user',
              options: { emailUsers: true },
          },
          { id: 'project' },
          {
              id: 'department',
              options: {
                  selectMode: 'usersAndDepartments'
              }
          },
      ],
    }
    

    Usually, you indicate only entity IDs in the entities option, with entity items to be dynamically loaded, as well as settings for data providers. Settings for the entities themselves (options for the structure EntityOptions) are usually defined globally. However, these global settings can be always re-defined:

    const options = {
      entities: [
          {
              id: 'user',
              dynamicLoad: false, // restrict dynamic loading
              dynamicSearch: false, // restrict dynamic search
              searchFields: [ // define other search fields
                  { name: 'title', type: 'email', system: true, searchable: true },
                  { name: 'subtitle', type: 'email', system: true, searchable: false },
                  { name: 'position', type: 'string' },
                  { name: 'email', type: 'email' }
              ],
          }
      ],
    }
    


  • popupOptions?: PopupOptions

    Additional settings for popup-dialog. Entity selector dialog based in this dialog. Defined by structure PopupOptions. However, only the following values are permitted: overlay, bindOptions, targetContainer, zIndexOptions.


  • multiple?: boolean

    By default, dialog operates in the multiple selection mode (true). False limits selection to a single item.


  • preload?: boolean

    By default, item loading from the backend (if required) occurs at the moment of dialog opening. When set as true data loading occurs automatically when creating a dialog object.


  • dropdownMode?: boolean

    True value enables the mode of a standard list. This mode hides "Recents" tab.


  • enableSearch?: boolean

    Enables search form inside the dialog.


  • searchOptions?: SearchOptions

    Sets search form settings. Defined by the structure SearchOptions.

    export type SearchOptions = {
      allowCreateItem?: boolean,
      footerOptions?: { [option: string]: any }
    } 
    

    • allowCreateItem?: boolean

      Enables the option to create new items using the search.


    • footerOptions?: { [option: string]: any }

      Additional settings for the footer at the "Search" tab. Option label defines the footer base title.

    const options = {
      searchOptions: {
          allowCreateItem: true,
          footerOptions: {
              label: 'Create city:'
          }
      },
    }
    


  • searchTabOptions?: TabOptions

    Allows re-defining the configuration for the "Search" system tab. Settings are defined by the structure TabOptions.


  • recentTabOptions?: TabOptions

    Allows re-defining настройки системной вкладки "Последние". Настройки определяются структурой TabOptions.


  • tagSelectorOptions?: TagSelectorOptions

    Sets additional settings for inbuilt search form (TagSelector) with enabled setting enableSearch=true. Settings are defined by the structure TagSelectorOptions.


  • events?: { [eventName: string]: (event: BaseEvent) => void }

    Sets dialog event handlers.


  • hideOnSelect?: boolean

    Hides dialog after item selection. By default, dialog opens for single item selection (multiple=false), for multiple selection — not hidden.


  • hideOnDeselect?: boolean

    Hide dialog after deselecting the item. Dialog doesn't hide by default.


  • clearSearchOnSelect?: boolean

    Clear search form after selecting an item. Default value: true.


  • width?: number

    Dialog width in pixels. Default value: 565.


  • height?: number

    Dialog height in pixels. Default value: 420.


  • autoHide?: boolean

    Automatically hide dialog by click at any page area. Default value: true.


  • hideByEsc?: boolean

    Automatically hides dialog by clicking at Escape. Default value: true.


  • offsetTop?: number

    Dialog offset relative to targetNode by X-axis. Default value: 5.


  • offsetLeft?: number

    Dialog offset relative to targetNode by X-axis. Default value: 0.


  • cacheable?: boolean

    When set as false, dialog will be automatically destroyed after being hidden. Default value: true (do not destroy).


  • focusOnFirst?: boolean

    Set focus to the first list item. Default value: true.


  • footer?: FooterContent

    Sets global (for all tabs) dialog footer. Defined by the structure FooterContent.

    export type FooterContent = string | HTMLElement | HTMLElement[] | Function;
    

    Footer can be set by several methods:

    • When passing the layout as a DOM-node, array with DOM-nodes or text string, creates the default footer (object of class DefaultFooter) with specified text content.

    • Creating an arbitrary footer requires passing either a link to class constructor (descendant for BaseFooter or DefaultFooter), or specify the full class name as a string.

    Link layout as a footer has the following available CSS-classes:

    • .ui-selector-footer-link — standard link.
    • .ui-selector-footer-link ui-selector-footer-link-add — link with "plus" icon.
    • .ui-selector-footer-conjunction — for defining linking words.

  • footerOptions?: { [option: string]: any }

    Arbitrary footer options. Passed to footer class constructor.


  • showAvatars?: boolean

    Show item avatars. True by default. This option defines behaviour for all default tabs, however, this option can be redefined for specific tab (similar option to showAvatars).


  • compactView?: boolean

    Defines compact view for item display. False by default. Recommended for items without avatars (showAvatars=false).


  • clearUnavailableItems?: boolean

    Delete item from "Recent" list when entity providers do not returns data from them. False by default.

Methods

Method Description Available from version
Dialog.getById(id: string): ?Dialog Static method, returns dialog object by ID.
Dialog.getInstances(): Dialog[] Static method, returns array with all dialog objects.
show(): void Shows dialog at the page.
hide(): void Hides dialog at the page.
destroy(): void Deletes dialog from page, as well as all its internal entities. Further use of dialog object after calling destroy() is impossible. You can use the option cacheable=true or method setCacheable(true) to automatically destroy the dialog.
isOpen(): boolean Returns true when is displayed at the page, otherwise returns false.
adjustPosition(): void Re-adjusts dialog position relative to targetNode.
search(queryString: string): void Executes item search bystring specified in queryString.
addItem(options: ItemOptions): Item Adds and returns new dialog item.
  • options — item options to be defined by the structure ItemOptions.
removeItem(item: Item | ItemOptions): ?Item Deletes item from dialog.
  • item — objects for class Item or object of type { id: string | number, entityId: string }.
removeItems(): void Deletes all dialog items.
getItem(item: ItemId | ItemOptions): ?Item Returns dialog item by its IDs.
  • itemItemId or object of type { id: string | number, entityId: string }.
getSelectedItems(): Item[] Returns array with selected items.
getItems(): Item[] Returns all dialog items.
getEntityItems(entityId: string): Item[] Returns all items for specified entity.
addTab(tab: Tab | TabOptions): Tab Adds new tab into dialog.
  • tab — object for class Tab or TabOptions.
getTabs(): Tab[] Returns array with all dialog tabs.
getTab(id: string): ?Tab Returns tab object by ID.
getRecentTab(): RecentTab Returns "Recent" tab object.
getSearchTab(): SearchTab Returns "Search"tab object.
selectTab(id: string): ?Tab Activates (selects) tab with specified ID.
selectFirstTab(onlyVisible = true): ?Tab Returns first dialog tab.
  • onlyVisible — consider only visible tabs.
selectLastTab(onlyVisible = true): ?Tab Returns the last dialog tab.
  • onlyVisible — consider only visible tabs.
getActiveTab(): ?Tab Returns active tab.
  • onlyVisible — consider only visible tabs.
getNextTab(onlyVisible = true): ?Tab Returns tab, next to the active tab.
  • onlyVisible — consider only the visible tabs.
getPreviousTab(onlyVisible = true): ?Tab Returns tab, previous to the active tab.
  • onlyVisible — consider only visible tabs.
removeTab(id: string): void Deletes tab by ID.
addEntity(entity: Entity | EntityOptions): Entity Adds entity to dialog.
getEntity(id: string): ?Entity Returns entity by ID.
hasEntity(id: string): boolean Returns true if entity with ID exists.
getEntities(): Entity[] Returns array with all dialog entities.
removeEntity(id: string): void Deletes an entity (including all its items) from dialog.
removeEntityItems(id: string): void Deletes all items for specified entity.
getFooter(): ?BaseFooter Returns dialog footer.
getActiveFooter(): ?BaseFooter Returns active footer. Depending on the current tab, method returns either tab footer or dialog footer.
setFooter(footerContent: ?FooterContent, footerOptions?: { [option: string]: any }): ?BaseFooter Sets or deletes footer from dialog.
  • footerContent — footer content. When set as null, footer is deleted.
  • footerOptions — additional footer options.
getId(): string Returns dialog ID.
getContext(): ?string Returns dialog context.
deselectAll(): void Removes selection from all dialog items.
isMultiple(): boolean Returns true when dialog has multiple item selection.
setTargetNode(node: HTMLElement | { left: number, top: number } | null | MouseEvent): void Set HTML item, with popup dialog near it. When node is set as null, dialog is displayed at the center of page.
getTargetNode(): ?HTMLElement Returns HTML item with display dialog.
setHideOnSelect(flag: boolean): void Enables or disables option to hide dialog after selecting the item.
shouldHideOnSelect(): boolean Returns true if dialog hides after selecting an item.
setHideOnDeselect(flag: boolean): void Enables or disables option to hide dialog after item deselecting.
shouldHideOnDeselect(): boolean Returns true if dialog is hidden after deselecting an item.
setClearSearchOnSelect(flag: boolean): void Enables or disables clearing of search form after selecting an item.
shouldClearSearchOnSelect(): boolean Returns true when search form is cleared after selecting an item.
setShowAvatars(flag: boolean): void Enables or disables avatar display for dialog items.
shouldShowAvatars(): boolean Returns true when dialog item avatar display is enabled.
isCompactView(): boolean Returns true when compact item view is enabled.
setAutoHide(enable: boolean): void Enables or disables automatic closing of dialog by clicking on any page area.
isAutoHide(): boolean Returns true when dialog is automatically closes by clicking at any page area.
setHideByEsc(enable: boolean): void Enables or disables automatic closure of dialog by clicking at Escape.
shouldHideByEsc(): boolean Returns true if dialog is automatically closes when clicking at Escape.
getWidth(): number Returns dialog width in pixels.
setWidth(width: number): void Sets dialog width in pixels.
getHeight(): number Returns dialog height in pixels.
setHeight(height: number): Promise Sets dialog height in pixels.
getOffsetLeft(): number Returns dialog offset relative to targetNode in X-direction in pixels.
setOffsetLeft(offset: number): void Sets dialog offset relative to targetNode in X-direction.
getOffsetTop(): number Returns dialog offset relative to targetNode in Y-direction in pixels.
setOffsetTop(offset: number): void Sets dialog offset relative to targetNode in Y-direction.
isCacheable(): boolean Returns false if dialog is automatically destroyed after closing.
setCacheable(cacheable: boolean): void Enables or disables automatic destruction of dialog after closing.
shouldFocusOnFirst(): boolean Returns true when automatic focusing is enabled at the first tab item.
setFocusOnFirst(flag: boolean): void Enables or disables automatic focusing at the first tab item.
focusOnFirstNode(): ?ItemNode Sets focus at the first item of active tab.
clearNodeFocus(): void Resets focus from current focused item.
getTagSelector(): ?TagSelector Returns object for widget TagSelector.
isTagSelectorInside(): boolean Returns true when widget TagSelector is located inside the dialog.
isTagSelectorOutside(): boolean Returns true when widget TagSelector is located outside the dialog.
getTagSelectorQuery(): string Returns search phrase from widget TagSelector.
focusSearch(): void Sets search focus to search form in widget TagSelector.
clearSearch(): void Clears the search form in widget TagSelector.
isRendered(): boolean Returns true when dialog layout was generated and inserted into the page.
freeze(): void Moves dialog to "frozen" mode. This mode disables the following:
  • Navigation by items using keyboard keys.
  • Dialog auto-closing by click at any page area.
  • Dialog auto-closing by click at Escape.
  • Any browser events inside the dialog.
unfreeze(): void Returns dialog from the "Frozen" mode to the standard.
isFrozen(): boolean Returns true when dialog is in the "frozen" mode.
load(): void Executes data loading from backend. Usually, called automatically when opening the dialog.
isLoaded(): boolean Returns true when dialog executed query to backend but have not yet loaded the data.
isLoading(): boolean Returns true when dialog executed query to backend, but have not yet loaded the data.
saveRecentItem(item: Item): void Saves item for "Recent" tab.

© «Bitrix24», 2001-2024
Up