UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

119 lines (116 loc) 4.08 kB
/** * @package @bitrix24/b24jssdk * @version 1.1.0 * @copyright (c) 2026 Bitrix24 * @license MIT * @see https://github.com/bitrix24/b24jssdk * @see https://bitrix24.github.io/b24jssdk/ */ import { MessageCommands } from './message/commands.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class DialogManager { static { __name(this, "DialogManager"); } #messageManager; constructor(messageManager) { this.#messageManager = messageManager; } /** * Method displays the standard single user selection dialog * It only shows company employees * * @return {Promise<null|SelectedUser>} * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-dialogues/bx24-select-user.html */ async selectUser() { return this.#messageManager.send(MessageCommands.selectUser, { mult: false }); } /** * Method displays the standard multiple user selection dialog * It only shows company employees * * @return {Promise<SelectedUser[]>} * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-dialogues/bx24-select-users.html */ async selectUsers() { return this.#messageManager.send(MessageCommands.selectUser, { mult: true }); } /** * Method displays a standard access permission selection dialog * * @param {string[]} blockedAccessPermissions * @return {Promise<SelectedAccess[]>} * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-dialogues/bx24-select-access.html */ async selectAccess(blockedAccessPermissions = []) { return this.#messageManager.send(MessageCommands.selectAccess, { value: blockedAccessPermissions }); } /** * Invokes the system dialog for selecting CRM entities * (leads, contacts, companies, deals, quotes). * * The resolved `SelectedCRM` object contains a separate bucket per * entity type. Each present bucket is a real `Array`, so consumers can * use `.length`, `.map()`, `for..of`, etc. directly. Buckets for entity * types that were not selected (or not requested via `entityType`) are * left `undefined` rather than being set to an empty array. * * Note: the parent window historically returned each bucket as a * `Record<string, SelectedCRMEntity>` (e.g. `{ 0: {...}, 1: {...} }`). * The SDK normalizes that response to a real array before returning it. * * @param {SelectCRMParams} [params] - Filter and behavior options. * - `entityType`: which entity types are shown in the dialog. * - `multiple`: allow multiple selection (default `false`). * - `value`: pre-selected entities (only applied when `multiple` is `true`). * @return {Promise<SelectedCRM>} Resolves to an object whose properties * (`lead`, `contact`, `company`, `deal`, `quote`) are arrays of * {@link SelectedCRMEntity} objects. * * @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/system-dialogues/bx24-select-crm.html */ async selectCRM(params) { const response = await this.#messageManager.send(MessageCommands.selectCRM, { entityType: params?.entityType, multiple: params?.multiple, value: params?.value }); const result = {}; if (!response) { return result; } const toArray = /* @__PURE__ */ __name((bucket) => { if (bucket === void 0 || bucket === null) { return void 0; } if (Array.isArray(bucket)) { return bucket; } return Object.values(bucket); }, "toArray"); const lead = toArray(response.lead); if (lead) result.lead = lead; const contact = toArray(response.contact); if (contact) result.contact = contact; const company = toArray(response.company); if (company) result.company = company; const deal = toArray(response.deal); if (deal) result.deal = deal; const quote = toArray(response.quote); if (quote) result.quote = quote; return result; } } export { DialogManager }; //# sourceMappingURL=dialog.mjs.map