UNPKG

devexpress-reporting

Version:

DevExpress Reporting provides the capability to develop a reporting application to create and customize reports.

80 lines (79 loc) 3.19 kB
/** * DevExpress HTML/JS Reporting (designer\widgets\canPublishEditor.js) * Version: 25.1.3 * Build date: Jun 26, 2025 * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * License: https://www.devexpress.com/Support/EULAs/universal.xml */ import * as ko from 'knockout'; import { Editor } from '@devexpress/analytics-core/analytics-widgets'; import { formatUnicorn, getLocalization } from '@devexpress/analytics-core/analytics-internal'; const CanPublishToFormatSpecifics = { Csv: 1 << 0, Docx: 1 << 1, Htm: 1 << 2, Image: 1 << 3, Mht: 1 << 4, Pdf: 1 << 5, Printing: 1 << 6, Rtf: 1 << 7, Txt: 1 << 8, Xls: 1 << 9, Xlsx: 1 << 10, }; const CanPublishToFormats = { None: 0, ...CanPublishToFormatSpecifics, All: 0x7FF, }; export class CanPublishEditor extends Editor { constructor(info, level, parentDisabled, textToSearch, popupService, popover, engineType) { super(info, level, parentDisabled, textToSearch, popupService, popover, engineType); this.maxDisplayedTags = 3; this.selectAllText = getLocalization('Select All', 'AnalyticsCoreStringId.SelectAll'); this._disposables.push(this.editorValue = ko.computed({ read: () => this.parseEnum(this._get('value')), write: (newValue) => this._set('value', this.serializeEnum(newValue)), owner: this })); } parseEnum(str) { const allowedKeys = Object.keys(CanPublishToFormatSpecifics); const items = str.split(',').map(item => item.trim()); if (items.length === 1 && CanPublishToFormats[items[0]] === CanPublishToFormats.None) { return []; } if (items.length === 1 && CanPublishToFormats[items[0]] === CanPublishToFormats.All) { return allowedKeys; } const result = items.filter((item) => allowedKeys.includes(item)); if (result.length !== items.length) { throw new Error('CanPublishOption has incorrect value: ' + str); } return result; } serializeEnum(values) { const separator = ', '; const processedValues = this.serializeEnumCore(values); return processedValues.length > 1 ? processedValues.join(separator) : processedValues[0]; } serializeEnumCore(values) { if (values.length === 0) { return ['None']; } const isAllFormats = values .map(item => CanPublishToFormats[item]) .reduce((acc, item) => acc | item, 0) === CanPublishToFormats.All; return isAllFormats ? ['All'] : values.sort((a, b) => CanPublishToFormats[a] - CanPublishToFormats[b]); } getValues() { return this._get('values'); } onMultiTagPreparing(args) { const selectedItemsLength = args.selectedItems.length, totalCount = Object.keys(CanPublishToFormatSpecifics).length; if (selectedItemsLength === totalCount) { const stringFormat = getLocalization('All selected ({0})', 'ASPxReportsStringId.WebDocumentViewer_MultiValueEditor_AllSelected'); args.text = formatUnicorn(stringFormat, selectedItemsLength); } } }