@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
1 lines • 9.33 kB
Source Map (JSON)
{"version":3,"file":"dialog.mjs","sources":["../../../src/frame/dialog.ts"],"sourcesContent":["import type { MessageManager } from './message'\nimport { MessageCommands } from './message'\nimport type { NumberString } from '../types/common'\n\nexport type SelectedUser = {\n /**\n * user identifier\n */\n id: NumberString\n\n /**\n * formatted username\n */\n name: string\n\n photo: string\n\n position: string\n\n url: string\n\n /**\n * The flag indicates that the selected user is a subordinate of the current user\n */\n sub: boolean\n\n /**\n * The flag indicates that the selected user is the manager of the current user\n */\n sup: boolean\n}\n\nexport type SelectedAccess = {\n /**\n * access permission identifier. Examples of identifiers:\n * - U1 — user with identifier 1\n * - IU1 — employees with identifier 1\n * - DR2 — all department and subdepartment employees with identifier 2\n * - D6 — all department employees with identifier 6\n * - G2 — group with identifier 2 (all visitors)\n * - SG4 — social network group with identifier 4\n * - AU — all authorized users\n * - CR — current user\n */\n id:\n | `AU`\n | `CR`\n | `U${number}`\n | `IU${number}`\n | `DR${number}`\n | `D${number}`\n | `G${number}`\n | `SG${number}`\n\n /**\n * name of the access permission\n */\n name: string\n}\n\nexport type SelectCRMParamsEntityType\n = | 'lead'\n | 'contact'\n | 'company'\n | 'deal'\n | 'quote'\n\nexport type SelectCRMParamsValue = {\n lead?: number[]\n contact?: number[]\n company?: number[]\n deal?: number[]\n quote?: number[]\n}\n\nexport type SelectCRMParams = {\n /**\n * Which types of objects to display in the dialog. Possible values:\n * - lead — Leads\n * - contact — Contacts\n * - company — Companies\n * - deal — Deals\n * - quote — Estimates\n */\n entityType: SelectCRMParamsEntityType[]\n\n /**\n * Whether multiple objects can be selected. Default is `false`\n */\n multiple: boolean\n\n /**\n * Which objects to initially add to the selected in the dialog. Works only if `multiple = true`\n */\n value?: SelectCRMParamsValue\n}\n\nexport type SelectedCRMEntity = {\n id: string\n type: SelectCRMParamsEntityType\n place: string\n title: string\n desc: string\n url: string\n}\n\nexport type SelectedCRM = {\n lead?: (SelectedCRMEntity & { id: `L_${number}` })[]\n contact?: (SelectedCRMEntity & { id: `C_${number}`, image: string })[]\n company?: (SelectedCRMEntity & { id: `CO_${number}`, image: string })[]\n deal?: (SelectedCRMEntity & { id: `D_${number}` })[]\n quote?: (SelectedCRMEntity & { id: `Q_${number}` })[]\n}\n\n/**\n * Select dialog manager\n *\n * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-dialogues/index.html\n */\nexport class DialogManager {\n #messageManager: MessageManager\n\n constructor(messageManager: MessageManager) {\n this.#messageManager = messageManager\n }\n\n /**\n * Method displays the standard single user selection dialog\n * It only shows company employees\n *\n * @return {Promise<null|SelectedUser>}\n *\n * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-dialogues/bx24-select-user.html\n */\n async selectUser(): Promise<null | SelectedUser> {\n return this.#messageManager.send(MessageCommands.selectUser, {\n mult: false\n })\n }\n\n /**\n * Method displays the standard multiple user selection dialog\n * It only shows company employees\n *\n * @return {Promise<SelectedUser[]>}\n *\n * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-dialogues/bx24-select-users.html\n */\n async selectUsers(): Promise<SelectedUser[]> {\n return this.#messageManager.send(MessageCommands.selectUser, {\n mult: true\n })\n }\n\n /**\n * Method displays a standard access permission selection dialog\n *\n * @param {string[]} blockedAccessPermissions\n * @return {Promise<SelectedAccess[]>}\n *\n * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-dialogues/bx24-select-access.html\n */\n async selectAccess(\n blockedAccessPermissions: string[] = []\n ): Promise<SelectedAccess[]> {\n return this.#messageManager.send(MessageCommands.selectAccess, {\n value: blockedAccessPermissions\n })\n }\n\n /**\n * Invokes the system dialog for selecting CRM entities\n * (leads, contacts, companies, deals, quotes).\n *\n * The resolved `SelectedCRM` object contains a separate bucket per\n * entity type. Each present bucket is a real `Array`, so consumers can\n * use `.length`, `.map()`, `for..of`, etc. directly. Buckets for entity\n * types that were not selected (or not requested via `entityType`) are\n * left `undefined` rather than being set to an empty array.\n *\n * Note: the parent window historically returned each bucket as a\n * `Record<string, SelectedCRMEntity>` (e.g. `{ 0: {...}, 1: {...} }`).\n * The SDK normalizes that response to a real array before returning it.\n *\n * @param {SelectCRMParams} [params] - Filter and behavior options.\n * - `entityType`: which entity types are shown in the dialog.\n * - `multiple`: allow multiple selection (default `false`).\n * - `value`: pre-selected entities (only applied when `multiple` is `true`).\n * @return {Promise<SelectedCRM>} Resolves to an object whose properties\n * (`lead`, `contact`, `company`, `deal`, `quote`) are arrays of\n * {@link SelectedCRMEntity} objects.\n *\n * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-dialogues/bx24-select-crm.html\n */\n async selectCRM(params?: SelectCRMParams): Promise<SelectedCRM> {\n const response = await this.#messageManager.send(MessageCommands.selectCRM, {\n entityType: params?.entityType,\n multiple: params?.multiple,\n value: params?.value\n }) as Partial<Record<SelectCRMParamsEntityType, unknown>> | null | undefined\n\n // The parent window returns each entity bucket as a Record<string, SelectedCRMEntity>\n // (e.g. { 0: {...}, 1: {...} }) rather than a real array. Normalize to arrays so\n // the runtime shape matches the documented `SelectedCRM` types.\n const result: SelectedCRM = {}\n if (!response) {\n return result\n }\n\n const toArray = <T>(bucket: unknown): T[] | undefined => {\n if (bucket === undefined || bucket === null) {\n return undefined\n }\n if (Array.isArray(bucket)) {\n return bucket as T[]\n }\n return Object.values(bucket as Record<string, T>)\n }\n\n const lead = toArray<SelectedCRMEntity & { id: `L_${number}` }>(response.lead)\n if (lead) result.lead = lead\n\n const contact = toArray<SelectedCRMEntity & { id: `C_${number}`, image: string }>(response.contact)\n if (contact) result.contact = contact\n\n const company = toArray<SelectedCRMEntity & { id: `CO_${number}`, image: string }>(response.company)\n if (company) result.company = company\n\n const deal = toArray<SelectedCRMEntity & { id: `D_${number}` }>(response.deal)\n if (deal) result.deal = deal\n\n const quote = toArray<SelectedCRMEntity & { id: `Q_${number}` }>(response.quote)\n if (quote) result.quote = quote\n\n return result\n }\n}\n"],"names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